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 = |
99 drawEffect.getCoordChangeMatrix().isIdentity()); | 100 useExplicitLocalCoords ? SkMatrix::I() : effectStage.getCoordCha
ngeMatrix(); |
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 = SkMatrix::kIdentity_Mask; |
163 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { | 166 if (kLocal_GrCoordSet == coordTransform.sourceCoords() && !useExplicitLo
calCoords) { |
164 type1 = drawEffect.getCoordChangeMatrix().getType(); | 167 type1 = effectStage.getCoordChangeMatrix().getType(); |
165 } else { | 168 } else if (kPosition_GrCoordSet == coordTransform.sourceCoords() && useE
xplicitLocalCoords) { |
166 if (drawEffect.programHasExplicitLocalCoords()) { | 169 // We only make the key indicate that device coords are referenced w
hen the local coords |
167 // We only make the key indicate that device coords are referenc
ed when the local coords | 170 // are not actually determined by positions. Otherwise the local coo
rds var and position |
168 // are not actually determined by positions. Otherwise the local
coords var and position | 171 // var are identical. |
169 // var are identical. | 172 key |= kPositionCoords_Flag; |
170 key |= kPositionCoords_Flag; | |
171 } | |
172 type1 = SkMatrix::kIdentity_Mask; | |
173 } | 173 } |
174 | 174 |
175 int combinedTypes = type0 | type1; | 175 int combinedTypes = type0 | type1; |
176 | 176 |
177 if (SkMatrix::kPerspective_Mask & combinedTypes) { | 177 if (SkMatrix::kPerspective_Mask & combinedTypes) { |
178 key |= kGeneral_MatrixType; | 178 key |= kGeneral_MatrixType; |
179 } else { | 179 } else { |
180 key |= kNoPersp_MatrixType; | 180 key |= kNoPersp_MatrixType; |
181 } | 181 } |
182 key <<= kTransformKeyBits * t; | 182 key <<= kTransformKeyBits * t; |
183 SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to
overlap | 183 SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to
overlap |
184 totalKey |= key; | 184 totalKey |= key; |
185 } | 185 } |
186 return totalKey; | 186 return totalKey; |
187 } | 187 } |
188 | 188 |
189 uint32_t GrGLProgramEffects::GenTextureKey(const GrDrawEffect& drawEffect, const
GrGLCaps& caps) { | 189 uint32_t GrGLProgramEffects::GenTextureKey(const GrEffect* effect, const GrGLCap
s& caps) { |
190 uint32_t key = 0; | 190 uint32_t key = 0; |
191 int numTextures = drawEffect.effect()->numTextures(); | 191 int numTextures = effect->numTextures(); |
192 for (int t = 0; t < numTextures; ++t) { | 192 for (int t = 0; t < numTextures; ++t) { |
193 const GrTextureAccess& access = drawEffect.effect()->textureAccess(t); | 193 const GrTextureAccess& access = effect->textureAccess(t); |
194 uint32_t configComponentMask = GrPixelConfigComponentMask(access.getText
ure()->config()); | 194 uint32_t configComponentMask = GrPixelConfigComponentMask(access.getText
ure()->config()); |
195 if (swizzle_requires_alpha_remapping(caps, configComponentMask, access.s
wizzleMask())) { | 195 if (swizzle_requires_alpha_remapping(caps, configComponentMask, access.s
wizzleMask())) { |
196 key |= 1 << t; | 196 key |= 1 << t; |
197 } | 197 } |
198 } | 198 } |
199 return key; | 199 return key; |
200 } | 200 } |
201 | 201 |
202 GrGLProgramEffects::~GrGLProgramEffects() { | 202 GrGLProgramEffects::~GrGLProgramEffects() { |
203 int numEffects = fGLEffects.count(); | 203 int numEffects = fGLEffects.count(); |
204 for (int e = 0; e < numEffects; ++e) { | 204 for (int e = 0; e < numEffects; ++e) { |
205 SkDELETE(fGLEffects[e]); | 205 SkDELETE(fGLEffects[e]); |
206 } | 206 } |
207 } | 207 } |
208 | 208 |
209 void GrGLProgramEffects::emitSamplers(GrGLProgramBuilder* builder, | 209 void GrGLProgramEffects::emitSamplers(GrGLProgramBuilder* builder, |
210 const GrEffect* effect, | 210 const GrEffect& effect, |
211 TextureSamplerArray* outSamplers) { | 211 TextureSamplerArray* outSamplers) { |
212 SkTArray<Sampler, true>& samplers = fSamplers.push_back(); | 212 SkTArray<Sampler, true>& samplers = fSamplers.push_back(); |
213 int numTextures = effect->numTextures(); | 213 int numTextures = effect.numTextures(); |
214 samplers.push_back_n(numTextures); | 214 samplers.push_back_n(numTextures); |
215 SkString name; | 215 SkString name; |
216 for (int t = 0; t < numTextures; ++t) { | 216 for (int t = 0; t < numTextures; ++t) { |
217 name.printf("Sampler%d", t); | 217 name.printf("Sampler%d", t); |
218 samplers[t].fUniform = builder->addUniform(GrGLProgramBuilder::kFragment
_Visibility, | 218 samplers[t].fUniform = builder->addUniform(GrGLProgramBuilder::kFragment
_Visibility, |
219 kSampler2D_GrSLType, | 219 kSampler2D_GrSLType, |
220 name.c_str()); | 220 name.c_str()); |
221 SkNEW_APPEND_TO_TARRAY(outSamplers, TextureSampler, | 221 SkNEW_APPEND_TO_TARRAY(outSamplers, TextureSampler, |
222 (samplers[t].fUniform, effect->textureAccess(t)))
; | 222 (samplers[t].fUniform, effect.textureAccess(t))); |
223 } | 223 } |
224 } | 224 } |
225 | 225 |
226 void GrGLProgramEffects::initSamplers(const GrGLProgramDataManager& programResou
rceManager, int* texUnitIdx) { | 226 void GrGLProgramEffects::initSamplers(const GrGLProgramDataManager& programResou
rceManager, int* texUnitIdx) { |
227 int numEffects = fGLEffects.count(); | 227 int numEffects = fGLEffects.count(); |
228 SkASSERT(numEffects == fSamplers.count()); | 228 SkASSERT(numEffects == fSamplers.count()); |
229 for (int e = 0; e < numEffects; ++e) { | 229 for (int e = 0; e < numEffects; ++e) { |
230 SkTArray<Sampler, true>& samplers = fSamplers[e]; | 230 SkTArray<Sampler, true>& samplers = fSamplers[e]; |
231 int numSamplers = samplers.count(); | 231 int numSamplers = samplers.count(); |
232 for (int s = 0; s < numSamplers; ++s) { | 232 for (int s = 0; s < numSamplers; ++s) { |
233 SkASSERT(samplers[s].fUniform.isValid()); | 233 SkASSERT(samplers[s].fUniform.isValid()); |
234 programResourceManager.setSampler(samplers[s].fUniform, *texUnitIdx)
; | 234 programResourceManager.setSampler(samplers[s].fUniform, *texUnitIdx)
; |
235 samplers[s].fTextureUnit = (*texUnitIdx)++; | 235 samplers[s].fTextureUnit = (*texUnitIdx)++; |
236 } | 236 } |
237 } | 237 } |
238 } | 238 } |
239 | 239 |
240 void GrGLProgramEffects::bindTextures(GrGpuGL* gpu, const GrEffect* effect, int
effectIdx) { | 240 void GrGLProgramEffects::bindTextures(GrGpuGL* gpu, const GrEffect& effect, int
effectIdx) { |
241 const SkTArray<Sampler, true>& samplers = fSamplers[effectIdx]; | 241 const SkTArray<Sampler, true>& samplers = fSamplers[effectIdx]; |
242 int numSamplers = samplers.count(); | 242 int numSamplers = samplers.count(); |
243 SkASSERT(numSamplers == effect->numTextures()); | 243 SkASSERT(numSamplers == effect.numTextures()); |
244 for (int s = 0; s < numSamplers; ++s) { | 244 for (int s = 0; s < numSamplers; ++s) { |
245 SkASSERT(samplers[s].fTextureUnit >= 0); | 245 SkASSERT(samplers[s].fTextureUnit >= 0); |
246 const GrTextureAccess& textureAccess = effect->textureAccess(s); | 246 const GrTextureAccess& textureAccess = effect.textureAccess(s); |
247 gpu->bindTexture(samplers[s].fTextureUnit, | 247 gpu->bindTexture(samplers[s].fTextureUnit, |
248 textureAccess.getParams(), | 248 textureAccess.getParams(), |
249 static_cast<GrGLTexture*>(textureAccess.getTexture())); | 249 static_cast<GrGLTexture*>(textureAccess.getTexture())); |
250 } | 250 } |
251 } | 251 } |
252 | 252 |
253 //////////////////////////////////////////////////////////////////////////////// | 253 //////////////////////////////////////////////////////////////////////////////// |
254 | 254 |
255 void GrGLVertexProgramEffects::emitEffect(GrGLFullProgramBuilder* builder, | 255 void GrGLVertexProgramEffects::emitEffect(GrGLFullProgramBuilder* builder, |
256 const GrEffectStage& stage, | 256 const GrEffectStage& stage, |
257 const GrEffectKey& key, | 257 const GrEffectKey& key, |
258 const char* outColor, | 258 const char* outColor, |
259 const char* inColor, | 259 const char* inColor, |
260 int stageIndex) { | 260 int stageIndex) { |
261 GrDrawEffect drawEffect(stage, fHasExplicitLocalCoords); | 261 const GrEffect& effect = *stage.getEffect(); |
262 const GrEffect* effect = stage.getEffect(); | 262 SkSTArray<2, TransformedCoords> coords(effect.numTransforms()); |
263 SkSTArray<2, TransformedCoords> coords(effect->numTransforms()); | 263 SkSTArray<4, TextureSampler> samplers(effect.numTextures()); |
264 SkSTArray<4, TextureSampler> samplers(effect->numTextures()); | |
265 | 264 |
266 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); | 265 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); |
267 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 266 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
268 vsBuilder->emitAttributes(stage); | 267 vsBuilder->emitAttributes(stage); |
269 this->emitTransforms(builder, drawEffect, &coords); | 268 this->emitTransforms(builder, stage, &coords); |
270 this->emitSamplers(builder, effect, &samplers); | 269 this->emitSamplers(builder, effect, &samplers); |
271 | 270 |
272 GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect); | 271 GrGLEffect* glEffect = effect.getFactory().createGLInstance(effect); |
273 fGLEffects.push_back(glEffect); | 272 fGLEffects.push_back(glEffect); |
274 | 273 |
275 // Enclose custom code in a block to avoid namespace conflicts | 274 // Enclose custom code in a block to avoid namespace conflicts |
276 SkString openBrace; | 275 SkString openBrace; |
277 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name()); | 276 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name()); |
278 fsBuilder->codeAppend(openBrace.c_str()); | 277 fsBuilder->codeAppend(openBrace.c_str()); |
279 vsBuilder->codeAppend(openBrace.c_str()); | 278 vsBuilder->codeAppend(openBrace.c_str()); |
280 | 279 |
281 if (glEffect->isVertexEffect()) { | 280 if (glEffect->isVertexEffect()) { |
282 GrGLGeometryProcessor* vertexEffect = static_cast<GrGLGeometryProcessor*
>(glEffect); | 281 GrGLGeometryProcessor* vertexEffect = static_cast<GrGLGeometryProcessor*
>(glEffect); |
283 vertexEffect->emitCode(builder, drawEffect, key, outColor, inColor, coor
ds, samplers); | 282 vertexEffect->emitCode(builder, effect, key, outColor, inColor, coords,
samplers); |
284 } else { | 283 } else { |
285 glEffect->emitCode(builder, drawEffect, key, outColor, inColor, coords,
samplers); | 284 glEffect->emitCode(builder, effect, key, outColor, inColor, coords, samp
lers); |
286 } | 285 } |
287 | 286 |
288 vsBuilder->codeAppend("\t}\n"); | 287 vsBuilder->codeAppend("\t}\n"); |
289 fsBuilder->codeAppend("\t}\n"); | 288 fsBuilder->codeAppend("\t}\n"); |
290 } | 289 } |
291 | 290 |
292 void GrGLVertexProgramEffects::emitTransforms(GrGLFullProgramBuilder* builder, | 291 void GrGLVertexProgramEffects::emitTransforms(GrGLFullProgramBuilder* builder, |
293 const GrDrawEffect& drawEffect, | 292 const GrEffectStage& effectStage, |
294 TransformedCoordsArray* outCoords)
{ | 293 TransformedCoordsArray* outCoords)
{ |
295 SkTArray<Transform, true>& transforms = fTransforms.push_back(); | 294 SkTArray<Transform, true>& transforms = fTransforms.push_back(); |
296 uint32_t totalKey = GenTransformKey(drawEffect); | 295 uint32_t totalKey = GenTransformKey(effectStage, fHasExplicitLocalCoords); |
297 int numTransforms = drawEffect.effect()->numTransforms(); | 296 int numTransforms = effectStage.getEffect()->numTransforms(); |
298 transforms.push_back_n(numTransforms); | 297 transforms.push_back_n(numTransforms); |
299 | 298 |
300 SkTArray<PathTransform, true>* pathTransforms = NULL; | 299 SkTArray<PathTransform, true>* pathTransforms = NULL; |
301 const GrGLCaps* glCaps = builder->ctxInfo().caps(); | 300 const GrGLCaps* glCaps = builder->ctxInfo().caps(); |
302 if (glCaps->pathRenderingSupport() && | 301 if (glCaps->pathRenderingSupport() && |
303 builder->gpu()->glPathRendering()->texturingMode() == | 302 builder->gpu()->glPathRendering()->texturingMode() == |
304 GrGLPathRendering::SeparableShaders_TexturingMode) { | 303 GrGLPathRendering::SeparableShaders_TexturingMode) { |
305 pathTransforms = &fPathTransforms.push_back(); | 304 pathTransforms = &fPathTransforms.push_back(); |
306 pathTransforms->push_back_n(numTransforms); | 305 pathTransforms->push_back_n(numTransforms); |
307 } | 306 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 } | 367 } |
369 | 368 |
370 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu, | 369 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu, |
371 GrGpu::DrawType drawType, | 370 GrGpu::DrawType drawType, |
372 const GrGLProgramDataManager& programData
Manager, | 371 const GrGLProgramDataManager& programData
Manager, |
373 const GrEffectStage* effectStages[]) { | 372 const GrEffectStage* effectStages[]) { |
374 int numEffects = fGLEffects.count(); | 373 int numEffects = fGLEffects.count(); |
375 SkASSERT(numEffects == fTransforms.count()); | 374 SkASSERT(numEffects == fTransforms.count()); |
376 SkASSERT(numEffects == fSamplers.count()); | 375 SkASSERT(numEffects == fSamplers.count()); |
377 for (int e = 0; e < numEffects; ++e) { | 376 for (int e = 0; e < numEffects; ++e) { |
378 GrDrawEffect drawEffect(*effectStages[e], fHasExplicitLocalCoords); | 377 const GrEffectStage& effectStage = *effectStages[e]; |
379 fGLEffects[e]->setData(programDataManager, drawEffect); | 378 const GrEffect& effect = *effectStage.getEffect(); |
| 379 fGLEffects[e]->setData(programDataManager, effect); |
380 if (GrGpu::IsPathRenderingDrawType(drawType)) { | 380 if (GrGpu::IsPathRenderingDrawType(drawType)) { |
381 this->setPathTransformData(gpu, programDataManager, drawEffect, e); | 381 this->setPathTransformData(gpu, programDataManager, effectStage, e); |
382 } else { | 382 } else { |
383 this->setTransformData(gpu, programDataManager, drawEffect, e); | 383 this->setTransformData(gpu, programDataManager, effectStage, e); |
384 } | 384 } |
385 | 385 |
386 this->bindTextures(gpu, drawEffect.effect(), e); | 386 this->bindTextures(gpu, effect, e); |
387 } | 387 } |
388 } | 388 } |
389 | 389 |
390 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu, | 390 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu, |
391 GrGpu::DrawType drawType, | 391 GrGpu::DrawType drawType, |
392 const GrGLProgramDataManager& programData
Manager, | 392 const GrGLProgramDataManager& programData
Manager, |
393 const GrEffectStage* effectStage) { | 393 const GrEffectStage* effectStage) { |
394 SkASSERT(1 == fTransforms.count()); | 394 SkASSERT(1 == fTransforms.count()); |
395 SkASSERT(1 == fSamplers.count()); | 395 SkASSERT(1 == fSamplers.count()); |
396 SkASSERT(1 == fGLEffects.count()); | 396 SkASSERT(1 == fGLEffects.count()); |
397 GrDrawEffect drawEffect(*effectStage, fHasExplicitLocalCoords); | 397 const GrEffect& effect = *effectStage->getEffect(); |
398 fGLEffects[0]->setData(programDataManager, drawEffect); | 398 fGLEffects[0]->setData(programDataManager, effect); |
399 if (GrGpu::IsPathRenderingDrawType(drawType)) { | 399 if (GrGpu::IsPathRenderingDrawType(drawType)) { |
400 this->setPathTransformData(gpu, programDataManager, drawEffect, 0); | 400 this->setPathTransformData(gpu, programDataManager, *effectStage, 0); |
401 } else { | 401 } else { |
402 this->setTransformData(gpu, programDataManager, drawEffect, 0); | 402 this->setTransformData(gpu, programDataManager, *effectStage, 0); |
403 } | 403 } |
404 | 404 |
405 this->bindTextures(gpu, drawEffect.effect(), 0); | 405 this->bindTextures(gpu, effect, 0); |
406 } | 406 } |
407 | 407 |
408 void GrGLVertexProgramEffects::setTransformData(GrGpuGL* gpu, | 408 void GrGLVertexProgramEffects::setTransformData(GrGpuGL* gpu, |
409 const GrGLProgramDataManager& pd
man, | 409 const GrGLProgramDataManager& pd
man, |
410 const GrDrawEffect& drawEffect, | 410 const GrEffectStage& effectStage
, |
411 int effectIdx) { | 411 int effectIdx) { |
412 SkTArray<Transform, true>& transforms = fTransforms[effectIdx]; | 412 SkTArray<Transform, true>& transforms = fTransforms[effectIdx]; |
413 int numTransforms = transforms.count(); | 413 int numTransforms = transforms.count(); |
414 SkASSERT(numTransforms == drawEffect.effect()->numTransforms()); | 414 SkASSERT(numTransforms == effectStage.getEffect()->numTransforms()); |
415 for (int t = 0; t < numTransforms; ++t) { | 415 for (int t = 0; t < numTransforms; ++t) { |
416 SkASSERT(transforms[t].fHandle.isValid()); | 416 SkASSERT(transforms[t].fHandle.isValid()); |
417 const SkMatrix& matrix = get_transform_matrix(drawEffect, t); | 417 const SkMatrix& matrix = get_transform_matrix(effectStage, fHasExplicitL
ocalCoords, t); |
418 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { | 418 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { |
419 pdman.setSkMatrix(transforms[t].fHandle, matrix); | 419 pdman.setSkMatrix(transforms[t].fHandle, matrix); |
420 transforms[t].fCurrentValue = matrix; | 420 transforms[t].fCurrentValue = matrix; |
421 } | 421 } |
422 } | 422 } |
423 } | 423 } |
424 | 424 |
425 void GrGLVertexProgramEffects::setPathTransformData(GrGpuGL* gpu, | 425 void GrGLVertexProgramEffects::setPathTransformData(GrGpuGL* gpu, |
426 const GrGLProgramDataManager
& pdman, | 426 const GrGLProgramDataManager
& pdman, |
427 const GrDrawEffect& drawEffe
ct, | 427 const GrEffectStage& effectS
tage, |
428 int effectIdx) { | 428 int effectIdx) { |
429 SkTArray<PathTransform, true>& transforms = fPathTransforms[effectIdx]; | 429 SkTArray<PathTransform, true>& transforms = fPathTransforms[effectIdx]; |
430 int numTransforms = transforms.count(); | 430 int numTransforms = transforms.count(); |
431 SkASSERT(numTransforms == drawEffect.effect()->numTransforms()); | 431 SkASSERT(numTransforms == effectStage.getEffect()->numTransforms()); |
432 for (int t = 0; t < numTransforms; ++t) { | 432 for (int t = 0; t < numTransforms; ++t) { |
433 SkASSERT(transforms[t].fHandle.isValid()); | 433 SkASSERT(transforms[t].fHandle.isValid()); |
434 const SkMatrix& transform = get_transform_matrix(drawEffect, t); | 434 const SkMatrix& transform = get_transform_matrix(effectStage, fHasExplic
itLocalCoords, t); |
435 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { | 435 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { |
436 continue; | 436 continue; |
437 } | 437 } |
438 transforms[t].fCurrentValue = transform; | 438 transforms[t].fCurrentValue = transform; |
439 switch (transforms[t].fType) { | 439 switch (transforms[t].fType) { |
440 case kVec2f_GrSLType: | 440 case kVec2f_GrSLType: |
441 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle
, 2, transform); | 441 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle
, 2, transform); |
442 break; | 442 break; |
443 case kVec3f_GrSLType: | 443 case kVec3f_GrSLType: |
444 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle
, 3, transform); | 444 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle
, 3, transform); |
(...skipping 21 matching lines...) Expand all Loading... |
466 } | 466 } |
467 | 467 |
468 //////////////////////////////////////////////////////////////////////////////// | 468 //////////////////////////////////////////////////////////////////////////////// |
469 | 469 |
470 void GrGLPathTexGenProgramEffects::emitEffect(GrGLFragmentOnlyProgramBuilder* bu
ilder, | 470 void GrGLPathTexGenProgramEffects::emitEffect(GrGLFragmentOnlyProgramBuilder* bu
ilder, |
471 const GrEffectStage& stage, | 471 const GrEffectStage& stage, |
472 const GrEffectKey& key, | 472 const GrEffectKey& key, |
473 const char* outColor, | 473 const char* outColor, |
474 const char* inColor, | 474 const char* inColor, |
475 int stageIndex) { | 475 int stageIndex) { |
476 GrDrawEffect drawEffect(stage, false); | 476 const GrEffect& effect = *stage.getEffect(); |
477 const GrEffect* effect = stage.getEffect(); | 477 SkSTArray<2, TransformedCoords> coords(effect.numTransforms()); |
478 SkSTArray<2, TransformedCoords> coords(effect->numTransforms()); | 478 SkSTArray<4, TextureSampler> samplers(effect.numTextures()); |
479 SkSTArray<4, TextureSampler> samplers(effect->numTextures()); | |
480 | 479 |
481 SkASSERT(0 == effect->getVertexAttribs().count()); | 480 SkASSERT(0 == effect.getVertexAttribs().count()); |
482 this->setupPathTexGen(builder, drawEffect, &coords); | 481 this->setupPathTexGen(builder, stage, &coords); |
483 this->emitSamplers(builder, effect, &samplers); | 482 this->emitSamplers(builder, effect, &samplers); |
484 | 483 |
485 GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect); | 484 GrGLEffect* glEffect = effect.getFactory().createGLInstance(effect); |
486 fGLEffects.push_back(glEffect); | 485 fGLEffects.push_back(glEffect); |
487 | 486 |
488 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 487 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
489 // Enclose custom code in a block to avoid namespace conflicts | 488 // Enclose custom code in a block to avoid namespace conflicts |
490 SkString openBrace; | 489 SkString openBrace; |
491 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name()); | 490 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name()); |
492 fsBuilder->codeAppend(openBrace.c_str()); | 491 fsBuilder->codeAppend(openBrace.c_str()); |
493 | 492 |
494 SkASSERT(!glEffect->isVertexEffect()); | 493 SkASSERT(!glEffect->isVertexEffect()); |
495 glEffect->emitCode(builder, drawEffect, key, outColor, inColor, coords, samp
lers); | 494 glEffect->emitCode(builder, effect, key, outColor, inColor, coords, samplers
); |
496 | 495 |
497 fsBuilder->codeAppend("\t}\n"); | 496 fsBuilder->codeAppend("\t}\n"); |
498 } | 497 } |
499 | 498 |
500 void GrGLPathTexGenProgramEffects::setupPathTexGen(GrGLFragmentOnlyProgramBuilde
r* builder, | 499 void GrGLPathTexGenProgramEffects::setupPathTexGen(GrGLFragmentOnlyProgramBuilde
r* builder, |
501 const GrDrawEffect& drawEffect, | 500 const GrEffectStage& effectStage, |
502 TransformedCoordsArray* outCoords) { | 501 TransformedCoordsArray* outCoords) { |
503 int numTransforms = drawEffect.effect()->numTransforms(); | 502 int numTransforms = effectStage.getEffect()->numTransforms(); |
504 uint32_t totalKey = GenTransformKey(drawEffect); | 503 uint32_t totalKey = GenTransformKey(effectStage, false); |
505 int texCoordIndex = builder->addTexCoordSets(numTransforms); | 504 int texCoordIndex = builder->addTexCoordSets(numTransforms); |
506 SkNEW_APPEND_TO_TARRAY(&fTransforms, Transforms, (totalKey, texCoordIndex)); | 505 SkNEW_APPEND_TO_TARRAY(&fTransforms, Transforms, (totalKey, texCoordIndex)); |
507 SkString name; | 506 SkString name; |
508 for (int t = 0; t < numTransforms; ++t) { | 507 for (int t = 0; t < numTransforms; ++t) { |
509 GrSLType type = kGeneral_MatrixType == get_matrix_type(totalKey, t) ? | 508 GrSLType type = kGeneral_MatrixType == get_matrix_type(totalKey, t) ? |
510 kVec3f_GrSLType : | 509 kVec3f_GrSLType : |
511 kVec2f_GrSLType; | 510 kVec2f_GrSLType; |
512 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex
++); | 511 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex
++); |
513 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (name, type)); | 512 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (name, type)); |
514 } | 513 } |
515 } | 514 } |
516 | 515 |
517 void GrGLPathTexGenProgramEffects::setData(GrGpuGL* gpu, | 516 void GrGLPathTexGenProgramEffects::setData(GrGpuGL* gpu, |
518 GrGpu::DrawType, | 517 GrGpu::DrawType, |
519 const GrGLProgramDataManager& pdman, | 518 const GrGLProgramDataManager& pdman, |
520 const GrEffectStage* effectStages[])
{ | 519 const GrEffectStage* effectStages[])
{ |
521 int numEffects = fGLEffects.count(); | 520 int numEffects = fGLEffects.count(); |
522 SkASSERT(numEffects == fTransforms.count()); | 521 SkASSERT(numEffects == fTransforms.count()); |
523 SkASSERT(numEffects == fSamplers.count()); | 522 SkASSERT(numEffects == fSamplers.count()); |
524 for (int e = 0; e < numEffects; ++e) { | 523 for (int e = 0; e < numEffects; ++e) { |
525 GrDrawEffect drawEffect(*effectStages[e], false); | 524 const GrEffectStage& effectStage = *effectStages[e]; |
526 fGLEffects[e]->setData(pdman, drawEffect); | 525 const GrEffect& effect = *effectStage.getEffect(); |
527 this->setPathTexGenState(gpu, drawEffect, e); | 526 fGLEffects[e]->setData(pdman, effect); |
528 this->bindTextures(gpu, drawEffect.effect(), e); | 527 this->setPathTexGenState(gpu, effectStage, e); |
| 528 this->bindTextures(gpu, effect, e); |
529 } | 529 } |
530 } | 530 } |
531 | 531 |
532 void GrGLPathTexGenProgramEffects::setPathTexGenState(GrGpuGL* gpu, | 532 void GrGLPathTexGenProgramEffects::setPathTexGenState(GrGpuGL* gpu, |
533 const GrDrawEffect& drawEffect, | 533 const GrEffectStage& effectStage, |
534 int effectIdx) { | 534 int effectIdx) { |
535 uint32_t totalKey = fTransforms[effectIdx].fTransformKey; | 535 uint32_t totalKey = fTransforms[effectIdx].fTransformKey; |
536 int texCoordIndex = fTransforms[effectIdx].fTexCoordIndex; | 536 int texCoordIndex = fTransforms[effectIdx].fTexCoordIndex; |
537 int numTransforms = drawEffect.effect()->numTransforms(); | 537 int numTransforms = effectStage.getEffect()->numTransforms(); |
538 for (int t = 0; t < numTransforms; ++t) { | 538 for (int t = 0; t < numTransforms; ++t) { |
539 switch (get_matrix_type(totalKey, t)) { | 539 switch (get_matrix_type(totalKey, t)) { |
540 case kNoPersp_MatrixType: { | 540 case kNoPersp_MatrixType: { |
541 const SkMatrix& transform = get_transform_matrix(drawEffect, t); | 541 const SkMatrix& transform = get_transform_matrix(effectStage, fa
lse, t); |
542 gpu->glPathRendering()->enablePathTexGen( | 542 gpu->glPathRendering()->enablePathTexGen( |
543 texCoordIndex++, | 543 texCoordIndex++, |
544 GrGLPathRendering::kST_PathTexGenComponents, | 544 GrGLPathRendering::kST_PathTexGenComponents, |
545 transform); | 545 transform); |
546 break; | 546 break; |
547 } | 547 } |
548 case kGeneral_MatrixType: { | 548 case kGeneral_MatrixType: { |
549 const SkMatrix& transform = get_transform_matrix(drawEffect, t); | 549 const SkMatrix& transform = get_transform_matrix(effectStage, fa
lse, t); |
550 gpu->glPathRendering()->enablePathTexGen( | 550 gpu->glPathRendering()->enablePathTexGen( |
551 texCoordIndex++, | 551 texCoordIndex++, |
552 GrGLPathRendering::kSTR_PathTexGenComponents, | 552 GrGLPathRendering::kSTR_PathTexGenComponents, |
553 transform); | 553 transform); |
554 break; | 554 break; |
555 } | 555 } |
556 default: | 556 default: |
557 SkFAIL("Unexpected matrixs type."); | 557 SkFAIL("Unexpected matrixs type."); |
558 } | 558 } |
559 } | 559 } |
560 } | 560 } |
561 | 561 |
562 GrGLPathTexGenProgramEffectsBuilder::GrGLPathTexGenProgramEffectsBuilder( | 562 GrGLPathTexGenProgramEffectsBuilder::GrGLPathTexGenProgramEffectsBuilder( |
563 GrGLFragmentOnlyProgramBuilder* builder, | 563 GrGLFragmentOnlyProgramBuilder* builder, |
564 int reserveCount) | 564 int reserveCount) |
565 : fBuilder(builder) | 565 : fBuilder(builder) |
566 , fProgramEffects(SkNEW_ARGS(GrGLPathTexGenProgramEffects, (reserveCount)))
{ | 566 , fProgramEffects(SkNEW_ARGS(GrGLPathTexGenProgramEffects, (reserveCount)))
{ |
567 } | 567 } |
568 void GrGLPathTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage, | 568 void GrGLPathTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage, |
569 const GrEffectKey& key, | 569 const GrEffectKey& key, |
570 const char* outColor, | 570 const char* outColor, |
571 const char* inColor, | 571 const char* inColor, |
572 int stageIndex) { | 572 int stageIndex) { |
573 SkASSERT(fProgramEffects.get()); | 573 SkASSERT(fProgramEffects.get()); |
574 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn
dex); | 574 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn
dex); |
575 } | 575 } |
576 | 576 |
OLD | NEW |