From 6674f823cfbbcc60c48b2646215a04d2ceea8c9c Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Thu, 11 Apr 2024 15:05:33 -0700 Subject: [PATCH] Clear the surface to transparent black when creating a PlatformViewWrapper (flutter/engine#52047) Without this, an opaque black surface may briefly flash onscreen when the platform view is shown (see internal issue b/332379081) This matches the behavior used before to the introduction of PlatformViewRenderTarget in https://github.com/flutter/engine/commit/b3945f77066cbc2449ebe45bc7a79f21bccef4cc That commit moved the clearing of the surface into SurfaceTexturePlatformViewRenderTarget. But that caused surface clearing to happen in scenarios where there was no PlatformViewWrapper, resulting in the issue seen in https://github.com/flutter/flutter/issues/141068 Later the surface clearing was removed from SurfaceTexturePlatformViewRenderTarget, causing the flashing black screen. --- .../flutter/plugin/platform/PlatformViewWrapper.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewWrapper.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewWrapper.java index f1e91a99aa..7defa9ef01 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewWrapper.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewWrapper.java @@ -61,6 +61,16 @@ public class PlatformViewWrapper extends FrameLayout { @NonNull Context context, @NonNull PlatformViewRenderTarget renderTarget) { this(context); this.renderTarget = renderTarget; + + Surface surface = renderTarget.getSurface(); + if (surface != null) { + final Canvas canvas = surface.lockHardwareCanvas(); + try { + canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); + } finally { + surface.unlockCanvasAndPost(canvas); + } + } } /**