| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright 2014 Google Inc. | 2  * Copyright 2014 Google Inc. | 
| 3  * | 3  * | 
| 4  * Use of this source code is governed by a BSD-style license that can be | 4  * Use of this source code is governed by a BSD-style license that can be | 
| 5  * found in the LICENSE file. | 5  * found in the LICENSE file. | 
| 6  */ | 6  */ | 
| 7 | 7 | 
| 8 #include "GrGLSLGeometryProcessor.h" | 8 #include "GrGLSLGeometryProcessor.h" | 
| 9 | 9 | 
| 10 #include "GrCoordTransform.h" | 10 #include "GrCoordTransform.h" | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 22         args.fVaryingHandler->setNoPerspective(); | 22         args.fVaryingHandler->setNoPerspective(); | 
| 23     } | 23     } | 
| 24 } | 24 } | 
| 25 | 25 | 
| 26 void GrGLSLGeometryProcessor::emitTransforms(GrGLSLVertexBuilder* vb, | 26 void GrGLSLGeometryProcessor::emitTransforms(GrGLSLVertexBuilder* vb, | 
| 27                                              GrGLSLVaryingHandler* varyingHandle
     r, | 27                                              GrGLSLVaryingHandler* varyingHandle
     r, | 
| 28                                              GrGLSLUniformHandler* uniformHandle
     r, | 28                                              GrGLSLUniformHandler* uniformHandle
     r, | 
| 29                                              const GrShaderVar& posVar, | 29                                              const GrShaderVar& posVar, | 
| 30                                              const char* localCoords, | 30                                              const char* localCoords, | 
| 31                                              const SkMatrix& localMatrix, | 31                                              const SkMatrix& localMatrix, | 
| 32                                              FPCoordTransformHandler* handler) { | 32                                              const TransformsIn& tin, | 
| 33     int i = 0; | 33                                              TransformsOut* tout) { | 
| 34     while (const GrCoordTransform* coordTransform = handler->nextCoordTransform(
     )) { | 34     tout->push_back_n(tin.count()); | 
| 35         SkString strUniName; | 35     fInstalledTransforms.push_back_n(tin.count()); | 
| 36         strUniName.printf("CoordTransformMatrix_%d", i); | 36     for (int i = 0; i < tin.count(); i++) { | 
| 37         GrSLType varyingType; | 37         const ProcCoords& coordTransforms = tin[i]; | 
|  | 38         fInstalledTransforms[i].push_back_n(coordTransforms.count()); | 
|  | 39         for (int t = 0; t < coordTransforms.count(); t++) { | 
|  | 40             SkString strUniName("StageMatrix"); | 
|  | 41             strUniName.appendf("_%i_%i", i, t); | 
|  | 42             GrSLType varyingType; | 
| 38 | 43 | 
| 39         GrCoordSet coordType = coordTransform->sourceCoords(); | 44             GrCoordSet coordType = coordTransforms[t]->sourceCoords(); | 
| 40         uint32_t type = coordTransform->getMatrix().getType(); | 45             uint32_t type = coordTransforms[t]->getMatrix().getType(); | 
| 41         if (kLocal_GrCoordSet == coordType) { | 46             if (kLocal_GrCoordSet == coordType) { | 
| 42             type |= localMatrix.getType(); | 47                 type |= localMatrix.getType(); | 
| 43         } | 48             } | 
| 44         varyingType = SkToBool(SkMatrix::kPerspective_Mask & type) ? kVec3f_GrSL
     Type : | 49             varyingType = SkToBool(SkMatrix::kPerspective_Mask & type) ? kVec3f_
     GrSLType : | 
| 45                                                                      kVec2f_GrSL
     Type; | 50                                                                          kVec2f_
     GrSLType; | 
| 46         GrSLPrecision precision = coordTransform->precision(); | 51             GrSLPrecision precision = coordTransforms[t]->precision(); | 
| 47 | 52 | 
| 48         const char* uniName; | 53             const char* uniName; | 
|  | 54             fInstalledTransforms[i][t].fHandle = | 
|  | 55                     uniformHandler->addUniform(kVertex_GrShaderFlag, | 
|  | 56                                                kMat33f_GrSLType, precision, | 
|  | 57                                                strUniName.c_str(), | 
|  | 58                                                &uniName).toIndex(); | 
| 49 | 59 | 
|  | 60             SkString strVaryingName("MatrixCoord"); | 
|  | 61             strVaryingName.appendf("_%i_%i", i, t); | 
| 50 | 62 | 
| 51         fInstalledTransforms.push_back().fHandle = uniformHandler->addUniform(kV
     ertex_GrShaderFlag, | 63             GrGLSLVertToFrag v(varyingType); | 
| 52                                                                               kM
     at33f_GrSLType, | 64             varyingHandler->addVarying(strVaryingName.c_str(), &v, precision); | 
| 53                                                                               pr
     ecision, |  | 
| 54                                                                               st
     rUniName.c_str(), |  | 
| 55                                                                               &u
     niName).toIndex(); |  | 
| 56         SkString strVaryingName; |  | 
| 57         strVaryingName.printf("TransformedCoords_%d", i); |  | 
| 58 | 65 | 
| 59         GrGLSLVertToFrag v(varyingType); | 66             SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyin
     gType); | 
| 60         varyingHandler->addVarying(strVaryingName.c_str(), &v, precision); | 67             (*tout)[i].emplace_back(SkString(v.fsIn()), varyingType); | 
| 61 | 68 | 
| 62         SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingTyp
     e); | 69             // varying = matrix * coords (logically) | 
| 63         handler->specifyCoordsForCurrCoordTransform(SkString(v.fsIn()), varyingT
     ype); | 70             if (kDevice_GrCoordSet == coordType) { | 
| 64 | 71                 if (kVec2f_GrSLType == varyingType) { | 
| 65         // varying = matrix * coords (logically) | 72                     if (kVec2f_GrSLType == posVar.getType()) { | 
| 66         if (kDevice_GrCoordSet == coordType) { | 73                         vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", | 
| 67             if (kVec2f_GrSLType == varyingType) { | 74                                         v.vsOut(), uniName, posVar.c_str()); | 
| 68                 if (kVec2f_GrSLType == posVar.getType()) { | 75                     } else { | 
| 69                     vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", | 76                         // The brackets here are just to scope the temp variable | 
| 70                                     v.vsOut(), uniName, posVar.c_str()); | 77                         vb->codeAppendf("{ vec3 temp = %s * %s;", uniName, posVa
     r.c_str()); | 
|  | 78                         vb->codeAppendf("%s = vec2(temp.x/temp.z, temp.y/temp.z)
     ; }", v.vsOut()); | 
|  | 79                     } | 
| 71                 } else { | 80                 } else { | 
| 72                     // The brackets here are just to scope the temp variable | 81                     if (kVec2f_GrSLType == posVar.getType()) { | 
| 73                     vb->codeAppendf("{ vec3 temp = %s * %s;", uniName, posVar.c_
     str()); | 82                         vb->codeAppendf("%s = %s * vec3(%s, 1);", | 
| 74                     vb->codeAppendf("%s = vec2(temp.x/temp.z, temp.y/temp.z); }"
     , v.vsOut()); | 83                                         v.vsOut(), uniName, posVar.c_str()); | 
|  | 84                     } else { | 
|  | 85                         vb->codeAppendf("%s = %s * %s;", v.vsOut(), uniName, pos
     Var.c_str()); | 
|  | 86                     } | 
| 75                 } | 87                 } | 
| 76             } else { | 88             } else { | 
| 77                 if (kVec2f_GrSLType == posVar.getType()) { | 89                 if (kVec2f_GrSLType == varyingType) { | 
| 78                     vb->codeAppendf("%s = %s * vec3(%s, 1);", | 90                     vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", v.vsOut(), un
     iName, localCoords); | 
| 79                                     v.vsOut(), uniName, posVar.c_str()); |  | 
| 80                 } else { | 91                 } else { | 
| 81                     vb->codeAppendf("%s = %s * %s;", v.vsOut(), uniName, posVar.
     c_str()); | 92                     vb->codeAppendf("%s = %s * vec3(%s, 1);", v.vsOut(), uniName
     , localCoords); | 
| 82                 } | 93                 } | 
| 83             } | 94             } | 
| 84         } else { |  | 
| 85             if (kVec2f_GrSLType == varyingType) { |  | 
| 86                 vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", v.vsOut(), uniNam
     e, localCoords); |  | 
| 87             } else { |  | 
| 88                 vb->codeAppendf("%s = %s * vec3(%s, 1);", v.vsOut(), uniName, lo
     calCoords); |  | 
| 89             } |  | 
| 90         } | 95         } | 
| 91         ++i; |  | 
| 92     } | 96     } | 
| 93 } | 97 } | 
| 94 | 98 | 
| 95 void GrGLSLGeometryProcessor::setTransformDataHelper(const SkMatrix& localMatrix
     , |  | 
| 96                                                      const GrGLSLProgramDataMana
     ger& pdman, |  | 
| 97                                                      FPCoordTransformIter* trans
     formIter) { |  | 
| 98     int i = 0; |  | 
| 99     while (const GrCoordTransform* coordTransform = transformIter->next()) { |  | 
| 100         const SkMatrix& m = GetTransformMatrix(localMatrix, *coordTransform); |  | 
| 101         if (!fInstalledTransforms[i].fCurrentValue.cheapEqualTo(m)) { |  | 
| 102             pdman.setSkMatrix(fInstalledTransforms[i].fHandle.toIndex(), m); |  | 
| 103             fInstalledTransforms[i].fCurrentValue = m; |  | 
| 104         } |  | 
| 105         ++i; |  | 
| 106     } |  | 
| 107     SkASSERT(i == fInstalledTransforms.count()); |  | 
| 108 } |  | 
| 109 |  | 
| 110 void GrGLSLGeometryProcessor::setupPosition(GrGLSLVertexBuilder* vertBuilder, | 99 void GrGLSLGeometryProcessor::setupPosition(GrGLSLVertexBuilder* vertBuilder, | 
| 111                                             GrGPArgs* gpArgs, | 100                                             GrGPArgs* gpArgs, | 
| 112                                             const char* posName) { | 101                                             const char* posName) { | 
| 113     gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2"); | 102     gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2"); | 
| 114     vertBuilder->codeAppendf("vec2 %s = %s;", gpArgs->fPositionVar.c_str(), posN
     ame); | 103     vertBuilder->codeAppendf("vec2 %s = %s;", gpArgs->fPositionVar.c_str(), posN
     ame); | 
| 115 } | 104 } | 
| 116 | 105 | 
| 117 void GrGLSLGeometryProcessor::setupPosition(GrGLSLVertexBuilder* vertBuilder, | 106 void GrGLSLGeometryProcessor::setupPosition(GrGLSLVertexBuilder* vertBuilder, | 
| 118                                             GrGLSLUniformHandler* uniformHandler
     , | 107                                             GrGLSLUniformHandler* uniformHandler
     , | 
| 119                                             GrGPArgs* gpArgs, | 108                                             GrGPArgs* gpArgs, | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 133             gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2"); | 122             gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2"); | 
| 134             vertBuilder->codeAppendf("vec2 %s = vec2(%s * vec3(%s, 1));", | 123             vertBuilder->codeAppendf("vec2 %s = vec2(%s * vec3(%s, 1));", | 
| 135                                      gpArgs->fPositionVar.c_str(), viewMatrixNam
     e, posName); | 124                                      gpArgs->fPositionVar.c_str(), viewMatrixNam
     e, posName); | 
| 136         } else { | 125         } else { | 
| 137             gpArgs->fPositionVar.set(kVec3f_GrSLType, "pos3"); | 126             gpArgs->fPositionVar.set(kVec3f_GrSLType, "pos3"); | 
| 138             vertBuilder->codeAppendf("vec3 %s = %s * vec3(%s, 1);", | 127             vertBuilder->codeAppendf("vec3 %s = %s * vec3(%s, 1);", | 
| 139                                      gpArgs->fPositionVar.c_str(), viewMatrixNam
     e, posName); | 128                                      gpArgs->fPositionVar.c_str(), viewMatrixNam
     e, posName); | 
| 140         } | 129         } | 
| 141     } | 130     } | 
| 142 } | 131 } | 
| OLD | NEW | 
|---|