From 540fdf89b1432f99e3c01d6ec838d434609eefb7 Mon Sep 17 00:00:00 2001 From: Huihong Luo Date: Fri, 25 Jun 2021 13:59:39 -0700 Subject: 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 --- libs/hwui/WebViewFunctorManager.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'libs/hwui/WebViewFunctorManager.cpp') diff --git a/libs/hwui/WebViewFunctorManager.cpp b/libs/hwui/WebViewFunctorManager.cpp index 92e20c477669..974c8635b3df 100644 --- a/libs/hwui/WebViewFunctorManager.cpp +++ b/libs/hwui/WebViewFunctorManager.cpp @@ -126,7 +126,14 @@ void WebViewFunctor::drawGl(const DrawGlInfo& drawInfo) { 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 @@ ASurfaceControl* WebViewFunctor::getSurfaceControl() { 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::mergeTransaction(ASurfaceTransaction* transaction) { } } +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; -- cgit v1.2.3 From eb93107b574ad3a8b567597af26e72bee276598b Mon Sep 17 00:00:00 2001 From: Huihong Luo Date: Wed, 30 Jun 2021 10:12:17 -0700 Subject: Add a sys prop to control WebView Overlays support The boolean system property is named as "debug.hwui.webview_overlays_enabled" Bug: 192267127 Test: change the property value, check presence of Webview Surface Control Change-Id: I01e3e26282a5fa79aa504a6e49c5abe1a1c3ea02 --- libs/hwui/WebViewFunctorManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libs/hwui/WebViewFunctorManager.cpp') diff --git a/libs/hwui/WebViewFunctorManager.cpp b/libs/hwui/WebViewFunctorManager.cpp index 974c8635b3df..93f2f42a00fd 100644 --- a/libs/hwui/WebViewFunctorManager.cpp +++ b/libs/hwui/WebViewFunctorManager.cpp @@ -121,7 +121,7 @@ void WebViewFunctor::drawGl(const DrawGlInfo& drawInfo) { .mergeTransaction = currentFunctor.mergeTransaction, }; - if (!drawInfo.isLayer) { + if (Properties::enableWebViewOverlays && !drawInfo.isLayer) { renderthread::CanvasContext* activeContext = renderthread::CanvasContext::getActiveContext(); if (activeContext != nullptr) { -- cgit v1.2.3 From ec68b7c973924e98592cd80e9be0690103c66831 Mon Sep 17 00:00:00 2001 From: Huihong Luo Date: Fri, 25 Jun 2021 21:54:16 -0700 Subject: Disable Webview Overlay when invisible Remove Webview overlays when Webview node is set to invisible Bug: 187292989 Test: play a video in a Webview, toggle visibility for the view, check existence of a surface control named as "Webview Overlay SurfaceControl#0" Change-Id: If47a78a8ae1f7b65b9e7ab983ec72f580d78191a --- libs/hwui/WebViewFunctorManager.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'libs/hwui/WebViewFunctorManager.cpp') diff --git a/libs/hwui/WebViewFunctorManager.cpp b/libs/hwui/WebViewFunctorManager.cpp index 93f2f42a00fd..df4101109a18 100644 --- a/libs/hwui/WebViewFunctorManager.cpp +++ b/libs/hwui/WebViewFunctorManager.cpp @@ -108,6 +108,13 @@ void WebViewFunctor::sync(const WebViewSyncData& syncData) const { mCallbacks.onSync(mFunctor, mData, syncData); } +void WebViewFunctor::onRemovedFromTree() { + ATRACE_NAME("WebViewFunctor::onRemovedFromTree"); + if (mSurfaceControl) { + removeOverlays(); + } +} + void WebViewFunctor::drawGl(const DrawGlInfo& drawInfo) { ATRACE_NAME("WebViewFunctor::drawGl"); if (!mHasContext) { @@ -185,6 +192,7 @@ void WebViewFunctor::removeOverlays() { ScopedCurrentFunctor currentFunctor(this); mCallbacks.removeOverlays(mFunctor, mData, currentFunctor.mergeTransaction); if (mSurfaceControl) { + reparentSurfaceControl(nullptr); auto funcs = renderthread::RenderThread::getInstance().getASurfaceControlFunctions(); funcs.releaseFunc(mSurfaceControl); mSurfaceControl = nullptr; @@ -217,9 +225,12 @@ ASurfaceControl* WebViewFunctor::getSurfaceControl() { void WebViewFunctor::mergeTransaction(ASurfaceTransaction* transaction) { ATRACE_NAME("WebViewFunctor::mergeTransaction"); if (transaction == nullptr) return; + bool done = false; renderthread::CanvasContext* activeContext = renderthread::CanvasContext::getActiveContext(); - LOG_ALWAYS_FATAL_IF(activeContext == nullptr, "Null active canvas context!"); - bool done = activeContext->mergeTransaction(transaction, mSurfaceControl); + // activeContext might be null when called from mCallbacks.removeOverlays() + if (activeContext != nullptr) { + done = activeContext->mergeTransaction(transaction, mSurfaceControl); + } if (!done) { auto funcs = renderthread::RenderThread::getInstance().getASurfaceControlFunctions(); funcs.transactionApplyFunc(transaction); -- cgit v1.2.3