Move some auto restore helpers from GrDrawTarget to GrDrawState.
authorbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 5 Oct 2012 20:13:28 +0000 (20:13 +0000)
committerbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 5 Oct 2012 20:13:28 +0000 (20:13 +0000)
R=robertphillips@google.com

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

src/gpu/GrContext.cpp
src/gpu/GrDrawState.cpp
src/gpu/GrDrawState.h
src/gpu/GrDrawTarget.cpp
src/gpu/GrDrawTarget.h
src/gpu/GrInOrderDrawBuffer.cpp
src/gpu/GrSWMaskHelper.cpp
src/gpu/GrSoftwarePathRenderer.cpp

index 3e53c19ff8f31e3b2e99666984dc7232c59c6d1d..7e0c915fc94a662fafb2fb1d5b8747bc377bbe60 100644 (file)
@@ -743,7 +743,7 @@ void GrContext::drawRect(const GrPaint& paint,
                                            &useVertexCoverage);
 
     if (doAA) {
-        GrDrawTarget::AutoDeviceCoordDraw adcd(target);
+        GrDrawState::AutoDeviceCoordDraw adcd(target->drawState());
         if (!adcd.succeeded()) {
             return;
         }
@@ -1034,7 +1034,7 @@ void GrContext::drawOval(const GrPaint& paint,
         return;
     }
 
-    GrDrawTarget::AutoDeviceCoordDraw adcd(target);
+    GrDrawState::AutoDeviceCoordDraw adcd(drawState);
     if (!adcd.succeeded()) {
         return;
     }
index f798cda59c1cd37fb978805205282d7a4bae83a7..b9b708e4bf828250ce628042a592a5bc2ef43276 100644 (file)
@@ -46,3 +46,44 @@ void GrDrawState::setFromPaint(const GrPaint& paint) {
     this->setColorFilter(paint.getColorFilterColor(), paint.getColorFilterMode());
     this->setCoverage(paint.getCoverage());
 }
+
+////////////////////////////////////////////////////////////////////////////////
+
+GrDrawState::AutoDeviceCoordDraw::AutoDeviceCoordDraw(GrDrawState* drawState,
+                                                      uint32_t explicitCoordStageMask) {
+    GrAssert(NULL != drawState);
+
+    fDrawState = drawState;
+    fViewMatrix = drawState->getViewMatrix();
+    fRestoreMask = 0;
+    GrMatrix invVM;
+    bool inverted = false;
+
+    for (int s = 0; s < GrDrawState::kNumStages; ++s) {
+        if (!(explicitCoordStageMask & (1 << s)) && drawState->isStageEnabled(s)) {
+            if (!inverted && !fViewMatrix.invert(&invVM)) {
+                // sad trombone sound
+                fDrawState = NULL;
+                return;
+            } else {
+                inverted = true;
+            }
+            fRestoreMask |= (1 << s);
+            GrSamplerState* sampler = drawState->sampler(s);
+            fSamplerMatrices[s] = sampler->getMatrix();
+            sampler->preConcatMatrix(invVM);
+        }
+    }
+    drawState->viewMatrix()->reset();
+}
+
+GrDrawState::AutoDeviceCoordDraw::~AutoDeviceCoordDraw() {
+    if (NULL != fDrawState) {
+        fDrawState->setViewMatrix(fViewMatrix);
+        for (int s = 0; s < GrDrawState::kNumStages; ++s) {
+            if (fRestoreMask & (1 << s)) {
+                *fDrawState->sampler(s)->matrix() = fSamplerMatrices[s];
+            }
+        }
+    }
+}
index ca3b2c18abdaf8d382c31fb2af033e02f374b1b6..ea8f41836445f1079848b442d28f8c52cc7a595a 100644 (file)
@@ -135,6 +135,24 @@ public:
     GrColor getColorFilterColor() const { return fColorFilterColor; }
     SkXfermode::Mode getColorFilterMode() const { return fColorFilterMode; }
 
+    /**
+     * Constructor sets the color to be 'color' which is undone by the destructor.
+     */
+    class AutoColorRestore : public ::GrNoncopyable {
+    public:
+        AutoColorRestore(GrDrawState* drawState, GrColor color) {
+            fDrawState = drawState;
+            fOldColor = fDrawState->getColor();
+            fDrawState->setColor(color);
+        }
+        ~AutoColorRestore() {
+            fDrawState->setColor(fOldColor);
+        }
+    private:
+        GrDrawState*    fDrawState;
+        GrColor         fOldColor;
+    };
+
     /// @}
 
     ///////////////////////////////////////////////////////////////////////////
@@ -446,6 +464,11 @@ public:
         return false;
     }
 
