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
diff --git a/src/gpu/GrAAConvexPathRenderer.cpp b/src/gpu/GrAAConvexPathRenderer.cpp
index 487878f..a525968 100644
--- a/src/gpu/GrAAConvexPathRenderer.cpp
+++ b/src/gpu/GrAAConvexPathRenderer.cpp
@@ -452,15 +452,13 @@
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 @@
// 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 @@
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 @@
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 5d30b24..06d8e71 100644
--- a/src/gpu/GrAAHairLinePathRenderer.cpp
+++ b/src/gpu/GrAAHairLinePathRenderer.cpp
@@ -587,29 +587,28 @@
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 @@
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 @@
kIdxsPerQuad*n); // iCount
quads += n;
}
+ drawState->setVertexEdgeType(oldEdgeType);
return true;
}
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index 5dccb15..8e063f7 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -483,6 +483,9 @@
~AutoViewMatrixRestore() { this->restore(); }
+ /**
+ * Can be called prior to destructor to restore the original matrix.
+ */
void restore();
void set(GrDrawState* drawState,
@@ -520,13 +523,30 @@
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;