| 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" |
| 11 #include "gl/GrGLSL.h" | 11 #include "gl/GrGLSL.h" |
| 12 #include "GrConvexPolyEffect.h" | 12 #include "GrConvexPolyEffect.h" |
| 13 #include "GrOvalEffect.h" |
| 13 #include "GrTBackendEffectFactory.h" | 14 #include "GrTBackendEffectFactory.h" |
| 14 | 15 |
| 15 #include "SkRRect.h" | 16 #include "SkRRect.h" |
| 16 | 17 |
| 17 // The effects defined here only handle rrect radii >= kRadiusMin. | 18 // The effects defined here only handle rrect radii >= kRadiusMin. |
| 18 static const SkScalar kRadiusMin = SK_ScalarHalf; | 19 static const SkScalar kRadiusMin = SK_ScalarHalf; |
| 19 | 20 |
| 20 ////////////////////////////////////////////////////////////////////////////// | 21 ////////////////////////////////////////////////////////////////////////////// |
| 21 | 22 |
| 22 class GLCircularRRectEffect; | 23 class GLCircularRRectEffect; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 uint32_t fCircularCornerFlags; | 71 uint32_t fCircularCornerFlags; |
| 71 | 72 |
| 72 GR_DECLARE_EFFECT_TEST; | 73 GR_DECLARE_EFFECT_TEST; |
| 73 | 74 |
| 74 typedef GrEffect INHERITED; | 75 typedef GrEffect INHERITED; |
| 75 }; | 76 }; |
| 76 | 77 |
| 77 GrEffectRef* CircularRRectEffect::Create(GrEffectEdgeType edgeType, | 78 GrEffectRef* CircularRRectEffect::Create(GrEffectEdgeType edgeType, |
| 78 uint32_t circularCornerFlags, | 79 uint32_t circularCornerFlags, |
| 79 const SkRRect& rrect) { | 80 const SkRRect& rrect) { |
| 80 SkASSERT(kFillAA_GrEffectEdgeType == edgeType || kInverseFillAA_GrEffectEdge
Type == edgeType); | 81 if (kFillAA_GrEffectEdgeType != edgeType && kInverseFillAA_GrEffectEdgeType
!= edgeType) { |
| 82 return NULL; |
| 83 } |
| 81 return CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(CircularRRectEffect, | 84 return CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(CircularRRectEffect, |
| 82 (edgeType, circularCornerF
lags, rrect)))); | 85 (edgeType, circularCornerF
lags, rrect)))); |
| 83 } | 86 } |
| 84 | 87 |
| 85 void CircularRRectEffect::getConstantColorComponents(GrColor* color, uint32_t* v
alidFlags) const { | 88 void CircularRRectEffect::getConstantColorComponents(GrColor* color, uint32_t* v
alidFlags) const { |
| 86 *validFlags = 0; | 89 *validFlags = 0; |
| 87 } | 90 } |
| 88 | 91 |
| 89 const GrBackendEffectFactory& CircularRRectEffect::getFactory() const { | 92 const GrBackendEffectFactory& CircularRRectEffect::getFactory() const { |
| 90 return GrTBackendEffectFactory<CircularRRectEffect>::getInstance(); | 93 return GrTBackendEffectFactory<CircularRRectEffect>::getInstance(); |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 | 406 |
| 404 SkRRect fRRect; | 407 SkRRect fRRect; |
| 405 GrEffectEdgeType fEdgeType; | 408 GrEffectEdgeType fEdgeType; |
| 406 | 409 |
| 407 GR_DECLARE_EFFECT_TEST; | 410 GR_DECLARE_EFFECT_TEST; |
| 408 | 411 |
| 409 typedef GrEffect INHERITED; | 412 typedef GrEffect INHERITED; |
| 410 }; | 413 }; |
| 411 | 414 |
| 412 GrEffectRef* EllipticalRRectEffect::Create(GrEffectEdgeType edgeType, const SkRR
ect& rrect) { | 415 GrEffectRef* EllipticalRRectEffect::Create(GrEffectEdgeType edgeType, const SkRR
ect& rrect) { |
| 413 SkASSERT(kFillAA_GrEffectEdgeType == edgeType || kInverseFillAA_GrEffectEdge
Type == edgeType); | 416 if (kFillAA_GrEffectEdgeType != edgeType && kInverseFillAA_GrEffectEdgeType
!= edgeType) { |
| 417 return NULL; |
| 418 } |
| 414 return CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(EllipticalRRectEffect, (ed
geType, rrect)))); | 419 return CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(EllipticalRRectEffect, (ed
geType, rrect)))); |
| 415 } | 420 } |
| 416 | 421 |
| 417 void EllipticalRRectEffect::getConstantColorComponents(GrColor* color, uint32_t*
validFlags) const { | 422 void EllipticalRRectEffect::getConstantColorComponents(GrColor* color, uint32_t*
validFlags) const { |
| 418 *validFlags = 0; | 423 *validFlags = 0; |
| 419 } | 424 } |
| 420 | 425 |
| 421 const GrBackendEffectFactory& EllipticalRRectEffect::getFactory() const { | 426 const GrBackendEffectFactory& EllipticalRRectEffect::getFactory() const { |
| 422 return GrTBackendEffectFactory<EllipticalRRectEffect>::getInstance(); | 427 return GrTBackendEffectFactory<EllipticalRRectEffect>::getInstance(); |
| 423 } | 428 } |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 GrCrash("RRect should always be simple or nine-patch."); | 625 GrCrash("RRect should always be simple or nine-patch."); |
| 621 } | 626 } |
| 622 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); |
| 623 fPrevRRect = rrect; | 628 fPrevRRect = rrect; |
| 624 } | 629 } |
| 625 } | 630 } |
| 626 | 631 |
| 627 ////////////////////////////////////////////////////////////////////////////// | 632 ////////////////////////////////////////////////////////////////////////////// |
| 628 | 633 |
| 629 GrEffectRef* GrRRectEffect::Create(GrEffectEdgeType edgeType, const SkRRect& rre
ct) { | 634 GrEffectRef* GrRRectEffect::Create(GrEffectEdgeType edgeType, const SkRRect& rre
ct) { |
| 630 if (kFillAA_GrEffectEdgeType != edgeType && kInverseFillAA_GrEffectEdgeType
!= edgeType) { | 635 if (rrect.isRect()) { |
| 631 return NULL; | 636 return GrConvexPolyEffect::Create(edgeType, rrect.getBounds()); |
| 632 } | 637 } |
| 633 | 638 |
| 634 if (rrect.isRect()) { | 639 if (rrect.isOval()) { |
| 635 return GrConvexPolyEffect::Create(edgeType, rrect.getBounds()); | 640 return GrOvalEffect::Create(edgeType, rrect.getBounds()); |
| 636 } | 641 } |
| 637 | 642 |
| 638 if (rrect.isSimple()) { | 643 if (rrect.isSimple()) { |
| 639 if (rrect.getSimpleRadii().fX < kRadiusMin || rrect.getSimpleRadii().fY
< kRadiusMin) { | 644 if (rrect.getSimpleRadii().fX < kRadiusMin || rrect.getSimpleRadii().fY
< kRadiusMin) { |
| 640 // In this case the corners are extremely close to rectangular and w
e collapse the | 645 // In this case the corners are extremely close to rectangular and w
e collapse the |
| 641 // clip to a rectangular clip. | 646 // clip to a rectangular clip. |
| 642 return GrConvexPolyEffect::Create(edgeType, rrect.getBounds()); | 647 return GrConvexPolyEffect::Create(edgeType, rrect.getBounds()); |
| 643 } | 648 } |
| 644 if (rrect.getSimpleRadii().fX == rrect.getSimpleRadii().fY) { | 649 if (rrect.getSimpleRadii().fX == rrect.getSimpleRadii().fY) { |
| 645 return CircularRRectEffect::Create(edgeType, CircularRRectEffect::kA
ll_CornerFlags, | 650 return CircularRRectEffect::Create(edgeType, CircularRRectEffect::kA
ll_CornerFlags, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 if (rrect.isNinePatch()) { | 720 if (rrect.isNinePatch()) { |
| 716 return EllipticalRRectEffect::Create(edgeType, rrect); | 721 return EllipticalRRectEffect::Create(edgeType, rrect); |
| 717 } | 722 } |
| 718 return NULL; | 723 return NULL; |
| 719 } | 724 } |
| 720 } | 725 } |
| 721 } | 726 } |
| 722 | 727 |
| 723 return NULL; | 728 return NULL; |
| 724 } | 729 } |
| OLD | NEW |