diff options
author | Stan Iliev <stani@google.com> | 2019-02-03 18:01:02 -0500 |
---|---|---|
committer | Stan Iliev <stani@google.com> | 2019-02-04 11:51:20 -0500 |
commit | 90276c86219c128d1343c6b26d95014fdd40b7fd (patch) | |
tree | 3abb27a51750062bf646390c4dfe2a15a75b077c /libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp | |
parent | 912ca4023c22c53d3526ce89fd6e7e1a90fe8e58 (diff) |
Fix crash when VulkanSurface is no longer valid
SkiaVulkanPipeline::mVkSurface can become obsolete if
RenderThread destroys Vulkan context. This CL enables
RenderThread to notify active Vulkan pipelines that their
surface is invalid.
Improve error handling, when trying to draw a frame with null
VulkanSurface.
Bug: 123640274
Bug: 123541940
Test: Ran several apps
Change-Id: If7fba00713d097192c96179df36e90b54f4f8090
Diffstat (limited to 'libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp')
-rw-r--r-- | libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp b/libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp index d0fe022616c5..15f53f286261 100644 --- a/libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp +++ b/libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp @@ -42,7 +42,13 @@ namespace uirenderer { namespace skiapipeline { SkiaVulkanPipeline::SkiaVulkanPipeline(renderthread::RenderThread& thread) - : SkiaPipeline(thread), mVkManager(thread.vulkanManager()) {} + : SkiaPipeline(thread), mVkManager(thread.vulkanManager()) { + thread.renderState().registerContextCallback(this); +} + +SkiaVulkanPipeline::~SkiaVulkanPipeline() { + mRenderThread.renderState().removeContextCallback(this); +} MakeCurrentResult SkiaVulkanPipeline::makeCurrent() { return MakeCurrentResult::AlreadyCurrent; @@ -53,6 +59,8 @@ Frame SkiaVulkanPipeline::getFrame() { "drawRenderNode called on a context with no surface!"); SkSurface* backBuffer = mVkManager.getBackbufferSurface(&mVkSurface); + LOG_ALWAYS_FATAL_IF(mVkSurface == nullptr, + "drawRenderNode called on a context with an invalid surface"); if (backBuffer == nullptr) { SkDebugf("failed to get backbuffer"); return Frame(-1, -1, 0); @@ -153,6 +161,13 @@ sk_sp<Bitmap> SkiaVulkanPipeline::allocateHardwareBitmap(renderthread::RenderThr return nullptr; } +void SkiaVulkanPipeline::onContextDestroyed() { + if (mVkSurface) { + mVkManager.destroySurface(mVkSurface); + mVkSurface = nullptr; + } +} + } /* namespace skiapipeline */ } /* namespace uirenderer */ } /* namespace android */ |