From 87a94eb1632d06eeeb89490a91565e786440d6d0 Mon Sep 17 00:00:00 2001 From: bsalomon Date: Mon, 3 Nov 2014 14:28:32 -0800 Subject: [PATCH] Rename and clarify semantics of GrContext::resolveRenderTarget. Review URL: https://codereview.chromium.org/696293004 --- include/gpu/GrContext.h | 16 +++++++--------- include/gpu/GrRenderTarget.h | 8 -------- include/gpu/GrSurface.h | 7 +++++++ src/gpu/GrContext.cpp | 15 +++++++++------ src/gpu/GrRenderTarget.cpp | 9 --------- src/gpu/GrSurface.cpp | 6 ++++++ src/gpu/SkGpuDevice.cpp | 2 +- 7 files changed, 30 insertions(+), 33 deletions(-) diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index d4c22349d1..464f36d123 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -659,17 +659,15 @@ public: void flushSurfaceWrites(GrSurface* surface); /** - * Resolves a render target that has MSAA. The intermediate MSAA buffer is - * down-sampled to the associated GrTexture (accessible via - * GrRenderTarget::asTexture()). Any pending draws to the render target will - * be executed before the resolve. + * Equivalent to flushSurfaceWrites but also performs MSAA resolve if necessary. This call is + * used to make the surface contents available to be read in the backend 3D API, usually for a + * compositing step external to Skia. * - * This is only necessary when a client wants to access the object directly - * using the backend API directly. GrContext will detect when it must - * perform a resolve to a GrTexture used as the source of a draw or before - * reading pixels back from a GrTexture or GrRenderTarget. + * It is not necessary to call this before reading the render target via Skia/GrContext. + * GrContext will detect when it must perform a resolve before reading pixels back from the + * surface or using it as a texture. */ - void resolveRenderTarget(GrRenderTarget*); + void prepareSurfaceForExternalRead(GrSurface*); /** * Provides a perfomance hint that the render target's contents are allowed diff --git a/include/gpu/GrRenderTarget.h b/include/gpu/GrRenderTarget.h index e0f11999f4..6b5a961f8b 100644 --- a/include/gpu/GrRenderTarget.h +++ b/include/gpu/GrRenderTarget.h @@ -86,14 +86,6 @@ public: */ const SkIRect& getResolveRect() const { return fResolveRect; } - /** - * If the render target is multisampled this will perform a multisample - * resolve. Any pending draws to the target are first flushed. This only - * applies to render targets that are associated with GrTextures. After the - * function returns the GrTexture will contain the resolved pixels. - */ - void resolve(); - /** * Provide a performance hint that the render target's contents are allowed * to become undefined. diff --git a/include/gpu/GrSurface.h b/include/gpu/GrSurface.h index 9d891493b0..0de626d16e 100644 --- a/include/gpu/GrSurface.h +++ b/include/gpu/GrSurface.h @@ -116,6 +116,13 @@ public: */ void flushWrites(); + + /** + * After this returns any pending writes to the surface will be issued to the backend 3D API and + * if the surface has MSAA it will be resolved. + */ + void prepareForExternalRead(); + /** Access methods that are only to be used within Skia code. */ inline GrSurfacePriv surfacePriv(); inline const GrSurfacePriv surfacePriv() const; diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 9d684aa135..d95b4fe088 100755 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -1534,12 +1534,15 @@ bool GrContext::readRenderTargetPixels(GrRenderTarget* target, return true; } -void GrContext::resolveRenderTarget(GrRenderTarget* target) { - SkASSERT(target); - ASSERT_OWNED_RESOURCE(target); - this->flush(); - if (fGpu) { - fGpu->resolveRenderTarget(target); +void GrContext::prepareSurfaceForExternalRead(GrSurface* surface) { + SkASSERT(surface); + ASSERT_OWNED_RESOURCE(surface); + if (surface->surfacePriv().hasPendingIO()) { + this->flush(); + } + GrRenderTarget* rt = surface->asRenderTarget(); + if (fGpu && rt) { + fGpu->resolveRenderTarget(rt); } } diff --git a/src/gpu/GrRenderTarget.cpp b/src/gpu/GrRenderTarget.cpp index 7aeb4eec1a..386bd2e779 100644 --- a/src/gpu/GrRenderTarget.cpp +++ b/src/gpu/GrRenderTarget.cpp @@ -13,15 +13,6 @@ #include "GrGpu.h" #include "GrStencilBuffer.h" -void GrRenderTarget::resolve() { - // go through context so that all necessary flushing occurs - GrContext* context = this->getContext(); - if (NULL == context) { - return; - } - context->resolveRenderTarget(this); -} - void GrRenderTarget::discard() { // go through context so that all necessary flushing occurs GrContext* context = this->getContext(); diff --git a/src/gpu/GrSurface.cpp b/src/gpu/GrSurface.cpp index 0aa5f681ab..1779f2441b 100644 --- a/src/gpu/GrSurface.cpp +++ b/src/gpu/GrSurface.cpp @@ -82,6 +82,12 @@ void GrSurface::flushWrites() { } } +void GrSurface::prepareForExternalRead() { + if (!this->wasDestroyed()) { + this->getContext()->prepareSurfaceForExternalRead(this); + } +} + bool GrSurface::hasPendingRead() const { const GrTexture* thisTex = this->asTexture(); if (thisTex && thisTex->internalHasPendingRead()) { diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 075d4d8af4..da81c696d2 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -1747,7 +1747,7 @@ bool SkGpuDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) { void SkGpuDevice::flush() { DO_DEFERRED_CLEAR(); - fContext->resolveRenderTarget(fRenderTarget); + fRenderTarget->prepareForExternalRead(); } ///////////////////////////////////////////////////////////////////////////////