From 34f42fdecdf380d82f2be32b3564517002cc2112 Mon Sep 17 00:00:00 2001 From: Huihong Luo Date: Mon, 3 May 2021 14:47:36 -0700 Subject: Fix z-order for webview surface control Set the root surface control transparent, and set the z order of the newly created child surface control to -1. A new callback is needed to update root surface control in sync from Java side. Bug: 186750329 Test: use latest APKs from Webview team, play a video, mini toolbar should be visible Change-Id: I0b37ee8f83fd2b41ff4f2856dbadd31ff6170baf --- core/java/android/view/ViewRootImpl.java | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'core/java/android/view/ViewRootImpl.java') diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index d42e0c367763..cf8c746d6ecb 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -461,6 +461,9 @@ public final class ViewRootImpl implements ViewParent, protected final ViewFrameInfo mViewFrameInfo = new ViewFrameInfo(); private final InputEventAssigner mInputEventAssigner = new InputEventAssigner(); + // Set to true if mSurfaceControl is used for Webview Overlay + private boolean mIsForWebviewOverlay; + /** * Update the Choreographer's FrameInfo object with the timing information for the current * ViewRootImpl instance. Erase the data in the current ViewFrameInfo to prepare for the next @@ -1374,6 +1377,23 @@ public final class ViewRootImpl implements ViewParent, mAttachInfo.mThreadedRenderer.setASurfaceTransactionCallback(callback); } + /** + * Register a callback to be executed when Webview overlay needs a surface control. + * This callback will be executed on RenderThread worker thread, and released inside native code + * when CanvasContext is destroyed. + */ + private void addPrepareSurfaceControlForWebviewCallback() { + HardwareRenderer.PrepareSurfaceControlForWebviewCallback callback = () -> { + // make mSurfaceControl transparent, so child surface controls are visible + if (mIsForWebviewOverlay) return; + synchronized (ViewRootImpl.this) { + mIsForWebviewOverlay = true; + } + mTransaction.setOpaque(mSurfaceControl, false).apply(); + }; + mAttachInfo.mThreadedRenderer.setPrepareSurfaceControlForWebviewCallback(callback); + } + @UnsupportedAppUsage private void enableHardwareAcceleration(WindowManager.LayoutParams attrs) { mAttachInfo.mHardwareAccelerated = false; @@ -1418,6 +1438,7 @@ public final class ViewRootImpl implements ViewParent, if (mHardwareRendererObserver != null) { mAttachInfo.mThreadedRenderer.addObserver(mHardwareRendererObserver); } + addPrepareSurfaceControlForWebviewCallback(); addASurfaceTransactionCallback(); mAttachInfo.mThreadedRenderer.setSurfaceControl(mSurfaceControl); } @@ -7743,6 +7764,7 @@ public final class ViewRootImpl implements ViewParent, } } if (mAttachInfo.mThreadedRenderer != null) { + addPrepareSurfaceControlForWebviewCallback(); addASurfaceTransactionCallback(); mAttachInfo.mThreadedRenderer.setSurfaceControl(mSurfaceControl); } @@ -7790,7 +7812,14 @@ public final class ViewRootImpl implements ViewParent, return; } - mTransaction.setOpaque(mSurfaceControl, opaque).apply(); + synchronized (this) { + if (mIsForWebviewOverlay) { + mIsSurfaceOpaque = false; + return; + } + mTransaction.setOpaque(mSurfaceControl, opaque).apply(); + } + mIsSurfaceOpaque = opaque; } -- cgit v1.2.3