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/builders/GrGLProgramBuilder.h" | |
11 #include "gl/GrGLProcessor.h" | 10 #include "gl/GrGLProcessor.h" |
12 #include "gl/GrGLSL.h" | 11 #include "gl/GrGLSL.h" |
13 #include "gl/GrGLGeometryProcessor.h" | 12 #include "gl/GrGLGeometryProcessor.h" |
14 #include "GrTBackendProcessorFactory.h" | 13 #include "gl/builders/GrGLProgramBuilder.h" |
15 | 14 |
16 class GrGLConicEffect : public GrGLGeometryProcessor { | 15 class GrGLConicEffect : public GrGLGeometryProcessor { |
17 public: | 16 public: |
18 GrGLConicEffect(const GrBackendProcessorFactory&, | 17 GrGLConicEffect(const GrGeometryProcessor&, |
19 const GrGeometryProcessor&, | |
20 const GrBatchTracker&); | 18 const GrBatchTracker&); |
21 | 19 |
22 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; | 20 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; |
23 | 21 |
24 static inline void GenKey(const GrGeometryProcessor&, | 22 static inline void GenKey(const GrGeometryProcessor&, |
25 const GrBatchTracker&, | 23 const GrBatchTracker&, |
26 const GrGLCaps&, | 24 const GrGLCaps&, |
27 GrProcessorKeyBuilder*); | 25 GrProcessorKeyBuilder*); |
28 | 26 |
29 virtual void setData(const GrGLProgramDataManager&, | 27 virtual void setData(const GrGLProgramDataManager&, |
30 const GrGeometryProcessor&, | 28 const GrGeometryProcessor&, |
31 const GrBatchTracker&) SK_OVERRIDE {} | 29 const GrBatchTracker&) SK_OVERRIDE {} |
32 | 30 |
33 private: | 31 private: |
34 GrPrimitiveEdgeType fEdgeType; | 32 GrPrimitiveEdgeType fEdgeType; |
35 | 33 |
36 typedef GrGLGeometryProcessor INHERITED; | 34 typedef GrGLGeometryProcessor INHERITED; |
37 }; | 35 }; |
38 | 36 |
39 GrGLConicEffect::GrGLConicEffect(const GrBackendProcessorFactory& factory, | 37 GrGLConicEffect::GrGLConicEffect(const GrGeometryProcessor& processor, |
40 const GrGeometryProcessor& processor, | 38 const GrBatchTracker& bt) { |
41 const GrBatchTracker& bt) | |
42 : INHERITED (factory) { | |
43 const GrConicEffect& ce = processor.cast<GrConicEffect>(); | 39 const GrConicEffect& ce = processor.cast<GrConicEffect>(); |
44 fEdgeType = ce.getEdgeType(); | 40 fEdgeType = ce.getEdgeType(); |
45 } | 41 } |
46 | 42 |
47 void GrGLConicEffect::emitCode(const EmitArgs& args) { | 43 void GrGLConicEffect::emitCode(const EmitArgs& args) { |
48 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 44 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
49 const GrConicEffect& gp = args.fGP.cast<GrConicEffect>(); | 45 const GrConicEffect& gp = args.fGP.cast<GrConicEffect>(); |
50 | 46 |
51 GrGLVertToFrag v(kVec4f_GrSLType); | 47 GrGLVertToFrag v(kVec4f_GrSLType); |
52 args.fPB->addVarying("ConicCoeffs", &v); | 48 args.fPB->addVarying("ConicCoeffs", &v); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 GrProcessorKeyBuilder* b) { | 122 GrProcessorKeyBuilder* b) { |
127 const GrConicEffect& ce = processor.cast<GrConicEffect>(); | 123 const GrConicEffect& ce = processor.cast<GrConicEffect>(); |
128 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 124 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
129 b->add32(key); | 125 b->add32(key); |
130 } | 126 } |
131 | 127 |
132 ////////////////////////////////////////////////////////////////////////////// | 128 ////////////////////////////////////////////////////////////////////////////// |
133 | 129 |
134 GrConicEffect::~GrConicEffect() {} | 130 GrConicEffect::~GrConicEffect() {} |
135 | 131 |
136 const GrBackendGeometryProcessorFactory& GrConicEffect::getFactory() const { | 132 void GrConicEffect::getGLProcessorKey(const GrBatchTracker& bt, |
137 return GrTBackendGeometryProcessorFactory<GrConicEffect>::getInstance(); | 133 const GrGLCaps& caps, |
| 134 GrProcessorKeyBuilder* b) const SK_OVERRID
E { |
| 135 GrGLConicEffect::GenKey(*this, bt, caps, b); |
| 136 } |
| 137 |
| 138 GrGLGeometryProcessor* GrConicEffect::createGLInstance(const GrBatchTracker& bt)
const SK_OVERRIDE { |
| 139 return SkNEW_ARGS(GrGLConicEffect, (*this, bt)); |
138 } | 140 } |
139 | 141 |
140 GrConicEffect::GrConicEffect(GrPrimitiveEdgeType edgeType) | 142 GrConicEffect::GrConicEffect(GrPrimitiveEdgeType edgeType) |
141 : fEdgeType(edgeType) { | 143 : fEdgeType(edgeType) { |
142 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); | 144 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
143 fInConicCoeffs = &this->addVertexAttrib(GrAttribute("inConicCoeffs", | 145 fInConicCoeffs = &this->addVertexAttrib(GrAttribute("inConicCoeffs", |
144 kVec4f_GrVertexAttribTyp
e)); | 146 kVec4f_GrVertexAttribTyp
e)); |
145 } | 147 } |
146 | 148 |
147 bool GrConicEffect::onIsEqual(const GrGeometryProcessor& other) const { | 149 bool GrConicEffect::onIsEqual(const GrGeometryProcessor& other) const { |
(...skipping 17 matching lines...) Expand all Loading... |
165 } while (NULL == gp); | 167 } while (NULL == gp); |
166 return gp; | 168 return gp; |
167 } | 169 } |
168 | 170 |
169 ////////////////////////////////////////////////////////////////////////////// | 171 ////////////////////////////////////////////////////////////////////////////// |
170 // Quad | 172 // Quad |
171 ////////////////////////////////////////////////////////////////////////////// | 173 ////////////////////////////////////////////////////////////////////////////// |
172 | 174 |
173 class GrGLQuadEffect : public GrGLGeometryProcessor { | 175 class GrGLQuadEffect : public GrGLGeometryProcessor { |
174 public: | 176 public: |
175 GrGLQuadEffect(const GrBackendProcessorFactory&, | 177 GrGLQuadEffect(const GrGeometryProcessor&, |
176 const GrGeometryProcessor&, | |
177 const GrBatchTracker&); | 178 const GrBatchTracker&); |
178 | 179 |
179 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; | 180 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; |
180 | 181 |
181 static inline void GenKey(const GrGeometryProcessor&, | 182 static inline void GenKey(const GrGeometryProcessor&, |
182 const GrBatchTracker&, | 183 const GrBatchTracker&, |
183 const GrGLCaps&, | 184 const GrGLCaps&, |
184 GrProcessorKeyBuilder*); | 185 GrProcessorKeyBuilder*); |
185 | 186 |
186 virtual void setData(const GrGLProgramDataManager&, | 187 virtual void setData(const GrGLProgramDataManager&, |
187 const GrGeometryProcessor&, | 188 const GrGeometryProcessor&, |
188 const GrBatchTracker&) SK_OVERRIDE {} | 189 const GrBatchTracker&) SK_OVERRIDE {} |
189 | 190 |
190 private: | 191 private: |
191 GrPrimitiveEdgeType fEdgeType; | 192 GrPrimitiveEdgeType fEdgeType; |
192 | 193 |
193 typedef GrGLGeometryProcessor INHERITED; | 194 typedef GrGLGeometryProcessor INHERITED; |
194 }; | 195 }; |
195 | 196 |
196 GrGLQuadEffect::GrGLQuadEffect(const GrBackendProcessorFactory& factory, | 197 GrGLQuadEffect::GrGLQuadEffect(const GrGeometryProcessor& processor, |
197 const GrGeometryProcessor& processor, | 198 const GrBatchTracker& bt) { |
198 const GrBatchTracker& bt) | |
199 : INHERITED (factory) { | |
200 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); | 199 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); |
201 fEdgeType = ce.getEdgeType(); | 200 fEdgeType = ce.getEdgeType(); |
202 } | 201 } |
203 | 202 |
204 void GrGLQuadEffect::emitCode(const EmitArgs& args) { | 203 void GrGLQuadEffect::emitCode(const EmitArgs& args) { |
205 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 204 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
206 const GrQuadEffect& gp = args.fGP.cast<GrQuadEffect>(); | 205 const GrQuadEffect& gp = args.fGP.cast<GrQuadEffect>(); |
207 | 206 |
208 GrGLVertToFrag v(kVec4f_GrSLType); | 207 GrGLVertToFrag v(kVec4f_GrSLType); |
209 args.fPB->addVarying("HairQuadEdge", &v); | 208 args.fPB->addVarying("HairQuadEdge", &v); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 GrProcessorKeyBuilder* b) { | 268 GrProcessorKeyBuilder* b) { |
270 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); | 269 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); |
271 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 270 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
272 b->add32(key); | 271 b->add32(key); |
273 } | 272 } |
274 | 273 |
275 ////////////////////////////////////////////////////////////////////////////// | 274 ////////////////////////////////////////////////////////////////////////////// |
276 | 275 |
277 GrQuadEffect::~GrQuadEffect() {} | 276 GrQuadEffect::~GrQuadEffect() {} |
278 | 277 |
279 const GrBackendGeometryProcessorFactory& GrQuadEffect::getFactory() const { | 278 void GrQuadEffect::getGLProcessorKey(const GrBatchTracker& bt, |
280 return GrTBackendGeometryProcessorFactory<GrQuadEffect>::getInstance(); | 279 const GrGLCaps& caps, |
| 280 GrProcessorKeyBuilder* b) const SK_OVERRIDE
{ |
| 281 GrGLQuadEffect::GenKey(*this, bt, caps, b); |
| 282 } |
| 283 |
| 284 GrGLGeometryProcessor* GrQuadEffect::createGLInstance(const GrBatchTracker& bt)
const SK_OVERRIDE { |
| 285 return SkNEW_ARGS(GrGLQuadEffect, (*this, bt)); |
281 } | 286 } |
282 | 287 |
283 GrQuadEffect::GrQuadEffect(GrPrimitiveEdgeType edgeType) | 288 GrQuadEffect::GrQuadEffect(GrPrimitiveEdgeType edgeType) |
284 : fEdgeType(edgeType) { | 289 : fEdgeType(edgeType) { |
285 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); | 290 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
286 fInHairQuadEdge = &this->addVertexAttrib(GrAttribute("inHairQuadEdge", | 291 fInHairQuadEdge = &this->addVertexAttrib(GrAttribute("inHairQuadEdge", |
287 kVec4f_GrVertexAttribTyp
e)); | 292 kVec4f_GrVertexAttribTyp
e)); |
288 } | 293 } |
289 | 294 |
290 bool GrQuadEffect::onIsEqual(const GrGeometryProcessor& other) const { | 295 bool GrQuadEffect::onIsEqual(const GrGeometryProcessor& other) const { |
(...skipping 17 matching lines...) Expand all Loading... |
308 } while (NULL == gp); | 313 } while (NULL == gp); |
309 return gp; | 314 return gp; |
310 } | 315 } |
311 | 316 |
312 ////////////////////////////////////////////////////////////////////////////// | 317 ////////////////////////////////////////////////////////////////////////////// |
313 // Cubic | 318 // Cubic |
314 ////////////////////////////////////////////////////////////////////////////// | 319 ////////////////////////////////////////////////////////////////////////////// |
315 | 320 |
316 class GrGLCubicEffect : public GrGLGeometryProcessor { | 321 class GrGLCubicEffect : public GrGLGeometryProcessor { |
317 public: | 322 public: |
318 GrGLCubicEffect(const GrBackendProcessorFactory&, | 323 GrGLCubicEffect(const GrGeometryProcessor&, |
319 const GrGeometryProcessor&, | |
320 const GrBatchTracker&); | 324 const GrBatchTracker&); |
321 | 325 |
322 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; | 326 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; |
323 | 327 |
324 static inline void GenKey(const GrGeometryProcessor&, | 328 static inline void GenKey(const GrGeometryProcessor&, |
325 const GrBatchTracker&, | 329 const GrBatchTracker&, |
326 const GrGLCaps&, | 330 const GrGLCaps&, |
327 GrProcessorKeyBuilder*); | 331 GrProcessorKeyBuilder*); |
328 | 332 |
329 virtual void setData(const GrGLProgramDataManager&, | 333 virtual void setData(const GrGLProgramDataManager&, |
330 const GrGeometryProcessor&, | 334 const GrGeometryProcessor&, |
331 const GrBatchTracker&) SK_OVERRIDE {} | 335 const GrBatchTracker&) SK_OVERRIDE {} |
332 | 336 |
333 private: | 337 private: |
334 GrPrimitiveEdgeType fEdgeType; | 338 GrPrimitiveEdgeType fEdgeType; |
335 | 339 |
336 typedef GrGLGeometryProcessor INHERITED; | 340 typedef GrGLGeometryProcessor INHERITED; |
337 }; | 341 }; |
338 | 342 |
339 GrGLCubicEffect::GrGLCubicEffect(const GrBackendProcessorFactory& factory, | 343 GrGLCubicEffect::GrGLCubicEffect(const GrGeometryProcessor& processor, |
340 const GrGeometryProcessor& processor, | 344 const GrBatchTracker&) { |
341 const GrBatchTracker&) | |
342 : INHERITED (factory) { | |
343 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); | 345 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); |
344 fEdgeType = ce.getEdgeType(); | 346 fEdgeType = ce.getEdgeType(); |
345 } | 347 } |
346 | 348 |
347 void GrGLCubicEffect::emitCode(const EmitArgs& args) { | 349 void GrGLCubicEffect::emitCode(const EmitArgs& args) { |
348 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 350 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
349 const GrCubicEffect& gp = args.fGP.cast<GrCubicEffect>(); | 351 const GrCubicEffect& gp = args.fGP.cast<GrCubicEffect>(); |
350 | 352 |
351 GrGLVertToFrag v(kVec4f_GrSLType); | 353 GrGLVertToFrag v(kVec4f_GrSLType); |
352 args.fPB->addVarying("CubicCoeffs", &v, GrGLShaderVar::kHigh_Precision); | 354 args.fPB->addVarying("CubicCoeffs", &v, GrGLShaderVar::kHigh_Precision); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 GrProcessorKeyBuilder* b) { | 455 GrProcessorKeyBuilder* b) { |
454 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); | 456 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); |
455 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 457 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
456 b->add32(key); | 458 b->add32(key); |
457 } | 459 } |
458 | 460 |
459 ////////////////////////////////////////////////////////////////////////////// | 461 ////////////////////////////////////////////////////////////////////////////// |
460 | 462 |
461 GrCubicEffect::~GrCubicEffect() {} | 463 GrCubicEffect::~GrCubicEffect() {} |
462 | 464 |
463 const GrBackendGeometryProcessorFactory& GrCubicEffect::getFactory() const { | 465 void GrCubicEffect::getGLProcessorKey(const GrBatchTracker& bt, |
464 return GrTBackendGeometryProcessorFactory<GrCubicEffect>::getInstance(); | 466 const GrGLCaps& caps, |
| 467 GrProcessorKeyBuilder* b) const SK_OVERRID
E { |
| 468 GrGLCubicEffect::GenKey(*this, bt, caps, b); |
| 469 } |
| 470 |
| 471 GrGLGeometryProcessor* GrCubicEffect::createGLInstance(const GrBatchTracker& bt)
const SK_OVERRIDE { |
| 472 return SkNEW_ARGS(GrGLCubicEffect, (*this, bt)); |
465 } | 473 } |
466 | 474 |
467 GrCubicEffect::GrCubicEffect(GrPrimitiveEdgeType edgeType) | 475 GrCubicEffect::GrCubicEffect(GrPrimitiveEdgeType edgeType) |
468 : fEdgeType(edgeType) { | 476 : fEdgeType(edgeType) { |
469 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); | 477 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
470 fInCubicCoeffs = &this->addVertexAttrib(GrAttribute("inCubicCoeffs", | 478 fInCubicCoeffs = &this->addVertexAttrib(GrAttribute("inCubicCoeffs", |
471 kVec4f_GrVertexAttribTyp
e)); | 479 kVec4f_GrVertexAttribTyp
e)); |
472 } | 480 } |
473 | 481 |
474 bool GrCubicEffect::onIsEqual(const GrGeometryProcessor& other) const { | 482 bool GrCubicEffect::onIsEqual(const GrGeometryProcessor& other) const { |
(...skipping 11 matching lines...) Expand all Loading... |
486 GrTexture*[]) { | 494 GrTexture*[]) { |
487 GrGeometryProcessor* gp; | 495 GrGeometryProcessor* gp; |
488 do { | 496 do { |
489 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 497 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
490 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); | 498 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); |
491 gp = GrCubicEffect::Create(edgeType, caps); | 499 gp = GrCubicEffect::Create(edgeType, caps); |
492 } while (NULL == gp); | 500 } while (NULL == gp); |
493 return gp; | 501 return gp; |
494 } | 502 } |
495 | 503 |
OLD | NEW |