| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrGLEffectMatrix.h" | 8 #include "GrGLEffectMatrix.h" |
| 9 #include "GrDrawEffect.h" | 9 #include "GrDrawEffect.h" |
| 10 #include "GrTexture.h" | 10 #include "GrTexture.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 SkString suffixedUniName; | 77 SkString suffixedUniName; |
| 78 if (NULL != suffix) { | 78 if (NULL != suffix) { |
| 79 suffixedUniName.append(uniName); | 79 suffixedUniName.append(uniName); |
| 80 suffixedUniName.append(suffix); | 80 suffixedUniName.append(suffix); |
| 81 uniName = suffixedUniName.c_str(); | 81 uniName = suffixedUniName.c_str(); |
| 82 } | 82 } |
| 83 if (kVoid_GrSLType != fUniType) { | 83 if (kVoid_GrSLType != fUniType) { |
| 84 fUni = builder->addUniform(GrGLShaderBuilder::kVertex_ShaderType, | 84 fUni = builder->addUniform(GrGLShaderBuilder::kVertex_ShaderType, |
| 85 fUniType, | 85 fUniType, |
| 86 uniName, | 86 uniName, |
| 87 &uniName); | 87 &uniName)->glUniform(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 const char* varyingName = "MatrixCoord"; | 90 const char* varyingName = "MatrixCoord"; |
| 91 SkString suffixedVaryingName; | 91 SkString suffixedVaryingName; |
| 92 if (NULL != suffix) { | 92 if (NULL != suffix) { |
| 93 suffixedVaryingName.append(varyingName); | 93 suffixedVaryingName.append(varyingName); |
| 94 suffixedVaryingName.append(suffix); | 94 suffixedVaryingName.append(suffix); |
| 95 varyingName = suffixedVaryingName.c_str(); | 95 varyingName = suffixedVaryingName.c_str(); |
| 96 } | 96 } |
| 97 const char* vsVaryingName; | 97 const char* vsVaryingName; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 *fsCoordName = coordName; | 178 *fsCoordName = coordName; |
| 179 } | 179 } |
| 180 } else if(NULL != fsCoordName) { | 180 } else if(NULL != fsCoordName) { |
| 181 *fsCoordName = fsVaryingName; | 181 *fsCoordName = fsVaryingName; |
| 182 } | 182 } |
| 183 if (NULL != vsVaryingType) { | 183 if (NULL != vsVaryingType) { |
| 184 *vsVaryingType = varyingType; | 184 *vsVaryingType = varyingType; |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 | 187 |
| 188 void GrGLEffectMatrix::setData(const GrGLUniformManager& uniformManager, | 188 void GrGLEffectMatrix::setData(const GrGLContext& context, |
| 189 const SkMatrix& matrix, | 189 const SkMatrix& matrix, |
| 190 const GrDrawEffect& drawEffect, | 190 const GrDrawEffect& drawEffect, |
| 191 const GrTexture* texture) { | 191 const GrTexture* texture) { |
| 192 GrAssert((GrGLUniformManager::kInvalidUniformHandle == fUni) == | 192 GrAssert((NULL != fUni) != (kVoid_GrSLType == fUniType)); |
| 193 (kVoid_GrSLType == fUniType)); | |
| 194 const SkMatrix& coordChangeMatrix = GrEffect::kLocal_CoordsType == fCoordsTy
pe ? | 193 const SkMatrix& coordChangeMatrix = GrEffect::kLocal_CoordsType == fCoordsTy
pe ? |
| 195 drawEffect.getCoordChangeMatrix() : | 194 drawEffect.getCoordChangeMatrix() : |
| 196 SkMatrix::I(); | 195 SkMatrix::I(); |
| 197 switch (fUniType) { | 196 switch (fUniType) { |
| 198 case kVoid_GrSLType: | 197 case kVoid_GrSLType: |
| 199 GrAssert(matrix.isIdentity()); | 198 GrAssert(matrix.isIdentity()); |
| 200 GrAssert(coordChangeMatrix.isIdentity()); | 199 GrAssert(coordChangeMatrix.isIdentity()); |
| 201 GrAssert(NULL == texture || kTopLeft_GrSurfaceOrigin == texture->ori
gin()); | 200 GrAssert(NULL == texture || kTopLeft_GrSurfaceOrigin == texture->ori
gin()); |
| 202 return; | 201 return; |
| 203 case kVec2f_GrSLType: { | 202 case kVec2f_GrSLType: { |
| 204 GrAssert(SkMatrix::kTranslate_Mask == (matrix.getType() | coordChang
eMatrix.getType())); | 203 GrAssert(SkMatrix::kTranslate_Mask == (matrix.getType() | coordChang
eMatrix.getType())); |
| 205 GrAssert(NULL == texture || kTopLeft_GrSurfaceOrigin == texture->ori
gin()); | 204 GrAssert(NULL == texture || kTopLeft_GrSurfaceOrigin == texture->ori
gin()); |
| 206 SkScalar tx = matrix[SkMatrix::kMTransX] + (coordChangeMatrix)[SkMat
rix::kMTransX]; | 205 SkScalar tx = matrix[SkMatrix::kMTransX] + (coordChangeMatrix)[SkMat
rix::kMTransX]; |
| 207 SkScalar ty = matrix[SkMatrix::kMTransY] + (coordChangeMatrix)[SkMat
rix::kMTransY]; | 206 SkScalar ty = matrix[SkMatrix::kMTransY] + (coordChangeMatrix)[SkMat
rix::kMTransY]; |
| 208 if (fPrevMatrix.get(SkMatrix::kMTransX) != tx || | 207 if (fPrevMatrix.get(SkMatrix::kMTransX) != tx || |
| 209 fPrevMatrix.get(SkMatrix::kMTransY) != ty) { | 208 fPrevMatrix.get(SkMatrix::kMTransY) != ty) { |
| 210 uniformManager.set2f(fUni, tx, ty); | 209 fUni->set2f(context, tx, ty); |
| 211 fPrevMatrix.set(SkMatrix::kMTransX, tx); | 210 fPrevMatrix.set(SkMatrix::kMTransX, tx); |
| 212 fPrevMatrix.set(SkMatrix::kMTransY, ty); | 211 fPrevMatrix.set(SkMatrix::kMTransY, ty); |
| 213 } | 212 } |
| 214 break; | 213 break; |
| 215 } | 214 } |
| 216 case kMat33f_GrSLType: { | 215 case kMat33f_GrSLType: { |
| 217 SkMatrix combined; | 216 SkMatrix combined; |
| 218 combined.setConcat(matrix, coordChangeMatrix); | 217 combined.setConcat(matrix, coordChangeMatrix); |
| 219 if (NULL != texture && kBottomLeft_GrSurfaceOrigin == texture->origi
n()) { | 218 if (NULL != texture && kBottomLeft_GrSurfaceOrigin == texture->origi
n()) { |
| 220 // combined.postScale(1,-1); | 219 // combined.postScale(1,-1); |
| 221 // combined.postTranslate(0,1); | 220 // combined.postTranslate(0,1); |
| 222 combined.set(SkMatrix::kMSkewY, | 221 combined.set(SkMatrix::kMSkewY, |
| 223 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); | 222 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); |
| 224 combined.set(SkMatrix::kMScaleY, | 223 combined.set(SkMatrix::kMScaleY, |
| 225 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY])
; | 224 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY])
; |
| 226 combined.set(SkMatrix::kMTransY, | 225 combined.set(SkMatrix::kMTransY, |
| 227 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY])
; | 226 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY])
; |
| 228 } | 227 } |
| 229 if (!fPrevMatrix.cheapEqualTo(combined)) { | 228 if (!fPrevMatrix.cheapEqualTo(combined)) { |
| 230 uniformManager.setSkMatrix(fUni, combined); | 229 fUni->setSkMatrix(context, combined); |
| 231 fPrevMatrix = combined; | 230 fPrevMatrix = combined; |
| 232 } | 231 } |
| 233 break; | 232 break; |
| 234 } | 233 } |
| 235 default: | 234 default: |
| 236 GrCrash("Unexpected uniform type."); | 235 GrCrash("Unexpected uniform type."); |
| 237 } | 236 } |
| 238 } | 237 } |
| OLD | NEW |