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 b3945f7706

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.
This commit is contained in:
Jason Simmons
2024-04-11 15:05:33 -07:00
committed by GitHub
parent 4776b2cddf
commit 6674f823cf

View File

@@ -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);
}
}
}
/**