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

Commit fd56bb4

Browse files
committed
Minor refactor to move flutterViewConvertedToImageView to FlutterView from PlatformViewsController.
1 parent 8c35499 commit fd56bb4

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ public class FlutterView extends FrameLayout implements MouseCursorPlugin.MouseC
135135
private final FlutterRenderer.ViewportMetrics viewportMetrics =
136136
new FlutterRenderer.ViewportMetrics();
137137

138+
// Tracks whether the flutterView has been converted to use a FlutterImageView.
139+
private boolean hasConvertedToImageView = false;
138140
private final AccessibilityBridge.OnAccessibilityChangeListener onAccessibilityChangeListener =
139141
new AccessibilityBridge.OnAccessibilityChangeListener() {
140142
@Override
@@ -406,6 +408,15 @@ public boolean hasRenderedFirstFrame() {
406408
return isFlutterUiDisplayed;
407409
}
408410

411+
/**
412+
* Whether this {@code FlutterView} has been converted to use a {@link FlutterImageView}.
413+
*
414+
* <p>Returns ture if the surface is rendered by a {@link FlutterImageView}.
415+
*/
416+
public boolean hasConvertedToImageView() {
417+
return hasConvertedToImageView;
418+
}
419+
409420
/**
410421
* Adds the given {@code listener} to this {@code FlutterView}, to be notified upon Flutter's
411422
* first rendered frame.
@@ -1264,6 +1275,7 @@ public void detachFromFlutterEngine() {
12641275
removeView(flutterImageView);
12651276
flutterImageView = null;
12661277
}
1278+
hasConvertedToImageView = false;
12671279
previousRenderSurface = null;
12681280
flutterEngine = null;
12691281
}
@@ -1294,6 +1306,8 @@ public void convertToImageView() {
12941306
if (flutterEngine != null) {
12951307
renderSurface.attachToRenderer(flutterEngine.getRenderer());
12961308
}
1309+
1310+
hasConvertedToImageView = true;
12971311
}
12981312

12991313
/**
@@ -1314,6 +1328,8 @@ public void revertImageView(@NonNull Runnable onDone) {
13141328
}
13151329
renderSurface = previousRenderSurface;
13161330
previousRenderSurface = null;
1331+
hasConvertedToImageView = false;
1332+
13171333
if (flutterEngine == null) {
13181334
flutterImageView.detachFromRenderer();
13191335
onDone.run();

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
102102
// Next available unique ID for use in overlayLayerViews.
103103
private int nextOverlayLayerId = 0;
104104

105-
// Tracks whether the flutterView has been converted to use a FlutterImageView.
106-
private boolean flutterViewConvertedToImageView = false;
107-
108105
// When adding platform views using Hybrid Composition, the engine converts the render surface
109106
// to a FlutterImageView to help improve animation synchronization on Android. This flag allows
110107
// disabling this conversion through the PlatformView platform channel.
@@ -510,7 +507,6 @@ public void detachFromView() {
510507
destroyOverlaySurfaces();
511508
removeOverlaySurfaces();
512509
this.flutterView = null;
513-
flutterViewConvertedToImageView = false;
514510

515511
// Inform all existing platform views that they are no longer associated with
516512
// a Flutter View.
@@ -726,9 +722,8 @@ private void flushAllViews() {
726722
}
727723

728724
private void initializeRootImageViewIfNeeded() {
729-
if (synchronizeToNativeViewHierarchy && !flutterViewConvertedToImageView) {
725+
if (synchronizeToNativeViewHierarchy && !flutterView.hasConvertedToImageView()) {
730726
flutterView.convertToImageView();
731-
flutterViewConvertedToImageView = true;
732727
}
733728
}
734729

@@ -863,8 +858,7 @@ public void onEndFrame() {
863858
// then revert the image view surface and use the previous surface.
864859
//
865860
// Otherwise, acquire the latest image.
866-
if (flutterViewConvertedToImageView && currentFrameUsedPlatformViewIds.isEmpty()) {
867-
flutterViewConvertedToImageView = false;
861+
if (flutterView.hasConvertedToImageView() && currentFrameUsedPlatformViewIds.isEmpty()) {
868862
flutterView.revertImageView(
869863
() -> {
870864
// Destroy overlay surfaces once the surface reversion is completed.
@@ -882,7 +876,7 @@ public void onEndFrame() {
882876
// dropped.
883877
// For example, a toolbar widget painted by Flutter may not be rendered.
884878
final boolean isFrameRenderedUsingImageReaders =
885-
flutterViewConvertedToImageView && flutterView.acquireLatestImageViewFrame();
879+
flutterView.hasConvertedToImageView() && flutterView.acquireLatestImageViewFrame();
886880
finishFrame(isFrameRenderedUsingImageReaders);
887881
}
888882

@@ -899,7 +893,7 @@ private void finishFrame(boolean isFrameRenderedUsingImageReaders) {
899893
// If the background surface isn't rendered by the image view, then the
900894
// overlay surfaces can be detached from the rendered.
901895
// This releases resources used by the ImageReader.
902-
if (!flutterViewConvertedToImageView) {
896+
if (!flutterView.hasConvertedToImageView()) {
903897
overlayView.detachFromRenderer();
904898
}
905899
// Hide overlay surfaces that aren't rendered in the current frame.

shell/platform/android/test/io/flutter/embedding/android/FlutterViewTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,11 @@ public void detachFromFlutterEngine_revertImageView() {
131131

132132
flutterView.convertToImageView();
133133
assertTrue(flutterView.renderSurface instanceof FlutterImageView);
134+
assertTrue(flutterView.hasConvertedToImageView());
134135

135136
flutterView.detachFromFlutterEngine();
136137
assertFalse(flutterView.renderSurface instanceof FlutterImageView);
138+
assertFalse(flutterView.hasConvertedToImageView());
137139
}
138140

139141
@Test

0 commit comments

Comments
 (0)