Use GrDrawTarget::AutoClipRestore to set temporary irect clips.
authorbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 13 Dec 2012 20:38:14 +0000 (20:38 +0000)
committerbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 13 Dec 2012 20:38:14 +0000 (20:38 +0000)
R=robertphillips@google.com
Review URL: https://codereview.appspot.com/6937048

git-svn-id: http://skia.googlecode.com/svn/trunk@6793 2bbb7eff-a529-9590-31e7-b0007b416f81

src/gpu/GrClipMaskManager.cpp
src/gpu/GrDrawTarget.cpp
src/gpu/GrDrawTarget.h

index 0a64dd1e49d37be4e1249519126ce26893b06947..311a40504c9f7497280c0874fa5faf73b4324d6e 100644 (file)
@@ -542,19 +542,10 @@ bool GrClipMaskManager::createStencilClipMask(InitialState initialState,
 
         stencilBuffer->setLastClip(genID, clipSpaceIBounds, clipSpaceToStencilOffset);
 
-        // we set the current clip to the bounds so that our recursive draws are scissored to them.
-        // We use the copy of the GrClipData we just stashed on the SB to render from. We set it
-        // back after we finish drawing it into the stencil.
-        const GrClipData* oldClipData = fGpu->getClip();
-
+        // We set the current clip to the bounds so that our recursive draws are scissored to them.
         SkIRect stencilSpaceIBounds(clipSpaceIBounds);
         stencilSpaceIBounds.offset(clipSpaceToStencilOffset);
-
-        SkClipStack newClipStack(stencilSpaceIBounds);
-        GrClipData newClipData; // origin defaults to (0,0)
-        newClipData.fClipStack = &newClipStack;
-
-        fGpu->setClip(&newClipData);
+        GrDrawTarget::AutoClipRestore(fGpu, stencilSpaceIBounds);
 
         GrDrawTarget::AutoStateRestore asr(fGpu, GrDrawTarget::kReset_ASRInit);
         drawState = fGpu->drawState();
@@ -624,7 +615,6 @@ bool GrClipMaskManager::createStencilClipMask(InitialState initialState,
                                                          GrPathRendererChain::kStencilOnly_DrawType,
                                                          &stencilSupport);
                 if (NULL == pr) {
-                    fGpu->setClip(oldClipData);
                     return false;
                 }
             }
@@ -691,8 +681,6 @@ bool GrClipMaskManager::createStencilClipMask(InitialState initialState,
                 }
             }
         }
-        // restore clip
-        fGpu->setClip(oldClipData);
     }
     // set this last because recursive draws may overwrite it back to kNone.
     GrAssert(kNone_ClipMaskType == fCurrClipMaskType);
index 92b8a0335871beca9e039ddb4daade27068f86e7..9ede7438ba1ed64179c7b342b01da360f8c64573 100644 (file)
@@ -1218,6 +1218,15 @@ void GrDrawTarget::AutoReleaseGeometry::reset() {
     fIndices = NULL;
 }
 
+GrDrawTarget::AutoClipRestore::AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip) {
+    fTarget = target;
+    fClip = fTarget->getClip();
+    fStack.init();
+    fStack.get()->clipDevRect(newClip, SkRegion::kReplace_Op);
+    fReplacementClip.fClipStack = fStack.get();
+    target->setClip(&fReplacementClip);
+}
+
 void GrDrawTarget::Caps::print() const {
     static const char* gNY[] = {"NO", "YES"};
     GrPrintf("8 Bit Palette Support       : %s\n", gNY[fInternals.f8BitPaletteSupport]);
index fb83c1e2f4eec2524493eddbbdbc6091f6e2770e..6b756b896eec64cc9b136ae893404649dba0b73e 100644 (file)
 #ifndef GrDrawTarget_DEFINED
 #define GrDrawTarget_DEFINED
 
+#include "GrClipData.h"
 #include "GrDrawState.h"
 #include "GrIndexBuffer.h"
 #include "SkMatrix.h"
 #include "GrRefCnt.h"
 #include "GrTemplates.h"
 
+#include "SkClipStack.h"
 #include "SkPath.h"
-#include "SkXfermode.h"
 #include "SkTLazy.h"
 #include "SkTArray.h"
+#include "SkXfermode.h"
 
 class GrClipData;
 class GrPath;
@@ -641,12 +643,16 @@ public:
             fClip = fTarget->getClip();
         }
 
+        AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip);
+
         ~AutoClipRestore() {
             fTarget->setClip(fClip);
         }
     private:
-        GrDrawTarget*      fTarget;
-        const GrClipData*  fClip;
+        GrDrawTarget*           fTarget;
+        const GrClipData*       fClip;
+        SkTLazy<SkClipStack>    fStack;
+        GrClipData              fReplacementClip;
     };
 
     ////////////////////////////////////////////////////////////////////////////