Don't allow renderTarget==NULL to GrContext::clear() and friends.
authorbsalomon <bsalomon@google.com>
Mon, 3 Nov 2014 20:08:42 +0000 (12:08 -0800)
committerCommit bot <commit-bot@chromium.org>
Mon, 3 Nov 2014 20:08:42 +0000 (12:08 -0800)
Review URL: https://codereview.chromium.org/680413005

include/gpu/GrContext.h
src/effects/SkAlphaThresholdFilter.cpp
src/effects/SkGpuBlurUtils.cpp
src/effects/SkMorphologyImageFilter.cpp
src/gpu/GrContext.cpp
src/gpu/GrDrawTarget.h
src/gpu/GrGpu.cpp
src/gpu/GrGpu.h
src/gpu/GrInOrderDrawBuffer.cpp
src/gpu/SkGpuDevice.cpp
src/gpu/gl/GrGpuGL.cpp

index 001ba880270f77b1dacbd88fd2e622afe0d336c3..d4c22349d1405f326660e80162c86bff2f27b277 100644 (file)
@@ -434,11 +434,9 @@ public:
      * @param color the color to clear to.
      * @param canIgnoreRect allows partial clears to be converted to whole
      *                      clears on platforms for which that is cheap
-     * @param target if non-NULL, the render target to clear otherwise clear
-     *               the current render target
+     * @param target The render target to clear.
      */
