ClearStencilClip in GrBatch
authorbsalomon <bsalomon@google.com>
Tue, 18 Aug 2015 17:33:30 +0000 (10:33 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 18 Aug 2015 17:33:30 +0000 (10:33 -0700)
Review URL: https://codereview.chromium.org/1288963004

12 files changed:
src/core/SkStringUtils.cpp
src/gpu/GrBufferedDrawTarget.cpp
src/gpu/GrBufferedDrawTarget.h
src/gpu/GrCommandBuilder.cpp
src/gpu/GrCommandBuilder.h
src/gpu/GrDrawTarget.cpp
src/gpu/GrDrawTarget.h
src/gpu/GrImmediateDrawTarget.cpp
src/gpu/GrImmediateDrawTarget.h
src/gpu/GrTargetCommands.cpp
src/gpu/GrTargetCommands.h
src/gpu/batches/GrClearBatch.h

index 35e5557..6f5699c 100644 (file)
@@ -57,7 +57,7 @@ SkString SkTabString(const SkString& string, int tabCnt) {
     }
     if (*input != '\0') {
         result.append(tabs);
+        result.append(input);
     }
-    result.append(input);
     return result;
 }
index c59d035..4959ddc 100644 (file)
@@ -69,12 +69,6 @@ void GrBufferedDrawTarget::onDrawPaths(const GrPathProcessor* pathProc,
                                opts);
 }
 
-void GrBufferedDrawTarget::clearStencilClip(const SkIRect& rect,
-                                            bool insideClip,
-                                            GrRenderTarget* renderTarget) {
-    fCommands->recordClearStencilClip(rect, insideClip, renderTarget);
-}
-
 void GrBufferedDrawTarget::onReset() {
     fCommands->reset();
     fPathIndexBuffer.rewind();
index e764512..962385e 100644 (file)
@@ -30,10 +30,6 @@ public:
 
     ~GrBufferedDrawTarget() override;
 
-    void clearStencilClip(const SkIRect& rect,
-                          bool insideClip,
-                          GrRenderTarget* renderTarget) override;
-
 protected:
     void appendIndicesAndTransforms(const void* indexValues, PathIndexType indexType, 
                                     const float* transformValues, PathTransformType transformType,
@@ -55,6 +51,8 @@ protected:
         }
     }
 
+    void onDrawBatch(GrBatch*) override;
+
 private:
     friend class GrInOrderCommandBuilder;
     friend class GrTargetCommands;
@@ -75,8 +73,6 @@ private:
     void onReset() override;
     void onFlush() override;
 
-    // overrides from GrDrawTarget
-    void onDrawBatch(GrBatch*) override;
     void onStencilPath(const GrPipelineBuilder&,
                        const GrPathProcessor*,
                        const GrPath*,
index 86c1668..2d86c1e 100644 (file)
@@ -18,20 +18,6 @@ GrCommandBuilder* GrCommandBuilder::Create(GrGpu* gpu, bool reorder) {
     }
 }
 
-GrTargetCommands::Cmd* GrCommandBuilder::recordClearStencilClip(const SkIRect& rect,
-                                                                bool insideClip,
-                                                                GrRenderTarget* renderTarget) {
-    SkASSERT(renderTarget);
-
-    ClearStencilClip* clr = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(),
-                                                     ClearStencilClip,
-                                                     (renderTarget));
-    clr->fRect = rect;
-    clr->fInsideClip = insideClip;
-    GrBATCH_INFO("Recording clear stencil clip %d\n", clr->uniqueID());
-    return clr;
-}
-
 GrTargetCommands::Cmd* GrCommandBuilder::recordCopySurface(GrSurface* dst,
                                                            GrSurface* src,
                                                            const SkIRect& srcRect,
index b50a6bb..473e0bf 100644 (file)
@@ -26,9 +26,6 @@ public:
     void reset() { fCommands.reset(); }
     void flush(GrGpu* gpu, GrResourceProvider* rp) { fCommands.flush(gpu, rp); }
 
-    virtual Cmd* recordClearStencilClip(const SkIRect& rect,
-                                        bool insideClip,
-                                        GrRenderTarget* renderTarget);
     virtual Cmd* recordDrawBatch(GrBatch*, const GrCaps&) = 0;
     virtual Cmd* recordStencilPath(const GrPipelineBuilder&,
                                    const GrPathProcessor*,
@@ -60,7 +57,6 @@ protected:
     typedef GrTargetCommands::StencilPath StencilPath;
     typedef GrTargetCommands::DrawPath DrawPath;
     typedef GrTargetCommands::DrawPaths DrawPaths;
-    typedef GrTargetCommands::ClearStencilClip ClearStencilClip;
     typedef GrTargetCommands::CopySurface CopySurface;
 
     GrCommandBuilder() {}
index d2c258d..3926739 100644 (file)
@@ -532,3 +532,9 @@ void GrClipTarget::purgeResources() {
     // get rid of them all.
     fClipMaskManager->purgeResources();
 };
+
+void GrClipTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* rt) {
+    GrBatch* batch = SkNEW_ARGS(GrClearStencilClipBatch, (rect, insideClip, rt));
+    this->onDrawBatch(batch);
+    batch->unref();
+}
index 1890883..b2d4aa5 100644 (file)
@@ -236,12 +236,13 @@ protected:
                                  GrXferProcessor::DstTexture*,
                                  const SkRect* drawBounds);
 
+    virtual void onDrawBatch(GrBatch*) = 0;
+
 private:
     virtual void onReset() = 0;
 
     virtual void onFlush() = 0;
 
