summaryrefslogtreecommitdiff
path: root/core/java/android/view/ViewRootImpl.java
diff options
context:
space:
mode:
authorHuihong Luo <huisinro@google.com>2021-05-03 14:47:36 -0700
committerHuihong Luo <huisinro@google.com>2021-06-18 10:14:22 -0700
commit34f42fdecdf380d82f2be32b3564517002cc2112 (patch)
treeb399058237780bf95b6b6a688e48e3fd727544bc /core/java/android/view/ViewRootImpl.java
parent1d88151a380c2a8f102c76b8413d17989215ccf8 (diff)
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
Diffstat (limited to 'core/java/android/view/ViewRootImpl.java')
-rw-r--r--core/java/android/view/ViewRootImpl.java31
1 files changed, 30 insertions, 1 deletions
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;
}