| 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 "GrGpuGL.h" | 15 #include "GrGpuGL.h" |
| 16 #include "GrGLPathRendering.h" | 16 #include "GrGLPathRendering.h" |
| 17 #include "GrGLShaderVar.h" | 17 #include "GrGLShaderVar.h" |
| 18 #include "GrGLSL.h" | 18 #include "GrGLSL.h" |
| 19 #include "GrOptDrawState.h" | 19 #include "GrOptDrawState.h" |
| 20 #include "SkXfermode.h" | 20 #include "SkXfermode.h" |
| 21 | 21 |
| 22 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) | 22 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) |
| 23 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) | 23 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * Retrieves the final matrix that a transform needs to apply to its source coor
ds. | 26 * Retrieves the final matrix that a transform needs to apply to its source coor
ds. |
| 27 */ | 27 */ |
| 28 static SkMatrix get_transform_matrix(const GrFragmentStage& processorStage, | 28 static SkMatrix get_transform_matrix(const GrPendingFragmentStage& stage, |
| 29 bool useExplicitLocalCoords, | 29 bool useExplicitLocalCoords, |
| 30 int transformIdx) { | 30 int transformIdx) { |
| 31 const GrCoordTransform& coordTransform = | 31 const GrCoordTransform& coordTransform = stage.getProcessor()->coordTransfor
m(transformIdx); |
| 32 processorStage.getProcessor()->coordTransform(transformIdx); | |
| 33 SkMatrix combined; | 32 SkMatrix combined; |
| 34 | 33 |
| 35 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { | 34 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { |
| 36 // If we have explicit local coords then we shouldn't need a coord chang
e. | 35 // If we have explicit local coords then we shouldn't need a coord chang
e. |
| 37 const SkMatrix& ccm = | 36 const SkMatrix& ccm = |
| 38 useExplicitLocalCoords ? SkMatrix::I() : processorStage.getCoord
ChangeMatrix(); | 37 useExplicitLocalCoords ? SkMatrix::I() : stage.getCoordChangeMat
rix(); |
| 39 combined.setConcat(coordTransform.getMatrix(), ccm); | 38 combined.setConcat(coordTransform.getMatrix(), ccm); |
| 40 } else { | 39 } else { |
| 41 combined = coordTransform.getMatrix(); | 40 combined = coordTransform.getMatrix(); |
| 42 } | 41 } |
| 43 if (coordTransform.reverseY()) { | 42 if (coordTransform.reverseY()) { |
| 44 // combined.postScale(1,-1); | 43 // combined.postScale(1,-1); |
| 45 // combined.postTranslate(0,1); | 44 // combined.postTranslate(0,1); |
| 46 combined.set(SkMatrix::kMSkewY, | 45 combined.set(SkMatrix::kMSkewY, |
| 47 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); | 46 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); |
| 48 combined.set(SkMatrix::kMScaleY, | 47 combined.set(SkMatrix::kMScaleY, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 } | 167 } |
| 169 this->setFragmentData(optState); | 168 this->setFragmentData(optState); |
| 170 | 169 |
| 171 // Some of GrGLProgram subclasses need to update state here | 170 // Some of GrGLProgram subclasses need to update state here |
| 172 this->didSetData(drawType); | 171 this->didSetData(drawType); |
| 173 } | 172 } |
| 174 | 173 |
| 175 void GrGLProgram::setFragmentData(const GrOptDrawState& optState) { | 174 void GrGLProgram::setFragmentData(const GrOptDrawState& optState) { |
| 176 int numProcessors = fFragmentProcessors->fProcs.count(); | 175 int numProcessors = fFragmentProcessors->fProcs.count(); |
| 177 for (int e = 0; e < numProcessors; ++e) { | 176 for (int e = 0; e < numProcessors; ++e) { |
| 178 const GrFragmentStage& stage = optState.getFragmentStage(e); | 177 const GrPendingFragmentStage& stage = optState.getFragmentStage(e); |
| 179 const GrProcessor& processor = *stage.getProcessor(); | 178 const GrProcessor& processor = *stage.getProcessor(); |
| 180 fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, pr
ocessor); | 179 fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, pr
ocessor); |
| 181 this->setTransformData(stage, fFragmentProcessors->fProcs[e]); | 180 this->setTransformData(stage, fFragmentProcessors->fProcs[e]); |
| 182 this->bindTextures(fFragmentProcessors->fProcs[e], processor); | 181 this->bindTextures(fFragmentProcessors->fProcs[e], processor); |
| 183 } | 182 } |
| 184 } | 183 } |
| 185 void GrGLProgram::setTransformData(const GrFragmentStage& processor, GrGLInstall
edFragProc* ip) { | 184 void GrGLProgram::setTransformData(const GrPendingFragmentStage& processor, |
| 185 GrGLInstalledFragProc* ip) { |
| 186 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransfor
ms; | 186 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransfor
ms; |
| 187 int numTransforms = transforms.count(); | 187 int numTransforms = transforms.count(); |
| 188 SkASSERT(numTransforms == processor.getProcessor()->numTransforms()); | 188 SkASSERT(numTransforms == processor.getProcessor()->numTransforms()); |
| 189 for (int t = 0; t < numTransforms; ++t) { | 189 for (int t = 0; t < numTransforms; ++t) { |
| 190 SkASSERT(transforms[t].fHandle.isValid()); | 190 SkASSERT(transforms[t].fHandle.isValid()); |
| 191 const SkMatrix& matrix = get_transform_matrix(processor, ip->fLocalCoord
Attrib, t); | 191 const SkMatrix& matrix = get_transform_matrix(processor, ip->fLocalCoord
Attrib, t); |
| 192 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { | 192 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { |
| 193 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUnifo
rmHandle(), matrix); | 193 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUnifo
rmHandle(), matrix); |
| 194 transforms[t].fCurrentValue = matrix; | 194 transforms[t].fCurrentValue = matrix; |
| 195 } | 195 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 varying.fType = builderVarying.fVariable.getType(); | 322 varying.fType = builderVarying.fVariable.getType(); |
| 323 ); | 323 ); |
| 324 varying.fLocation = builderVarying.fLocation; | 324 varying.fLocation = builderVarying.fLocation; |
| 325 } | 325 } |
| 326 } | 326 } |
| 327 | 327 |
| 328 void GrGLNvprProgram::didSetData(GrGpu::DrawType drawType) { | 328 void GrGLNvprProgram::didSetData(GrGpu::DrawType drawType) { |
| 329 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); | 329 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); |
| 330 } | 330 } |
| 331 | 331 |
| 332 void GrGLNvprProgram::setTransformData(const GrFragmentStage& proc, GrGLInstalle
dFragProc* ip) { | 332 void GrGLNvprProgram::setTransformData(const GrPendingFragmentStage& proc, |
| 333 GrGLInstalledFragProc* ip) { |
| 333 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransfor
ms; | 334 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransfor
ms; |
| 334 int numTransforms = transforms.count(); | 335 int numTransforms = transforms.count(); |
| 335 SkASSERT(numTransforms == proc.getProcessor()->numTransforms()); | 336 SkASSERT(numTransforms == proc.getProcessor()->numTransforms()); |
| 336 for (int t = 0; t < numTransforms; ++t) { | 337 for (int t = 0; t < numTransforms; ++t) { |
| 337 SkASSERT(transforms[t].fHandle.isValid()); | 338 SkASSERT(transforms[t].fHandle.isValid()); |
| 338 const SkMatrix& transform = get_transform_matrix(proc, false, t); | 339 const SkMatrix& transform = get_transform_matrix(proc, false, t); |
| 339 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { | 340 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { |
| 340 continue; | 341 continue; |
| 341 } | 342 } |
| 342 transforms[t].fCurrentValue = transform; | 343 transforms[t].fCurrentValue = transform; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 363 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fps) | 364 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fps) |
| 364 , fTexCoordSetCnt(texCoordSetCnt) { | 365 , fTexCoordSetCnt(texCoordSetCnt) { |
| 365 } | 366 } |
| 366 | 367 |
| 367 void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) { | 368 void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) { |
| 368 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); | 369 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); |
| 369 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); | 370 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); |
| 370 } | 371 } |
| 371 | 372 |
| 372 void | 373 void |
| 373 GrGLLegacyNvprProgram::setTransformData(const GrFragmentStage& proc, GrGLInstall
edFragProc* ip) { | 374 GrGLLegacyNvprProgram::setTransformData(const GrPendingFragmentStage& proc, |
| 375 GrGLInstalledFragProc* ip) { |
| 374 // We've hidden the texcoord index in the first entry of the transforms arra
y for each effect | 376 // We've hidden the texcoord index in the first entry of the transforms arra
y for each effect |
| 375 int texCoordIndex = ip->fTransforms[0].fHandle.handle(); | 377 int texCoordIndex = ip->fTransforms[0].fHandle.handle(); |
| 376 int numTransforms = proc.getProcessor()->numTransforms(); | 378 int numTransforms = proc.getProcessor()->numTransforms(); |
| 377 for (int t = 0; t < numTransforms; ++t) { | 379 for (int t = 0; t < numTransforms; ++t) { |
| 378 const SkMatrix& transform = get_transform_matrix(proc, false, t); | 380 const SkMatrix& transform = get_transform_matrix(proc, false, t); |
| 379 GrGLPathRendering::PathTexGenComponents components = | 381 GrGLPathRendering::PathTexGenComponents components = |
| 380 GrGLPathRendering::kST_PathTexGenComponents; | 382 GrGLPathRendering::kST_PathTexGenComponents; |
| 381 if (proc.isPerspectiveCoordTransform(t, false)) { | 383 if (proc.isPerspectiveCoordTransform(t)) { |
| 382 components = GrGLPathRendering::kSTR_PathTexGenComponents; | 384 components = GrGLPathRendering::kSTR_PathTexGenComponents; |
| 383 } | 385 } |
| 384 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t
ransform); | 386 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t
ransform); |
| 385 } | 387 } |
| 386 } | 388 } |
| OLD | NEW |