diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-08 18:59:39 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-08 18:59:39 +0000 |
commit | a834746cc1bd92301fd0840a221ca1623c0bbb29 (patch) | |
tree | fb1028fc986fc05584d089286df3177d6a4e0ba9 /src | |
parent | 042aff872a22cadd28368676839a21be8b33e119 (diff) |
Make additional code paths go through GrDrawState helper classes for their matrix manipulations.
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
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/GrAAConvexPathRenderer.cpp | 19 | ||||
-rw-r--r-- | src/gpu/GrAAHairLinePathRenderer.cpp | 22 | ||||
-rw-r--r-- | src/gpu/GrDrawState.h | 24 |
3 files changed, 43 insertions, 22 deletions
diff --git a/src/gpu/GrAAConvexPathRenderer.cpp b/src/gpu/GrAAConvexPathRenderer.cpp index 487878f898..a525968283 100644 --- a/src/gpu/GrAAConvexPathRenderer.cpp +++ b/src/gpu/GrAAConvexPathRenderer.cpp @@ -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; } diff --git a/src/gpu/GrAAHairLinePathRenderer.cpp b/src/gpu/GrAAHairLinePathRenderer.cpp index 5d30b24a8b..06d8e71f98 100644 --- a/src/gpu/GrAAHairLinePathRenderer.cpp +++ b/src/gpu/GrAAHairLinePathRenderer.cpp @@ -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; } diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h index 5dccb1581d..8e063f775e 100644 --- a/src/gpu/GrDrawState.h +++ b/src/gpu/GrDrawState.h @@ -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; |