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/GrGLProcessor.h" | 10 #include "gl/GrGLProcessor.h" |
11 #include "gl/GrGLSL.h" | 11 #include "gl/GrGLSL.h" |
12 #include "gl/GrGLGeometryProcessor.h" | 12 #include "gl/GrGLGeometryProcessor.h" |
13 #include "gl/builders/GrGLProgramBuilder.h" | 13 #include "gl/builders/GrGLProgramBuilder.h" |
14 | 14 |
15 struct ConicBatchTracker { | 15 struct ConicBatchTracker { |
16 GrGPInput fInputColorType; | 16 GrGPInput fInputColorType; |
17 GrColor fColor; | 17 GrColor fColor; |
18 uint8_t fCoverageScale; | 18 uint8_t fCoverageScale; |
| 19 bool fUsesLocalCoords; |
19 }; | 20 }; |
20 | 21 |
21 class GrGLConicEffect : public GrGLGeometryProcessor { | 22 class GrGLConicEffect : public GrGLGeometryProcessor { |
22 public: | 23 public: |
23 GrGLConicEffect(const GrGeometryProcessor&, | 24 GrGLConicEffect(const GrGeometryProcessor&, |
24 const GrBatchTracker&); | 25 const GrBatchTracker&); |
25 | 26 |
26 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; | 27 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; |
27 | 28 |
28 static inline void GenKey(const GrGeometryProcessor&, | 29 static inline void GenKey(const GrGeometryProcessor&, |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 192 |
192 bool GrConicEffect::onIsEqual(const GrGeometryProcessor& other) const { | 193 bool GrConicEffect::onIsEqual(const GrGeometryProcessor& other) const { |
193 const GrConicEffect& ce = other.cast<GrConicEffect>(); | 194 const GrConicEffect& ce = other.cast<GrConicEffect>(); |
194 return (ce.fEdgeType == fEdgeType); | 195 return (ce.fEdgeType == fEdgeType); |
195 } | 196 } |
196 | 197 |
197 void GrConicEffect::initBatchTracker(GrBatchTracker* bt, const InitBT& init) con
st { | 198 void GrConicEffect::initBatchTracker(GrBatchTracker* bt, const InitBT& init) con
st { |
198 ConicBatchTracker* local = bt->cast<ConicBatchTracker>(); | 199 ConicBatchTracker* local = bt->cast<ConicBatchTracker>(); |
199 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, false); | 200 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, false); |
200 local->fCoverageScale = fCoverageScale; | 201 local->fCoverageScale = fCoverageScale; |
| 202 local->fUsesLocalCoords = init.fUsesLocalCoords; |
201 } | 203 } |
202 | 204 |
203 bool GrConicEffect::onCanMakeEqual(const GrBatchTracker& m, const GrBatchTracker
& t) const { | 205 bool GrConicEffect::onCanMakeEqual(const GrBatchTracker& m, |
| 206 const GrGeometryProcessor& that, |
| 207 const GrBatchTracker& t) const { |
204 const ConicBatchTracker& mine = m.cast<ConicBatchTracker>(); | 208 const ConicBatchTracker& mine = m.cast<ConicBatchTracker>(); |
205 const ConicBatchTracker& theirs = t.cast<ConicBatchTracker>(); | 209 const ConicBatchTracker& theirs = t.cast<ConicBatchTracker>(); |
206 return CanCombineOutput(mine.fInputColorType, mine.fColor, | 210 return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, |
| 211 that, theirs.fUsesLocalCoords) && |
| 212 CanCombineOutput(mine.fInputColorType, mine.fColor, |
207 theirs.fInputColorType, theirs.fColor) && | 213 theirs.fInputColorType, theirs.fColor) && |
208 mine.fCoverageScale == theirs.fCoverageScale; | 214 mine.fCoverageScale == theirs.fCoverageScale; |
209 } | 215 } |
210 | 216 |
211 ////////////////////////////////////////////////////////////////////////////// | 217 ////////////////////////////////////////////////////////////////////////////// |
212 | 218 |
213 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrConicEffect); | 219 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrConicEffect); |
214 | 220 |
215 GrGeometryProcessor* GrConicEffect::TestCreate(SkRandom* random, | 221 GrGeometryProcessor* GrConicEffect::TestCreate(SkRandom* random, |
216 GrContext*, | 222 GrContext*, |
217 const GrDrawTargetCaps& caps, | 223 const GrDrawTargetCaps& caps, |
218 GrTexture*[]) { | 224 GrTexture*[]) { |
219 GrGeometryProcessor* gp; | 225 GrGeometryProcessor* gp; |
220 do { | 226 do { |
221 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 227 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
222 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); | 228 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); |
223 gp = GrConicEffect::Create(GrRandomColor(random), edgeType, caps); | 229 gp = GrConicEffect::Create(GrRandomColor(random), edgeType, caps); |
224 } while (NULL == gp); | 230 } while (NULL == gp); |
225 return gp; | 231 return gp; |
226 } | 232 } |
227 | 233 |
228 ////////////////////////////////////////////////////////////////////////////// | 234 ////////////////////////////////////////////////////////////////////////////// |
229 // Quad | 235 // Quad |
230 ////////////////////////////////////////////////////////////////////////////// | 236 ////////////////////////////////////////////////////////////////////////////// |
231 | 237 |
232 struct QuadBatchTracker { | 238 struct QuadBatchTracker { |
233 GrGPInput fInputColorType; | 239 GrGPInput fInputColorType; |
234 GrColor fColor; | 240 GrColor fColor; |
235 uint8_t fCoverageScale; | 241 uint8_t fCoverageScale; |
| 242 bool fUsesLocalCoords; |
236 }; | 243 }; |
237 | 244 |
238 class GrGLQuadEffect : public GrGLGeometryProcessor { | 245 class GrGLQuadEffect : public GrGLGeometryProcessor { |
239 public: | 246 public: |
240 GrGLQuadEffect(const GrGeometryProcessor&, | 247 GrGLQuadEffect(const GrGeometryProcessor&, |
241 const GrBatchTracker&); | 248 const GrBatchTracker&); |
242 | 249 |
243 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; | 250 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; |
244 | 251 |
245 static inline void GenKey(const GrGeometryProcessor&, | 252 static inline void GenKey(const GrGeometryProcessor&, |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 | 401 |
395 bool GrQuadEffect::onIsEqual(const GrGeometryProcessor& other) const { | 402 bool GrQuadEffect::onIsEqual(const GrGeometryProcessor& other) const { |
396 const GrQuadEffect& ce = other.cast<GrQuadEffect>(); | 403 const GrQuadEffect& ce = other.cast<GrQuadEffect>(); |
397 return (ce.fEdgeType == fEdgeType); | 404 return (ce.fEdgeType == fEdgeType); |
398 } | 405 } |
399 | 406 |
400 void GrQuadEffect::initBatchTracker(GrBatchTracker* bt, const InitBT& init) cons
t { | 407 void GrQuadEffect::initBatchTracker(GrBatchTracker* bt, const InitBT& init) cons
t { |
401 QuadBatchTracker* local = bt->cast<QuadBatchTracker>(); | 408 QuadBatchTracker* local = bt->cast<QuadBatchTracker>(); |
402 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, false); | 409 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, false); |
403 local->fCoverageScale = fCoverageScale; | 410 local->fCoverageScale = fCoverageScale; |
| 411 local->fUsesLocalCoords = init.fUsesLocalCoords; |
404 } | 412 } |
405 | 413 |
406 bool GrQuadEffect::onCanMakeEqual(const GrBatchTracker& m, const GrBatchTracker&
t) const { | 414 bool GrQuadEffect::onCanMakeEqual(const GrBatchTracker& m, |
| 415 const GrGeometryProcessor& that, |
| 416 const GrBatchTracker& t) const { |
407 const QuadBatchTracker& mine = m.cast<QuadBatchTracker>(); | 417 const QuadBatchTracker& mine = m.cast<QuadBatchTracker>(); |
408 const QuadBatchTracker& theirs = t.cast<QuadBatchTracker>(); | 418 const QuadBatchTracker& theirs = t.cast<QuadBatchTracker>(); |
409 return CanCombineOutput(mine.fInputColorType, mine.fColor, | 419 return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, |
| 420 that, theirs.fUsesLocalCoords) && |
| 421 CanCombineOutput(mine.fInputColorType, mine.fColor, |
410 theirs.fInputColorType, theirs.fColor) && | 422 theirs.fInputColorType, theirs.fColor) && |
411 mine.fCoverageScale == theirs.fCoverageScale; | 423 mine.fCoverageScale == theirs.fCoverageScale; |
412 } | 424 } |
413 | 425 |
414 ////////////////////////////////////////////////////////////////////////////// | 426 ////////////////////////////////////////////////////////////////////////////// |
415 | 427 |
416 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrQuadEffect); | 428 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrQuadEffect); |
417 | 429 |
418 GrGeometryProcessor* GrQuadEffect::TestCreate(SkRandom* random, | 430 GrGeometryProcessor* GrQuadEffect::TestCreate(SkRandom* random, |
419 GrContext*, | 431 GrContext*, |
420 const GrDrawTargetCaps& caps, | 432 const GrDrawTargetCaps& caps, |
421 GrTexture*[]) { | 433 GrTexture*[]) { |
422 GrGeometryProcessor* gp; | 434 GrGeometryProcessor* gp; |
423 do { | 435 do { |
424 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 436 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
425 random->nextULessThan(kGrProcessorEdgeTypeCnt)); | 437 random->nextULessThan(kGrProcessorEdgeTypeCnt)); |
426 gp = GrQuadEffect::Create(GrRandomColor(random), edgeType, caps); | 438 gp = GrQuadEffect::Create(GrRandomColor(random), edgeType, caps); |
427 } while (NULL == gp); | 439 } while (NULL == gp); |
428 return gp; | 440 return gp; |
429 } | 441 } |
430 | 442 |
431 ////////////////////////////////////////////////////////////////////////////// | 443 ////////////////////////////////////////////////////////////////////////////// |
432 // Cubic | 444 // Cubic |
433 ////////////////////////////////////////////////////////////////////////////// | 445 ////////////////////////////////////////////////////////////////////////////// |
434 | 446 |
435 struct CubicBatchTracker { | 447 struct CubicBatchTracker { |
436 GrGPInput fInputColorType; | 448 GrGPInput fInputColorType; |
437 GrColor fColor; | 449 GrColor fColor; |
| 450 bool fUsesLocalCoords; |
438 }; | 451 }; |
439 | 452 |
440 class GrGLCubicEffect : public GrGLGeometryProcessor { | 453 class GrGLCubicEffect : public GrGLGeometryProcessor { |
441 public: | 454 public: |
442 GrGLCubicEffect(const GrGeometryProcessor&, | 455 GrGLCubicEffect(const GrGeometryProcessor&, |
443 const GrBatchTracker&); | 456 const GrBatchTracker&); |
444 | 457 |
445 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; | 458 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; |
446 | 459 |
447 static inline void GenKey(const GrGeometryProcessor&, | 460 static inline void GenKey(const GrGeometryProcessor&, |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 } | 631 } |
619 | 632 |
620 bool GrCubicEffect::onIsEqual(const GrGeometryProcessor& other) const { | 633 bool GrCubicEffect::onIsEqual(const GrGeometryProcessor& other) const { |
621 const GrCubicEffect& ce = other.cast<GrCubicEffect>(); | 634 const GrCubicEffect& ce = other.cast<GrCubicEffect>(); |
622 return (ce.fEdgeType == fEdgeType); | 635 return (ce.fEdgeType == fEdgeType); |
623 } | 636 } |
624 | 637 |
625 void GrCubicEffect::initBatchTracker(GrBatchTracker* bt, const InitBT& init) con
st { | 638 void GrCubicEffect::initBatchTracker(GrBatchTracker* bt, const InitBT& init) con
st { |
626 CubicBatchTracker* local = bt->cast<CubicBatchTracker>(); | 639 CubicBatchTracker* local = bt->cast<CubicBatchTracker>(); |
627 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, false); | 640 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, false); |
| 641 local->fUsesLocalCoords = init.fUsesLocalCoords; |
628 } | 642 } |
629 | 643 |
630 bool GrCubicEffect::onCanMakeEqual(const GrBatchTracker& m, const GrBatchTracker
& t) const { | 644 bool GrCubicEffect::onCanMakeEqual(const GrBatchTracker& m, |
| 645 const GrGeometryProcessor& that, |
| 646 const GrBatchTracker& t) const { |
631 const CubicBatchTracker& mine = m.cast<CubicBatchTracker>(); | 647 const CubicBatchTracker& mine = m.cast<CubicBatchTracker>(); |
632 const CubicBatchTracker& theirs = t.cast<CubicBatchTracker>(); | 648 const CubicBatchTracker& theirs = t.cast<CubicBatchTracker>(); |
633 return CanCombineOutput(mine.fInputColorType, mine.fColor, | 649 return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, |
| 650 that, theirs.fUsesLocalCoords) && |
| 651 CanCombineOutput(mine.fInputColorType, mine.fColor, |
634 theirs.fInputColorType, theirs.fColor); | 652 theirs.fInputColorType, theirs.fColor); |
635 } | 653 } |
636 | 654 |
637 ////////////////////////////////////////////////////////////////////////////// | 655 ////////////////////////////////////////////////////////////////////////////// |
638 | 656 |
639 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCubicEffect); | 657 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCubicEffect); |
640 | 658 |
641 GrGeometryProcessor* GrCubicEffect::TestCreate(SkRandom* random, | 659 GrGeometryProcessor* GrCubicEffect::TestCreate(SkRandom* random, |
642 GrContext*, | 660 GrContext*, |
643 const GrDrawTargetCaps& caps, | 661 const GrDrawTargetCaps& caps, |
644 GrTexture*[]) { | 662 GrTexture*[]) { |
645 GrGeometryProcessor* gp; | 663 GrGeometryProcessor* gp; |
646 do { | 664 do { |
647 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 665 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
648 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); | 666 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); |
649 gp = GrCubicEffect::Create(GrRandomColor(random), edgeType, caps); | 667 gp = GrCubicEffect::Create(GrRandomColor(random), edgeType, caps); |
650 } while (NULL == gp); | 668 } while (NULL == gp); |
651 return gp; | 669 return gp; |
652 } | 670 } |
653 | 671 |
OLD | NEW |