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 "GrBezierEffect.h" | 8 #include "GrBezierEffect.h" |
9 | 9 |
10 #include "gl/GrGLEffect.h" | 10 #include "gl/GrGLEffect.h" |
11 #include "gl/GrGLShaderBuilder.h" | 11 #include "gl/GrGLShaderBuilder.h" |
12 #include "gl/GrGLSL.h" | 12 #include "gl/GrGLSL.h" |
13 #include "gl/GrGLVertexEffect.h" | 13 #include "gl/GrGLVertexEffect.h" |
14 #include "GrTBackendEffectFactory.h" | 14 #include "GrTBackendEffectFactory.h" |
15 | 15 |
16 class GrGLConicEffect : public GrGLVertexEffect { | 16 class GrGLConicEffect : public GrGLVertexEffect { |
17 public: | 17 public: |
18 GrGLConicEffect(const GrBackendEffectFactory&, const GrDrawEffect&); | 18 GrGLConicEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
19 | 19 |
20 virtual void emitCode(GrGLFullShaderBuilder* builder, | 20 virtual void emitCode(GrGLFullShaderBuilder* builder, |
21 const GrDrawEffect& drawEffect, | 21 const GrDrawEffect& drawEffect, |
22 EffectKey key, | 22 const GrEffectKey& key, |
23 const char* outputColor, | 23 const char* outputColor, |
24 const char* inputColor, | 24 const char* inputColor, |
25 const TransformedCoordsArray&, | 25 const TransformedCoordsArray&, |
26 const TextureSamplerArray&) SK_OVERRIDE; | 26 const TextureSamplerArray&) SK_OVERRIDE; |
27 | 27 |
28 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); | 28 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); |
29 | 29 |
30 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE {} | 30 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE {} |
31 | 31 |
32 private: | 32 private: |
33 GrEffectEdgeType fEdgeType; | 33 GrEffectEdgeType fEdgeType; |
34 | 34 |
35 typedef GrGLVertexEffect INHERITED; | 35 typedef GrGLVertexEffect INHERITED; |
36 }; | 36 }; |
37 | 37 |
38 GrGLConicEffect::GrGLConicEffect(const GrBackendEffectFactory& factory, | 38 GrGLConicEffect::GrGLConicEffect(const GrBackendEffectFactory& factory, |
39 const GrDrawEffect& drawEffect) | 39 const GrDrawEffect& drawEffect) |
40 : INHERITED (factory) { | 40 : INHERITED (factory) { |
41 const GrConicEffect& ce = drawEffect.castEffect<GrConicEffect>(); | 41 const GrConicEffect& ce = drawEffect.castEffect<GrConicEffect>(); |
42 fEdgeType = ce.getEdgeType(); | 42 fEdgeType = ce.getEdgeType(); |
43 } | 43 } |
44 | 44 |
45 void GrGLConicEffect::emitCode(GrGLFullShaderBuilder* builder, | 45 void GrGLConicEffect::emitCode(GrGLFullShaderBuilder* builder, |
46 const GrDrawEffect& drawEffect, | 46 const GrDrawEffect& drawEffect, |
47 EffectKey key, | 47 const GrEffectKey& key, |
48 const char* outputColor, | 48 const char* outputColor, |
49 const char* inputColor, | 49 const char* inputColor, |
50 const TransformedCoordsArray&, | 50 const TransformedCoordsArray&, |
51 const TextureSamplerArray& samplers) { | 51 const TextureSamplerArray& samplers) { |
52 const char *vsName, *fsName; | 52 const char *vsName, *fsName; |
53 | 53 |
54 builder->addVarying(kVec4f_GrSLType, "ConicCoeffs", | 54 builder->addVarying(kVec4f_GrSLType, "ConicCoeffs", |
55 &vsName, &fsName); | 55 &vsName, &fsName); |
56 const SkString* attr0Name = | 56 const SkString* attr0Name = |
57 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); | 57 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 break; | 110 break; |
111 } | 111 } |
112 default: | 112 default: |
113 SkFAIL("Shouldn't get here"); | 113 SkFAIL("Shouldn't get here"); |
114 } | 114 } |
115 | 115 |
116 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, | 116 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
117 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeAlpha")).
c_str()); | 117 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeAlpha")).
c_str()); |
118 } | 118 } |
119 | 119 |
120 GrGLEffect::EffectKey GrGLConicEffect::GenKey(const GrDrawEffect& drawEffect, co
nst GrGLCaps&) { | 120 void GrGLConicEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
| 121 GrEffectKeyBuilder* b) { |
121 const GrConicEffect& ce = drawEffect.castEffect<GrConicEffect>(); | 122 const GrConicEffect& ce = drawEffect.castEffect<GrConicEffect>(); |
122 return ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 123 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
| 124 b->add32(key); |
123 } | 125 } |
124 | 126 |
125 ////////////////////////////////////////////////////////////////////////////// | 127 ////////////////////////////////////////////////////////////////////////////// |
126 | 128 |
127 GrConicEffect::~GrConicEffect() {} | 129 GrConicEffect::~GrConicEffect() {} |
128 | 130 |
129 const GrBackendEffectFactory& GrConicEffect::getFactory() const { | 131 const GrBackendEffectFactory& GrConicEffect::getFactory() const { |
130 return GrTBackendEffectFactory<GrConicEffect>::getInstance(); | 132 return GrTBackendEffectFactory<GrConicEffect>::getInstance(); |
131 } | 133 } |
132 | 134 |
(...skipping 27 matching lines...) Expand all Loading... |
160 ////////////////////////////////////////////////////////////////////////////// | 162 ////////////////////////////////////////////////////////////////////////////// |
161 // Quad | 163 // Quad |
162 ////////////////////////////////////////////////////////////////////////////// | 164 ////////////////////////////////////////////////////////////////////////////// |
163 | 165 |
164 class GrGLQuadEffect : public GrGLVertexEffect { | 166 class GrGLQuadEffect : public GrGLVertexEffect { |
165 public: | 167 public: |
166 GrGLQuadEffect(const GrBackendEffectFactory&, const GrDrawEffect&); | 168 GrGLQuadEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
167 | 169 |
168 virtual void emitCode(GrGLFullShaderBuilder* builder, | 170 virtual void emitCode(GrGLFullShaderBuilder* builder, |
169 const GrDrawEffect& drawEffect, | 171 const GrDrawEffect& drawEffect, |
170 EffectKey key, | 172 const GrEffectKey& key, |
171 const char* outputColor, | 173 const char* outputColor, |
172 const char* inputColor, | 174 const char* inputColor, |
173 const TransformedCoordsArray&, | 175 const TransformedCoordsArray&, |
174 const TextureSamplerArray&) SK_OVERRIDE; | 176 const TextureSamplerArray&) SK_OVERRIDE; |
175 | 177 |
176 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); | 178 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); |
177 | 179 |
178 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE {} | 180 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE {} |
179 | 181 |
180 private: | 182 private: |
181 GrEffectEdgeType fEdgeType; | 183 GrEffectEdgeType fEdgeType; |
182 | 184 |
183 typedef GrGLVertexEffect INHERITED; | 185 typedef GrGLVertexEffect INHERITED; |
184 }; | 186 }; |
185 | 187 |
186 GrGLQuadEffect::GrGLQuadEffect(const GrBackendEffectFactory& factory, | 188 GrGLQuadEffect::GrGLQuadEffect(const GrBackendEffectFactory& factory, |
187 const GrDrawEffect& drawEffect) | 189 const GrDrawEffect& drawEffect) |
188 : INHERITED (factory) { | 190 : INHERITED (factory) { |
189 const GrQuadEffect& ce = drawEffect.castEffect<GrQuadEffect>(); | 191 const GrQuadEffect& ce = drawEffect.castEffect<GrQuadEffect>(); |
190 fEdgeType = ce.getEdgeType(); | 192 fEdgeType = ce.getEdgeType(); |
191 } | 193 } |
192 | 194 |
193 void GrGLQuadEffect::emitCode(GrGLFullShaderBuilder* builder, | 195 void GrGLQuadEffect::emitCode(GrGLFullShaderBuilder* builder, |
194 const GrDrawEffect& drawEffect, | 196 const GrDrawEffect& drawEffect, |
195 EffectKey key, | 197 const GrEffectKey& key, |
196 const char* outputColor, | 198 const char* outputColor, |
197 const char* inputColor, | 199 const char* inputColor, |
198 const TransformedCoordsArray&, | 200 const TransformedCoordsArray&, |
199 const TextureSamplerArray& samplers) { | 201 const TextureSamplerArray& samplers) { |
200 const char *vsName, *fsName; | 202 const char *vsName, *fsName; |
201 | 203 |
202 const SkString* attrName = | 204 const SkString* attrName = |
203 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); | 205 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); |
204 builder->fsCodeAppendf("\t\tfloat edgeAlpha;\n"); | 206 builder->fsCodeAppendf("\t\tfloat edgeAlpha;\n"); |
205 | 207 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 SkFAIL("Shouldn't get here"); | 250 SkFAIL("Shouldn't get here"); |
249 } | 251 } |
250 | 252 |
251 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, | 253 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
252 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeAlpha")).
c_str()); | 254 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeAlpha")).
c_str()); |
253 | 255 |
254 | 256 |
255 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str()); | 257 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str()); |
256 } | 258 } |
257 | 259 |
258 GrGLEffect::EffectKey GrGLQuadEffect::GenKey(const GrDrawEffect& drawEffect, con
st GrGLCaps&) { | 260 void GrGLQuadEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
| 261 GrEffectKeyBuilder* b) { |
259 const GrQuadEffect& ce = drawEffect.castEffect<GrQuadEffect>(); | 262 const GrQuadEffect& ce = drawEffect.castEffect<GrQuadEffect>(); |
260 return ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 263 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
| 264 b->add32(key); |
261 } | 265 } |
262 | 266 |
263 ////////////////////////////////////////////////////////////////////////////// | 267 ////////////////////////////////////////////////////////////////////////////// |
264 | 268 |
265 GrQuadEffect::~GrQuadEffect() {} | 269 GrQuadEffect::~GrQuadEffect() {} |
266 | 270 |
267 const GrBackendEffectFactory& GrQuadEffect::getFactory() const { | 271 const GrBackendEffectFactory& GrQuadEffect::getFactory() const { |
268 return GrTBackendEffectFactory<GrQuadEffect>::getInstance(); | 272 return GrTBackendEffectFactory<GrQuadEffect>::getInstance(); |
269 } | 273 } |
270 | 274 |
(...skipping 27 matching lines...) Expand all Loading... |
298 ////////////////////////////////////////////////////////////////////////////// | 302 ////////////////////////////////////////////////////////////////////////////// |
299 // Cubic | 303 // Cubic |
300 ////////////////////////////////////////////////////////////////////////////// | 304 ////////////////////////////////////////////////////////////////////////////// |
301 | 305 |
302 class GrGLCubicEffect : public GrGLVertexEffect { | 306 class GrGLCubicEffect : public GrGLVertexEffect { |
303 public: | 307 public: |
304 GrGLCubicEffect(const GrBackendEffectFactory&, const GrDrawEffect&); | 308 GrGLCubicEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
305 | 309 |
306 virtual void emitCode(GrGLFullShaderBuilder* builder, | 310 virtual void emitCode(GrGLFullShaderBuilder* builder, |
307 const GrDrawEffect& drawEffect, | 311 const GrDrawEffect& drawEffect, |
308 EffectKey key, | 312 const GrEffectKey& key, |
309 const char* outputColor, | 313 const char* outputColor, |
310 const char* inputColor, | 314 const char* inputColor, |
311 const TransformedCoordsArray&, | 315 const TransformedCoordsArray&, |
312 const TextureSamplerArray&) SK_OVERRIDE; | 316 const TextureSamplerArray&) SK_OVERRIDE; |
313 | 317 |
314 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); | 318 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); |
315 | 319 |
316 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE {} | 320 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE {} |
317 | 321 |
318 private: | 322 private: |
319 GrEffectEdgeType fEdgeType; | 323 GrEffectEdgeType fEdgeType; |
320 | 324 |
321 typedef GrGLVertexEffect INHERITED; | 325 typedef GrGLVertexEffect INHERITED; |
322 }; | 326 }; |
323 | 327 |
324 GrGLCubicEffect::GrGLCubicEffect(const GrBackendEffectFactory& factory, | 328 GrGLCubicEffect::GrGLCubicEffect(const GrBackendEffectFactory& factory, |
325 const GrDrawEffect& drawEffect) | 329 const GrDrawEffect& drawEffect) |
326 : INHERITED (factory) { | 330 : INHERITED (factory) { |
327 const GrCubicEffect& ce = drawEffect.castEffect<GrCubicEffect>(); | 331 const GrCubicEffect& ce = drawEffect.castEffect<GrCubicEffect>(); |
328 fEdgeType = ce.getEdgeType(); | 332 fEdgeType = ce.getEdgeType(); |
329 } | 333 } |
330 | 334 |
331 void GrGLCubicEffect::emitCode(GrGLFullShaderBuilder* builder, | 335 void GrGLCubicEffect::emitCode(GrGLFullShaderBuilder* builder, |
332 const GrDrawEffect& drawEffect, | 336 const GrDrawEffect& drawEffect, |
333 EffectKey key, | 337 const GrEffectKey& key, |
334 const char* outputColor, | 338 const char* outputColor, |
335 const char* inputColor, | 339 const char* inputColor, |
336 const TransformedCoordsArray&, | 340 const TransformedCoordsArray&, |
337 const TextureSamplerArray& samplers) { | 341 const TextureSamplerArray& samplers) { |
338 const char *vsName, *fsName; | 342 const char *vsName, *fsName; |
339 | 343 |
340 builder->addVarying(kVec4f_GrSLType, "CubicCoeffs", | 344 builder->addVarying(kVec4f_GrSLType, "CubicCoeffs", |
341 &vsName, &fsName); | 345 &vsName, &fsName); |
342 const SkString* attr0Name = | 346 const SkString* attr0Name = |
343 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); | 347 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 break; | 400 break; |
397 } | 401 } |
398 default: | 402 default: |
399 SkFAIL("Shouldn't get here"); | 403 SkFAIL("Shouldn't get here"); |
400 } | 404 } |
401 | 405 |
402 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, | 406 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
403 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeAlpha")).
c_str()); | 407 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeAlpha")).
c_str()); |
404 } | 408 } |
405 | 409 |
406 GrGLEffect::EffectKey GrGLCubicEffect::GenKey(const GrDrawEffect& drawEffect, co
nst GrGLCaps&) { | 410 void GrGLCubicEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
| 411 GrEffectKeyBuilder* b) { |
407 const GrCubicEffect& ce = drawEffect.castEffect<GrCubicEffect>(); | 412 const GrCubicEffect& ce = drawEffect.castEffect<GrCubicEffect>(); |
408 return ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 413 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
| 414 b->add32(key); |
409 } | 415 } |
410 | 416 |
411 ////////////////////////////////////////////////////////////////////////////// | 417 ////////////////////////////////////////////////////////////////////////////// |
412 | 418 |
413 GrCubicEffect::~GrCubicEffect() {} | 419 GrCubicEffect::~GrCubicEffect() {} |
414 | 420 |
415 const GrBackendEffectFactory& GrCubicEffect::getFactory() const { | 421 const GrBackendEffectFactory& GrCubicEffect::getFactory() const { |
416 return GrTBackendEffectFactory<GrCubicEffect>::getInstance(); | 422 return GrTBackendEffectFactory<GrCubicEffect>::getInstance(); |
417 } | 423 } |
418 | 424 |
(...skipping 16 matching lines...) Expand all Loading... |
435 const GrDrawTargetCaps& caps, | 441 const GrDrawTargetCaps& caps, |
436 GrTexture*[]) { | 442 GrTexture*[]) { |
437 GrEffect* effect; | 443 GrEffect* effect; |
438 do { | 444 do { |
439 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>( | 445 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>( |
440 random->nextULessThan(kGrEff
ectEdgeTypeCnt)); | 446 random->nextULessThan(kGrEff
ectEdgeTypeCnt)); |
441 effect = GrCubicEffect::Create(edgeType, caps); | 447 effect = GrCubicEffect::Create(edgeType, caps); |
442 } while (NULL == effect); | 448 } while (NULL == effect); |
443 return effect; | 449 return effect; |
444 } | 450 } |
OLD | NEW |