diff options
author | Stan Iliev <stani@google.com> | 2019-03-22 14:42:36 -0400 |
---|---|---|
committer | Stan Iliev <stani@google.com> | 2019-03-29 13:49:20 +0000 |
commit | 27b119ba5c1d94d6e3bc8ce8ee5da1a34efe196f (patch) | |
tree | 3d2c22950052a7576e486b9f3365e61e6c80abb5 /libs/hwui/pipeline/skia/VkFunctorDrawable.cpp | |
parent | 60852eab5cc5c505b1142f8c36b14fb97ec1cadb (diff) |
Fix crash in Vulkan WebView drawable when parent View has alpha
HWUI uses SkPaintFilterCanvas to apply View alpha in nested draw
calls. This conflicts with new SkDrawable::snapGpuDrawHandler
API used by Vulkan WebView. The new API works only with GPU
device (see SkGpuDevice::drawDrawable), which SkPaintFilterCanvas
does not have (it uses SkNoPixelsDevice instead).
This CL uses new Skia API to find wrapped GPU canvas and
draw SkDrawable on it.
Improve SKP capture for Vulkan WebView to match GL.
Test: Ran Fandango app with Vulkan. Captured a SKP.
Bug: 128792554
Change-Id: I27040347dc25c799b4e75f50526f426e9e33b663
Diffstat (limited to 'libs/hwui/pipeline/skia/VkFunctorDrawable.cpp')
-rw-r--r-- | libs/hwui/pipeline/skia/VkFunctorDrawable.cpp | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/libs/hwui/pipeline/skia/VkFunctorDrawable.cpp b/libs/hwui/pipeline/skia/VkFunctorDrawable.cpp index ceab407cb939..1b9e53b21adb 100644 --- a/libs/hwui/pipeline/skia/VkFunctorDrawable.cpp +++ b/libs/hwui/pipeline/skia/VkFunctorDrawable.cpp @@ -19,6 +19,7 @@ #include "renderthread/VulkanManager.h" #include "renderthread/RenderThread.h" +#include <SkAndroidFrameworkUtils.h> #include <GrBackendDrawableInfo.h> #include <SkImage.h> #include <utils/Color.h> @@ -89,9 +90,29 @@ void VkFunctorDrawHandler::draw(const GrBackendDrawableInfo& info) { VkFunctorDrawable::~VkFunctorDrawable() { } -void VkFunctorDrawable::onDraw(SkCanvas* /*canvas*/) { - LOG_ALWAYS_FATAL("VkFunctorDrawable::onDraw() should never be called."); - // Instead of calling onDraw(), the call should come from onSnapGpuDrawHandler. +void VkFunctorDrawable::onDraw(SkCanvas* canvas) { + // "canvas" is either SkNWayCanvas created by SkiaPipeline::tryCapture (SKP capture use case) or + // AlphaFilterCanvas (used by RenderNodeDrawable to apply alpha in certain cases). + // "VkFunctorDrawable::onDraw" is not invoked for the most common case, when drawing in a GPU + // canvas. + + if (canvas->getGrContext() == nullptr) { + // We're dumping a picture, render a light-blue rectangle instead + SkPaint paint; + paint.setColor(0xFF81D4FA); + canvas->drawRect(mBounds, paint); + } else { + // Handle the case when "canvas" is AlphaFilterCanvas. Find the wrapped GPU canvas. + SkCanvas* gpuCanvas = SkAndroidFrameworkUtils::getBaseWrappedCanvas(canvas); + // Enforce "canvas" must be an AlphaFilterCanvas. For GPU canvas, the call should come from + // onSnapGpuDrawHandler. + LOG_ALWAYS_FATAL_IF( + gpuCanvas == canvas, + "VkFunctorDrawable::onDraw() should not be called with a GPU canvas!"); + + // This will invoke onSnapGpuDrawHandler and regular draw flow. + gpuCanvas->drawDrawable(this); + } } std::unique_ptr<FunctorDrawable::GpuDrawHandler> VkFunctorDrawable::onSnapGpuDrawHandler( |