Reparent surface control for Webview overlay
When the root surface control changes, the parent of the Webview surface control must be changed.
Bug: 191900007
Test: switch app, or turn on/off screen
Change-Id: Ib7b34133776fd5944afc638bfee471afe6a17349
diff --git a/libs/hwui/WebViewFunctorManager.cpp b/libs/hwui/WebViewFunctorManager.cpp
index 92e20c4..974c863 100644
--- a/libs/hwui/WebViewFunctorManager.cpp
+++ b/libs/hwui/WebViewFunctorManager.cpp
@@ -126,7 +126,14 @@
renderthread::CanvasContext::getActiveContext();
if (activeContext != nullptr) {
ASurfaceControl* rootSurfaceControl = activeContext->getSurfaceControl();
- if (rootSurfaceControl) overlayParams.overlaysMode = OverlaysMode::Enabled;
+ if (rootSurfaceControl) {
+ overlayParams.overlaysMode = OverlaysMode::Enabled;
+ int32_t rgid = activeContext->getSurfaceControlGenerationId();
+ if (mParentSurfaceControlGenerationId != rgid) {
+ reparentSurfaceControl(rootSurfaceControl);
+ mParentSurfaceControlGenerationId = rgid;
+ }
+ }
}
}
@@ -195,6 +202,7 @@
LOG_ALWAYS_FATAL_IF(rootSurfaceControl == nullptr, "Null root surface control!");
auto funcs = renderthread::RenderThread::getInstance().getASurfaceControlFunctions();
+ mParentSurfaceControlGenerationId = activeContext->getSurfaceControlGenerationId();
mSurfaceControl = funcs.createFunc(rootSurfaceControl, "Webview Overlay SurfaceControl");
ASurfaceTransaction* transaction = funcs.transactionCreateFunc();
activeContext->prepareSurfaceControlForWebview();
@@ -218,6 +226,17 @@
}
}
+void WebViewFunctor::reparentSurfaceControl(ASurfaceControl* parent) {
+ ATRACE_NAME("WebViewFunctor::reparentSurfaceControl");
+ if (mSurfaceControl == nullptr) return;
+
+ auto funcs = renderthread::RenderThread::getInstance().getASurfaceControlFunctions();
+ ASurfaceTransaction* transaction = funcs.transactionCreateFunc();
+ funcs.transactionReparentFunc(transaction, mSurfaceControl, parent);
+ mergeTransaction(transaction);
+ funcs.transactionDeleteFunc(transaction);
+}
+
WebViewFunctorManager& WebViewFunctorManager::instance() {
static WebViewFunctorManager sInstance;
return sInstance;
diff --git a/libs/hwui/WebViewFunctorManager.h b/libs/hwui/WebViewFunctorManager.h
index a84cda5..048d1fb 100644
--- a/libs/hwui/WebViewFunctorManager.h
+++ b/libs/hwui/WebViewFunctorManager.h
@@ -85,12 +85,16 @@
}
private:
+ void reparentSurfaceControl(ASurfaceControl* parent);
+
+private:
WebViewFunctorCallbacks mCallbacks;
void* const mData;
int mFunctor;
RenderMode mMode;
bool mHasContext = false;
bool mCreatedHandle = false;
+ int32_t mParentSurfaceControlGenerationId = 0;
ASurfaceControl* mSurfaceControl = nullptr;
};
diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp
index 0c9711b..81cee61 100644
--- a/libs/hwui/renderthread/CanvasContext.cpp
+++ b/libs/hwui/renderthread/CanvasContext.cpp
@@ -201,6 +201,7 @@
funcs.releaseFunc(mSurfaceControl);
}
mSurfaceControl = surfaceControl;
+ mSurfaceControlGenerationId++;
mExpectSurfaceStats = surfaceControl != nullptr;
if (mSurfaceControl != nullptr) {
funcs.acquireFunc(mSurfaceControl);
diff --git a/libs/hwui/renderthread/CanvasContext.h b/libs/hwui/renderthread/CanvasContext.h
index 3279ccb..85af3e4 100644
--- a/libs/hwui/renderthread/CanvasContext.h
+++ b/libs/hwui/renderthread/CanvasContext.h
@@ -110,6 +110,7 @@
GrDirectContext* getGrContext() const { return mRenderThread.getGrContext(); }
ASurfaceControl* getSurfaceControl() const { return mSurfaceControl; }
+ int32_t getSurfaceControlGenerationId() const { return mSurfaceControlGenerationId; }
// Won't take effect until next EGLSurface creation
void setSwapBehavior(SwapBehavior swapBehavior);
@@ -253,6 +254,9 @@
// The SurfaceControl reference is passed from ViewRootImpl, can be set to
// NULL to remove the reference
ASurfaceControl* mSurfaceControl = nullptr;
+ // id to track surface control changes and WebViewFunctor uses it to determine
+ // whether reparenting is needed
+ int32_t mSurfaceControlGenerationId = 0;
// stopped indicates the CanvasContext will reject actual redraw operations,
// and defer repaint until it is un-stopped
bool mStopped = false;
diff --git a/libs/hwui/renderthread/RenderThread.cpp b/libs/hwui/renderthread/RenderThread.cpp
index 524407d..f83c0a4 100644
--- a/libs/hwui/renderthread/RenderThread.cpp
+++ b/libs/hwui/renderthread/RenderThread.cpp
@@ -98,6 +98,10 @@
LOG_ALWAYS_FATAL_IF(transactionApplyFunc == nullptr,
"Failed to find required symbol ASurfaceTransaction_apply!");
+ transactionReparentFunc = (AST_reparent)dlsym(handle_, "ASurfaceTransaction_reparent");
+ LOG_ALWAYS_FATAL_IF(transactionReparentFunc == nullptr,
+ "Failed to find required symbol transactionReparentFunc!");
+
transactionSetVisibilityFunc =
(AST_setVisibility)dlsym(handle_, "ASurfaceTransaction_setVisibility");
LOG_ALWAYS_FATAL_IF(transactionSetVisibilityFunc == nullptr,
diff --git a/libs/hwui/renderthread/RenderThread.h b/libs/hwui/renderthread/RenderThread.h
index c5e3746..05d225b 100644
--- a/libs/hwui/renderthread/RenderThread.h
+++ b/libs/hwui/renderthread/RenderThread.h
@@ -94,6 +94,9 @@
typedef ASurfaceTransaction* (*AST_create)();
typedef void (*AST_delete)(ASurfaceTransaction* transaction);
typedef void (*AST_apply)(ASurfaceTransaction* transaction);
+typedef void (*AST_reparent)(ASurfaceTransaction* aSurfaceTransaction,
+ ASurfaceControl* aSurfaceControl,
+ ASurfaceControl* newParentASurfaceControl);
typedef void (*AST_setVisibility)(ASurfaceTransaction* transaction,
ASurfaceControl* surface_control, int8_t visibility);
typedef void (*AST_setZOrder)(ASurfaceTransaction* transaction, ASurfaceControl* surface_control,
@@ -113,6 +116,7 @@
AST_create transactionCreateFunc;
AST_delete transactionDeleteFunc;
AST_apply transactionApplyFunc;
+ AST_reparent transactionReparentFunc;
AST_setVisibility transactionSetVisibilityFunc;
AST_setZOrder transactionSetZOrderFunc;
};