From ab762153fb6156ac014bd715100697e20aac9516 Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Wed, 16 Sep 2020 10:37:19 -0400 Subject: [PATCH] Migrate from SkCanvas::getGrContext to SkCanvas::recordingContext This is part of API cleanup as we make DDL usage more mainstream in Skia. Since Android doesn't use DDLs, the cast from recordingContext to directContext will always succeed and there's no functional change. Change-Id: Ie585cf6c97d01fecf082f146d5692999371fd39d --- libs/hwui/pipeline/skia/GLFunctorDrawable.cpp | 9 +++++---- libs/hwui/pipeline/skia/SkiaPipeline.cpp | 7 ++++--- libs/hwui/pipeline/skia/VkFunctorDrawable.cpp | 2 +- libs/hwui/pipeline/skia/VkInteropFunctorDrawable.cpp | 2 +- libs/hwui/renderthread/CanvasContext.h | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/libs/hwui/pipeline/skia/GLFunctorDrawable.cpp b/libs/hwui/pipeline/skia/GLFunctorDrawable.cpp index dd0fc695c246a..bfbdc5c009c0d 100644 --- a/libs/hwui/pipeline/skia/GLFunctorDrawable.cpp +++ b/libs/hwui/pipeline/skia/GLFunctorDrawable.cpp @@ -56,7 +56,8 @@ static void GetFboDetails(SkCanvas* canvas, GLuint* outFboID, SkISize* outFboSiz } void GLFunctorDrawable::onDraw(SkCanvas* canvas) { - if (canvas->getGrContext() == nullptr) { + GrDirectContext* directContext = GrAsDirectContext(canvas->recordingContext()); + if (directContext == nullptr) { // We're dumping a picture, render a light-blue rectangle instead // TODO: Draw the WebView text on top? Seemingly complicated as SkPaint doesn't // seem to have a default typeface that works. We only ever use drawGlyphs, which @@ -87,7 +88,7 @@ void GLFunctorDrawable::onDraw(SkCanvas* canvas) { SkImageInfo surfaceInfo = canvas->imageInfo().makeWH(clipBounds.width(), clipBounds.height()); tmpSurface = - SkSurface::MakeRenderTarget(canvas->getGrContext(), SkBudgeted::kYes, surfaceInfo); + SkSurface::MakeRenderTarget(directContext, SkBudgeted::kYes, surfaceInfo); tmpSurface->getCanvas()->clear(SK_ColorTRANSPARENT); GrGLFramebufferInfo fboInfo; @@ -141,7 +142,7 @@ void GLFunctorDrawable::onDraw(SkCanvas* canvas) { // notify Skia that we just updated the FBO and stencil const uint32_t grState = kStencil_GrGLBackendState | kRenderTarget_GrGLBackendState; - canvas->getGrContext()->resetContext(grState); + directContext->resetContext(grState); SkCanvas* tmpCanvas = canvas; if (tmpSurface) { @@ -188,7 +189,7 @@ void GLFunctorDrawable::onDraw(SkCanvas* canvas) { glClear(GL_STENCIL_BUFFER_BIT); } - canvas->getGrContext()->resetContext(); + directContext->resetContext(); // if there were unclipped save layers involved we draw our offscreen surface to the canvas if (tmpSurface) { diff --git a/libs/hwui/pipeline/skia/SkiaPipeline.cpp b/libs/hwui/pipeline/skia/SkiaPipeline.cpp index 6dd36981e8aab..6e7493cb443d7 100644 --- a/libs/hwui/pipeline/skia/SkiaPipeline.cpp +++ b/libs/hwui/pipeline/skia/SkiaPipeline.cpp @@ -86,7 +86,7 @@ void SkiaPipeline::renderLayers(const LightGeometry& lightGeometry, } void SkiaPipeline::renderLayersImpl(const LayerUpdateQueue& layers, bool opaque) { - sk_sp cachedContext; + sk_sp cachedContext; // Render all layers that need to be updated, in order. for (size_t i = 0; i < layers.entries().size(); i++) { @@ -142,7 +142,8 @@ void SkiaPipeline::renderLayersImpl(const LayerUpdateQueue& layers, bool opaque) // cache the current context so that we can defer flushing it until // either all the layers have been rendered or the context changes - GrContext* currentContext = layerNode->getLayerSurface()->getCanvas()->getGrContext(); + GrDirectContext* currentContext = + GrAsDirectContext(layerNode->getLayerSurface()->getCanvas()->recordingContext()); if (cachedContext.get() != currentContext) { if (cachedContext.get()) { ATRACE_NAME("flush layers (context changed)"); @@ -201,7 +202,7 @@ bool SkiaPipeline::createOrUpdateLayer(RenderNode* node, const DamageAccumulator } void SkiaPipeline::prepareToDraw(const RenderThread& thread, Bitmap* bitmap) { - GrContext* context = thread.getGrContext(); + GrDirectContext* context = thread.getGrContext(); if (context) { ATRACE_FORMAT("Bitmap#prepareToDraw %dx%d", bitmap->width(), bitmap->height()); auto image = bitmap->makeImage(); diff --git a/libs/hwui/pipeline/skia/VkFunctorDrawable.cpp b/libs/hwui/pipeline/skia/VkFunctorDrawable.cpp index 50b45e6eb7ec8..6efe1762976b5 100644 --- a/libs/hwui/pipeline/skia/VkFunctorDrawable.cpp +++ b/libs/hwui/pipeline/skia/VkFunctorDrawable.cpp @@ -96,7 +96,7 @@ void VkFunctorDrawable::onDraw(SkCanvas* canvas) { // "VkFunctorDrawable::onDraw" is not invoked for the most common case, when drawing in a GPU // canvas. - if (canvas->getGrContext() == nullptr) { + if (canvas->recordingContext() == nullptr) { // We're dumping a picture, render a light-blue rectangle instead SkPaint paint; paint.setColor(0xFF81D4FA); diff --git a/libs/hwui/pipeline/skia/VkInteropFunctorDrawable.cpp b/libs/hwui/pipeline/skia/VkInteropFunctorDrawable.cpp index 403d9075dbd13..bc8ce428ce2e5 100644 --- a/libs/hwui/pipeline/skia/VkInteropFunctorDrawable.cpp +++ b/libs/hwui/pipeline/skia/VkInteropFunctorDrawable.cpp @@ -67,7 +67,7 @@ void VkInteropFunctorDrawable::vkInvokeFunctor(Functor* functor) { void VkInteropFunctorDrawable::onDraw(SkCanvas* canvas) { ATRACE_CALL(); - if (canvas->getGrContext() == nullptr) { + if (canvas->recordingContext() == nullptr) { SkDEBUGF(("Attempting to draw VkInteropFunctor into an unsupported surface")); return; } diff --git a/libs/hwui/renderthread/CanvasContext.h b/libs/hwui/renderthread/CanvasContext.h index cba710f010632..cc4eb3285bbec 100644 --- a/libs/hwui/renderthread/CanvasContext.h +++ b/libs/hwui/renderthread/CanvasContext.h @@ -106,7 +106,7 @@ public: * If Properties::isSkiaEnabled() is true then this will return the Skia * grContext associated with the current RenderPipeline. */ - GrContext* getGrContext() const { return mRenderThread.getGrContext(); } + GrDirectContext* getGrContext() const { return mRenderThread.getGrContext(); } // Won't take effect until next EGLSurface creation void setSwapBehavior(SwapBehavior swapBehavior);