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 "gl/builders/GrGLProgramBuilder.h" | 8 #include "gl/builders/GrGLProgramBuilder.h" |
9 #include "GrGLProgramEffects.h" | 9 #include "GrGLProgramEffects.h" |
10 #include "GrDrawEffect.h" | |
11 #include "gl/GrGLEffect.h" | 10 #include "gl/GrGLEffect.h" |
12 #include "gl/GrGLPathRendering.h" | 11 #include "gl/GrGLPathRendering.h" |
13 #include "gl/builders/GrGLProgramBuilder.h" | 12 #include "gl/builders/GrGLProgramBuilder.h" |
14 #include "gl/GrGLGeometryProcessor.h" | 13 #include "gl/GrGLGeometryProcessor.h" |
15 #include "gl/GrGpuGL.h" | 14 #include "gl/GrGpuGL.h" |
16 | 15 |
17 typedef GrGLProgramEffects::TransformedCoords TransformedCoords; | 16 typedef GrGLProgramEffects::TransformedCoords TransformedCoords; |
18 typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray; | 17 typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray; |
19 typedef GrGLProgramEffects::TextureSampler TextureSampler; | 18 typedef GrGLProgramEffects::TextureSampler TextureSampler; |
20 typedef GrGLProgramEffects::TextureSamplerArray TextureSamplerArray; | 19 typedef GrGLProgramEffects::TextureSamplerArray TextureSamplerArray; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 */ | 81 */ |
83 GrCoordSet get_source_coords(uint32_t transformKey, int transformIdx) { | 82 GrCoordSet get_source_coords(uint32_t transformKey, int transformIdx) { |
84 return (transformKey >> (kTransformKeyBits * transformIdx)) & kPositionCoord s_Flag ? | 83 return (transformKey >> (kTransformKeyBits * transformIdx)) & kPositionCoord s_Flag ? |
85 kPosition_GrCoordSet : | 84 kPosition_GrCoordSet : |
86 kLocal_GrCoordSet; | 85 kLocal_GrCoordSet; |
87 } | 86 } |
88 | 87 |
89 /** | 88 /** |
90 * Retrieves the final matrix that a transform needs to apply to its source coor ds. | 89 * Retrieves the final matrix that a transform needs to apply to its source coor ds. |
91 */ | 90 */ |
92 SkMatrix get_transform_matrix(const GrDrawEffect& drawEffect, int transformIdx) { | 91 SkMatrix get_transform_matrix(const GrEffectStage& effectStage, |
93 const GrCoordTransform& coordTransform = drawEffect.effect()->coordTransform (transformIdx); | 92 bool useExplicitLocalCoords, |
93 int transformIdx) { | |
94 const GrCoordTransform& coordTransform = effectStage.getEffect()->coordTrans form(transformIdx); | |
94 SkMatrix combined; | 95 SkMatrix combined; |
95 | 96 |
96 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { | 97 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { |
97 // If we have explicit local coords then we shouldn't need a coord chang e. | 98 // If we have explicit local coords then we shouldn't need a coord chang e. |
98 SkASSERT(!drawEffect.programHasExplicitLocalCoords() || | 99 const SkMatrix& ccm = effectStage.getCoordChangeMatrix(useExplicitLocalC oords); |
bsalomon
2014/09/15 19:54:25
It feels like having this variant of getCoordChang
| |
99 drawEffect.getCoordChangeMatrix().isIdentity()); | 100 SkASSERT(!useExplicitLocalCoords || ccm.isIdentity()); |
100 combined.setConcat(coordTransform.getMatrix(), drawEffect.getCoordChange Matrix()); | 101 combined.setConcat(coordTransform.getMatrix(), ccm); |
101 } else { | 102 } else { |
102 combined = coordTransform.getMatrix(); | 103 combined = coordTransform.getMatrix(); |
103 } | 104 } |
104 if (coordTransform.reverseY()) { | 105 if (coordTransform.reverseY()) { |
105 // combined.postScale(1,-1); | 106 // combined.postScale(1,-1); |
106 // combined.postTranslate(0,1); | 107 // combined.postTranslate(0,1); |
107 combined.set(SkMatrix::kMSkewY, | 108 combined.set(SkMatrix::kMSkewY, |
108 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); | 109 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); |
109 combined.set(SkMatrix::kMScaleY, | 110 combined.set(SkMatrix::kMScaleY, |
110 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]); | 111 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]); |
111 combined.set(SkMatrix::kMTransY, | 112 combined.set(SkMatrix::kMTransY, |
112 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]); | 113 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]); |
113 } | 114 } |
114 return combined; | 115 return combined; |
115 } | 116 } |
116 | |
117 } | 117 } |
118 | 118 |
119 //////////////////////////////////////////////////////////////////////////////// | 119 //////////////////////////////////////////////////////////////////////////////// |
120 | 120 |
121 bool GrGLProgramEffects::GenEffectMetaKey(const GrDrawEffect& drawEffect, const GrGLCaps& caps, | 121 bool GrGLProgramEffects::GenEffectMetaKey(const GrEffectStage& effectStage, |
122 bool useExplicitLocalCoords, | |
123 const GrGLCaps& caps, | |
122 GrEffectKeyBuilder* b) { | 124 GrEffectKeyBuilder* b) { |
123 | 125 |
124 uint32_t textureKey = GrGLProgramEffects::GenTextureKey(drawEffect, caps); | 126 uint32_t textureKey = GrGLProgramEffects::GenTextureKey(effectStage.getEffec t(), caps); |
125 uint32_t transformKey = GrGLProgramEffects::GenTransformKey(drawEffect); | 127 uint32_t transformKey = GrGLProgramEffects::GenTransformKey(effectStage,useE xplicitLocalCoords); |
126 uint32_t attribKey = GrGLProgramEffects::GenAttribKey(drawEffect.castEffect< GrEffect>()); | 128 uint32_t attribKey = GrGLProgramEffects::GenAttribKey(effectStage.getEffect( )); |
127 uint32_t classID = drawEffect.effect()->getFactory().effectClassID(); | 129 uint32_t classID = effectStage.getEffect()->getFactory().effectClassID(); |
128 | 130 |
129 // Currently we allow 16 bits for each of the above portions of the meta-key . Fail if they | 131 // Currently we allow 16 bits for each of the above portions of the meta-key . Fail if they |
130 // don't fit. | 132 // don't fit. |
131 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16); | 133 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16); |
132 if ((textureKey | transformKey | attribKey | classID) & kMetaKeyInvalidMask) { | 134 if ((textureKey | transformKey | attribKey | classID) & kMetaKeyInvalidMask) { |
133 return false; | 135 return false; |
134 } | 136 } |
135 | 137 |
136 uint32_t* key = b->add32n(2); | 138 uint32_t* key = b->add32n(2); |
137 key[0] = (textureKey << 16 | transformKey); | 139 key[0] = (textureKey << 16 | transformKey); |
138 key[1] = (classID << 16 | attribKey); | 140 key[1] = (classID << 16 | attribKey); |
139 return true; | 141 return true; |
140 } | 142 } |
141 | 143 |
142 uint32_t GrGLProgramEffects::GenAttribKey(const GrEffect& effect) { | 144 uint32_t GrGLProgramEffects::GenAttribKey(const GrEffect* effect) { |
143 uint32_t key = 0; | 145 uint32_t key = 0; |
144 | 146 |
145 const GrEffect::VertexAttribArray& vars = effect.getVertexAttribs(); | 147 const GrEffect::VertexAttribArray& vars = effect->getVertexAttribs(); |
146 int numAttributes = vars.count(); | 148 int numAttributes = vars.count(); |
147 SkASSERT(numAttributes <= 2); | 149 SkASSERT(numAttributes <= 2); |
148 for (int a = 0; a < numAttributes; ++a) { | 150 for (int a = 0; a < numAttributes; ++a) { |
149 uint32_t value = 1 << a; | 151 uint32_t value = 1 << a; |
150 key |= value; | 152 key |= value; |
151 } | 153 } |
152 return key; | 154 return key; |
153 } | 155 } |
154 | 156 |
155 uint32_t GrGLProgramEffects::GenTransformKey(const GrDrawEffect& drawEffect) { | 157 uint32_t GrGLProgramEffects::GenTransformKey(const GrEffectStage& effectStage, |
158 bool useExplicitLocalCoords) { | |
156 uint32_t totalKey = 0; | 159 uint32_t totalKey = 0; |
157 int numTransforms = drawEffect.effect()->numTransforms(); | 160 int numTransforms = effectStage.getEffect()->numTransforms(); |
158 for (int t = 0; t < numTransforms; ++t) { | 161 for (int t = 0; t < numTransforms; ++t) { |
159 uint32_t key = 0; | 162 uint32_t key = 0; |
160 const GrCoordTransform& coordTransform = drawEffect.effect()->coordTrans form(t); | 163 const GrCoordTransform& coordTransform = effectStage.getEffect()->coordT ransform(t); |
161 SkMatrix::TypeMask type0 = coordTransform.getMatrix().getType(); | 164 SkMatrix::TypeMask type0 = coordTransform.getMatrix().getType(); |
162 SkMatrix::TypeMask type1; | 165 SkMatrix::TypeMask type1; |
163 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { | 166 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { |
164 type1 = drawEffect.getCoordChangeMatrix().getType(); | 167 type1 = effectStage.getCoordChangeMatrix(useExplicitLocalCoords).get Type(); |
165 } else { | 168 } else { |
166 if (drawEffect.programHasExplicitLocalCoords()) { | 169 if (useExplicitLocalCoords) { |
167 // We only make the key indicate that device coords are referenc ed when the local coords | 170 // We only make the key indicate that device coords are referenc ed when the local coords |
168 // are not actually determined by positions. Otherwise the local coords var and position | 171 // are not actually determined by positions. Otherwise the local coords var and position |
169 // var are identical. | 172 // var are identical. |
170 key |= kPositionCoords_Flag; | 173 key |= kPositionCoords_Flag; |
171 } | 174 } |
172 type1 = SkMatrix::kIdentity_Mask; | 175 type1 = SkMatrix::kIdentity_Mask; |
173 } | 176 } |
174 | 177 |
175 int combinedTypes = type0 | type1; | 178 int combinedTypes = type0 | type1; |
176 | 179 |
177 if (SkMatrix::kPerspective_Mask & combinedTypes) { | 180 if (SkMatrix::kPerspective_Mask & combinedTypes) { |
178 key |= kGeneral_MatrixType; | 181 key |= kGeneral_MatrixType; |
179 } else { | 182 } else { |
180 key |= kNoPersp_MatrixType; | 183 key |= kNoPersp_MatrixType; |
181 } | 184 } |
182 key <<= kTransformKeyBits * t; | 185 key <<= kTransformKeyBits * t; |
183 SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to overlap | 186 SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to overlap |
184 totalKey |= key; | 187 totalKey |= key; |
185 } | 188 } |
186 return totalKey; | 189 return totalKey; |
187 } | 190 } |
188 | 191 |
189 uint32_t GrGLProgramEffects::GenTextureKey(const GrDrawEffect& drawEffect, const GrGLCaps& caps) { | 192 uint32_t GrGLProgramEffects::GenTextureKey(const GrEffect* effect, const GrGLCap s& caps) { |
190 uint32_t key = 0; | 193 uint32_t key = 0; |
191 int numTextures = drawEffect.effect()->numTextures(); | 194 int numTextures = effect->numTextures(); |
192 for (int t = 0; t < numTextures; ++t) { | 195 for (int t = 0; t < numTextures; ++t) { |
193 const GrTextureAccess& access = drawEffect.effect()->textureAccess(t); | 196 const GrTextureAccess& access = effect->textureAccess(t); |
194 uint32_t configComponentMask = GrPixelConfigComponentMask(access.getText ure()->config()); | 197 uint32_t configComponentMask = GrPixelConfigComponentMask(access.getText ure()->config()); |
195 if (swizzle_requires_alpha_remapping(caps, configComponentMask, access.s wizzleMask())) { | 198 if (swizzle_requires_alpha_remapping(caps, configComponentMask, access.s wizzleMask())) { |
196 key |= 1 << t; | 199 key |= 1 << t; |
197 } | 200 } |
198 } | 201 } |
199 return key; | 202 return key; |
200 } | 203 } |
201 | 204 |
202 GrGLProgramEffects::~GrGLProgramEffects() { | 205 GrGLProgramEffects::~GrGLProgramEffects() { |
203 int numEffects = fGLEffects.count(); | 206 int numEffects = fGLEffects.count(); |
204 for (int e = 0; e < numEffects; ++e) { | 207 for (int e = 0; e < numEffects; ++e) { |
205 SkDELETE(fGLEffects[e]); | 208 SkDELETE(fGLEffects[e]); |
206 } | 209 } |
207 } | 210 } |
208 | 211 |
209 void GrGLProgramEffects::emitSamplers(GrGLProgramBuilder* builder, | 212 void GrGLProgramEffects::emitSamplers(GrGLProgramBuilder* builder, |
210 const GrEffect* effect, | 213 const GrEffect& effect, |
211 TextureSamplerArray* outSamplers) { | 214 TextureSamplerArray* outSamplers) { |
212 SkTArray<Sampler, true>& samplers = fSamplers.push_back(); | 215 SkTArray<Sampler, true>& samplers = fSamplers.push_back(); |
213 int numTextures = effect->numTextures(); | 216 int numTextures = effect.numTextures(); |
214 samplers.push_back_n(numTextures); | 217 samplers.push_back_n(numTextures); |
215 SkString name; | 218 SkString name; |
216 for (int t = 0; t < numTextures; ++t) { | 219 for (int t = 0; t < numTextures; ++t) { |
217 name.printf("Sampler%d", t); | 220 name.printf("Sampler%d", t); |
218 samplers[t].fUniform = builder->addUniform(GrGLProgramBuilder::kFragment _Visibility, | 221 samplers[t].fUniform = builder->addUniform(GrGLProgramBuilder::kFragment _Visibility, |
219 kSampler2D_GrSLType, | 222 kSampler2D_GrSLType, |
220 name.c_str()); | 223 name.c_str()); |
221 SkNEW_APPEND_TO_TARRAY(outSamplers, TextureSampler, | 224 SkNEW_APPEND_TO_TARRAY(outSamplers, TextureSampler, |
222 (samplers[t].fUniform, effect->textureAccess(t))) ; | 225 (samplers[t].fUniform, effect.textureAccess(t))); |
223 } | 226 } |
224 } | 227 } |
225 | 228 |
226 void GrGLProgramEffects::initSamplers(const GrGLProgramDataManager& programResou rceManager, int* texUnitIdx) { | 229 void GrGLProgramEffects::initSamplers(const GrGLProgramDataManager& programResou rceManager, int* texUnitIdx) { |
227 int numEffects = fGLEffects.count(); | 230 int numEffects = fGLEffects.count(); |
228 SkASSERT(numEffects == fSamplers.count()); | 231 SkASSERT(numEffects == fSamplers.count()); |
229 for (int e = 0; e < numEffects; ++e) { | 232 for (int e = 0; e < numEffects; ++e) { |
230 SkTArray<Sampler, true>& samplers = fSamplers[e]; | 233 SkTArray<Sampler, true>& samplers = fSamplers[e]; |
231 int numSamplers = samplers.count(); | 234 int numSamplers = samplers.count(); |
232 for (int s = 0; s < numSamplers; ++s) { | 235 for (int s = 0; s < numSamplers; ++s) { |
233 SkASSERT(samplers[s].fUniform.isValid()); | 236 SkASSERT(samplers[s].fUniform.isValid()); |
234 programResourceManager.setSampler(samplers[s].fUniform, *texUnitIdx) ; | 237 programResourceManager.setSampler(samplers[s].fUniform, *texUnitIdx) ; |
235 samplers[s].fTextureUnit = (*texUnitIdx)++; | 238 samplers[s].fTextureUnit = (*texUnitIdx)++; |
236 } | 239 } |
237 } | 240 } |
238 } | 241 } |
239 | 242 |
240 void GrGLProgramEffects::bindTextures(GrGpuGL* gpu, const GrEffect* effect, int effectIdx) { | 243 void GrGLProgramEffects::bindTextures(GrGpuGL* gpu, const GrEffect& effect, int effectIdx) { |
241 const SkTArray<Sampler, true>& samplers = fSamplers[effectIdx]; | 244 const SkTArray<Sampler, true>& samplers = fSamplers[effectIdx]; |
242 int numSamplers = samplers.count(); | 245 int numSamplers = samplers.count(); |
243 SkASSERT(numSamplers == effect->numTextures()); | 246 SkASSERT(numSamplers == effect.numTextures()); |
244 for (int s = 0; s < numSamplers; ++s) { | 247 for (int s = 0; s < numSamplers; ++s) { |
245 SkASSERT(samplers[s].fTextureUnit >= 0); | 248 SkASSERT(samplers[s].fTextureUnit >= 0); |
246 const GrTextureAccess& textureAccess = effect->textureAccess(s); | 249 const GrTextureAccess& textureAccess = effect.textureAccess(s); |
247 gpu->bindTexture(samplers[s].fTextureUnit, | 250 gpu->bindTexture(samplers[s].fTextureUnit, |
248 textureAccess.getParams(), | 251 textureAccess.getParams(), |
249 static_cast<GrGLTexture*>(textureAccess.getTexture())); | 252 static_cast<GrGLTexture*>(textureAccess.getTexture())); |
250 } | 253 } |
251 } | 254 } |
252 | 255 |
253 //////////////////////////////////////////////////////////////////////////////// | 256 //////////////////////////////////////////////////////////////////////////////// |
254 | 257 |
255 void GrGLVertexProgramEffects::emitEffect(GrGLFullProgramBuilder* builder, | 258 void GrGLVertexProgramEffects::emitEffect(GrGLFullProgramBuilder* builder, |
256 const GrEffectStage& stage, | 259 const GrEffectStage& stage, |
257 const GrEffectKey& key, | 260 const GrEffectKey& key, |
258 const char* outColor, | 261 const char* outColor, |
259 const char* inColor, | 262 const char* inColor, |
260 int stageIndex) { | 263 int stageIndex) { |
261 GrDrawEffect drawEffect(stage, fHasExplicitLocalCoords); | 264 const GrEffect& effect = *stage.getEffect(); |
262 const GrEffect* effect = stage.getEffect(); | 265 SkSTArray<2, TransformedCoords> coords(effect.numTransforms()); |
263 SkSTArray<2, TransformedCoords> coords(effect->numTransforms()); | 266 SkSTArray<4, TextureSampler> samplers(effect.numTextures()); |
264 SkSTArray<4, TextureSampler> samplers(effect->numTextures()); | |
265 | 267 |
266 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); | 268 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); |
267 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 269 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
268 vsBuilder->emitAttributes(stage); | 270 vsBuilder->emitAttributes(stage); |
269 this->emitTransforms(builder, drawEffect, &coords); | 271 this->emitTransforms(builder, stage, &coords); |
270 this->emitSamplers(builder, effect, &samplers); | 272 this->emitSamplers(builder, effect, &samplers); |
271 | 273 |
272 GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect); | 274 GrGLEffect* glEffect = effect.getFactory().createGLInstance(effect); |
273 fGLEffects.push_back(glEffect); | 275 fGLEffects.push_back(glEffect); |
274 | 276 |
275 // Enclose custom code in a block to avoid namespace conflicts | 277 // Enclose custom code in a block to avoid namespace conflicts |
276 SkString openBrace; | 278 SkString openBrace; |
277 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name()); | 279 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name()); |
278 fsBuilder->codeAppend(openBrace.c_str()); | 280 fsBuilder->codeAppend(openBrace.c_str()); |
279 vsBuilder->codeAppend(openBrace.c_str()); | 281 vsBuilder->codeAppend(openBrace.c_str()); |
280 | 282 |
281 if (glEffect->isVertexEffect()) { | 283 if (glEffect->isVertexEffect()) { |
282 GrGLGeometryProcessor* vertexEffect = static_cast<GrGLGeometryProcessor* >(glEffect); | 284 GrGLGeometryProcessor* vertexEffect = static_cast<GrGLGeometryProcessor* >(glEffect); |
283 vertexEffect->emitCode(builder, drawEffect, key, outColor, inColor, coor ds, samplers); | 285 vertexEffect->emitCode(builder, effect, key, outColor, inColor, coords, samplers); |
284 } else { | 286 } else { |
285 glEffect->emitCode(builder, drawEffect, key, outColor, inColor, coords, samplers); | 287 glEffect->emitCode(builder, effect, key, outColor, inColor, coords, samp lers); |
286 } | 288 } |
287 | 289 |
288 vsBuilder->codeAppend("\t}\n"); | 290 vsBuilder->codeAppend("\t}\n"); |
289 fsBuilder->codeAppend("\t}\n"); | 291 fsBuilder->codeAppend("\t}\n"); |
290 } | 292 } |
291 | 293 |
292 void GrGLVertexProgramEffects::emitTransforms(GrGLFullProgramBuilder* builder, | 294 void GrGLVertexProgramEffects::emitTransforms(GrGLFullProgramBuilder* builder, |
293 const GrDrawEffect& drawEffect, | 295 const GrEffectStage& effectStage, |
294 TransformedCoordsArray* outCoords) { | 296 TransformedCoordsArray* outCoords) { |
295 SkTArray<Transform, true>& transforms = fTransforms.push_back(); | 297 SkTArray<Transform, true>& transforms = fTransforms.push_back(); |
296 uint32_t totalKey = GenTransformKey(drawEffect); | 298 uint32_t totalKey = GenTransformKey(effectStage, fHasExplicitLocalCoords); |
297 int numTransforms = drawEffect.effect()->numTransforms(); | 299 int numTransforms = effectStage.getEffect()->numTransforms(); |
298 transforms.push_back_n(numTransforms); | 300 transforms.push_back_n(numTransforms); |
299 | 301 |
300 SkTArray<PathTransform, true>* pathTransforms = NULL; | 302 SkTArray<PathTransform, true>* pathTransforms = NULL; |
301 const GrGLCaps* glCaps = builder->ctxInfo().caps(); | 303 const GrGLCaps* glCaps = builder->ctxInfo().caps(); |
302 if (glCaps->pathRenderingSupport() && | 304 if (glCaps->pathRenderingSupport() && |
303 builder->gpu()->glPathRendering()->texturingMode() == | 305 builder->gpu()->glPathRendering()->texturingMode() == |
304 GrGLPathRendering::SeparableShaders_TexturingMode) { | 306 GrGLPathRendering::SeparableShaders_TexturingMode) { |
305 pathTransforms = &fPathTransforms.push_back(); | 307 pathTransforms = &fPathTransforms.push_back(); |
306 pathTransforms->push_back_n(numTransforms); | 308 pathTransforms->push_back_n(numTransforms); |
307 } | 309 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 } | 370 } |
369 | 371 |
370 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu, | 372 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu, |
371 GrGpu::DrawType drawType, | 373 GrGpu::DrawType drawType, |
372 const GrGLProgramDataManager& programData Manager, | 374 const GrGLProgramDataManager& programData Manager, |
373 const GrEffectStage* effectStages[]) { | 375 const GrEffectStage* effectStages[]) { |
374 int numEffects = fGLEffects.count(); | 376 int numEffects = fGLEffects.count(); |
375 SkASSERT(numEffects == fTransforms.count()); | 377 SkASSERT(numEffects == fTransforms.count()); |
376 SkASSERT(numEffects == fSamplers.count()); | 378 SkASSERT(numEffects == fSamplers.count()); |
377 for (int e = 0; e < numEffects; ++e) { | 379 for (int e = 0; e < numEffects; ++e) { |
378 GrDrawEffect drawEffect(*effectStages[e], fHasExplicitLocalCoords); | 380 const GrEffectStage& effectStage = *effectStages[e]; |
379 fGLEffects[e]->setData(programDataManager, drawEffect); | 381 const GrEffect& effect = *effectStage.getEffect(); |
382 fGLEffects[e]->setData(programDataManager, effect); | |
380 if (GrGpu::IsPathRenderingDrawType(drawType)) { | 383 if (GrGpu::IsPathRenderingDrawType(drawType)) { |
381 this->setPathTransformData(gpu, programDataManager, drawEffect, e); | 384 this->setPathTransformData(gpu, programDataManager, effectStage, e); |
382 } else { | 385 } else { |
383 this->setTransformData(gpu, programDataManager, drawEffect, e); | 386 this->setTransformData(gpu, programDataManager, effectStage, e); |
384 } | 387 } |
385 | 388 |
386 this->bindTextures(gpu, drawEffect.effect(), e); | 389 this->bindTextures(gpu, effect, e); |
387 } | 390 } |
388 } | 391 } |
389 | 392 |
390 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu, | 393 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu, |
391 GrGpu::DrawType drawType, | 394 GrGpu::DrawType drawType, |
392 const GrGLProgramDataManager& programData Manager, | 395 const GrGLProgramDataManager& programData Manager, |
393 const GrEffectStage* effectStage) { | 396 const GrEffectStage* effectStage) { |
394 SkASSERT(1 == fTransforms.count()); | 397 SkASSERT(1 == fTransforms.count()); |
395 SkASSERT(1 == fSamplers.count()); | 398 SkASSERT(1 == fSamplers.count()); |
396 SkASSERT(1 == fGLEffects.count()); | 399 SkASSERT(1 == fGLEffects.count()); |
397 GrDrawEffect drawEffect(*effectStage, fHasExplicitLocalCoords); | 400 const GrEffect& effect = *effectStage->getEffect(); |
398 fGLEffects[0]->setData(programDataManager, drawEffect); | 401 fGLEffects[0]->setData(programDataManager, effect); |
399 if (GrGpu::IsPathRenderingDrawType(drawType)) { | 402 if (GrGpu::IsPathRenderingDrawType(drawType)) { |
400 this->setPathTransformData(gpu, programDataManager, drawEffect, 0); | 403 this->setPathTransformData(gpu, programDataManager, *effectStage, 0); |
401 } else { | 404 } else { |
402 this->setTransformData(gpu, programDataManager, drawEffect, 0); | 405 this->setTransformData(gpu, programDataManager, *effectStage, 0); |
403 } | 406 } |
404 | 407 |
405 this->bindTextures(gpu, drawEffect.effect(), 0); | 408 this->bindTextures(gpu, effect, 0); |
406 } | 409 } |
407 | 410 |
408 void GrGLVertexProgramEffects::setTransformData(GrGpuGL* gpu, | 411 void GrGLVertexProgramEffects::setTransformData(GrGpuGL* gpu, |
409 const GrGLProgramDataManager& pd man, | 412 const GrGLProgramDataManager& pd man, |
410 const GrDrawEffect& drawEffect, | 413 const GrEffectStage& effectStage , |
411 int effectIdx) { | 414 int effectIdx) { |
412 SkTArray<Transform, true>& transforms = fTransforms[effectIdx]; | 415 SkTArray<Transform, true>& transforms = fTransforms[effectIdx]; |
413 int numTransforms = transforms.count(); | 416 int numTransforms = transforms.count(); |
414 SkASSERT(numTransforms == drawEffect.effect()->numTransforms()); | 417 SkASSERT(numTransforms == effectStage.getEffect()->numTransforms()); |
415 for (int t = 0; t < numTransforms; ++t) { | 418 for (int t = 0; t < numTransforms; ++t) { |
416 SkASSERT(transforms[t].fHandle.isValid()); | 419 SkASSERT(transforms[t].fHandle.isValid()); |
417 const SkMatrix& matrix = get_transform_matrix(drawEffect, t); | 420 const SkMatrix& matrix = get_transform_matrix(effectStage, fHasExplicitL ocalCoords, t); |
418 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { | 421 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { |
419 pdman.setSkMatrix(transforms[t].fHandle, matrix); | 422 pdman.setSkMatrix(transforms[t].fHandle, matrix); |
420 transforms[t].fCurrentValue = matrix; | 423 transforms[t].fCurrentValue = matrix; |
421 } | 424 } |
422 } | 425 } |
423 } | 426 } |
424 | 427 |
425 void GrGLVertexProgramEffects::setPathTransformData(GrGpuGL* gpu, | 428 void GrGLVertexProgramEffects::setPathTransformData(GrGpuGL* gpu, |
426 const GrGLProgramDataManager & pdman, | 429 const GrGLProgramDataManager & pdman, |
427 const GrDrawEffect& drawEffe ct, | 430 const GrEffectStage& effectS tage, |
428 int effectIdx) { | 431 int effectIdx) { |
429 SkTArray<PathTransform, true>& transforms = fPathTransforms[effectIdx]; | 432 SkTArray<PathTransform, true>& transforms = fPathTransforms[effectIdx]; |
430 int numTransforms = transforms.count(); | 433 int numTransforms = transforms.count(); |
431 SkASSERT(numTransforms == drawEffect.effect()->numTransforms()); | 434 SkASSERT(numTransforms == effectStage.getEffect()->numTransforms()); |
432 for (int t = 0; t < numTransforms; ++t) { | 435 for (int t = 0; t < numTransforms; ++t) { |
433 SkASSERT(transforms[t].fHandle.isValid()); | 436 SkASSERT(transforms[t].fHandle.isValid()); |
434 const SkMatrix& transform = get_transform_matrix(drawEffect, t); | 437 const SkMatrix& transform = get_transform_matrix(effectStage, fHasExplic itLocalCoords, t); |
435 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { | 438 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { |
436 continue; | 439 continue; |
437 } | 440 } |
438 transforms[t].fCurrentValue = transform; | 441 transforms[t].fCurrentValue = transform; |
439 switch (transforms[t].fType) { | 442 switch (transforms[t].fType) { |
440 case kVec2f_GrSLType: | 443 case kVec2f_GrSLType: |
441 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle , 2, transform); | 444 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle , 2, transform); |
442 break; | 445 break; |
443 case kVec3f_GrSLType: | 446 case kVec3f_GrSLType: |
444 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle , 3, transform); | 447 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle , 3, transform); |
(...skipping 21 matching lines...) Expand all Loading... | |
466 } | 469 } |
467 | 470 |
468 //////////////////////////////////////////////////////////////////////////////// | 471 //////////////////////////////////////////////////////////////////////////////// |
469 | 472 |
470 void GrGLPathTexGenProgramEffects::emitEffect(GrGLFragmentOnlyProgramBuilder* bu ilder, | 473 void GrGLPathTexGenProgramEffects::emitEffect(GrGLFragmentOnlyProgramBuilder* bu ilder, |
471 const GrEffectStage& stage, | 474 const GrEffectStage& stage, |
472 const GrEffectKey& key, | 475 const GrEffectKey& key, |
473 const char* outColor, | 476 const char* outColor, |
474 const char* inColor, | 477 const char* inColor, |
475 int stageIndex) { | 478 int stageIndex) { |
476 GrDrawEffect drawEffect(stage, false); | 479 const GrEffect& effect = *stage.getEffect(); |
477 const GrEffect* effect = stage.getEffect(); | 480 SkSTArray<2, TransformedCoords> coords(effect.numTransforms()); |
478 SkSTArray<2, TransformedCoords> coords(effect->numTransforms()); | 481 SkSTArray<4, TextureSampler> samplers(effect.numTextures()); |
479 SkSTArray<4, TextureSampler> samplers(effect->numTextures()); | |
480 | 482 |
481 SkASSERT(0 == effect->getVertexAttribs().count()); | 483 SkASSERT(0 == effect.getVertexAttribs().count()); |
482 this->setupPathTexGen(builder, drawEffect, &coords); | 484 this->setupPathTexGen(builder, stage, &coords); |
483 this->emitSamplers(builder, effect, &samplers); | 485 this->emitSamplers(builder, effect, &samplers); |
484 | 486 |
485 GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect); | 487 GrGLEffect* glEffect = effect.getFactory().createGLInstance(effect); |
486 fGLEffects.push_back(glEffect); | 488 fGLEffects.push_back(glEffect); |
487 | 489 |
488 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 490 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
489 // Enclose custom code in a block to avoid namespace conflicts | 491 // Enclose custom code in a block to avoid namespace conflicts |
490 SkString openBrace; | 492 SkString openBrace; |
491 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name()); | 493 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name()); |
492 fsBuilder->codeAppend(openBrace.c_str()); | 494 fsBuilder->codeAppend(openBrace.c_str()); |
493 | 495 |
494 SkASSERT(!glEffect->isVertexEffect()); | 496 SkASSERT(!glEffect->isVertexEffect()); |
495 glEffect->emitCode(builder, drawEffect, key, outColor, inColor, coords, samp lers); | 497 glEffect->emitCode(builder, effect, key, outColor, inColor, coords, samplers ); |
496 | 498 |
497 fsBuilder->codeAppend("\t}\n"); | 499 fsBuilder->codeAppend("\t}\n"); |
498 } | 500 } |
499 | 501 |
500 void GrGLPathTexGenProgramEffects::setupPathTexGen(GrGLFragmentOnlyProgramBuilde r* builder, | 502 void GrGLPathTexGenProgramEffects::setupPathTexGen(GrGLFragmentOnlyProgramBuilde r* builder, |
501 const GrDrawEffect& drawEffect, | 503 const GrEffectStage& effectStage, |
502 TransformedCoordsArray* outCoords) { | 504 TransformedCoordsArray* outCoords) { |
503 int numTransforms = drawEffect.effect()->numTransforms(); | 505 int numTransforms = effectStage.getEffect()->numTransforms(); |
504 uint32_t totalKey = GenTransformKey(drawEffect); | 506 uint32_t totalKey = GenTransformKey(effectStage, false); |
505 int texCoordIndex = builder->addTexCoordSets(numTransforms); | 507 int texCoordIndex = builder->addTexCoordSets(numTransforms); |
506 SkNEW_APPEND_TO_TARRAY(&fTransforms, Transforms, (totalKey, texCoordIndex)); | 508 SkNEW_APPEND_TO_TARRAY(&fTransforms, Transforms, (totalKey, texCoordIndex)); |
507 SkString name; | 509 SkString name; |
508 for (int t = 0; t < numTransforms; ++t) { | 510 for (int t = 0; t < numTransforms; ++t) { |
509 GrSLType type = kGeneral_MatrixType == get_matrix_type(totalKey, t) ? | 511 GrSLType type = kGeneral_MatrixType == get_matrix_type(totalKey, t) ? |
510 kVec3f_GrSLType : | 512 kVec3f_GrSLType : |
511 kVec2f_GrSLType; | 513 kVec2f_GrSLType; |
512 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex ++); | 514 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex ++); |
513 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (name, type)); | 515 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (name, type)); |
514 } | 516 } |
515 } | 517 } |
516 | 518 |
517 void GrGLPathTexGenProgramEffects::setData(GrGpuGL* gpu, | 519 void GrGLPathTexGenProgramEffects::setData(GrGpuGL* gpu, |
518 GrGpu::DrawType, | 520 GrGpu::DrawType, |
519 const GrGLProgramDataManager& pdman, | 521 const GrGLProgramDataManager& pdman, |
520 const GrEffectStage* effectStages[]) { | 522 const GrEffectStage* effectStages[]) { |
521 int numEffects = fGLEffects.count(); | 523 int numEffects = fGLEffects.count(); |
522 SkASSERT(numEffects == fTransforms.count()); | 524 SkASSERT(numEffects == fTransforms.count()); |
523 SkASSERT(numEffects == fSamplers.count()); | 525 SkASSERT(numEffects == fSamplers.count()); |
524 for (int e = 0; e < numEffects; ++e) { | 526 for (int e = 0; e < numEffects; ++e) { |
525 GrDrawEffect drawEffect(*effectStages[e], false); | 527 const GrEffectStage& effectStage = *effectStages[e]; |
526 fGLEffects[e]->setData(pdman, drawEffect); | 528 const GrEffect& effect = *effectStage.getEffect(); |
527 this->setPathTexGenState(gpu, drawEffect, e); | 529 fGLEffects[e]->setData(pdman, effect); |
528 this->bindTextures(gpu, drawEffect.effect(), e); | 530 this->setPathTexGenState(gpu, effectStage, e); |
531 this->bindTextures(gpu, effect, e); | |
529 } | 532 } |
530 } | 533 } |
531 | 534 |
532 void GrGLPathTexGenProgramEffects::setPathTexGenState(GrGpuGL* gpu, | 535 void GrGLPathTexGenProgramEffects::setPathTexGenState(GrGpuGL* gpu, |
533 const GrDrawEffect& drawEffect, | 536 const GrEffectStage& effectStage, |
534 int effectIdx) { | 537 int effectIdx) { |
535 uint32_t totalKey = fTransforms[effectIdx].fTransformKey; | 538 uint32_t totalKey = fTransforms[effectIdx].fTransformKey; |
536 int texCoordIndex = fTransforms[effectIdx].fTexCoordIndex; | 539 int texCoordIndex = fTransforms[effectIdx].fTexCoordIndex; |
537 int numTransforms = drawEffect.effect()->numTransforms(); | 540 int numTransforms = effectStage.getEffect()->numTransforms(); |
538 for (int t = 0; t < numTransforms; ++t) { | 541 for (int t = 0; t < numTransforms; ++t) { |
539 switch (get_matrix_type(totalKey, t)) { | 542 switch (get_matrix_type(totalKey, t)) { |
540 case kNoPersp_MatrixType: { | 543 case kNoPersp_MatrixType: { |
541 const SkMatrix& transform = get_transform_matrix(drawEffect, t); | 544 const SkMatrix& transform = get_transform_matrix(effectStage, fa lse, t); |
542 gpu->glPathRendering()->enablePathTexGen( | 545 gpu->glPathRendering()->enablePathTexGen( |
543 texCoordIndex++, | 546 texCoordIndex++, |
544 GrGLPathRendering::kST_PathTexGenComponents, | 547 GrGLPathRendering::kST_PathTexGenComponents, |
545 transform); | 548 transform); |
546 break; | 549 break; |
547 } | 550 } |
548 case kGeneral_MatrixType: { | 551 case kGeneral_MatrixType: { |
549 const SkMatrix& transform = get_transform_matrix(drawEffect, t); | 552 const SkMatrix& transform = get_transform_matrix(effectStage, fa lse, t); |
550 gpu->glPathRendering()->enablePathTexGen( | 553 gpu->glPathRendering()->enablePathTexGen( |
551 texCoordIndex++, | 554 texCoordIndex++, |
552 GrGLPathRendering::kSTR_PathTexGenComponents, | 555 GrGLPathRendering::kSTR_PathTexGenComponents, |
553 transform); | 556 transform); |
554 break; | 557 break; |
555 } | 558 } |
556 default: | 559 default: |
557 SkFAIL("Unexpected matrixs type."); | 560 SkFAIL("Unexpected matrixs type."); |
558 } | 561 } |
559 } | 562 } |
560 } | 563 } |
561 | 564 |
562 GrGLPathTexGenProgramEffectsBuilder::GrGLPathTexGenProgramEffectsBuilder( | 565 GrGLPathTexGenProgramEffectsBuilder::GrGLPathTexGenProgramEffectsBuilder( |
563 GrGLFragmentOnlyProgramBuilder* builder, | 566 GrGLFragmentOnlyProgramBuilder* builder, |
564 int reserveCount) | 567 int reserveCount) |
565 : fBuilder(builder) | 568 : fBuilder(builder) |
566 , fProgramEffects(SkNEW_ARGS(GrGLPathTexGenProgramEffects, (reserveCount))) { | 569 , fProgramEffects(SkNEW_ARGS(GrGLPathTexGenProgramEffects, (reserveCount))) { |
567 } | 570 } |
568 void GrGLPathTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage, | 571 void GrGLPathTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage, |
569 const GrEffectKey& key, | 572 const GrEffectKey& key, |
570 const char* outColor, | 573 const char* outColor, |
571 const char* inColor, | 574 const char* inColor, |
572 int stageIndex) { | 575 int stageIndex) { |
573 SkASSERT(fProgramEffects.get()); | 576 SkASSERT(fProgramEffects.get()); |
574 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn dex); | 577 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn dex); |
575 } | 578 } |
576 | 579 |
OLD | NEW |