| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrRRectEffect.h" | 8 #include "GrRRectEffect.h" |
| 9 | 9 |
| 10 #include "gl/GrGLEffect.h" | 10 #include "gl/GrGLEffect.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 kBottom_CornerFlags = kBottomLeft_CornerFlag | kBottomRight_CornerFlag, | 37 kBottom_CornerFlags = kBottomLeft_CornerFlag | kBottomRight_CornerFlag, |
| 38 | 38 |
| 39 kAll_CornerFlags = kTopLeft_CornerFlag | kTopRight_CornerFlag | | 39 kAll_CornerFlags = kTopLeft_CornerFlag | kTopRight_CornerFlag | |
| 40 kBottomLeft_CornerFlag | kBottomRight_CornerFlag, | 40 kBottomLeft_CornerFlag | kBottomRight_CornerFlag, |
| 41 | 41 |
| 42 kNone_CornerFlags = 0 | 42 kNone_CornerFlags = 0 |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 // The flags are used to indicate which corners are circluar (unflagged corn
ers are assumed to | 45 // The flags are used to indicate which corners are circluar (unflagged corn
ers are assumed to |
| 46 // be square). | 46 // be square). |
| 47 static GrEffectRef* Create(GrEffectEdgeType, uint32_t circularCornerFlags, c
onst SkRRect&); | 47 static GrEffect* Create(GrEffectEdgeType, uint32_t circularCornerFlags, cons
t SkRRect&); |
| 48 | 48 |
| 49 virtual ~CircularRRectEffect() {}; | 49 virtual ~CircularRRectEffect() {}; |
| 50 static const char* Name() { return "CircularRRect"; } | 50 static const char* Name() { return "CircularRRect"; } |
| 51 | 51 |
| 52 const SkRRect& getRRect() const { return fRRect; } | 52 const SkRRect& getRRect() const { return fRRect; } |
| 53 | 53 |
| 54 uint32_t getCircularCornerFlags() const { return fCircularCornerFlags; } | 54 uint32_t getCircularCornerFlags() const { return fCircularCornerFlags; } |
| 55 | 55 |
| 56 GrEffectEdgeType getEdgeType() const { return fEdgeType; } | 56 GrEffectEdgeType getEdgeType() const { return fEdgeType; } |
| 57 | 57 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 68 | 68 |
| 69 SkRRect fRRect; | 69 SkRRect fRRect; |
| 70 GrEffectEdgeType fEdgeType; | 70 GrEffectEdgeType fEdgeType; |
| 71 uint32_t fCircularCornerFlags; | 71 uint32_t fCircularCornerFlags; |
| 72 | 72 |
| 73 GR_DECLARE_EFFECT_TEST; | 73 GR_DECLARE_EFFECT_TEST; |
| 74 | 74 |
| 75 typedef GrEffect INHERITED; | 75 typedef GrEffect INHERITED; |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 GrEffectRef* CircularRRectEffect::Create(GrEffectEdgeType edgeType, | 78 GrEffect* CircularRRectEffect::Create(GrEffectEdgeType edgeType, |
| 79 uint32_t circularCornerFlags, | 79 uint32_t circularCornerFlags, |
| 80 const SkRRect& rrect) { | 80 const SkRRect& rrect) { |
| 81 if (kFillAA_GrEffectEdgeType != edgeType && kInverseFillAA_GrEffectEdgeType
!= edgeType) { | 81 if (kFillAA_GrEffectEdgeType != edgeType && kInverseFillAA_GrEffectEdgeType
!= edgeType) { |
| 82 return NULL; | 82 return NULL; |
| 83 } | 83 } |
| 84 return SkNEW_ARGS(CircularRRectEffect, (edgeType, circularCornerFlags, rrect
)); | 84 return SkNEW_ARGS(CircularRRectEffect, (edgeType, circularCornerFlags, rrect
)); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void CircularRRectEffect::getConstantColorComponents(GrColor* color, uint32_t* v
alidFlags) const { | 87 void CircularRRectEffect::getConstantColorComponents(GrColor* color, uint32_t* v
alidFlags) const { |
| 88 *validFlags = 0; | 88 *validFlags = 0; |
| 89 } | 89 } |
| 90 | 90 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 103 bool CircularRRectEffect::onIsEqual(const GrEffect& other) const { | 103 bool CircularRRectEffect::onIsEqual(const GrEffect& other) const { |
| 104 const CircularRRectEffect& crre = CastEffect<CircularRRectEffect>(other); | 104 const CircularRRectEffect& crre = CastEffect<CircularRRectEffect>(other); |
| 105 // The corner flags are derived from fRRect, so no need to check them. | 105 // The corner flags are derived from fRRect, so no need to check them. |
| 106 return fEdgeType == crre.fEdgeType && fRRect == crre.fRRect; | 106 return fEdgeType == crre.fEdgeType && fRRect == crre.fRRect; |
| 107 } | 107 } |
| 108 | 108 |
| 109 ////////////////////////////////////////////////////////////////////////////// | 109 ////////////////////////////////////////////////////////////////////////////// |
| 110 | 110 |
| 111 GR_DEFINE_EFFECT_TEST(CircularRRectEffect); | 111 GR_DEFINE_EFFECT_TEST(CircularRRectEffect); |
| 112 | 112 |
| 113 GrEffectRef* CircularRRectEffect::TestCreate(SkRandom* random, | 113 GrEffect* CircularRRectEffect::TestCreate(SkRandom* random, |
| 114 GrContext*, | 114 GrContext*, |
| 115 const GrDrawTargetCaps& caps, | 115 const GrDrawTargetCaps& caps, |
| 116 GrTexture*[]) { | 116 GrTexture*[]) { |
| 117 SkScalar w = random->nextRangeScalar(20.f, 1000.f); | 117 SkScalar w = random->nextRangeScalar(20.f, 1000.f); |
| 118 SkScalar h = random->nextRangeScalar(20.f, 1000.f); | 118 SkScalar h = random->nextRangeScalar(20.f, 1000.f); |
| 119 SkScalar r = random->nextRangeF(kRadiusMin, 9.f); | 119 SkScalar r = random->nextRangeF(kRadiusMin, 9.f); |
| 120 SkRRect rrect; | 120 SkRRect rrect; |
| 121 rrect.setRectXY(SkRect::MakeWH(w, h), r, r); | 121 rrect.setRectXY(SkRect::MakeWH(w, h), r, r); |
| 122 GrEffectRef* effect; | 122 GrEffect* effect; |
| 123 do { | 123 do { |
| 124 GrEffectEdgeType et = (GrEffectEdgeType)random->nextULessThan(kGrEffectE
dgeTypeCnt); | 124 GrEffectEdgeType et = (GrEffectEdgeType)random->nextULessThan(kGrEffectE
dgeTypeCnt); |
| 125 effect = GrRRectEffect::Create(et, rrect); | 125 effect = GrRRectEffect::Create(et, rrect); |
| 126 } while (NULL == effect); | 126 } while (NULL == effect); |
| 127 return effect; | 127 return effect; |
| 128 } | 128 } |
| 129 | 129 |
| 130 ////////////////////////////////////////////////////////////////////////////// | 130 ////////////////////////////////////////////////////////////////////////////// |
| 131 | 131 |
| 132 class GLCircularRRectEffect : public GrGLEffect { | 132 class GLCircularRRectEffect : public GrGLEffect { |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 fPrevRRect = rrect; | 375 fPrevRRect = rrect; |
| 376 } | 376 } |
| 377 } | 377 } |
| 378 | 378 |
| 379 ////////////////////////////////////////////////////////////////////////////// | 379 ////////////////////////////////////////////////////////////////////////////// |
| 380 | 380 |
| 381 class GLEllipticalRRectEffect; | 381 class GLEllipticalRRectEffect; |
| 382 | 382 |
| 383 class EllipticalRRectEffect : public GrEffect { | 383 class EllipticalRRectEffect : public GrEffect { |
| 384 public: | 384 public: |
| 385 static GrEffectRef* Create(GrEffectEdgeType, const SkRRect&); | 385 static GrEffect* Create(GrEffectEdgeType, const SkRRect&); |
| 386 | 386 |
| 387 virtual ~EllipticalRRectEffect() {}; | 387 virtual ~EllipticalRRectEffect() {}; |
| 388 static const char* Name() { return "EllipticalRRect"; } | 388 static const char* Name() { return "EllipticalRRect"; } |
| 389 | 389 |
| 390 const SkRRect& getRRect() const { return fRRect; } | 390 const SkRRect& getRRect() const { return fRRect; } |
| 391 | 391 |
| 392 | 392 |
| 393 GrEffectEdgeType getEdgeType() const { return fEdgeType; } | 393 GrEffectEdgeType getEdgeType() const { return fEdgeType; } |
| 394 | 394 |
| 395 typedef GLEllipticalRRectEffect GLEffect; | 395 typedef GLEllipticalRRectEffect GLEffect; |
| 396 | 396 |
| 397 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; | 397 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; |
| 398 | 398 |
| 399 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 399 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| 400 | 400 |
| 401 private: | 401 private: |
| 402 EllipticalRRectEffect(GrEffectEdgeType, const SkRRect&); | 402 EllipticalRRectEffect(GrEffectEdgeType, const SkRRect&); |
| 403 | 403 |
| 404 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; | 404 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; |
| 405 | 405 |
| 406 SkRRect fRRect; | 406 SkRRect fRRect; |
| 407 GrEffectEdgeType fEdgeType; | 407 GrEffectEdgeType fEdgeType; |
| 408 | 408 |
| 409 GR_DECLARE_EFFECT_TEST; | 409 GR_DECLARE_EFFECT_TEST; |
| 410 | 410 |
| 411 typedef GrEffect INHERITED; | 411 typedef GrEffect INHERITED; |
| 412 }; | 412 }; |
| 413 | 413 |
| 414 GrEffectRef* EllipticalRRectEffect::Create(GrEffectEdgeType edgeType, const SkRR
ect& rrect) { | 414 GrEffect* EllipticalRRectEffect::Create(GrEffectEdgeType edgeType, const SkRRect
& rrect) { |
| 415 if (kFillAA_GrEffectEdgeType != edgeType && kInverseFillAA_GrEffectEdgeType
!= edgeType) { | 415 if (kFillAA_GrEffectEdgeType != edgeType && kInverseFillAA_GrEffectEdgeType
!= edgeType) { |
| 416 return NULL; | 416 return NULL; |
| 417 } | 417 } |
| 418 return SkNEW_ARGS(EllipticalRRectEffect, (edgeType, rrect)); | 418 return SkNEW_ARGS(EllipticalRRectEffect, (edgeType, rrect)); |
| 419 } | 419 } |
| 420 | 420 |
| 421 void EllipticalRRectEffect::getConstantColorComponents(GrColor* color, uint32_t*
validFlags) const { | 421 void EllipticalRRectEffect::getConstantColorComponents(GrColor* color, uint32_t*
validFlags) const { |
| 422 *validFlags = 0; | 422 *validFlags = 0; |
| 423 } | 423 } |
| 424 | 424 |
| 425 const GrBackendEffectFactory& EllipticalRRectEffect::getFactory() const { | 425 const GrBackendEffectFactory& EllipticalRRectEffect::getFactory() const { |
| 426 return GrTBackendEffectFactory<EllipticalRRectEffect>::getInstance(); | 426 return GrTBackendEffectFactory<EllipticalRRectEffect>::getInstance(); |
| 427 } | 427 } |
| 428 | 428 |
| 429 EllipticalRRectEffect::EllipticalRRectEffect(GrEffectEdgeType edgeType, const Sk
RRect& rrect) | 429 EllipticalRRectEffect::EllipticalRRectEffect(GrEffectEdgeType edgeType, const Sk
RRect& rrect) |
| 430 : fRRect(rrect) | 430 : fRRect(rrect) |
| 431 , fEdgeType(edgeType){ | 431 , fEdgeType(edgeType){ |
| 432 this->setWillReadFragmentPosition(); | 432 this->setWillReadFragmentPosition(); |
| 433 } | 433 } |
| 434 | 434 |
| 435 bool EllipticalRRectEffect::onIsEqual(const GrEffect& other) const { | 435 bool EllipticalRRectEffect::onIsEqual(const GrEffect& other) const { |
| 436 const EllipticalRRectEffect& erre = CastEffect<EllipticalRRectEffect>(other)
; | 436 const EllipticalRRectEffect& erre = CastEffect<EllipticalRRectEffect>(other)
; |
| 437 return fEdgeType == erre.fEdgeType && fRRect == erre.fRRect; | 437 return fEdgeType == erre.fEdgeType && fRRect == erre.fRRect; |
| 438 } | 438 } |
| 439 | 439 |
| 440 ////////////////////////////////////////////////////////////////////////////// | 440 ////////////////////////////////////////////////////////////////////////////// |
| 441 | 441 |
| 442 GR_DEFINE_EFFECT_TEST(EllipticalRRectEffect); | 442 GR_DEFINE_EFFECT_TEST(EllipticalRRectEffect); |
| 443 | 443 |
| 444 GrEffectRef* EllipticalRRectEffect::TestCreate(SkRandom* random, | 444 GrEffect* EllipticalRRectEffect::TestCreate(SkRandom* random, |
| 445 GrContext*, | 445 GrContext*, |
| 446 const GrDrawTargetCaps& caps, | 446 const GrDrawTargetCaps& caps, |
| 447 GrTexture*[]) { | 447 GrTexture*[]) { |
| 448 SkScalar w = random->nextRangeScalar(20.f, 1000.f); | 448 SkScalar w = random->nextRangeScalar(20.f, 1000.f); |
| 449 SkScalar h = random->nextRangeScalar(20.f, 1000.f); | 449 SkScalar h = random->nextRangeScalar(20.f, 1000.f); |
| 450 SkVector r[4]; | 450 SkVector r[4]; |
| 451 r[SkRRect::kUpperLeft_Corner].fX = random->nextRangeF(kRadiusMin, 9.f); | 451 r[SkRRect::kUpperLeft_Corner].fX = random->nextRangeF(kRadiusMin, 9.f); |
| 452 // ensure at least one corner really is elliptical | 452 // ensure at least one corner really is elliptical |
| 453 do { | 453 do { |
| 454 r[SkRRect::kUpperLeft_Corner].fY = random->nextRangeF(kRadiusMin, 9.f); | 454 r[SkRRect::kUpperLeft_Corner].fY = random->nextRangeF(kRadiusMin, 9.f); |
| 455 } while (r[SkRRect::kUpperLeft_Corner].fY == r[SkRRect::kUpperLeft_Corner].f
X); | 455 } while (r[SkRRect::kUpperLeft_Corner].fY == r[SkRRect::kUpperLeft_Corner].f
X); |
| 456 | 456 |
| 457 SkRRect rrect; | 457 SkRRect rrect; |
| 458 if (random->nextBool()) { | 458 if (random->nextBool()) { |
| 459 // half the time create a four-radii rrect. | 459 // half the time create a four-radii rrect. |
| 460 r[SkRRect::kLowerRight_Corner].fX = random->nextRangeF(kRadiusMin, 9.f); | 460 r[SkRRect::kLowerRight_Corner].fX = random->nextRangeF(kRadiusMin, 9.f); |
| 461 r[SkRRect::kLowerRight_Corner].fY = random->nextRangeF(kRadiusMin, 9.f); | 461 r[SkRRect::kLowerRight_Corner].fY = random->nextRangeF(kRadiusMin, 9.f); |
| 462 | 462 |
| 463 r[SkRRect::kUpperRight_Corner].fX = r[SkRRect::kLowerRight_Corner].fX; | 463 r[SkRRect::kUpperRight_Corner].fX = r[SkRRect::kLowerRight_Corner].fX; |
| 464 r[SkRRect::kUpperRight_Corner].fY = r[SkRRect::kUpperLeft_Corner].fY; | 464 r[SkRRect::kUpperRight_Corner].fY = r[SkRRect::kUpperLeft_Corner].fY; |
| 465 | 465 |
| 466 r[SkRRect::kLowerLeft_Corner].fX = r[SkRRect::kUpperLeft_Corner].fX; | 466 r[SkRRect::kLowerLeft_Corner].fX = r[SkRRect::kUpperLeft_Corner].fX; |
| 467 r[SkRRect::kLowerLeft_Corner].fY = r[SkRRect::kLowerRight_Corner].fY; | 467 r[SkRRect::kLowerLeft_Corner].fY = r[SkRRect::kLowerRight_Corner].fY; |
| 468 | 468 |
| 469 rrect.setRectRadii(SkRect::MakeWH(w, h), r); | 469 rrect.setRectRadii(SkRect::MakeWH(w, h), r); |
| 470 } else { | 470 } else { |
| 471 rrect.setRectXY(SkRect::MakeWH(w, h), r[SkRRect::kUpperLeft_Corner].fX, | 471 rrect.setRectXY(SkRect::MakeWH(w, h), r[SkRRect::kUpperLeft_Corner].fX, |
| 472 r[SkRRect::kUpperLeft_Corner].fY); | 472 r[SkRRect::kUpperLeft_Corner].fY); |
| 473 } | 473 } |
| 474 GrEffectRef* effect; | 474 GrEffect* effect; |
| 475 do { | 475 do { |
| 476 GrEffectEdgeType et = (GrEffectEdgeType)random->nextULessThan(kGrEffectE
dgeTypeCnt); | 476 GrEffectEdgeType et = (GrEffectEdgeType)random->nextULessThan(kGrEffectE
dgeTypeCnt); |
| 477 effect = GrRRectEffect::Create(et, rrect); | 477 effect = GrRRectEffect::Create(et, rrect); |
| 478 } while (NULL == effect); | 478 } while (NULL == effect); |
| 479 return effect; | 479 return effect; |
| 480 } | 480 } |
| 481 | 481 |
| 482 ////////////////////////////////////////////////////////////////////////////// | 482 ////////////////////////////////////////////////////////////////////////////// |
| 483 | 483 |
| 484 class GLEllipticalRRectEffect : public GrGLEffect { | 484 class GLEllipticalRRectEffect : public GrGLEffect { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 default: | 624 default: |
| 625 SkFAIL("RRect should always be simple or nine-patch."); | 625 SkFAIL("RRect should always be simple or nine-patch."); |
| 626 } | 626 } |
| 627 uman.set4f(fInnerRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.f
Bottom); | 627 uman.set4f(fInnerRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.f
Bottom); |
| 628 fPrevRRect = rrect; | 628 fPrevRRect = rrect; |
| 629 } | 629 } |
| 630 } | 630 } |
| 631 | 631 |
| 632 ////////////////////////////////////////////////////////////////////////////// | 632 ////////////////////////////////////////////////////////////////////////////// |
| 633 | 633 |
| 634 GrEffectRef* GrRRectEffect::Create(GrEffectEdgeType edgeType, const SkRRect& rre
ct) { | 634 GrEffect* GrRRectEffect::Create(GrEffectEdgeType edgeType, const SkRRect& rrect)
{ |
| 635 if (rrect.isRect()) { | 635 if (rrect.isRect()) { |
| 636 return GrConvexPolyEffect::Create(edgeType, rrect.getBounds()); | 636 return GrConvexPolyEffect::Create(edgeType, rrect.getBounds()); |
| 637 } | 637 } |
| 638 | 638 |
| 639 if (rrect.isOval()) { | 639 if (rrect.isOval()) { |
| 640 return GrOvalEffect::Create(edgeType, rrect.getBounds()); | 640 return GrOvalEffect::Create(edgeType, rrect.getBounds()); |
| 641 } | 641 } |
| 642 | 642 |
| 643 if (rrect.isSimple()) { | 643 if (rrect.isSimple()) { |
| 644 if (rrect.getSimpleRadii().fX < kRadiusMin || rrect.getSimpleRadii().fY
< kRadiusMin) { | 644 if (rrect.getSimpleRadii().fX < kRadiusMin || rrect.getSimpleRadii().fY
< kRadiusMin) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 if (rrect.isNinePatch()) { | 720 if (rrect.isNinePatch()) { |
| 721 return EllipticalRRectEffect::Create(edgeType, rrect); | 721 return EllipticalRRectEffect::Create(edgeType, rrect); |
| 722 } | 722 } |
| 723 return NULL; | 723 return NULL; |
| 724 } | 724 } |
| 725 } | 725 } |
| 726 } | 726 } |
| 727 | 727 |
| 728 return NULL; | 728 return NULL; |
| 729 } | 729 } |
| OLD | NEW |