Commit 506aa2c9 by andrewlewis Committed by christosts

Instantiate `SurfaceView` on main thread

On some devices/builds it seems that the `SurfaceView` constructor tries to create a handler. Move instantiation to the main thread when getting the debug surface view so that handler creation succeeds.

PiperOrigin-RevId: 505745387
parent d7cc12c0
...@@ -738,9 +738,9 @@ public final class TransformerActivity extends AppCompatActivity { ...@@ -738,9 +738,9 @@ public final class TransformerActivity extends AppCompatActivity {
// Update the UI on the main thread and wait for the output surface to be available. // Update the UI on the main thread and wait for the output surface to be available.
CountDownLatch surfaceCreatedCountDownLatch = new CountDownLatch(1); CountDownLatch surfaceCreatedCountDownLatch = new CountDownLatch(1);
SurfaceView surfaceView = new SurfaceView(/* context= */ TransformerActivity.this);
runOnUiThread( runOnUiThread(
() -> { () -> {
surfaceView = new SurfaceView(/* context= */ TransformerActivity.this);
AspectRatioFrameLayout debugFrame = checkNotNull(TransformerActivity.this.debugFrame); AspectRatioFrameLayout debugFrame = checkNotNull(TransformerActivity.this.debugFrame);
debugFrame.addView(surfaceView); debugFrame.addView(surfaceView);
debugFrame.setAspectRatio((float) width / height); debugFrame.setAspectRatio((float) width / height);
...@@ -772,7 +772,6 @@ public final class TransformerActivity extends AppCompatActivity { ...@@ -772,7 +772,6 @@ public final class TransformerActivity extends AppCompatActivity {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
return null; return null;
} }
this.surfaceView = surfaceView;
return surfaceView; return surfaceView;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment