Merge "Enable WebView overlays for Vulkan"

This commit is contained in:
Vasiliy Telezhnikov
2021-11-19 19:08:46 +00:00
committed by Android (Google) Code Review
5 changed files with 30 additions and 16 deletions

View File

@@ -118,6 +118,24 @@ void WebViewFunctor::onRemovedFromTree() {
}
}
bool WebViewFunctor::prepareRootSurfaceControl() {
if (!Properties::enableWebViewOverlays) return false;
renderthread::CanvasContext* activeContext = renderthread::CanvasContext::getActiveContext();
if (!activeContext) return false;
ASurfaceControl* rootSurfaceControl = activeContext->getSurfaceControl();
if (!rootSurfaceControl) return false;
int32_t rgid = activeContext->getSurfaceControlGenerationId();
if (mParentSurfaceControlGenerationId != rgid) {
reparentSurfaceControl(rootSurfaceControl);
mParentSurfaceControlGenerationId = rgid;
}
return true;
}
void WebViewFunctor::drawGl(const DrawGlInfo& drawInfo) {
ATRACE_NAME("WebViewFunctor::drawGl");
if (!mHasContext) {
@@ -131,20 +149,8 @@ void WebViewFunctor::drawGl(const DrawGlInfo& drawInfo) {
.mergeTransaction = currentFunctor.mergeTransaction,
};
if (Properties::enableWebViewOverlays && !drawInfo.isLayer) {
renderthread::CanvasContext* activeContext =
renderthread::CanvasContext::getActiveContext();
if (activeContext != nullptr) {
ASurfaceControl* rootSurfaceControl = activeContext->getSurfaceControl();
if (rootSurfaceControl) {
overlayParams.overlaysMode = OverlaysMode::Enabled;
int32_t rgid = activeContext->getSurfaceControlGenerationId();
if (mParentSurfaceControlGenerationId != rgid) {
reparentSurfaceControl(rootSurfaceControl);
mParentSurfaceControlGenerationId = rgid;
}
}
}
if (!drawInfo.isLayer && prepareRootSurfaceControl()) {
overlayParams.overlaysMode = OverlaysMode::Enabled;
}
mCallbacks.gles.draw(mFunctor, mData, drawInfo, overlayParams);
@@ -170,7 +176,10 @@ void WebViewFunctor::drawVk(const VkFunctorDrawParams& params) {
.mergeTransaction = currentFunctor.mergeTransaction,
};
// TODO, enable surface control once offscreen mode figured out
if (!params.is_layer && prepareRootSurfaceControl()) {
overlayParams.overlaysMode = OverlaysMode::Enabled;
}
mCallbacks.vk.draw(mFunctor, mData, params, overlayParams);
}

View File

@@ -88,6 +88,7 @@ public:
}
private:
bool prepareRootSurfaceControl();
void reparentSurfaceControl(ASurfaceControl* parent);
private:

View File

@@ -72,6 +72,7 @@ void VkFunctorDrawHandler::draw(const GrBackendDrawableInfo& info) {
.clip_top = mClip.fTop,
.clip_right = mClip.fRight,
.clip_bottom = mClip.fBottom,
.is_layer = !vulkan_info.fFromSwapchainOrAndroidWindow,
};
mat4.getColMajor(&params.transform[0]);
params.secondary_command_buffer = vulkan_info.fSecondaryCommandBuffer;

View File

@@ -68,6 +68,9 @@ struct VkFunctorDrawParams {
int clip_top;
int clip_right;
int clip_bottom;
// Input: Whether destination surface is offscreen surface.
bool is_layer;
};
} // namespace uirenderer

View File

@@ -426,7 +426,7 @@ VulkanSurface::NativeBufferInfo* VulkanSurface::dequeueNativeBuffer() {
if (bufferInfo->skSurface.get() == nullptr) {
bufferInfo->skSurface = SkSurface::MakeFromAHardwareBuffer(
mGrContext, ANativeWindowBuffer_getHardwareBuffer(bufferInfo->buffer.get()),
kTopLeft_GrSurfaceOrigin, mWindowInfo.colorspace, nullptr);
kTopLeft_GrSurfaceOrigin, mWindowInfo.colorspace, nullptr, /*from_window=*/true);
if (bufferInfo->skSurface.get() == nullptr) {
ALOGE("SkSurface::MakeFromAHardwareBuffer failed");
mNativeWindow->cancelBuffer(mNativeWindow.get(), buffer,