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

Commit 7538310

Browse files
authored
Revert "Use preDraw for the Android embedding (#27645)" (#27788)
This reverts commit ff770aa.
1 parent 5072622 commit 7538310

File tree

8 files changed

+25
-264
lines changed

8 files changed

+25
-264
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,7 @@ private View createFlutterView() {
542542
/* inflater=*/ null,
543543
/* container=*/ null,
544544
/* savedInstanceState=*/ null,
545-
/*flutterViewId=*/ FLUTTER_VIEW_ID,
546-
/*shouldDelayFirstAndroidViewDraw=*/ getRenderMode() == RenderMode.surface);
545+
/*flutterViewId=*/ FLUTTER_VIEW_ID);
547546
}
548547

549548
private void configureStatusBarForFullscreenFlutterExperience() {

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

Lines changed: 7 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import android.view.LayoutInflater;
1616
import android.view.View;
1717
import android.view.ViewGroup;
18-
import android.view.ViewTreeObserver.OnPreDrawListener;
1918
import androidx.annotation.NonNull;
2019
import androidx.annotation.Nullable;
2120
import androidx.annotation.VisibleForTesting;
@@ -68,31 +67,27 @@
6867
private static final String TAG = "FlutterActivityAndFragmentDelegate";
6968
private static final String FRAMEWORK_RESTORATION_BUNDLE_KEY = "framework";
7069
private static final String PLUGINS_RESTORATION_BUNDLE_KEY = "plugins";
71-
private static final int FLUTTER_SPLASH_VIEW_FALLBACK_ID = 486947586;
7270

7371
// The FlutterActivity or FlutterFragment that is delegating most of its calls
7472
// to this FlutterActivityAndFragmentDelegate.
7573
@NonNull private Host host;
7674
@Nullable private FlutterEngine flutterEngine;
75+
@Nullable private FlutterSplashView flutterSplashView;
7776
@Nullable private FlutterView flutterView;
7877
@Nullable private PlatformPlugin platformPlugin;
79-
@VisibleForTesting @Nullable OnPreDrawListener activePreDrawListener;
8078
private boolean isFlutterEngineFromHost;
81-
private boolean isFlutterUiDisplayed;
8279

8380
@NonNull
8481
private final FlutterUiDisplayListener flutterUiDisplayListener =
8582
new FlutterUiDisplayListener() {
8683
@Override
8784
public void onFlutterUiDisplayed() {
8885
host.onFlutterUiDisplayed();
89-
isFlutterUiDisplayed = true;
9086
}
9187

9288
@Override
9389
public void onFlutterUiNoLongerDisplayed() {
9490
host.onFlutterUiNoLongerDisplayed();
95-
isFlutterUiDisplayed = false;
9691
}
9792
};
9893

@@ -259,16 +254,6 @@ void onAttach(@NonNull Context context) {
259254
*
260255
* <p>{@code inflater} and {@code container} may be null when invoked from an {@code Activity}.
261256
*
262-
* <p>{@code shouldDelayFirstAndroidViewDraw} determines whether to set up an {@link
263-
* android.view.ViewTreeObserver.OnPreDrawListener}, which will defer the current drawing pass
264-
* till after the Flutter UI has been displayed. This results in more accurate timings reported
265-
* with Android tools, such as "Displayed" timing printed with `am start`.
266-
*
267-
* <p>Note that it should only be set to true when {@code Host#getRenderMode()} is {@code
268-
* RenderMode.surface}. This parameter is also ignored, disabling the delay should the legacy
269-
* {@code Host#provideSplashScreen()} be non-null. See <a
270-
* href="https://flutter.dev/go/android-splash-migration">Android Splash Migration</a>.
271-
*
272257
* <p>This method:
273258
*
274259
* <ol>
@@ -284,8 +269,7 @@ View onCreateView(
284269
LayoutInflater inflater,
285270
@Nullable ViewGroup container,
286271
@Nullable Bundle savedInstanceState,
287-
int flutterViewId,
288-
boolean shouldDelayFirstAndroidViewDraw) {
272+
int flutterViewId) {
289273
Log.v(TAG, "Creating FlutterView.");
290274
ensureAlive();
291275

@@ -314,28 +298,15 @@ View onCreateView(
314298
// Add listener to be notified when Flutter renders its first frame.
315299
flutterView.addOnFirstFrameRenderedListener(flutterUiDisplayListener);
316300

301+
flutterSplashView = new FlutterSplashView(host.getContext());
302+
flutterSplashView.setId(ViewUtils.generateViewId(486947586));
303+
flutterSplashView.displayFlutterViewWithSplash(flutterView, host.provideSplashScreen());
304+
317305
Log.v(TAG, "Attaching FlutterEngine to FlutterView.");
318306
flutterView.attachToFlutterEngine(flutterEngine);
319307
flutterView.setId(flutterViewId);
320308

321-
SplashScreen splashScreen = host.provideSplashScreen();
322-
323-
if (splashScreen != null) {
324-
Log.w(
325-
TAG,
326-
"A splash screen was provided to Flutter, but this is deprecated. See"
327-
+ " flutter.dev/go/android-splash-migration for migration steps.");
328-
FlutterSplashView flutterSplashView = new FlutterSplashView(host.getContext());
329-
flutterSplashView.setId(ViewUtils.generateViewId(FLUTTER_SPLASH_VIEW_FALLBACK_ID));
330-
flutterSplashView.displayFlutterViewWithSplash(flutterView, splashScreen);
331-
332-
return flutterSplashView;
333-
}
334-
335-
if (shouldDelayFirstAndroidViewDraw) {
336-
delayFirstAndroidViewDraw(flutterView);
337-
}
338-
return flutterView;
309+
return flutterSplashView;
339310
}
340311

341312
void onRestoreInstanceState(@Nullable Bundle bundle) {
@@ -444,38 +415,6 @@ private String maybeGetInitialRouteFromIntent(Intent intent) {
444415
return null;
445416
}
446417

447-
/**
448-
* Delays the first drawing of the {@code flutterView} until the Flutter first has been displayed.
449-
*/
450-
private void delayFirstAndroidViewDraw(FlutterView flutterView) {
451-
if (host.getRenderMode() != RenderMode.surface) {
452-
// Using a TextureView will cause a deadlock, where the underlying SurfaceTexture is never
453-
// available since it will wait for drawing to be completed first. At the same time, the
454-
// preDraw listener keeps returning false since the Flutter Engine waits for the
455-
// SurfaceTexture to be available.
456-
throw new IllegalArgumentException(
457-
"Cannot delay the first Android view draw when the render mode is not set to"
458-
+ " `RenderMode.surface`.");
459-
}
460-
461-
if (activePreDrawListener != null) {
462-
flutterView.getViewTreeObserver().removeOnPreDrawListener(activePreDrawListener);
463-
}
464-
465-
activePreDrawListener =
466-
new OnPreDrawListener() {
467-
@Override
468-
public boolean onPreDraw() {
469-
if (isFlutterUiDisplayed && activePreDrawListener != null) {
470-
flutterView.getViewTreeObserver().removeOnPreDrawListener(this);
471-
activePreDrawListener = null;
472-
}
473-
return isFlutterUiDisplayed;
474-
}
475-
};
476-
flutterView.getViewTreeObserver().addOnPreDrawListener(activePreDrawListener);
477-
}
478-
479418
/**
480419
* Invoke this from {@code Activity#onResume()} or {@code Fragment#onResume()}.
481420
*
@@ -557,10 +496,6 @@ void onDestroyView() {
557496
Log.v(TAG, "onDestroyView()");
558497
ensureAlive();
559498

560-
if (activePreDrawListener != null) {
561-
flutterView.getViewTreeObserver().removeOnPreDrawListener(activePreDrawListener);
562-
activePreDrawListener = null;
563-
}
564499
flutterView.detachFromFlutterEngine();
565500
flutterView.removeOnFirstFrameRenderedListener(flutterUiDisplayListener);
566501
}

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

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,6 @@ public class FlutterFragment extends Fragment
113113
protected static final String ARG_HANDLE_DEEPLINKING = "handle_deeplinking";
114114
/** Path to Flutter's Dart code. */
115115
protected static final String ARG_APP_BUNDLE_PATH = "app_bundle_path";
116-
/** Whether to delay the Android drawing pass till after the Flutter UI has been displayed. */
117-
protected static final String ARG_SHOULD_DELAY_FIRST_ANDROID_VIEW_DRAW =
118-
"should_delay_first_android_view_draw";
119-
120116
/** Flutter shell arguments. */
121117
protected static final String ARG_FLUTTER_INITIALIZATION_ARGS = "initialization_args";
122118
/**
@@ -233,7 +229,6 @@ public static class NewEngineFragmentBuilder {
233229
private TransparencyMode transparencyMode = TransparencyMode.transparent;
234230
private boolean shouldAttachEngineToActivity = true;
235231
private boolean shouldAutomaticallyHandleOnBackPressed = false;
236-
private boolean shouldDelayFirstAndroidViewDraw = false;
237232

238233
/**
239234
* Constructs a {@code NewEngineFragmentBuilder} that is configured to construct an instance of
@@ -387,18 +382,6 @@ public NewEngineFragmentBuilder shouldAutomaticallyHandleOnBackPressed(
387382
return this;
388383
}
389384

390-
/**
391-
* Whether to delay the Android drawing pass till after the Flutter UI has been displayed.
392-
*
393-
* <p>See {#link FlutterActivityAndFragmentDelegate#onCreateView} for more details.
394-
*/
395-
@NonNull
396-
public NewEngineFragmentBuilder shouldDelayFirstAndroidViewDraw(
397-
boolean shouldDelayFirstAndroidViewDraw) {
398-
this.shouldDelayFirstAndroidViewDraw = shouldDelayFirstAndroidViewDraw;
399-
return this;
400-
}
401-
402385
/**
403386
* Creates a {@link Bundle} of arguments that are assigned to the new {@code FlutterFragment}.
404387
*
@@ -427,7 +410,6 @@ protected Bundle createArgs() {
427410
args.putBoolean(ARG_DESTROY_ENGINE_WITH_FRAGMENT, true);
428411
args.putBoolean(
429412
ARG_SHOULD_AUTOMATICALLY_HANDLE_ON_BACK_PRESSED, shouldAutomaticallyHandleOnBackPressed);
430-
args.putBoolean(ARG_SHOULD_DELAY_FIRST_ANDROID_VIEW_DRAW, shouldDelayFirstAndroidViewDraw);
431413
return args;
432414
}
433415

@@ -514,7 +496,6 @@ public static class CachedEngineFragmentBuilder {
514496
private TransparencyMode transparencyMode = TransparencyMode.transparent;
515497
private boolean shouldAttachEngineToActivity = true;
516498
private boolean shouldAutomaticallyHandleOnBackPressed = false;
517-
private boolean shouldDelayFirstAndroidViewDraw = false;
518499

519500
private CachedEngineFragmentBuilder(@NonNull String engineId) {
520501
this(FlutterFragment.class, engineId);
@@ -640,18 +621,6 @@ public CachedEngineFragmentBuilder shouldAutomaticallyHandleOnBackPressed(
640621
return this;
641622
}
642623

643-
/**
644-
* Whether to delay the Android drawing pass till after the Flutter UI has been displayed.
645-
*
646-
* <p>See {#link FlutterActivityAndFragmentDelegate#onCreateView} for more details.
647-
*/
648-
@NonNull
649-
public CachedEngineFragmentBuilder shouldDelayFirstAndroidViewDraw(
650-
@NonNull boolean shouldDelayFirstAndroidViewDraw) {
651-
this.shouldDelayFirstAndroidViewDraw = shouldDelayFirstAndroidViewDraw;
652-
return this;
653-
}
654-
655624
/**
656625
* Creates a {@link Bundle} of arguments that are assigned to the new {@code FlutterFragment}.
657626
*
@@ -673,7 +642,6 @@ protected Bundle createArgs() {
673642
args.putBoolean(ARG_SHOULD_ATTACH_ENGINE_TO_ACTIVITY, shouldAttachEngineToActivity);
674643
args.putBoolean(
675644
ARG_SHOULD_AUTOMATICALLY_HANDLE_ON_BACK_PRESSED, shouldAutomaticallyHandleOnBackPressed);
676-
args.putBoolean(ARG_SHOULD_DELAY_FIRST_ANDROID_VIEW_DRAW, shouldDelayFirstAndroidViewDraw);
677645
return args;
678646
}
679647

@@ -759,11 +727,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
759727
public View onCreateView(
760728
LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
761729
return delegate.onCreateView(
762-
inflater,
763-
container,
764-
savedInstanceState,
765-
/*flutterViewId=*/ FLUTTER_VIEW_ID,
766-
shouldDelayFirstAndroidViewDraw());
730+
inflater, container, savedInstanceState, /*flutterViewId=*/ FLUTTER_VIEW_ID);
767731
}
768732

769733
@Override
@@ -1303,12 +1267,6 @@ public boolean popSystemNavigator() {
13031267
return false;
13041268
}
13051269

1306-
@VisibleForTesting
1307-
@NonNull
1308-
boolean shouldDelayFirstAndroidViewDraw() {
1309-
return getArguments().getBoolean(ARG_SHOULD_DELAY_FIRST_ANDROID_VIEW_DRAW);
1310-
}
1311-
13121270
private boolean stillAttachedForEvent(String event) {
13131271
if (delegate == null) {
13141272
Log.w(TAG, "FlutterFragment " + hashCode() + " " + event + " called after release.");

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,6 @@ protected FlutterFragment createFlutterFragment() {
424424
backgroundMode == BackgroundMode.opaque
425425
? TransparencyMode.opaque
426426
: TransparencyMode.transparent;
427-
final boolean shouldDelayFirstAndroidViewDraw = renderMode == RenderMode.surface;
428427

429428
if (getCachedEngineId() != null) {
430429
Log.v(
@@ -448,7 +447,6 @@ protected FlutterFragment createFlutterFragment() {
448447
.handleDeeplinking(shouldHandleDeeplinking())
449448
.shouldAttachEngineToActivity(shouldAttachEngineToActivity())
450449
.destroyEngineWithFragment(shouldDestroyEngineWithHost())
451-
.shouldDelayFirstAndroidViewDraw(shouldDelayFirstAndroidViewDraw)
452450
.build();
453451
} else {
454452
Log.v(
@@ -478,7 +476,6 @@ protected FlutterFragment createFlutterFragment() {
478476
.renderMode(renderMode)
479477
.transparencyMode(transparencyMode)
480478
.shouldAttachEngineToActivity(shouldAttachEngineToActivity())
481-
.shouldDelayFirstAndroidViewDraw(shouldDelayFirstAndroidViewDraw)
482479
.build();
483480
}
484481
}

0 commit comments

Comments
 (0)