-    void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect,
-               GrRenderTarget* target = NULL);
+    void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect, GrRenderTarget* target);
 
     /**
      *  Draw everywhere (respecting the clip) with the paint.
@@ -586,7 +584,7 @@ public:
 
     /**
      * Reads a rectangle of pixels from a render target.
-     * @param target        the render target to read from. NULL means the current render target.
+     * @param target        the render target to read from.
      * @param left          left edge of the rectangle to read (inclusive)
      * @param top           top edge of the rectangle to read (inclusive)
      * @param width         width of rectangle to read in pixels.
index 326f005e36290310c1685e747d05c3e8507e7056..c3ad87a3b8a23bb91f8b1db54d1e26c98441abc2 100644 (file)
@@ -294,7 +294,7 @@ bool SkAlphaThresholdFilterImpl::asFragmentProcessor(GrFragmentProcessor** fp,
             GrPaint grPaint;
             grPaint.setBlendFunc(kOne_GrBlendCoeff, kZero_GrBlendCoeff);
             SkRegion::Iterator iter(fRegion);
-            context->clear(NULL, 0x0, true);
+            context->clear(NULL, 0x0, true, maskTexture->asRenderTarget());
 
             SkMatrix old_matrix = context->getMatrix();
             context->setMatrix(in_matrix);
index 3654407ddaf2b114f4592903041ce9b31b8eb10c..2d836842728a3a9bb8c8d84e92e0a60f53cdcc00 100644 (file)
@@ -250,7 +250,7 @@ GrTexture* GaussianBlur(GrContext* context,
                 // X convolution from reading garbage.
                 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop,
                                               radiusX, srcIRect.height());
-                context->clear(&clearRect, 0x0, false);
+                context->clear(&clearRect, 0x0, false, context->getRenderTarget());
             }
             context->setRenderTarget(dstTexture->asRenderTarget());
             SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
@@ -267,7 +267,7 @@ GrTexture* GaussianBlur(GrContext* context,
                 // convolution from reading garbage.
                 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom,
                                               srcIRect.width(), radiusY);
-                context->clear(&clearRect, 0x0, false);
+                context->clear(&clearRect, 0x0, false, context->getRenderTarget());
             }
 
             context->setRenderTarget(dstTexture->asRenderTarget());
@@ -285,10 +285,10 @@ GrTexture* GaussianBlur(GrContext* context,
         // upsampling.
         clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom,
                                       srcIRect.width() + 1, 1);
-        context->clear(&clearRect, 0x0, false);
+        context->clear(&clearRect, 0x0, false, context->getRenderTarget());
         clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop,
                                       1, srcIRect.height());
-        context->clear(&clearRect, 0x0, false);
+        context->clear(&clearRect, 0x0, false, context->getRenderTarget());
         SkMatrix matrix;
         matrix.setIDiv(srcTexture->width(), srcTexture->height());
         context->setRenderTarget(dstTexture->asRenderTarget());
index 05fc1fdb211fc028ccea6a1a2ee61ac2d6238b76..72c98dd97eaa1592ee7aeb5ef5e60ac20858f4f1 100644 (file)
@@ -530,9 +530,10 @@ bool apply_morphology(const SkBitmap& input,
                               morphType, Gr1DKernelEffect::kX_Direction);
         SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom,
                                               dstRect.width(), radius.fHeight);
-        context->clear(&clearRect, GrMorphologyEffect::kErode_MorphologyType == morphType ?
-                                   SK_ColorWHITE :
-                                   SK_ColorTRANSPARENT, false);
+        GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphType ?
+                                SK_ColorWHITE :
+                                SK_ColorTRANSPARENT;
+        context->clear(&clearRect, clearColor, false, texture->asRenderTarget());
         srcTexture.reset(texture);
         srcRect = dstRect;
     }
index c1fee0acb82b5a17b338b735e4fc0f66dd5a0a5e..8c5abe78357eebb08731b3c887d603f4b56ca9ff 100755 (executable)
@@ -580,6 +580,8 @@ void GrContext::clear(const SkIRect* rect,
                       bool canIgnoreRect,
                       GrRenderTarget* renderTarget) {
     ASSERT_OWNED_RESOURCE(renderTarget);
+    SkASSERT(renderTarget);
+
     AutoRestoreEffects are;
     AutoCheckFlush acf(this);
     GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this);
@@ -753,7 +755,7 @@ void GrContext::drawRect(const GrPaint& paint,
                 // Will it blend?
                 GrColor clearColor;
                 if (paint.isOpaqueAndConstantColor(&clearColor)) {
-                    target->clear(NULL, clearColor, true);
+                    target->clear(NULL, clearColor, true, fRenderTarget);
                     return;
                 }
             }
@@ -1400,13 +1402,7 @@ bool GrContext::readRenderTargetPixels(GrRenderTarget* target,
                                        GrPixelConfig dstConfig, void* buffer, size_t rowBytes,
                                        uint32_t flags) {
     ASSERT_OWNED_RESOURCE(target);
-
-    if (NULL == target) {
-        target = fRenderTarget.get();
-        if (NULL == target) {
-            return false;
-        }
-    }
+    SkASSERT(target);
 
     if (!(kDontFlush_PixelOpsFlag & flags) && target->surfacePriv().hasPendingWrite()) {
         this->flush();
@@ -1541,10 +1537,12 @@ bool GrContext::readRenderTargetPixels(GrRenderTarget* target,
 void GrContext::resolveRenderTarget(GrRenderTarget* target) {
     SkASSERT(target);
     ASSERT_OWNED_RESOURCE(target);
-    // In the future we may track whether there are any pending draws to this
-    // target. We don't today so we always perform a flush. We don't promise
-    // this to our clients, though.
-    this->flush();
+    if (!target->needsResolve()) {
+        return;
+    }
+    if (target->surfacePriv().hasPendingIO()) {
+        this->flush();
+    }
     if (fGpu) {
         fGpu->resolveRenderTarget(target);
     }
index 4545f74d256c6c7849d8e2f636295030c12ef508..955581b68368f7f3cddd766994a077b924e12d55 100644 (file)
@@ -410,21 +410,17 @@ public:
                               const SkRect* devBounds = NULL);
 
     /**
-     * Clear the current render target if one isn't passed in. Ignores the
-     * clip and all other draw state (blend mode, stages, etc). Clears the
-     * whole thing if rect is NULL, otherwise just the rect. If canIgnoreRect
-     * is set then the entire render target can be optionally cleared.
+     * Clear the passed in render target. Ignores the draw state and clip. Clears the whole thing if
+     * rect is NULL, otherwise just the rect. If canIgnoreRect is set then the entire render target
+     * can be optionally cleared.
      */
