diff options
author | Haamed Gheibi <haamed@google.com> | 2021-07-12 20:47:45 +0000 |
---|---|---|
committer | Haamed Gheibi <haamed@google.com> | 2021-07-14 18:21:17 +0000 |
commit | 02a7ee5d65cb8d40fd1dde9aaf6b5ead9222a5a6 (patch) | |
tree | 6fb30a5bc0d0e7fadd37d62cdba537c4d5d9237b /libs/hwui/WebViewFunctorManager.cpp | |
parent | bab7c6ab6b363574baaace4df576c1abb67f4507 (diff) | |
parent | fa0439912edd9559d7c0f46bef2b2898de68f50f (diff) |
Merge SP1A.210709.002
Change-Id: I4610885d5d770d858895057cdd9fea387a5e33dd
Diffstat (limited to 'libs/hwui/WebViewFunctorManager.cpp')
-rw-r--r-- | libs/hwui/WebViewFunctorManager.cpp | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/libs/hwui/WebViewFunctorManager.cpp b/libs/hwui/WebViewFunctorManager.cpp index 92e20c477669..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) { @@ -121,12 +128,19 @@ 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) { 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; + } + } } } @@ -178,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; @@ -195,6 +210,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(); @@ -209,15 +225,29 @@ 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); } } +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; |