+    ////////////////////////////////////////////////////////////////////////////
+
+    /**
+     * TODO: Automatically handle stage matrices.
+     */
     class AutoViewMatrixRestore : public ::GrNoncopyable {
     public:
         AutoViewMatrixRestore() : fDrawState(NULL) {}
@@ -485,6 +508,31 @@ public:
         GrMatrix fSavedMatrix;
     };
 
+    ////////////////////////////////////////////////////////////////////////////
+
+    /**
+     * This sets the view matrix to identity and adjusts stage matrices to
+     * compensate. The destructor undoes the changes, restoring the view matrix
+     * that was set before the constructor.
+     */
+    class AutoDeviceCoordDraw : ::GrNoncopyable {
+    public:
+        /**
+         * If a stage's texture matrix is applied to explicit per-vertex coords,
+         * rather than to positions, then we don't want to modify its matrix.
+         * The explicitCoordStageMask is used to specify such stages.
+         */
+        AutoDeviceCoordDraw(GrDrawState* drawState,
+                            uint32_t explicitCoordStageMask = 0);
+        bool succeeded() const { return NULL != fDrawState; }
+        ~AutoDeviceCoordDraw();
+    private:
+        GrDrawState*       fDrawState;
+        GrMatrix           fViewMatrix;
+        GrMatrix           fSamplerMatrices[GrDrawState::kNumStages];
+        int                fRestoreMask;
+    };
+
     /// @}
 
     ///////////////////////////////////////////////////////////////////////////
