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 "GrGLProcessor.h" | 13 #include "GrGLProcessor.h" |
14 #include "GrGpuGL.h" | 14 #include "GrGpuGL.h" |
15 #include "GrGLPathRendering.h" | 15 #include "GrGLPathRendering.h" |
16 #include "GrGLShaderVar.h" | 16 #include "GrGLShaderVar.h" |
17 #include "GrGLSL.h" | 17 #include "GrGLSL.h" |
18 #include "GrOptDrawState.h" | 18 #include "GrOptDrawState.h" |
19 #include "SkXfermode.h" | 19 #include "SkXfermode.h" |
20 | 20 |
21 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) | 21 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) |
22 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) | 22 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) |
23 | 23 |
24 /** | 24 /** |
25 * Retrieves the final matrix that a transform needs to apply to its source coor ds. | 25 * Retrieves the final matrix that a transform needs to apply to its source coor ds. |
26 */ | 26 */ |
27 static SkMatrix get_transform_matrix(const GrProcessorStage& processorStage, | 27 static SkMatrix get_transform_matrix(const GrFragmentStage& processorStage, |
28 bool useExplicitLocalCoords, | 28 bool useExplicitLocalCoords, |
29 int transformIdx) { | 29 int transformIdx) { |
30 const GrCoordTransform& coordTransform = | 30 const GrCoordTransform& coordTransform = |
31 processorStage.getProcessor()->coordTransform(transformIdx); | 31 processorStage.getProcessor()->coordTransform(transformIdx); |
32 SkMatrix combined; | 32 SkMatrix combined; |
33 | 33 |
34 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { | 34 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { |
35 // 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. |
36 const SkMatrix& ccm = | 36 const SkMatrix& ccm = |
37 useExplicitLocalCoords ? SkMatrix::I() : processorStage.getCoord ChangeMatrix(); | 37 useExplicitLocalCoords ? SkMatrix::I() : processorStage.getCoord ChangeMatrix(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 SkTArray<GrGLInstalledProcessors::Sampler, true>& samplers = ip->fSample rs[e]; | 107 SkTArray<GrGLInstalledProcessors::Sampler, true>& samplers = ip->fSample rs[e]; |
108 int numSamplers = samplers.count(); | 108 int numSamplers = samplers.count(); |
109 for (int s = 0; s < numSamplers; ++s) { | 109 for (int s = 0; s < numSamplers; ++s) { |
110 SkASSERT(samplers[s].fUniform.isValid()); | 110 SkASSERT(samplers[s].fUniform.isValid()); |
111 fProgramDataManager.setSampler(samplers[s].fUniform, *texUnitIdx); | 111 fProgramDataManager.setSampler(samplers[s].fUniform, *texUnitIdx); |
112 samplers[s].fTextureUnit = (*texUnitIdx)++; | 112 samplers[s].fTextureUnit = (*texUnitIdx)++; |
113 } | 113 } |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 void GrGLProgram::bindTextures(const GrGLInstalledProcessors* ip, | 117 void GrGLProgram::bindTextures(const GrGLInstalledProcessors& ip, |
118 const GrProcessor& processor, | 118 const GrProcessor& processor, |
119 int effectIdx) { | 119 int effectIdx) { |
120 const SkTArray<GrGLInstalledProcessors::Sampler, true>& samplers = ip->fSamp lers[effectIdx]; | 120 const SkTArray<GrGLInstalledProcessors::Sampler, true>& samplers = ip.fSampl ers[effectIdx]; |
121 int numSamplers = samplers.count(); | 121 int numSamplers = samplers.count(); |
122 SkASSERT(numSamplers == processor.numTextures()); | 122 SkASSERT(numSamplers == processor.numTextures()); |
123 for (int s = 0; s < numSamplers; ++s) { | 123 for (int s = 0; s < numSamplers; ++s) { |
124 SkASSERT(samplers[s].fTextureUnit >= 0); | 124 SkASSERT(samplers[s].fTextureUnit >= 0); |
125 const GrTextureAccess& textureAccess = processor.textureAccess(s); | 125 const GrTextureAccess& textureAccess = processor.textureAccess(s); |
126 fGpu->bindTexture(samplers[s].fTextureUnit, | 126 fGpu->bindTexture(samplers[s].fTextureUnit, |
127 textureAccess.getParams(), | 127 textureAccess.getParams(), |
128 static_cast<GrGLTexture*>(textureAccess.getTexture())) ; | 128 static_cast<GrGLTexture*>(textureAccess.getTexture())) ; |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 | 132 |
133 /////////////////////////////////////////////////////////////////////////////// | 133 /////////////////////////////////////////////////////////////////////////////// |
134 | 134 |
135 struct ColorStageMapper { | |
136 static const GrFragmentStage& GetStage(const GrOptDrawState& optState, int i ndex) { | |
137 return optState.getColorStage(index); | |
138 } | |
139 }; | |
140 | |
141 struct CoverageStageMapper { | |
142 static const GrFragmentStage& GetStage(const GrOptDrawState& optState, int i ndex) { | |
143 return optState.getCoverageStage(index); | |
144 } | |
145 }; | |
146 | |
135 void GrGLProgram::setData(const GrOptDrawState& optState, | 147 void GrGLProgram::setData(const GrOptDrawState& optState, |
136 GrGpu::DrawType drawType, | 148 GrGpu::DrawType drawType, |
137 const GrGeometryStage* geometryProcessor, | |
138 const GrFragmentStage* colorStages[], | |
139 const GrFragmentStage* coverageStages[], | |
140 const GrDeviceCoordTexture* dstCopy, | 149 const GrDeviceCoordTexture* dstCopy, |
141 SharedGLState* sharedState) { | 150 SharedGLState* sharedState) { |
142 GrColor color = optState.getColor(); | 151 GrColor color = optState.getColor(); |
143 GrColor coverage = optState.getCoverageColor(); | 152 GrColor coverage = optState.getCoverageColor(); |
144 | 153 |
145 this->setColor(optState, color, sharedState); | 154 this->setColor(optState, color, sharedState); |
146 this->setCoverage(optState, coverage, sharedState); | 155 this->setCoverage(optState, coverage, sharedState); |
147 this->setMatrixAndRenderTargetHeight(drawType, optState); | 156 this->setMatrixAndRenderTargetHeight(drawType, optState); |
148 | 157 |
149 if (dstCopy) { | 158 if (dstCopy) { |
(...skipping 13 matching lines...) Expand all Loading... | |
163 } | 172 } |
164 } else { | 173 } else { |
165 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()); | 174 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()); |
166 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); | 175 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); |
167 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); | 176 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); |
168 } | 177 } |
169 | 178 |
170 // we set the textures, and uniforms for installed processors in a generic w ay, but subclasses | 179 // we set the textures, and uniforms for installed processors in a generic w ay, but subclasses |
171 // of GLProgram determine how to set coord transforms | 180 // of GLProgram determine how to set coord transforms |
172 if (fGeometryProcessor.get()) { | 181 if (fGeometryProcessor.get()) { |
173 SkASSERT(geometryProcessor); | 182 SkASSERT(optState.hasGeometryProcessor()); |
bsalomon
2014/10/09 18:35:45
Something feels off here... all these asserts make
| |
174 this->setData<GrGeometryStage>(&geometryProcessor, fGeometryProcessor.ge t()); | 183 const GrGLInstalledProcessors& ip = *fGeometryProcessor.get(); |
184 SkASSERT(1 == ip.fGLProcessors.count()); | |
185 // GPs do not have coord transforms | |
186 SkASSERT(0 == ip.fTransforms.count()); | |
187 SkASSERT(1 == ip.fSamplers.count()); | |
188 ip.fGLProcessors[0]->setData(fProgramDataManager, *optState.getGeometryP rocessor()); | |
189 this->bindTextures(ip, *optState.getGeometryProcessor(), 0); | |
175 } | 190 } |
176 this->setData<GrFragmentStage>(colorStages, fColorEffects.get()); | 191 this->setData<ColorStageMapper>(optState, fColorEffects.get()); |
177 this->setData<GrFragmentStage>(coverageStages, fCoverageEffects.get()); | 192 this->setData<CoverageStageMapper>(optState, fCoverageEffects.get()); |
178 | 193 |
179 // Some of GrGLProgram subclasses need to update state here | 194 // Some of GrGLProgram subclasses need to update state here |
180 this->didSetData(drawType); | 195 this->didSetData(drawType); |
181 } | 196 } |
182 | 197 |
183 void GrGLProgram::setTransformData(const GrProcessorStage& processor, | 198 void GrGLProgram::setTransformData(const GrFragmentStage& processor, |
184 int effectIdx, | 199 int effectIdx, |
185 GrGLInstalledProcessors* ip) { | 200 GrGLInstalledProcessors* ip) { |
186 SkTArray<GrGLInstalledProcessors::Transform, true>& transforms = ip->fTransf orms[effectIdx]; | 201 SkTArray<GrGLInstalledProcessors::Transform, true>& transforms = ip->fTransf orms[effectIdx]; |
187 int numTransforms = transforms.count(); | 202 int numTransforms = transforms.count(); |
188 SkASSERT(numTransforms == processor.getProcessor()->numTransforms()); | 203 SkASSERT(numTransforms == processor.getProcessor()->numTransforms()); |
189 for (int t = 0; t < numTransforms; ++t) { | 204 for (int t = 0; t < numTransforms; ++t) { |
190 SkASSERT(transforms[t].fHandle.isValid()); | 205 SkASSERT(transforms[t].fHandle.isValid()); |
191 const SkMatrix& matrix = get_transform_matrix(processor, ip->fHasExplici tLocalCoords, t); | 206 const SkMatrix& matrix = get_transform_matrix(processor, ip->fHasExplici tLocalCoords, t); |
192 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { | 207 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { |
193 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUnifo rmHandle(), matrix); | 208 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUnifo rmHandle(), matrix); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 varying.fType = builderVarying.fVariable.getType(); | 373 varying.fType = builderVarying.fVariable.getType(); |
359 ); | 374 ); |
360 varying.fLocation = builderVarying.fLocation; | 375 varying.fLocation = builderVarying.fLocation; |
361 } | 376 } |
362 } | 377 } |
363 | 378 |
364 void GrGLNvprProgram::didSetData(GrGpu::DrawType drawType) { | 379 void GrGLNvprProgram::didSetData(GrGpu::DrawType drawType) { |
365 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); | 380 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); |
366 } | 381 } |
367 | 382 |
368 void GrGLNvprProgram::setTransformData(const GrProcessorStage& processor, | 383 void GrGLNvprProgram::setTransformData(const GrFragmentStage& processor, |
369 int effectIdx, | 384 int effectIdx, |
370 GrGLInstalledProcessors* ip) { | 385 GrGLInstalledProcessors* ip) { |
371 SkTArray<GrGLInstalledProcessors::Transform, true>& transforms = ip->fTransf orms[effectIdx]; | 386 SkTArray<GrGLInstalledProcessors::Transform, true>& transforms = ip->fTransf orms[effectIdx]; |
372 int numTransforms = transforms.count(); | 387 int numTransforms = transforms.count(); |
373 SkASSERT(numTransforms == processor.getProcessor()->numTransforms()); | 388 SkASSERT(numTransforms == processor.getProcessor()->numTransforms()); |
374 for (int t = 0; t < numTransforms; ++t) { | 389 for (int t = 0; t < numTransforms; ++t) { |
375 SkASSERT(transforms[t].fHandle.isValid()); | 390 SkASSERT(transforms[t].fHandle.isValid()); |
376 const SkMatrix& transform = get_transform_matrix(processor, ip->fHasExpl icitLocalCoords, t); | 391 const SkMatrix& transform = get_transform_matrix(processor, ip->fHasExpl icitLocalCoords, t); |
377 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { | 392 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { |
378 continue; | 393 continue; |
(...skipping 23 matching lines...) Expand all Loading... | |
402 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, colorProcessors , | 417 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, colorProcessors , |
403 coverageProcessors) | 418 coverageProcessors) |
404 , fTexCoordSetCnt(texCoordSetCnt) { | 419 , fTexCoordSetCnt(texCoordSetCnt) { |
405 } | 420 } |
406 | 421 |
407 void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) { | 422 void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) { |
408 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); | 423 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); |
409 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); | 424 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); |
410 } | 425 } |
411 | 426 |
412 void GrGLLegacyNvprProgram::setTransformData(const GrProcessorStage& processorSt age, | 427 void GrGLLegacyNvprProgram::setTransformData(const GrFragmentStage& processorSta ge, |
413 int effectIdx, | 428 int effectIdx, |
414 GrGLInstalledProcessors* ip) { | 429 GrGLInstalledProcessors* ip) { |
415 // We've hidden the texcoord index in the first entry of the transforms arra y for each effect | 430 // We've hidden the texcoord index in the first entry of the transforms arra y for each effect |
416 int texCoordIndex = ip->fTransforms[effectIdx][0].fHandle.handle(); | 431 int texCoordIndex = ip->fTransforms[effectIdx][0].fHandle.handle(); |
417 int numTransforms = processorStage.getProcessor()->numTransforms(); | 432 int numTransforms = processorStage.getProcessor()->numTransforms(); |
418 for (int t = 0; t < numTransforms; ++t) { | 433 for (int t = 0; t < numTransforms; ++t) { |
419 const SkMatrix& transform = get_transform_matrix(processorStage, false, t); | 434 const SkMatrix& transform = get_transform_matrix(processorStage, false, t); |
420 GrGLPathRendering::PathTexGenComponents components = | 435 GrGLPathRendering::PathTexGenComponents components = |
421 GrGLPathRendering::kST_PathTexGenComponents; | 436 GrGLPathRendering::kST_PathTexGenComponents; |
422 if (processorStage.isPerspectiveCoordTransform(t, false)) { | 437 if (processorStage.isPerspectiveCoordTransform(t, false)) { |
423 components = GrGLPathRendering::kSTR_PathTexGenComponents; | 438 components = GrGLPathRendering::kSTR_PathTexGenComponents; |
424 } | 439 } |
425 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t ransform); | 440 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t ransform); |
426 } | 441 } |
427 } | 442 } |
OLD | NEW |