OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "GrGLProgramEffects.h" | 8 #include "GrGLProgramEffects.h" |
9 #include "gl/GrGLEffect.h" | 9 #include "gl/GrGLProcessor.h" |
10 #include "gl/GrGLPathRendering.h" | 10 #include "gl/GrGLPathRendering.h" |
11 #include "gl/builders/GrGLFullProgramBuilder.h" | 11 #include "gl/builders/GrGLFullProgramBuilder.h" |
12 #include "gl/builders/GrGLFragmentOnlyProgramBuilder.h" | 12 #include "gl/builders/GrGLFragmentOnlyProgramBuilder.h" |
13 #include "gl/GrGLGeometryProcessor.h" | 13 #include "gl/GrGLGeometryProcessor.h" |
14 #include "gl/GrGpuGL.h" | 14 #include "gl/GrGpuGL.h" |
15 | 15 |
16 typedef GrGLEffect::TransformedCoords TransformedCoords; | 16 typedef GrGLProcessor::TransformedCoords TransformedCoords; |
17 typedef GrGLEffect::TransformedCoordsArray TransformedCoordsArray; | 17 typedef GrGLProcessor::TransformedCoordsArray TransformedCoordsArray; |
18 typedef GrGLEffect::TextureSampler TextureSampler; | 18 typedef GrGLProcessor::TextureSampler TextureSampler; |
19 typedef GrGLEffect::TextureSamplerArray TextureSamplerArray; | 19 typedef GrGLProcessor::TextureSamplerArray TextureSamplerArray; |
20 | 20 |
21 namespace { | 21 namespace { |
22 /** | 22 /** |
23 * Retrieves the final matrix that a transform needs to apply to its source coor ds. | 23 * Retrieves the final matrix that a transform needs to apply to its source coor ds. |
24 */ | 24 */ |
25 SkMatrix get_transform_matrix(const GrEffectStage& effectStage, | 25 SkMatrix get_transform_matrix(const GrProcessorStage& effectStage, |
26 bool useExplicitLocalCoords, | 26 bool useExplicitLocalCoords, |
27 int transformIdx) { | 27 int transformIdx) { |
28 const GrCoordTransform& coordTransform = effectStage.getEffect()->coordTrans form(transformIdx); | 28 const GrCoordTransform& coordTransform = effectStage.getProcessor()->coordTr ansform(transformIdx); |
29 SkMatrix combined; | 29 SkMatrix combined; |
30 | 30 |
31 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { | 31 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { |
32 // If we have explicit local coords then we shouldn't need a coord chang e. | 32 // If we have explicit local coords then we shouldn't need a coord chang e. |
33 const SkMatrix& ccm = | 33 const SkMatrix& ccm = |
34 useExplicitLocalCoords ? SkMatrix::I() : effectStage.getCoordCha ngeMatrix(); | 34 useExplicitLocalCoords ? SkMatrix::I() : effectStage.getCoordCha ngeMatrix(); |
35 combined.setConcat(coordTransform.getMatrix(), ccm); | 35 combined.setConcat(coordTransform.getMatrix(), ccm); |
36 } else { | 36 } else { |
37 combined = coordTransform.getMatrix(); | 37 combined = coordTransform.getMatrix(); |
38 } | 38 } |
39 if (coordTransform.reverseY()) { | 39 if (coordTransform.reverseY()) { |
40 // combined.postScale(1,-1); | 40 // combined.postScale(1,-1); |
41 // combined.postTranslate(0,1); | 41 // combined.postTranslate(0,1); |
42 combined.set(SkMatrix::kMSkewY, | 42 combined.set(SkMatrix::kMSkewY, |
43 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); | 43 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); |
44 combined.set(SkMatrix::kMScaleY, | 44 combined.set(SkMatrix::kMScaleY, |
45 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]); | 45 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]); |
46 combined.set(SkMatrix::kMTransY, | 46 combined.set(SkMatrix::kMTransY, |
47 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]); | 47 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]); |
48 } | 48 } |
49 return combined; | 49 return combined; |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 //////////////////////////////////////////////////////////////////////////////// | 53 //////////////////////////////////////////////////////////////////////////////// |
54 | 54 |
55 GrGLProgramEffects::~GrGLProgramEffects() { | 55 GrGLProgramEffects::~GrGLProgramEffects() { |
56 int numEffects = fGLEffects.count(); | 56 int numEffects = fGLProcessors.count(); |
57 for (int e = 0; e < numEffects; ++e) { | 57 for (int e = 0; e < numEffects; ++e) { |
58 SkDELETE(fGLEffects[e]); | 58 SkDELETE(fGLProcessors[e]); |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 void GrGLProgramEffects::initSamplers(const GrGLProgramDataManager& programResou rceManager, int* texUnitIdx) { | 62 void GrGLProgramEffects::initSamplers(const GrGLProgramDataManager& programResou rceManager, int* texUnitIdx) { |
63 int numEffects = fGLEffects.count(); | 63 int numEffects = fGLProcessors.count(); |
64 SkASSERT(numEffects == fSamplers.count()); | 64 SkASSERT(numEffects == fSamplers.count()); |
65 for (int e = 0; e < numEffects; ++e) { | 65 for (int e = 0; e < numEffects; ++e) { |
66 SkTArray<Sampler, true>& samplers = fSamplers[e]; | 66 SkTArray<Sampler, true>& samplers = fSamplers[e]; |
67 int numSamplers = samplers.count(); | 67 int numSamplers = samplers.count(); |
68 for (int s = 0; s < numSamplers; ++s) { | 68 for (int s = 0; s < numSamplers; ++s) { |
69 SkASSERT(samplers[s].fUniform.isValid()); | 69 SkASSERT(samplers[s].fUniform.isValid()); |
70 programResourceManager.setSampler(samplers[s].fUniform, *texUnitIdx) ; | 70 programResourceManager.setSampler(samplers[s].fUniform, *texUnitIdx) ; |
71 samplers[s].fTextureUnit = (*texUnitIdx)++; | 71 samplers[s].fTextureUnit = (*texUnitIdx)++; |
72 } | 72 } |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 void GrGLProgramEffects::bindTextures(GrGpuGL* gpu, const GrEffect& effect, int effectIdx) { | 76 void GrGLProgramEffects::bindTextures(GrGpuGL* gpu, const GrProcessor& effect, i nt effectIdx) { |
77 const SkTArray<Sampler, true>& samplers = fSamplers[effectIdx]; | 77 const SkTArray<Sampler, true>& samplers = fSamplers[effectIdx]; |
78 int numSamplers = samplers.count(); | 78 int numSamplers = samplers.count(); |
79 SkASSERT(numSamplers == effect.numTextures()); | 79 SkASSERT(numSamplers == effect.numTextures()); |
80 for (int s = 0; s < numSamplers; ++s) { | 80 for (int s = 0; s < numSamplers; ++s) { |
81 SkASSERT(samplers[s].fTextureUnit >= 0); | 81 SkASSERT(samplers[s].fTextureUnit >= 0); |
82 const GrTextureAccess& textureAccess = effect.textureAccess(s); | 82 const GrTextureAccess& textureAccess = effect.textureAccess(s); |
83 gpu->bindTexture(samplers[s].fTextureUnit, | 83 gpu->bindTexture(samplers[s].fTextureUnit, |
84 textureAccess.getParams(), | 84 textureAccess.getParams(), |
85 static_cast<GrGLTexture*>(textureAccess.getTexture())); | 85 static_cast<GrGLTexture*>(textureAccess.getTexture())); |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 //////////////////////////////////////////////////////////////////////////////// | 89 //////////////////////////////////////////////////////////////////////////////// |
90 | 90 |
91 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu, | 91 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu, |
92 GrGpu::DrawType drawType, | 92 GrGpu::DrawType drawType, |
93 const GrGLProgramDataManager& programData Manager, | 93 const GrGLProgramDataManager& programData Manager, |
94 const GrEffectStage* effectStages[]) { | 94 const GrGeometryStage* effectStages) { |
95 int numEffects = fGLEffects.count(); | 95 SkASSERT(1 == fGLProcessors.count()); |
96 SkASSERT(1 == fTransforms.count()); | |
97 SkASSERT(1 == fSamplers.count()); | |
98 setDataInternal(gpu, drawType, programDataManager, *effectStages, 0); | |
bsalomon
2014/09/22 15:35:24
this->
| |
99 } | |
100 | |
101 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu, | |
102 GrGpu::DrawType drawType, | |
103 const GrGLProgramDataManager& programData Manager, | |
104 const GrFragmentStage* effectStages[]) { | |
105 int numEffects = fGLProcessors.count(); | |
96 SkASSERT(numEffects == fTransforms.count()); | 106 SkASSERT(numEffects == fTransforms.count()); |
97 SkASSERT(numEffects == fSamplers.count()); | 107 SkASSERT(numEffects == fSamplers.count()); |
98 for (int e = 0; e < numEffects; ++e) { | 108 for (int e = 0; e < numEffects; ++e) { |
99 const GrEffectStage& effectStage = *effectStages[e]; | 109 setDataInternal(gpu, drawType, programDataManager, *effectStages[e], e); |
bsalomon
2014/09/22 15:35:24
this->
| |
100 const GrEffect& effect = *effectStage.getEffect(); | 110 } |
101 fGLEffects[e]->setData(programDataManager, effect); | 111 } |
102 if (GrGpu::IsPathRenderingDrawType(drawType)) { | |
103 this->setPathTransformData(gpu, programDataManager, effectStage, e); | |
104 } else { | |
105 this->setTransformData(gpu, programDataManager, effectStage, e); | |
106 } | |
107 | 112 |
108 this->bindTextures(gpu, effect, e); | 113 void GrGLVertexProgramEffects::setDataInternal(GrGpuGL* gpu, |
114 GrGpu::DrawType drawType, | |
115 const GrGLProgramDataManager& pro gramDataManager, | |
116 const GrProcessorStage& effectSta ge, | |
117 int index) { | |
118 const GrProcessor& effect = *effectStage.getProcessor(); | |
119 fGLProcessors[index]->setData(programDataManager, effect); | |
120 if (GrGpu::IsPathRenderingDrawType(drawType)) { | |
121 this->setPathTransformData(gpu, programDataManager, effectStage, index); | |
122 } else { | |
123 this->setTransformData(gpu, programDataManager, effectStage, index); | |
109 } | 124 } |
125 this->bindTextures(gpu, effect, index); | |
110 } | 126 } |
111 | 127 |
112 void GrGLVertexProgramEffects::setTransformData(GrGpuGL* gpu, | 128 void GrGLVertexProgramEffects::setTransformData(GrGpuGL* gpu, |
113 const GrGLProgramDataManager& pd man, | 129 const GrGLProgramDataManager& pd man, |
114 const GrEffectStage& effectStage , | 130 const GrProcessorStage& effectSt age, |
115 int effectIdx) { | 131 int effectIdx) { |
116 SkTArray<Transform, true>& transforms = fTransforms[effectIdx]; | 132 SkTArray<Transform, true>& transforms = fTransforms[effectIdx]; |
117 int numTransforms = transforms.count(); | 133 int numTransforms = transforms.count(); |
118 SkASSERT(numTransforms == effectStage.getEffect()->numTransforms()); | 134 SkASSERT(numTransforms == effectStage.getProcessor()->numTransforms()); |
119 for (int t = 0; t < numTransforms; ++t) { | 135 for (int t = 0; t < numTransforms; ++t) { |
120 SkASSERT(transforms[t].fHandle.isValid()); | 136 SkASSERT(transforms[t].fHandle.isValid()); |
121 const SkMatrix& matrix = get_transform_matrix(effectStage, fHasExplicitL ocalCoords, t); | 137 const SkMatrix& matrix = get_transform_matrix(effectStage, fHasExplicitL ocalCoords, t); |
122 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { | 138 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { |
123 pdman.setSkMatrix(transforms[t].fHandle, matrix); | 139 pdman.setSkMatrix(transforms[t].fHandle, matrix); |
124 transforms[t].fCurrentValue = matrix; | 140 transforms[t].fCurrentValue = matrix; |
125 } | 141 } |
126 } | 142 } |
127 } | 143 } |
128 | 144 |
129 void GrGLVertexProgramEffects::setPathTransformData(GrGpuGL* gpu, | 145 void GrGLVertexProgramEffects::setPathTransformData(GrGpuGL* gpu, |
130 const GrGLProgramDataManager & pdman, | 146 const GrGLProgramDataManager & pdman, |
131 const GrEffectStage& effectS tage, | 147 const GrProcessorStage& effe ctStage, |
132 int effectIdx) { | 148 int effectIdx) { |
133 SkTArray<PathTransform, true>& transforms = fPathTransforms[effectIdx]; | 149 SkTArray<PathTransform, true>& transforms = fPathTransforms[effectIdx]; |
134 int numTransforms = transforms.count(); | 150 int numTransforms = transforms.count(); |
135 SkASSERT(numTransforms == effectStage.getEffect()->numTransforms()); | 151 SkASSERT(numTransforms == effectStage.getProcessor()->numTransforms()); |
136 for (int t = 0; t < numTransforms; ++t) { | 152 for (int t = 0; t < numTransforms; ++t) { |
137 SkASSERT(transforms[t].fHandle.isValid()); | 153 SkASSERT(transforms[t].fHandle.isValid()); |
138 const SkMatrix& transform = get_transform_matrix(effectStage, fHasExplic itLocalCoords, t); | 154 const SkMatrix& transform = get_transform_matrix(effectStage, fHasExplic itLocalCoords, t); |
139 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { | 155 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { |
140 continue; | 156 continue; |
141 } | 157 } |
142 transforms[t].fCurrentValue = transform; | 158 transforms[t].fCurrentValue = transform; |
143 switch (transforms[t].fType) { | 159 switch (transforms[t].fType) { |
144 case kVec2f_GrSLType: | 160 case kVec2f_GrSLType: |
145 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle , 2, transform); | 161 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle , 2, transform); |
146 break; | 162 break; |
147 case kVec3f_GrSLType: | 163 case kVec3f_GrSLType: |
148 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle , 3, transform); | 164 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle , 3, transform); |
149 break; | 165 break; |
150 default: | 166 default: |
151 SkFAIL("Unexpected matrix type."); | 167 SkFAIL("Unexpected matrix type."); |
152 } | 168 } |
153 } | 169 } |
154 } | 170 } |
155 | 171 |
156 //////////////////////////////////////////////////////////////////////////////// | 172 //////////////////////////////////////////////////////////////////////////////// |
157 | 173 |
158 void GrGLPathTexGenProgramEffects::setData(GrGpuGL* gpu, | 174 void GrGLPathTexGenProgramEffects::setData(GrGpuGL* gpu, |
159 GrGpu::DrawType, | 175 GrGpu::DrawType, |
160 const GrGLProgramDataManager& pdman, | 176 const GrGLProgramDataManager& pdman, |
161 const GrEffectStage* effectStages[]) { | 177 const GrFragmentStage* effectStages[] ) { |
162 int numEffects = fGLEffects.count(); | 178 int numEffects = fGLProcessors.count(); |
163 SkASSERT(numEffects == fTransforms.count()); | 179 SkASSERT(numEffects == fTransforms.count()); |
164 SkASSERT(numEffects == fSamplers.count()); | 180 SkASSERT(numEffects == fSamplers.count()); |
165 for (int e = 0; e < numEffects; ++e) { | 181 for (int e = 0; e < numEffects; ++e) { |
166 const GrEffectStage& effectStage = *effectStages[e]; | 182 const GrProcessorStage& effectStage = *effectStages[e]; |
167 const GrEffect& effect = *effectStage.getEffect(); | 183 const GrProcessor& effect = *effectStage.getProcessor(); |
168 fGLEffects[e]->setData(pdman, effect); | 184 fGLProcessors[e]->setData(pdman, effect); |
169 this->setPathTexGenState(gpu, effectStage, e); | 185 this->setPathTexGenState(gpu, effectStage, e); |
170 this->bindTextures(gpu, effect, e); | 186 this->bindTextures(gpu, effect, e); |
171 } | 187 } |
172 } | 188 } |
173 | 189 |
174 void GrGLPathTexGenProgramEffects::setPathTexGenState(GrGpuGL* gpu, | 190 void GrGLPathTexGenProgramEffects::setPathTexGenState(GrGpuGL* gpu, |
175 const GrEffectStage& effectStage, | 191 const GrProcessorStage& effectStag e, |
176 int effectIdx) { | 192 int effectIdx) { |
177 int texCoordIndex = fTransforms[effectIdx].fTexCoordIndex; | 193 int texCoordIndex = fTransforms[effectIdx].fTexCoordIndex; |
178 int numTransforms = effectStage.getEffect()->numTransforms(); | 194 int numTransforms = effectStage.getProcessor()->numTransforms(); |
179 for (int t = 0; t < numTransforms; ++t) { | 195 for (int t = 0; t < numTransforms; ++t) { |
180 const SkMatrix& transform = get_transform_matrix(effectStage, false, t); | 196 const SkMatrix& transform = get_transform_matrix(effectStage, false, t); |
181 GrGLPathRendering::PathTexGenComponents components = | 197 GrGLPathRendering::PathTexGenComponents components = |
182 GrGLPathRendering::kST_PathTexGenComponents; | 198 GrGLPathRendering::kST_PathTexGenComponents; |
183 if (effectStage.isPerspectiveCoordTransform(t, false)) { | 199 if (effectStage.isPerspectiveCoordTransform(t, false)) { |
184 components = GrGLPathRendering::kSTR_PathTexGenComponents; | 200 components = GrGLPathRendering::kSTR_PathTexGenComponents; |
185 } | 201 } |
186 gpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, tr ansform); | 202 gpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, tr ansform); |
187 } | 203 } |
188 } | 204 } |
OLD | NEW |