| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "GrGLProgram.h" | 8 #include "GrGLProgram.h" |
| 9 | 9 |
| 10 #include "GrAllocator.h" | 10 #include "GrAllocator.h" |
| 11 #include "GrProcessor.h" | 11 #include "GrProcessor.h" |
| 12 #include "GrCoordTransform.h" | 12 #include "GrCoordTransform.h" |
| 13 #include "GrGLGeometryProcessor.h" | 13 #include "GrGLGeometryProcessor.h" |
| 14 #include "GrGLProcessor.h" | 14 #include "GrGLProcessor.h" |
| 15 #include "GrGLXferProcessor.h" | 15 #include "GrGLXferProcessor.h" |
| 16 #include "GrGpuGL.h" | 16 #include "GrGpuGL.h" |
| 17 #include "GrGLPathRendering.h" | 17 #include "GrGLPathRendering.h" |
| 18 #include "GrGLShaderVar.h" | 18 #include "GrGLShaderVar.h" |
| 19 #include "GrGLSL.h" | 19 #include "GrGLSL.h" |
| 20 #include "GrOptDrawState.h" | 20 #include "GrOptDrawState.h" |
| 21 #include "GrXferProcessor.h" | 21 #include "GrXferProcessor.h" |
| 22 #include "SkXfermode.h" | 22 #include "SkXfermode.h" |
| 23 | 23 |
| 24 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) | 24 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) |
| 25 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) | 25 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) |
| 26 | 26 |
| 27 /** | 27 /** |
| 28 * Retrieves the final matrix that a transform needs to apply to its source coor
ds. | 28 * Retrieves the final matrix that a transform needs to apply to its source coor
ds. |
| 29 */ | 29 */ |
| 30 static SkMatrix get_transform_matrix(const GrPendingFragmentStage& stage, int tr
ansformIdx) { | 30 static SkMatrix get_transform_matrix(const GrPendingFragmentStage& stage, |
| 31 int transformIdx, |
| 32 const SkMatrix& localMatrix) { |
| 31 const GrCoordTransform& coordTransform = stage.getProcessor()->coordTransfor
m(transformIdx); | 33 const GrCoordTransform& coordTransform = stage.getProcessor()->coordTransfor
m(transformIdx); |
| 32 SkMatrix combined; | 34 SkMatrix combined; |
| 33 | 35 |
| 34 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { | 36 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { |
| 35 // If we have explicit local coords or are in device coords then we shou
ldn't need a coord | 37 // If we have explicit local coords or are in device coords then we shou
ldn't need a coord |
| 36 // change. | 38 // change. |
| 37 const SkMatrix& ccm = stage.getCoordChangeMatrix(); | 39 // TODO shortly we will get rid of coord change matrices entirely, and t
he PrimProc will |
| 38 combined.setConcat(coordTransform.getMatrix(), ccm); | 40 // always have a local matrix, often Identity, which can be used to tran
sform coord |
| 41 // transforms. Until we actually do this, we need some way for a PrimPr
oc to say 'use my |
| 42 // matrix' instead of the coord change mechanism. Temporarily, we have
overloaded |
| 43 // The identity matrix to be this value, ie if a primproc has an identit
y matrix for a |
| 44 // local matrix then use the coord change matrix, otherwise use the matr
ix on the primproc |
| 45 if (localMatrix.isIdentity()) { |
| 46 const SkMatrix& ccm = stage.getCoordChangeMatrix(); |
| 47 combined.setConcat(coordTransform.getMatrix(), ccm); |
| 48 } else { |
| 49 combined.setConcat(coordTransform.getMatrix(), localMatrix); |
| 50 } |
| 39 } else { | 51 } else { |
| 40 combined = coordTransform.getMatrix(); | 52 combined = coordTransform.getMatrix(); |
| 41 } | 53 } |
| 42 if (coordTransform.reverseY()) { | 54 if (coordTransform.reverseY()) { |
| 43 // combined.postScale(1,-1); | 55 // combined.postScale(1,-1); |
| 44 // combined.postTranslate(0,1); | 56 // combined.postTranslate(0,1); |
| 45 combined.set(SkMatrix::kMSkewY, | 57 combined.set(SkMatrix::kMSkewY, |
| 46 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); | 58 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); |
| 47 combined.set(SkMatrix::kMScaleY, | 59 combined.set(SkMatrix::kMScaleY, |
| 48 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]); | 60 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 // Some of GrGLProgram subclasses need to update state here | 185 // Some of GrGLProgram subclasses need to update state here |
| 174 this->didSetData(optState.drawType()); | 186 this->didSetData(optState.drawType()); |
| 175 } | 187 } |
| 176 | 188 |
| 177 void GrGLProgram::setFragmentData(const GrOptDrawState& optState) { | 189 void GrGLProgram::setFragmentData(const GrOptDrawState& optState) { |
| 178 int numProcessors = fFragmentProcessors->fProcs.count(); | 190 int numProcessors = fFragmentProcessors->fProcs.count(); |
| 179 for (int e = 0; e < numProcessors; ++e) { | 191 for (int e = 0; e < numProcessors; ++e) { |
| 180 const GrPendingFragmentStage& stage = optState.getFragmentStage(e); | 192 const GrPendingFragmentStage& stage = optState.getFragmentStage(e); |
| 181 const GrProcessor& processor = *stage.getProcessor(); | 193 const GrProcessor& processor = *stage.getProcessor(); |
| 182 fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, pr
ocessor); | 194 fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, pr
ocessor); |
| 183 this->setTransformData(stage, fFragmentProcessors->fProcs[e]); | 195 const SkMatrix& localMatrix = optState.getPrimitiveProcessor()->localMat
rix(); |
| 196 this->setTransformData(stage, localMatrix, fFragmentProcessors->fProcs[e
]); |
| 184 this->bindTextures(fFragmentProcessors->fProcs[e], processor); | 197 this->bindTextures(fFragmentProcessors->fProcs[e], processor); |
| 185 } | 198 } |
| 186 } | 199 } |
| 187 void GrGLProgram::setTransformData(const GrPendingFragmentStage& processor, | 200 void GrGLProgram::setTransformData(const GrPendingFragmentStage& processor, |
| 201 const SkMatrix& localMatrix, |
| 188 GrGLInstalledFragProc* ip) { | 202 GrGLInstalledFragProc* ip) { |
| 189 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransfor
ms; | 203 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransfor
ms; |
| 190 int numTransforms = transforms.count(); | 204 int numTransforms = transforms.count(); |
| 191 SkASSERT(numTransforms == processor.getProcessor()->numTransforms()); | 205 SkASSERT(numTransforms == processor.getProcessor()->numTransforms()); |
| 192 for (int t = 0; t < numTransforms; ++t) { | 206 for (int t = 0; t < numTransforms; ++t) { |
| 193 SkASSERT(transforms[t].fHandle.isValid()); | 207 SkASSERT(transforms[t].fHandle.isValid()); |
| 194 const SkMatrix& matrix = get_transform_matrix(processor, t); | 208 const SkMatrix& matrix = get_transform_matrix(processor, t, localMatrix)
; |
| 195 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { | 209 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { |
| 196 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUnifo
rmHandle(), matrix); | 210 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUnifo
rmHandle(), matrix); |
| 197 transforms[t].fCurrentValue = matrix; | 211 transforms[t].fCurrentValue = matrix; |
| 198 } | 212 } |
| 199 } | 213 } |
| 200 } | 214 } |
| 201 | 215 |
| 202 void GrGLProgram::didSetData(GrGpu::DrawType drawType) { | 216 void GrGLProgram::didSetData(GrGpu::DrawType drawType) { |
| 203 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType)); | 217 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType)); |
| 204 } | 218 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 ); | 298 ); |
| 285 varying.fLocation = builderVarying.fLocation; | 299 varying.fLocation = builderVarying.fLocation; |
| 286 } | 300 } |
| 287 } | 301 } |
| 288 | 302 |
| 289 void GrGLNvprProgram::didSetData(GrGpu::DrawType drawType) { | 303 void GrGLNvprProgram::didSetData(GrGpu::DrawType drawType) { |
| 290 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); | 304 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); |
| 291 } | 305 } |
| 292 | 306 |
| 293 void GrGLNvprProgram::setTransformData(const GrPendingFragmentStage& proc, | 307 void GrGLNvprProgram::setTransformData(const GrPendingFragmentStage& proc, |
| 308 const SkMatrix& localMatrix, |
| 294 GrGLInstalledFragProc* ip) { | 309 GrGLInstalledFragProc* ip) { |
| 295 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransfor
ms; | 310 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransfor
ms; |
| 296 int numTransforms = transforms.count(); | 311 int numTransforms = transforms.count(); |
| 297 SkASSERT(numTransforms == proc.getProcessor()->numTransforms()); | 312 SkASSERT(numTransforms == proc.getProcessor()->numTransforms()); |
| 298 for (int t = 0; t < numTransforms; ++t) { | 313 for (int t = 0; t < numTransforms; ++t) { |
| 299 SkASSERT(transforms[t].fHandle.isValid()); | 314 SkASSERT(transforms[t].fHandle.isValid()); |
| 300 const SkMatrix& transform = get_transform_matrix(proc, t); | 315 const SkMatrix& transform = get_transform_matrix(proc, t, localMatrix); |
| 301 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { | 316 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { |
| 302 continue; | 317 continue; |
| 303 } | 318 } |
| 304 transforms[t].fCurrentValue = transform; | 319 transforms[t].fCurrentValue = transform; |
| 305 const Varying& fragmentInput = fVaryings[transforms[t].fHandle.handle()]
; | 320 const Varying& fragmentInput = fVaryings[transforms[t].fHandle.handle()]
; |
| 306 SkASSERT(transforms[t].fType == kVec2f_GrSLType || transforms[t].fType =
= kVec3f_GrSLType); | 321 SkASSERT(transforms[t].fType == kVec2f_GrSLType || transforms[t].fType =
= kVec3f_GrSLType); |
| 307 unsigned components = transforms[t].fType == kVec2f_GrSLType ? 2 : 3; | 322 unsigned components = transforms[t].fType == kVec2f_GrSLType ? 2 : 3; |
| 308 fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID
, | 323 fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID
, |
| 309 fragmentIn
put.fLocation, | 324 fragmentIn
put.fLocation, |
| 310 GR_GL_OBJE
CT_LINEAR, | 325 GR_GL_OBJE
CT_LINEAR, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 328 , fTexCoordSetCnt(texCoordSetCnt) { | 343 , fTexCoordSetCnt(texCoordSetCnt) { |
| 329 } | 344 } |
| 330 | 345 |
| 331 void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) { | 346 void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) { |
| 332 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); | 347 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); |
| 333 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); | 348 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); |
| 334 } | 349 } |
| 335 | 350 |
| 336 void | 351 void |
| 337 GrGLLegacyNvprProgram::setTransformData(const GrPendingFragmentStage& proc, | 352 GrGLLegacyNvprProgram::setTransformData(const GrPendingFragmentStage& proc, |
| 353 const SkMatrix& localMatrix, |
| 338 GrGLInstalledFragProc* ip) { | 354 GrGLInstalledFragProc* ip) { |
| 339 // We've hidden the texcoord index in the first entry of the transforms arra
y for each effect | 355 // We've hidden the texcoord index in the first entry of the transforms arra
y for each effect |
| 340 int texCoordIndex = ip->fTransforms[0].fHandle.handle(); | 356 int texCoordIndex = ip->fTransforms[0].fHandle.handle(); |
| 341 int numTransforms = proc.getProcessor()->numTransforms(); | 357 int numTransforms = proc.getProcessor()->numTransforms(); |
| 342 for (int t = 0; t < numTransforms; ++t) { | 358 for (int t = 0; t < numTransforms; ++t) { |
| 343 const SkMatrix& transform = get_transform_matrix(proc, t); | 359 const SkMatrix& transform = get_transform_matrix(proc, t, localMatrix); |
| 344 GrGLPathRendering::PathTexGenComponents components = | 360 GrGLPathRendering::PathTexGenComponents components = |
| 345 GrGLPathRendering::kST_PathTexGenComponents; | 361 GrGLPathRendering::kST_PathTexGenComponents; |
| 346 if (proc.isPerspectiveCoordTransform(t)) { | 362 if (proc.isPerspectiveCoordTransform(t)) { |
| 347 components = GrGLPathRendering::kSTR_PathTexGenComponents; | 363 components = GrGLPathRendering::kSTR_PathTexGenComponents; |
| 348 } | 364 } |
| 349 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t
ransform); | 365 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t
ransform); |
| 350 } | 366 } |
| 351 } | 367 } |
| OLD | NEW |