-    virtual void onDrawBatch(GrBatch*) = 0;
     virtual void onStencilPath(const GrPipelineBuilder&,
                                const GrPathProcessor*,
                                const GrPath*,
@@ -311,7 +312,7 @@ public:
      * is free to clear the remaining bits to zero if masked clears are more
      * expensive than clearing all bits.
      */
-    virtual void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* = NULL) = 0;
+    void clearStencilClip(const SkIRect&, bool insideClip, GrRenderTarget*);
 
     /**
      * Release any resources that are cached but not currently in use. This
index 55af985..dee30d2 100644 (file)
@@ -47,12 +47,6 @@ void GrImmediateDrawTarget::onCopySurface(GrSurface* dst,
     this->getGpu()->copySurface(dst, src, srcRect, dstPoint);
 }
 
-void GrImmediateDrawTarget::clearStencilClip(const SkIRect& rect,
-                                             bool insideClip,
-                                             GrRenderTarget* renderTarget) {
-    this->getGpu()->clearStencilClip(rect, insideClip, renderTarget);
-}
-
 void GrImmediateDrawTarget::onReset() {}
 
 void GrImmediateDrawTarget::onFlush() {
index 10b7e24..e1baebe 100644 (file)
@@ -26,16 +26,13 @@ public:
 
     ~GrImmediateDrawTarget() override;
 
-    void clearStencilClip(const SkIRect& rect,
-                          bool insideClip,
-                          GrRenderTarget* renderTarget) override;
+protected:
+    void onDrawBatch(GrBatch*) override;
 
 private:
     void onReset() override;
     void onFlush() override;
 
-    // overrides from GrDrawTarget
-    void onDrawBatch(GrBatch*) override;
     void onStencilPath(const GrPipelineBuilder&,
                        const GrPathProcessor*,
                        const GrPath*,
index 7a75661..befee79 100644 (file)
@@ -76,10 +76,6 @@ void GrTargetCommands::DrawBatch::execute(GrBatchFlushState* state) {
     fBatch->draw(state);
 }
 
-void GrTargetCommands::ClearStencilClip::execute(GrBatchFlushState* state) {
-    state->gpu()->clearStencilClip(fRect, fInsideClip, this->renderTarget());
-}
-
 void GrTargetCommands::CopySurface::execute(GrBatchFlushState* state) {
     state->gpu()->copySurface(this->dst(), this->src(), fSrcRect, fDstPoint);
 }
index cf3054d..39199f3 100644 (file)
@@ -31,11 +31,10 @@ public:
     public:
         enum CmdType {
             kStencilPath_CmdType       = 1,
-            kClearStencil_CmdType      = 2,
-            kCopySurface_CmdType       = 3,
-            kDrawPath_CmdType          = 4,
-            kDrawPaths_CmdType         = 5,
-            kDrawBatch_CmdType         = 6,
+            kCopySurface_CmdType       = 2,
+            kDrawPath_CmdType          = 3,
+            kDrawPaths_CmdType         = 4,
+            kDrawBatch_CmdType         = 5,
         };
 
         Cmd(CmdType type)
@@ -177,21 +176,6 @@ private:
         GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange;
     };
 
-    // This command is ONLY used by the clip mask manager to clear the stencil clip bits
-    struct ClearStencilClip : public Cmd {
-        ClearStencilClip(GrRenderTarget* rt) : Cmd(kClearStencil_CmdType), fRenderTarget(rt) {}
-
-        GrRenderTarget* renderTarget() const { return fRenderTarget.get(); }
-
-        void execute(GrBatchFlushState*) override;
-
-        SkIRect fRect;
-        bool    fInsideClip;
-
-    private:
-        GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget;
-    };
-
     struct CopySurface : public Cmd {
         CopySurface(GrSurface* dst, GrSurface* src)
             : Cmd(kCopySurface_CmdType)
index 0a2153f..f13b073 100644 (file)
@@ -52,4 +52,40 @@ private:
     GrPendingIOResource<GrRenderTarget, kWrite_GrIOType>    fRenderTarget;
 };
 
+class GrClearStencilClipBatch final : public GrBatch {
+public:
+    GrClearStencilClipBatch(const SkIRect& rect, bool insideClip, GrRenderTarget* rt)
+        : fRect(rect)
+        , fInsideClip(insideClip)
+        , fRenderTarget(rt) {
+        this->initClassID<GrClearStencilClipBatch>();
+        fBounds = SkRect::Make(rect);
+    }
+
+    const char* name() const override { return "ClearStencilClip"; }
+
+    uint32_t renderTargetUniqueID() const override { return fRenderTarget.get()->getUniqueID(); }
+
+    SkString dumpInfo() const override {
+        SkString string;
+        string.printf("Rect [L: %d, T: %d, R: %d, B: %d], IC: %d, RT: 0x%p",
+                      fRect.fLeft, fRect.fTop, fRect.fRight, fRect.fBottom, fInsideClip,
+                      fRenderTarget.get());
+        return string;
+    }
+
+private:
+    bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { return false; }
+
+    void onPrepare(GrBatchFlushState*) override {}
+
+    void onDraw(GrBatchFlushState* state) override {
+        state->gpu()->clearStencilClip(fRect, fInsideClip, fRenderTarget.get());
+    }
+
+    SkIRect                                                 fRect;
+    bool                                                    fInsideClip;
+    GrPendingIOResource<GrRenderTarget, kWrite_GrIOType>    fRenderTarget;
+};
+
 #endif