Index: src/gpu/glsl/GrGLSLGeometryProcessor.cpp |
diff --git a/src/gpu/glsl/GrGLSLGeometryProcessor.cpp b/src/gpu/glsl/GrGLSLGeometryProcessor.cpp |
index ddbe8e133a81f55ca039c21621550c7496f9a764..bea49e5069df3c5e5b132ddb1432049ed32e7349 100644 |
--- a/src/gpu/glsl/GrGLSLGeometryProcessor.cpp |
+++ b/src/gpu/glsl/GrGLSLGeometryProcessor.cpp |
@@ -29,71 +29,82 @@ void GrGLSLGeometryProcessor::emitTransforms(GrGLSLVertexBuilder* vb, |
const GrShaderVar& posVar, |
const char* localCoords, |
const SkMatrix& localMatrix, |
- const TransformsIn& tin, |
- TransformsOut* tout) { |
- tout->push_back_n(tin.count()); |
- fInstalledTransforms.push_back_n(tin.count()); |
- for (int i = 0; i < tin.count(); i++) { |
- const ProcCoords& coordTransforms = tin[i]; |
- fInstalledTransforms[i].push_back_n(coordTransforms.count()); |
- for (int t = 0; t < coordTransforms.count(); t++) { |
- SkString strUniName("StageMatrix"); |
- strUniName.appendf("_%i_%i", i, t); |
- GrSLType varyingType; |
+ FPCoordTransformHandler* handler) { |
+ int i = 0; |
+ while (const GrCoordTransform* coordTransform = handler->nextCoordTransform()) { |
+ SkString strUniName; |
+ strUniName.printf("CoordTransformMatrix_%d", i); |
+ GrSLType varyingType; |
- GrCoordSet coordType = coordTransforms[t]->sourceCoords(); |
- uint32_t type = coordTransforms[t]->getMatrix().getType(); |
- if (kLocal_GrCoordSet == coordType) { |
- type |= localMatrix.getType(); |
- } |
- varyingType = SkToBool(SkMatrix::kPerspective_Mask & type) ? kVec3f_GrSLType : |
- kVec2f_GrSLType; |
- GrSLPrecision precision = coordTransforms[t]->precision(); |
+ GrCoordSet coordType = coordTransform->sourceCoords(); |
+ uint32_t type = coordTransform->getMatrix().getType(); |
+ if (kLocal_GrCoordSet == coordType) { |
+ type |= localMatrix.getType(); |
+ } |
+ varyingType = SkToBool(SkMatrix::kPerspective_Mask & type) ? kVec3f_GrSLType : |
+ kVec2f_GrSLType; |
+ GrSLPrecision precision = coordTransform->precision(); |
+ |
+ const char* uniName; |
- const char* uniName; |
- fInstalledTransforms[i][t].fHandle = |
- uniformHandler->addUniform(kVertex_GrShaderFlag, |
- kMat33f_GrSLType, precision, |
- strUniName.c_str(), |
- &uniName).toIndex(); |
- SkString strVaryingName("MatrixCoord"); |
- strVaryingName.appendf("_%i_%i", i, t); |
+ fInstalledTransforms.push_back().fHandle = uniformHandler->addUniform(kVertex_GrShaderFlag, |
+ kMat33f_GrSLType, |
+ precision, |
+ strUniName.c_str(), |
+ &uniName).toIndex(); |
+ SkString strVaryingName; |
+ strVaryingName.printf("TransformedCoords_%d", i); |
- GrGLSLVertToFrag v(varyingType); |
- varyingHandler->addVarying(strVaryingName.c_str(), &v, precision); |
+ GrGLSLVertToFrag v(varyingType); |
+ varyingHandler->addVarying(strVaryingName.c_str(), &v, precision); |
- SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingType); |
- (*tout)[i].emplace_back(SkString(v.fsIn()), varyingType); |
+ SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingType); |
+ handler->specifyCoordsForCurrCoordTransform(SkString(v.fsIn()), varyingType); |
- // varying = matrix * coords (logically) |
- if (kDevice_GrCoordSet == coordType) { |
- if (kVec2f_GrSLType == varyingType) { |
- if (kVec2f_GrSLType == posVar.getType()) { |
- vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", |
- v.vsOut(), uniName, posVar.c_str()); |
- } else { |
- // The brackets here are just to scope the temp variable |
- vb->codeAppendf("{ vec3 temp = %s * %s;", uniName, posVar.c_str()); |
- vb->codeAppendf("%s = vec2(temp.x/temp.z, temp.y/temp.z); }", v.vsOut()); |
- } |
+ // varying = matrix * coords (logically) |
+ if (kDevice_GrCoordSet == coordType) { |
+ if (kVec2f_GrSLType == varyingType) { |
+ if (kVec2f_GrSLType == posVar.getType()) { |
+ vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", |
+ v.vsOut(), uniName, posVar.c_str()); |
} else { |
- if (kVec2f_GrSLType == posVar.getType()) { |
- vb->codeAppendf("%s = %s * vec3(%s, 1);", |
- v.vsOut(), uniName, posVar.c_str()); |
- } else { |
- vb->codeAppendf("%s = %s * %s;", v.vsOut(), uniName, posVar.c_str()); |
- } |
+ // The brackets here are just to scope the temp variable |
+ vb->codeAppendf("{ vec3 temp = %s * %s;", uniName, posVar.c_str()); |
+ vb->codeAppendf("%s = vec2(temp.x/temp.z, temp.y/temp.z); }", v.vsOut()); |
} |
} else { |
- if (kVec2f_GrSLType == varyingType) { |
- vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", v.vsOut(), uniName, localCoords); |
+ if (kVec2f_GrSLType == posVar.getType()) { |
+ vb->codeAppendf("%s = %s * vec3(%s, 1);", |
+ v.vsOut(), uniName, posVar.c_str()); |
} else { |
- vb->codeAppendf("%s = %s * vec3(%s, 1);", v.vsOut(), uniName, localCoords); |
+ vb->codeAppendf("%s = %s * %s;", v.vsOut(), uniName, posVar.c_str()); |
} |
} |
+ } else { |
+ if (kVec2f_GrSLType == varyingType) { |
+ vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", v.vsOut(), uniName, localCoords); |
+ } else { |
+ vb->codeAppendf("%s = %s * vec3(%s, 1);", v.vsOut(), uniName, localCoords); |
+ } |
+ } |
+ ++i; |
+ } |
+} |
+ |
+void GrGLSLGeometryProcessor::setTransformDataHelper(const SkMatrix& localMatrix, |
+ const GrGLSLProgramDataManager& pdman, |
+ FPCoordTransformIter* transformIter) { |
+ int i = 0; |
+ while (const GrCoordTransform* coordTransform = transformIter->next()) { |
+ const SkMatrix& m = GetTransformMatrix(localMatrix, *coordTransform); |
+ if (!fInstalledTransforms[i].fCurrentValue.cheapEqualTo(m)) { |
+ pdman.setSkMatrix(fInstalledTransforms[i].fHandle.toIndex(), m); |
+ fInstalledTransforms[i].fCurrentValue = m; |
} |
+ ++i; |
} |
+ SkASSERT(i == fInstalledTransforms.count()); |
} |
void GrGLSLGeometryProcessor::setupPosition(GrGLSLVertexBuilder* vertBuilder, |