index ab345bc6cb56d4d28f1329ce6958e7b254db2022..4c028c3d0a1f92ab0a40d10545c89561db93db89 100644 (file)
@@ -1160,47 +1160,6 @@ void GrDrawTarget::AutoStateRestore::set(GrDrawTarget* target, ASRInit init) {
 
 ////////////////////////////////////////////////////////////////////////////////
 
-GrDrawTarget::AutoDeviceCoordDraw::AutoDeviceCoordDraw(GrDrawTarget* target,
-                                                       uint32_t explicitCoordStageMask) {
-    GrAssert(NULL != target);
-    GrDrawState* drawState = target->drawState();
-
-    fDrawTarget = target;
-    fViewMatrix = drawState->getViewMatrix();
-    fRestoreMask = 0;
-    GrMatrix invVM;
-    bool inverted = false;
-
-    for (int s = 0; s < GrDrawState::kNumStages; ++s) {
-        if (!(explicitCoordStageMask & (1 << s)) && drawState->isStageEnabled(s)) {
-            if (!inverted && !fViewMatrix.invert(&invVM)) {
-                // sad trombone sound
-                fDrawTarget = NULL;
-                return;
-            } else {
-                inverted = true;
-            }
-            fRestoreMask |= (1 << s);
-            GrSamplerState* sampler = drawState->sampler(s);
-            fSamplerMatrices[s] = sampler->getMatrix();
-            sampler->preConcatMatrix(invVM);
-        }
-    }
-    drawState->viewMatrix()->reset();
-}
-
-GrDrawTarget::AutoDeviceCoordDraw::~AutoDeviceCoordDraw() {
-    GrDrawState* drawState = fDrawTarget->drawState();
-    drawState->setViewMatrix(fViewMatrix);
-    for (int s = 0; s < GrDrawState::kNumStages; ++s) {
-        if (fRestoreMask & (1 << s)) {
-            *drawState->sampler(s)->matrix() = fSamplerMatrices[s];
-        }
-    }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
 GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry(
                                          GrDrawTarget*  target,
                                          GrVertexLayout vertexLayout,
index b975f69797890fa5ada153a2acdab0a560611105..134cccd9de4815de136cc2435ae48cf60258c637 100644 (file)
@@ -599,54 +599,6 @@ public:
 
     ////////////////////////////////////////////////////////////////////////////
 
-    /**
-     * Sets the view matrix to I and preconcats all stage matrices enabled in
-     * mask by the view inverse. Destructor undoes these changes.
-     */
-    class AutoDeviceCoordDraw : ::GrNoncopyable {
-    public:
-        /**
-         * If a stage's texture matrix is applied to explicit per-vertex coords,
-         * rather than to positions, then we don't want to modify its matrix.
-         * The explicitCoordStageMask is used to specify such stages.
-         *
-         * TODO: Remove this when custom stage's control their own texture
-         * matrix and there is a "view matrix has changed" notification to the
-         * custom stages.
-         */
-        AutoDeviceCoordDraw(GrDrawTarget* target,
-                            uint32_t explicitCoordStageMask = 0);
-        bool succeeded() const { return NULL != fDrawTarget; }
-        ~AutoDeviceCoordDraw();
-    private:
-        GrDrawTarget*       fDrawTarget;
-        GrMatrix            fViewMatrix;
-        GrMatrix            fSamplerMatrices[GrDrawState::kNumStages];
-        int                 fRestoreMask;
-    };
-
-    ////////////////////////////////////////////////////////////////////////////
-
-    /**
-     * Constructor sets the color to be 'color' which is undone by the destructor.
-     */
-    class AutoColorRestore : public ::GrNoncopyable {
-    public:
-        AutoColorRestore(GrDrawTarget* target, GrColor color) {
-            fDrawTarget = target;
-            fOldColor = target->drawState()->getColor();
-            target->drawState()->setColor(color);
-        }
-        ~AutoColorRestore() {
-            fDrawTarget->drawState()->setColor(fOldColor);
-        }
-    private:
-        GrDrawTarget*   fDrawTarget;
-        GrColor         fOldColor;
-    };
-
-    ////////////////////////////////////////////////////////////////////////////
-
     class AutoReleaseGeometry : ::GrNoncopyable {
     public:
         AutoReleaseGeometry(GrDrawTarget*  target,
index c3c1e8982aedf8b4bf4bcdd16589cbe6cc1ac747..eaee5c9204e2c92e7b08ab8f17af4ff648bef5f9 100644 (file)
@@ -115,7 +115,7 @@ void GrInOrderDrawBuffer::drawRect(const GrRect& rect,
                 }
             }
         }
-        GrDrawTarget::AutoDeviceCoordDraw adcd(this, explicitCoordMask);
+        GrDrawState::AutoDeviceCoordDraw adcd(this->drawState(), explicitCoordMask);
         if (!adcd.succeeded()) {
             return;
         }
@@ -129,7 +129,7 @@ void GrInOrderDrawBuffer::drawRect(const GrRect& rect,
         // Now that the paint's color is stored in the vertices set it to
         // white so that the following code can batch all the rects regardless
         // of paint color
-        AutoColorRestore acr(this, SK_ColorWHITE);
+        GrDrawState::AutoColorRestore acr(this->drawState(), SK_ColorWHITE);
 
         // we don't want to miss an opportunity to batch rects together
         // simply because the clip has changed if the clip doesn't affect
index 9e7012bfca1cfa6bd2deb2feb61f438f9b3bd507..ec0dbf188fb708dcd423878c3768ad5fb7989e5e 100644 (file)
@@ -202,7 +202,7 @@ void GrSWMaskHelper::DrawToTargetWithPathMask(GrTexture* texture,
                                               const GrIRect& rect) {
     GrDrawState* drawState = target->drawState();
 
-    GrDrawTarget::AutoDeviceCoordDraw adcd(target);
+    GrDrawState::AutoDeviceCoordDraw adcd(drawState);
     if (!adcd.succeeded()) {
         return;
     }
index edac161c912760f9ac7548a877dfa293b435dd1e..a2c5867c51abeb5ad15b0571df7a4fd70aadd3a9 100644 (file)
@@ -75,7 +75,7 @@ bool get_path_and_clip_bounds(const GrDrawTarget* target,
 void draw_around_inv_path(GrDrawTarget* target,
                           const GrIRect& devClipBounds,
                           const GrIRect& devPathBounds) {
-    GrDrawTarget::AutoDeviceCoordDraw adcd(target);
+    GrDrawState::AutoDeviceCoordDraw adcd(target->drawState());
     if (!adcd.succeeded()) {
         return;
     }