Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 372a21b3 authored by Vasiliy Telezhnikov's avatar Vasiliy Telezhnikov
Browse files

Enable WebView overlays for Vulkan

This CL uses new skia api to determine if we're drawing on screen or
offscreen for vulkan and enables overlays when possible.

Bug: 185730234
Test: manual
Change-Id: Ib7748535431e4dc56b1af6d7ccc729b3b649df96
parent f3a0bf47
Loading
Loading
Loading
Loading
+24 −15
Original line number Diff line number Diff line
@@ -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) {
    if (!drawInfo.isLayer && prepareRootSurfaceControl()) {
        overlayParams.overlaysMode = OverlaysMode::Enabled;
                int32_t rgid = activeContext->getSurfaceControlGenerationId();
                if (mParentSurfaceControlGenerationId != rgid) {
                    reparentSurfaceControl(rootSurfaceControl);
                    mParentSurfaceControlGenerationId = rgid;
                }
            }
        }
    }

    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);
}

+1 −0
Original line number Diff line number Diff line
@@ -88,6 +88,7 @@ public:
    }

private:
    bool prepareRootSurfaceControl();
    void reparentSurfaceControl(ASurfaceControl* parent);

private:
+1 −0
Original line number Diff line number Diff line
@@ -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;
+3 −0
Original line number Diff line number Diff line
@@ -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
+1 −1
Original line number Diff line number Diff line
@@ -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,