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 GrPendingFragmentStage& stage, | 28 static SkMatrix get_transform_matrix(const GrPendingFragmentStage& stage, int tr
ansformIdx) { |
29 bool useExplicitLocalCoords, | |
30 int transformIdx) { | |
31 const GrCoordTransform& coordTransform = stage.getProcessor()->coordTransfor
m(transformIdx); | 29 const GrCoordTransform& coordTransform = stage.getProcessor()->coordTransfor
m(transformIdx); |
32 SkMatrix combined; | 30 SkMatrix combined; |
33 | 31 |
34 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { | 32 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { |
35 // If we have explicit local coords then we shouldn't need a coord chang
e. | 33 // If we have explicit local coords then we shouldn't need a coord chang
e. |
36 const SkMatrix& ccm = | 34 const SkMatrix& ccm = stage.getCoordChangeMatrix(); |
37 useExplicitLocalCoords ? SkMatrix::I() : stage.getCoordChangeMat
rix(); | |
38 combined.setConcat(coordTransform.getMatrix(), ccm); | 35 combined.setConcat(coordTransform.getMatrix(), ccm); |
39 } else { | 36 } else { |
40 combined = coordTransform.getMatrix(); | 37 combined = coordTransform.getMatrix(); |
41 } | 38 } |
42 if (coordTransform.reverseY()) { | 39 if (coordTransform.reverseY()) { |
43 // combined.postScale(1,-1); | 40 // combined.postScale(1,-1); |
44 // combined.postTranslate(0,1); | 41 // combined.postTranslate(0,1); |
45 combined.set(SkMatrix::kMSkewY, | 42 combined.set(SkMatrix::kMSkewY, |
46 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); | 43 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); |
47 combined.set(SkMatrix::kMScaleY, | 44 combined.set(SkMatrix::kMScaleY, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 this->bindTextures(fFragmentProcessors->fProcs[e], processor); | 177 this->bindTextures(fFragmentProcessors->fProcs[e], processor); |
181 } | 178 } |
182 } | 179 } |
183 void GrGLProgram::setTransformData(const GrPendingFragmentStage& processor, | 180 void GrGLProgram::setTransformData(const GrPendingFragmentStage& processor, |
184 GrGLInstalledFragProc* ip) { | 181 GrGLInstalledFragProc* ip) { |
185 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransfor
ms; | 182 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransfor
ms; |
186 int numTransforms = transforms.count(); | 183 int numTransforms = transforms.count(); |
187 SkASSERT(numTransforms == processor.getProcessor()->numTransforms()); | 184 SkASSERT(numTransforms == processor.getProcessor()->numTransforms()); |
188 for (int t = 0; t < numTransforms; ++t) { | 185 for (int t = 0; t < numTransforms; ++t) { |
189 SkASSERT(transforms[t].fHandle.isValid()); | 186 SkASSERT(transforms[t].fHandle.isValid()); |
190 const SkMatrix& matrix = get_transform_matrix(processor, ip->fLocalCoord
Attrib, t); | 187 const SkMatrix& matrix = get_transform_matrix(processor, t); |
191 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { | 188 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { |
192 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUnifo
rmHandle(), matrix); | 189 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUnifo
rmHandle(), matrix); |
193 transforms[t].fCurrentValue = matrix; | 190 transforms[t].fCurrentValue = matrix; |
194 } | 191 } |
195 } | 192 } |
196 } | 193 } |
197 | 194 |
198 void GrGLProgram::didSetData(GrGpu::DrawType drawType) { | 195 void GrGLProgram::didSetData(GrGpu::DrawType drawType) { |
199 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType)); | 196 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType)); |
200 } | 197 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); | 325 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); |
329 } | 326 } |
330 | 327 |
331 void GrGLNvprProgram::setTransformData(const GrPendingFragmentStage& proc, | 328 void GrGLNvprProgram::setTransformData(const GrPendingFragmentStage& proc, |
332 GrGLInstalledFragProc* ip) { | 329 GrGLInstalledFragProc* ip) { |
333 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransfor
ms; | 330 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransfor
ms; |
334 int numTransforms = transforms.count(); | 331 int numTransforms = transforms.count(); |
335 SkASSERT(numTransforms == proc.getProcessor()->numTransforms()); | 332 SkASSERT(numTransforms == proc.getProcessor()->numTransforms()); |
336 for (int t = 0; t < numTransforms; ++t) { | 333 for (int t = 0; t < numTransforms; ++t) { |
337 SkASSERT(transforms[t].fHandle.isValid()); | 334 SkASSERT(transforms[t].fHandle.isValid()); |
338 const SkMatrix& transform = get_transform_matrix(proc, false, t); | 335 const SkMatrix& transform = get_transform_matrix(proc, t); |
339 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { | 336 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { |
340 continue; | 337 continue; |
341 } | 338 } |
342 transforms[t].fCurrentValue = transform; | 339 transforms[t].fCurrentValue = transform; |
343 const Varying& fragmentInput = fVaryings[transforms[t].fHandle.handle()]
; | 340 const Varying& fragmentInput = fVaryings[transforms[t].fHandle.handle()]
; |
344 SkASSERT(transforms[t].fType == kVec2f_GrSLType || transforms[t].fType =
= kVec3f_GrSLType); | 341 SkASSERT(transforms[t].fType == kVec2f_GrSLType || transforms[t].fType =
= kVec3f_GrSLType); |
345 unsigned components = transforms[t].fType == kVec2f_GrSLType ? 2 : 3; | 342 unsigned components = transforms[t].fType == kVec2f_GrSLType ? 2 : 3; |
346 fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID
, | 343 fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID
, |
347 fragmentIn
put.fLocation, | 344 fragmentIn
put.fLocation, |
348 GR_GL_OBJE
CT_LINEAR, | 345 GR_GL_OBJE
CT_LINEAR, |
(...skipping 20 matching lines...) Expand all Loading... |
369 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); | 366 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); |
370 } | 367 } |
371 | 368 |
372 void | 369 void |
373 GrGLLegacyNvprProgram::setTransformData(const GrPendingFragmentStage& proc, | 370 GrGLLegacyNvprProgram::setTransformData(const GrPendingFragmentStage& proc, |
374 GrGLInstalledFragProc* ip) { | 371 GrGLInstalledFragProc* ip) { |
375 // We've hidden the texcoord index in the first entry of the transforms arra
y for each effect | 372 // We've hidden the texcoord index in the first entry of the transforms arra
y for each effect |
376 int texCoordIndex = ip->fTransforms[0].fHandle.handle(); | 373 int texCoordIndex = ip->fTransforms[0].fHandle.handle(); |
377 int numTransforms = proc.getProcessor()->numTransforms(); | 374 int numTransforms = proc.getProcessor()->numTransforms(); |
378 for (int t = 0; t < numTransforms; ++t) { | 375 for (int t = 0; t < numTransforms; ++t) { |
379 const SkMatrix& transform = get_transform_matrix(proc, false, t); | 376 const SkMatrix& transform = get_transform_matrix(proc, t); |
380 GrGLPathRendering::PathTexGenComponents components = | 377 GrGLPathRendering::PathTexGenComponents components = |
381 GrGLPathRendering::kST_PathTexGenComponents; | 378 GrGLPathRendering::kST_PathTexGenComponents; |
382 if (proc.isPerspectiveCoordTransform(t)) { | 379 if (proc.isPerspectiveCoordTransform(t)) { |
383 components = GrGLPathRendering::kSTR_PathTexGenComponents; | 380 components = GrGLPathRendering::kSTR_PathTexGenComponents; |
384 } | 381 } |
385 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t
ransform); | 382 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t
ransform); |
386 } | 383 } |
387 } | 384 } |
OLD | NEW |