-    virtual void clear(const SkIRect* rect,
-                       GrColor color,
-                       bool canIgnoreRect,
-                       GrRenderTarget* renderTarget = NULL) = 0;
+    virtual void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect,
+                       GrRenderTarget* renderTarget) = 0;
 
     /**
-     * Discards the contents render target. NULL indicates that the current render target should
-     * be discarded.
+     * Discards the contents render target.
      **/
-    virtual void discard(GrRenderTarget* = NULL) = 0;
+    virtual void discard(GrRenderTarget*) = 0;
 
     /**
      * Called at start and end of gpu trace marking
index 2f4f0a68c873c3546d3b0db68861c20d14de016e..f7b9537ecc8eb7f98e372b73cc69d214488a8cc9 100644 (file)
@@ -198,13 +198,7 @@ void GrGpu::clear(const SkIRect* rect,
                   GrColor color,
                   bool canIgnoreRect,
                   GrRenderTarget* renderTarget) {
-    if (NULL == renderTarget) {
-        renderTarget = this->getDrawState().getRenderTarget();
-    }
-    if (NULL == renderTarget) {
-        SkASSERT(0);
-        return;
-    }
+    SkASSERT(renderTarget);
     this->handleDirtyContext();
     this->onClear(renderTarget, rect, color, canIgnoreRect);
 }
index 0e2ec88b8c19a15e332fca6d37d09ffaa4e2ab07..5f6505549ba0f4e6219aa587548584dade0c00cd 100644 (file)
@@ -266,10 +266,8 @@ public:
                             size_t rowBytes);
 
     // GrDrawTarget overrides
-    virtual void clear(const SkIRect* rect,
-                       GrColor color,
-                       bool canIgnoreRect,
-                       GrRenderTarget* renderTarget = NULL) SK_OVERRIDE;
+    virtual void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect,
+                       GrRenderTarget* renderTarget) SK_OVERRIDE;
 
     virtual void clearStencilClip(const SkIRect& rect,
                                   bool insideClip,
index b671742309f862783f77b07a53b18795305f36cb..04ce17b8b6d2f55ed3291144493dbc4c76fdb37d 100644 (file)
@@ -450,13 +450,10 @@ void GrInOrderDrawBuffer::clearStencilClip(const SkIRect& rect,
 }
 
 void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) {
+    SkASSERT(renderTarget);
     if (!this->caps()->discardRenderTargetSupport()) {
         return;
     }
-    if (NULL == renderTarget) {
-        renderTarget = this->drawState()->getRenderTarget();
-        SkASSERT(renderTarget);
-    }
     Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget));
     clr->fColor = GrColor_ILLEGAL;
     this->recordTraceMarkersIfNecessary();
index 330a2fc420e0b1bfc1fa0916bd86350bdd47f4a9..075d4d8af49f337e32c6abc6fe1f855ee07ea673 100644 (file)
@@ -658,7 +658,7 @@ GrTexture* create_mask_GPU(GrContext* context,
     GrContext::AutoRenderTarget art(context, mask->asRenderTarget());
     GrContext::AutoClip ac(context, clipRect);
 
-    context->clear(NULL, 0x0, true);
+    context->clear(NULL, 0x0, true, mask->asRenderTarget());
 
     GrPaint tempPaint;
     if (doAA) {
index 6c35e9f2d3f888b626e8a1f8eb3375c6408dba80..621bef8f87517e3c18f5066d72d01f46c245783e 100644 (file)
@@ -1401,15 +1401,10 @@ void GrGpuGL::onClear(GrRenderTarget* target, const SkIRect* rect, GrColor color
 }
 
 void GrGpuGL::discard(GrRenderTarget* renderTarget) {
+    SkASSERT(renderTarget);
     if (!this->caps()->discardRenderTargetSupport()) {
         return;
     }
-    if (NULL == renderTarget) {
-        renderTarget = this->drawState()->getRenderTarget();
-        if (NULL == renderTarget) {
-            return;
-        }
-    }
 
     GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(renderTarget);
     if (renderTarget->getUniqueID() != fHWBoundRenderTargetUniqueID) {