Commit 4fb651b1 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 ff56b7d2
...@@ -737,9 +737,9 @@ public final class TransformerActivity extends AppCompatActivity { ...@@ -737,9 +737,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);
...@@ -771,7 +771,6 @@ public final class TransformerActivity extends AppCompatActivity { ...@@ -771,7 +771,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