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;
// 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;
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;
}
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;
}
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
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
kIdxsPerQuad*n); // iCount
quads += n;
}
+ drawState->setVertexEdgeType(oldEdgeType);
return true;
}
~AutoViewMatrixRestore() { this->restore(); }
+ /**
+ * Can be called prior to destructor to restore the original matrix.
+ */
void restore();
void set(GrDrawState* drawState,
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;