Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 98ca5ed

Browse files
author
Emmanuel Garcia
authored
Revert "Replace Flutter surface only after all platform views are destroyed (#24363)" (#24800)
This reverts commit 1dc8695.
1 parent f177211 commit 98ca5ed

File tree

3 files changed

+7
-75
lines changed

3 files changed

+7
-75
lines changed

shell/platform/android/io/flutter/embedding/android/FlutterView.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -999,12 +999,6 @@ public void detachFromFlutterEngine() {
999999
flutterEngine = null;
10001000
}
10011001

1002-
@VisibleForTesting
1003-
@NonNull
1004-
public RenderSurface getRenderSurface() {
1005-
return renderSurface;
1006-
}
1007-
10081002
@VisibleForTesting
10091003
@NonNull
10101004
public FlutterImageView createImageView() {

shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -788,11 +788,11 @@ public void onBeginFrame() {
788788

789789
public void onEndFrame() {
790790
final FlutterView view = (FlutterView) flutterView;
791-
// If there are no platform views, then revert the image view surface,
792-
// and use the previous surface.
791+
// If there are no platform views in the current frame,
792+
// then revert the image view surface and use the previous surface.
793793
//
794794
// Otherwise, acquire the latest image.
795-
if (flutterViewConvertedToImageView && platformViews.size() == 0) {
795+
if (flutterViewConvertedToImageView && currentFrameUsedPlatformViewIds.isEmpty()) {
796796
flutterViewConvertedToImageView = false;
797797
view.revertImageView(
798798
() -> {

shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java

Lines changed: 4 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@ public void onEndFrame__destroysOverlaySurfaceAfterFrameOnFlutterSurfaceView() {
415415

416416
// Produce a frame that doesn't display platform views.
417417
platformViewsController.onBeginFrame();
418-
disposePlatformView(jni, platformViewsController, platformViewId);
419418
platformViewsController.onEndFrame();
420419

421420
verify(overlayImageView, never()).detachFromRenderer();
@@ -486,80 +485,17 @@ public void onEndFrame__removesPlatformViewParent() {
486485

487486
// Simulate create call from the framework.
488487
createPlatformView(jni, platformViewsController, platformViewId, "testType");
489-
assertEquals(flutterView.getChildCount(), 1);
490-
assertEquals(flutterView.getChildAt(0).getClass().getSimpleName(), "FlutterSurfaceView");
488+
platformViewsController.initializePlatformViewIfNeeded(platformViewId);
489+
assertEquals(flutterView.getChildCount(), 2);
491490

492491
// Simulate first frame from the framework.
493492
jni.onFirstFrame();
494493
platformViewsController.onBeginFrame();
495-
platformViewsController.onDisplayPlatformView(
496-
platformViewId, 0, 0, 100, 100, 200, 200, new FlutterMutatorsStack());
497-
assertEquals(flutterView.getChildCount(), 3);
498-
assertEquals(flutterView.getChildAt(0).getClass().getSimpleName(), "FlutterSurfaceView");
499-
assertTrue(flutterView.getChildAt(1).getClass().getSimpleName().startsWith("FlutterImageView"));
500-
501494
platformViewsController.onEndFrame();
502-
assertEquals(flutterView.getChildCount(), 3);
503-
assertEquals(flutterView.getChildAt(0).getClass().getSimpleName(), "FlutterSurfaceView");
504-
assertTrue(flutterView.getChildAt(1).getClass().getSimpleName().startsWith("FlutterImageView"));
505495

506496
// Simulate dispose call from the framework.
507497
disposePlatformView(jni, platformViewsController, platformViewId);
508-
assertEquals(flutterView.getChildCount(), 2);
509-
assertEquals(flutterView.getChildAt(0).getClass().getSimpleName(), "FlutterSurfaceView");
510-
assertTrue(flutterView.getChildAt(1).getClass().getSimpleName().startsWith("FlutterImageView"));
511-
}
512-
513-
@Test
514-
@Config(shadows = {ShadowFlutterSurfaceView.class, ShadowFlutterJNI.class})
515-
public void onEndFrame__revertsFlutterSurface() {
516-
final PlatformViewsController platformViewsController = new PlatformViewsController();
517-
518-
final int platformViewId = 0;
519-
assertNull(platformViewsController.getPlatformViewById(platformViewId));
520-
521-
final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
522-
final PlatformView platformView = mock(PlatformView.class);
523-
final View androidView = mock(View.class);
524-
when(platformView.getView()).thenReturn(androidView);
525-
when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
526-
527-
platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
528-
529-
final FlutterJNI jni = new FlutterJNI();
530-
jni.attachToNative(false);
531-
532-
final FlutterView flutterView = attach(jni, platformViewsController);
533-
534-
jni.onFirstFrame();
535-
536-
// Simulate create call from the framework.
537-
createPlatformView(jni, platformViewsController, platformViewId, "testType");
538498
assertEquals(flutterView.getChildCount(), 1);
539-
assertEquals(flutterView.getChildAt(0).getClass().getSimpleName(), "FlutterSurfaceView");
540-
541-
// Simulate first frame from the framework.
542-
jni.onFirstFrame();
543-
platformViewsController.onBeginFrame();
544-
platformViewsController.onDisplayPlatformView(
545-
platformViewId, 0, 0, 100, 100, 200, 200, new FlutterMutatorsStack());
546-
assertTrue(
547-
flutterView.getRenderSurface().getClass().getSimpleName().contains("FlutterImageView"));
548-
549-
platformViewsController.onEndFrame();
550-
assertTrue(
551-
flutterView.getRenderSurface().getClass().getSimpleName().contains("FlutterImageView"));
552-
553-
platformViewsController.onBeginFrame();
554-
platformViewsController.onEndFrame();
555-
assertTrue(
556-
flutterView.getRenderSurface().getClass().getSimpleName().contains("FlutterImageView"));
557-
558-
platformViewsController.onBeginFrame();
559-
// Dispose the platform view is sufficient to flip the Flutter surface.
560-
disposePlatformView(jni, platformViewsController, platformViewId);
561-
platformViewsController.onEndFrame();
562-
assertEquals(flutterView.getRenderSurface().getClass().getSimpleName(), "FlutterSurfaceView");
563499
}
564500

565501
@Test
@@ -675,6 +611,8 @@ private static FlutterView attach(
675611
new FlutterView(context, FlutterView.RenderMode.surface) {
676612
@Override
677613
public FlutterImageView createImageView() {
614+
final FlutterImageView view = mock(FlutterImageView.class);
615+
when(view.acquireLatestImage()).thenReturn(true);
678616
return mock(FlutterImageView.class);
679617
}
680618
};

0 commit comments

Comments
 (0)