Make additional code paths go through GrDrawState helper classes for their matrix...
authorbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 8 Oct 2012 18:59:39 +0000 (18:59 +0000)
committerbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 8 Oct 2012 18:59:39 +0000 (18:59 +0000)
R=robertphillips@google.com
Review URL: https://codereview.appspot.com/6615064

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

src/gpu/GrAAConvexPathRenderer.cpp
src/gpu/GrAAHairLinePathRenderer.cpp
src/gpu/GrDrawState.h

index 487878f..a525968 100644 (file)
@@ -452,15 +452,13 @@ bool GrAAConvexPathRenderer::onDrawPath(const SkPath& origPath,
     if (path->isEmpty()) {
         return true;
     }
-    GrDrawTarget::AutoStateRestore asr(target,
-                                       GrDrawTarget::kPreserve_ASRInit);
     GrDrawState* drawState = target->drawState();
 
-    GrMatrix vm = drawState->getViewMatrix();
-    if (!drawState->preConcatSamplerMatricesWithInverse(vm)) {
+    GrDrawState::AutoDeviceCoordDraw adcd(drawState);
+    if (!adcd.succeeded()) {
         return false;
     }
-    drawState->viewMatrix()->reset();
+    const GrMatrix* vm = &adcd.getOriginalMatrix();
 
     GrVertexLayout layout = 0;
     layout |= GrDrawTarget::kEdge_VertexLayoutBit;
@@ -469,10 +467,10 @@ bool GrAAConvexPathRenderer::onDrawPath(const SkPath& origPath,
     // perspective. Otherwise, we apply the view matrix when copying to the
     // segment representation.
     SkPath tmpPath;
-    if (vm.hasPerspective()) {
-        origPath.transform(vm, &tmpPath);
+    if (vm->hasPerspective()) {
+        origPath.transform(*vm, &tmpPath);
         path = &tmpPath;
-        vm.reset();
+        vm = &GrMatrix::I();
     }
 
     QuadVertex *verts;
@@ -486,7 +484,7 @@ bool GrAAConvexPathRenderer::onDrawPath(const SkPath& origPath,
     SkSTArray<kPreallocSegmentCnt, Segment, true> segments;
     SkPoint fanPt;
 
-    if (!get_segments(*path, vm, &segments, &fanPt, &vCount, &iCount)) {
+    if (!get_segments(*path, *vm, &segments, &fanPt, &vCount, &iCount)) {
         return false;
     }
 
@@ -499,12 +497,15 @@ bool GrAAConvexPathRenderer::onDrawPath(const SkPath& origPath,
 
     create_vertices(segments, fanPt, verts, idxs);
 
+    GrDrawState::VertexEdgeType oldEdgeType = drawState->getVertexEdgeType();
     drawState->setVertexEdgeType(GrDrawState::kQuad_EdgeType);
     target->drawIndexed(kTriangles_GrPrimitiveType,
                         0,        // start vertex
                         0,        // start index
                         vCount,
                         iCount);
+    drawState->setVertexEdgeType(oldEdgeType);
+
     return true;
 }
 
index 5d30b24..06d8e71 100644 (file)
@@ -587,29 +587,28 @@ bool GrAAHairLinePathRenderer::onDrawPath(const SkPath& path,
         return false;
     }
 
-    GrDrawTarget::AutoStateRestore asr;
+    GrDrawState::AutoDeviceCoordDraw adcd;
     GrDrawState* drawState = target->drawState();
+    // createGeom transforms the geometry to device space when the matrix does not have
+    // perspective.
     if (!drawState->getViewMatrix().hasPerspective()) {
-        // we are going to whack the view matrix to identity to remove
-        // perspective.
-        asr.set(target,
-                GrDrawTarget::kPreserve_ASRInit);
-        drawState = target->drawState();
-        if (!drawState->preConcatSamplerMatricesWithInverse(drawState->getViewMatrix())) {
+        adcd.set(drawState);
+        if (!adcd.succeeded()) {
             return false;
         }
-        drawState->viewMatrix()->reset();
     }
 
-
     // TODO: See whether rendering lines as degenerate quads improves perf
     // when we have a mix
+
+    GrDrawState::VertexEdgeType oldEdgeType = drawState->getVertexEdgeType();
+
     target->setIndexSourceToBuffer(fLinesIndexBuffer);
     int lines = 0;
     int nBufLines = fLinesIndexBuffer->maxQuads();
+    drawState->setVertexEdgeType(GrDrawState::kHairLine_EdgeType);
     while (lines < lineCnt) {
         int n = GrMin(lineCnt - lines, nBufLines);
-        drawState->setVertexEdgeType(GrDrawState::kHairLine_EdgeType);
         target->drawIndexed(kTriangles_GrPrimitiveType,
                             kVertsPerLineSeg*lines,    // startV
                             0,                         // startI
@@ -620,9 +619,9 @@ bool GrAAHairLinePathRenderer::onDrawPath(const SkPath& path,
 
     target->setIndexSourceToBuffer(fQuadsIndexBuffer);
     int quads = 0;
+    drawState->setVertexEdgeType(GrDrawState::kHairQuad_EdgeType);
     while (quads < quadCnt) {
         int n = GrMin(quadCnt - quads, kNumQuadsInIdxBuffer);
-        drawState->setVertexEdgeType(GrDrawState::kHairQuad_EdgeType);
         target->drawIndexed(kTriangles_GrPrimitiveType,
                             4 * lineCnt + kVertsPerQuad*quads, // startV
                             0,                                 // startI
@@ -630,6 +629,7 @@ bool GrAAHairLinePathRenderer::onDrawPath(const SkPath& path,
                             kIdxsPerQuad*n);                   // iCount
         quads += n;
     }
+    drawState->setVertexEdgeType(oldEdgeType);
     return true;
 }
 
index 5dccb15..8e063f7 100644 (file)
@@ -483,6 +483,9 @@ public:
 
         ~AutoViewMatrixRestore() { this->restore(); }
 
+        /**
+         * Can be called prior to destructor to restore the original matrix.
+         */
         void restore();
         
         void set(GrDrawState* drawState,
@@ -520,13 +523,30 @@ public:
             this->set(drawState, explicitCoordStageMask);
         }
 
+        ~AutoDeviceCoordDraw() { this->restore(); }
+
         bool set(GrDrawState* drawState, uint32_t explicitCoordStageMask = 0);
 
+        /**
+         * Returns true if this object was successfully initialized on to a GrDrawState. It may
+         * return false because a non-default constructor or set() were never called or because
+         * the view matrix was not invertible.
+         */
         bool succeeded() const { return NULL != fDrawState; }
 
-        void restore();
+        /**
+         * Returns the matrix that was set previously set on the drawState. This is only valid
+         * if succeeded returns true.
+         */
+        const GrMatrix& getOriginalMatrix() const {
+            GrAssert(this->succeeded());
+            return fViewMatrix;
+        }
 
-        ~AutoDeviceCoordDraw() { this->restore(); }
+        /**
+         * Can be called prior to destructor to restore the original matrix.
+         */
+        void restore();
 
     private:
         GrDrawState*       fDrawState;