| 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 "GrConvexPolyEffect.h" | 10 #include "GrConvexPolyEffect.h" |
| 11 #include "GrFragmentProcessor.h" | 11 #include "GrFragmentProcessor.h" |
| 12 #include "GrInvariantOutput.h" | 12 #include "GrInvariantOutput.h" |
| 13 #include "GrOvalEffect.h" | 13 #include "GrOvalEffect.h" |
| 14 #include "SkRRect.h" | 14 #include "SkRRect.h" |
| 15 #include "gl/GrGLFragmentProcessor.h" | 15 #include "gl/GrGLFragmentProcessor.h" |
| 16 #include "gl/builders/GrGLProgramBuilder.h" | 16 #include "gl/builders/GrGLProgramBuilder.h" |
| 17 #include "glsl/GrGLSLProgramDataManager.h" |
| 17 | 18 |
| 18 // The effects defined here only handle rrect radii >= kRadiusMin. | 19 // The effects defined here only handle rrect radii >= kRadiusMin. |
| 19 static const SkScalar kRadiusMin = SK_ScalarHalf; | 20 static const SkScalar kRadiusMin = SK_ScalarHalf; |
| 20 | 21 |
| 21 ////////////////////////////////////////////////////////////////////////////// | 22 ////////////////////////////////////////////////////////////////////////////// |
| 22 | 23 |
| 23 class CircularRRectEffect : public GrFragmentProcessor { | 24 class CircularRRectEffect : public GrFragmentProcessor { |
| 24 public: | 25 public: |
| 25 | 26 |
| 26 enum CornerFlags { | 27 enum CornerFlags { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 127 |
| 127 class GLCircularRRectEffect : public GrGLFragmentProcessor { | 128 class GLCircularRRectEffect : public GrGLFragmentProcessor { |
| 128 public: | 129 public: |
| 129 GLCircularRRectEffect(const GrProcessor&); | 130 GLCircularRRectEffect(const GrProcessor&); |
| 130 | 131 |
| 131 virtual void emitCode(EmitArgs&) override; | 132 virtual void emitCode(EmitArgs&) override; |
| 132 | 133 |
| 133 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); | 134 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); |
| 134 | 135 |
| 135 protected: | 136 protected: |
| 136 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; | 137 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
| 137 | 138 |
| 138 private: | 139 private: |
| 139 GrGLProgramDataManager::UniformHandle fInnerRectUniform; | 140 GrGLSLProgramDataManager::UniformHandle fInnerRectUniform; |
| 140 GrGLProgramDataManager::UniformHandle fRadiusPlusHalfUniform; | 141 GrGLSLProgramDataManager::UniformHandle fRadiusPlusHalfUniform; |
| 141 SkRRect fPrevRRect; | 142 SkRRect fPrevRRect; |
| 142 typedef GrGLFragmentProcessor INHERITED; | 143 typedef GrGLFragmentProcessor INHERITED; |
| 143 }; | 144 }; |
| 144 | 145 |
| 145 GLCircularRRectEffect::GLCircularRRectEffect(const GrProcessor& ) { | 146 GLCircularRRectEffect::GLCircularRRectEffect(const GrProcessor& ) { |
| 146 fPrevRRect.setEmpty(); | 147 fPrevRRect.setEmpty(); |
| 147 } | 148 } |
| 148 | 149 |
| 149 void GLCircularRRectEffect::emitCode(EmitArgs& args) { | 150 void GLCircularRRectEffect::emitCode(EmitArgs& args) { |
| 150 const CircularRRectEffect& crre = args.fFp.cast<CircularRRectEffect>(); | 151 const CircularRRectEffect& crre = args.fFp.cast<CircularRRectEffect>(); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha")
).c_str()); | 275 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha")
).c_str()); |
| 275 } | 276 } |
| 276 | 277 |
| 277 void GLCircularRRectEffect::GenKey(const GrProcessor& processor, const GrGLSLCap
s&, | 278 void GLCircularRRectEffect::GenKey(const GrProcessor& processor, const GrGLSLCap
s&, |
| 278 GrProcessorKeyBuilder* b) { | 279 GrProcessorKeyBuilder* b) { |
| 279 const CircularRRectEffect& crre = processor.cast<CircularRRectEffect>(); | 280 const CircularRRectEffect& crre = processor.cast<CircularRRectEffect>(); |
| 280 GR_STATIC_ASSERT(kGrProcessorEdgeTypeCnt <= 8); | 281 GR_STATIC_ASSERT(kGrProcessorEdgeTypeCnt <= 8); |
| 281 b->add32((crre.getCircularCornerFlags() << 3) | crre.getEdgeType()); | 282 b->add32((crre.getCircularCornerFlags() << 3) | crre.getEdgeType()); |
| 282 } | 283 } |
| 283 | 284 |
| 284 void GLCircularRRectEffect::onSetData(const GrGLProgramDataManager& pdman, | 285 void GLCircularRRectEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
| 285 const GrProcessor& processor) { | 286 const GrProcessor& processor) { |
| 286 const CircularRRectEffect& crre = processor.cast<CircularRRectEffect>(); | 287 const CircularRRectEffect& crre = processor.cast<CircularRRectEffect>(); |
| 287 const SkRRect& rrect = crre.getRRect(); | 288 const SkRRect& rrect = crre.getRRect(); |
| 288 if (rrect != fPrevRRect) { | 289 if (rrect != fPrevRRect) { |
| 289 SkRect rect = rrect.getBounds(); | 290 SkRect rect = rrect.getBounds(); |
| 290 SkScalar radius = 0; | 291 SkScalar radius = 0; |
| 291 switch (crre.getCircularCornerFlags()) { | 292 switch (crre.getCircularCornerFlags()) { |
| 292 case CircularRRectEffect::kAll_CornerFlags: | 293 case CircularRRectEffect::kAll_CornerFlags: |
| 293 SkASSERT(rrect.isSimpleCircular()); | 294 SkASSERT(rrect.isSimpleCircular()); |
| 294 radius = rrect.getSimpleRadii().fX; | 295 radius = rrect.getSimpleRadii().fX; |
| 295 SkASSERT(radius >= kRadiusMin); | 296 SkASSERT(radius >= kRadiusMin); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 | 473 |
| 473 class GLEllipticalRRectEffect : public GrGLFragmentProcessor { | 474 class GLEllipticalRRectEffect : public GrGLFragmentProcessor { |
| 474 public: | 475 public: |
| 475 GLEllipticalRRectEffect(const GrProcessor&); | 476 GLEllipticalRRectEffect(const GrProcessor&); |
| 476 | 477 |
| 477 virtual void emitCode(EmitArgs&) override; | 478 virtual void emitCode(EmitArgs&) override; |
| 478 | 479 |
| 479 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); | 480 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); |
| 480 | 481 |
| 481 protected: | 482 protected: |
| 482 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; | 483 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
| 483 | 484 |
| 484 private: | 485 private: |
| 485 GrGLProgramDataManager::UniformHandle fInnerRectUniform; | 486 GrGLSLProgramDataManager::UniformHandle fInnerRectUniform; |
| 486 GrGLProgramDataManager::UniformHandle fInvRadiiSqdUniform; | 487 GrGLSLProgramDataManager::UniformHandle fInvRadiiSqdUniform; |
| 487 SkRRect fPrevRRect; | 488 SkRRect fPrevRRect; |
| 488 typedef GrGLFragmentProcessor INHERITED; | 489 typedef GrGLFragmentProcessor INHERITED; |
| 489 }; | 490 }; |
| 490 | 491 |
| 491 GLEllipticalRRectEffect::GLEllipticalRRectEffect(const GrProcessor& effect) { | 492 GLEllipticalRRectEffect::GLEllipticalRRectEffect(const GrProcessor& effect) { |
| 492 fPrevRRect.setEmpty(); | 493 fPrevRRect.setEmpty(); |
| 493 } | 494 } |
| 494 | 495 |
| 495 void GLEllipticalRRectEffect::emitCode(EmitArgs& args) { | 496 void GLEllipticalRRectEffect::emitCode(EmitArgs& args) { |
| 496 const EllipticalRRectEffect& erre = args.fFp.cast<EllipticalRRectEffect>(); | 497 const EllipticalRRectEffect& erre = args.fFp.cast<EllipticalRRectEffect>(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha")
).c_str()); | 566 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha")
).c_str()); |
| 566 } | 567 } |
| 567 | 568 |
| 568 void GLEllipticalRRectEffect::GenKey(const GrProcessor& effect, const GrGLSLCaps
&, | 569 void GLEllipticalRRectEffect::GenKey(const GrProcessor& effect, const GrGLSLCaps
&, |
| 569 GrProcessorKeyBuilder* b) { | 570 GrProcessorKeyBuilder* b) { |
| 570 const EllipticalRRectEffect& erre = effect.cast<EllipticalRRectEffect>(); | 571 const EllipticalRRectEffect& erre = effect.cast<EllipticalRRectEffect>(); |
| 571 GR_STATIC_ASSERT(kLast_GrProcessorEdgeType < (1 << 3)); | 572 GR_STATIC_ASSERT(kLast_GrProcessorEdgeType < (1 << 3)); |
| 572 b->add32(erre.getRRect().getType() | erre.getEdgeType() << 3); | 573 b->add32(erre.getRRect().getType() | erre.getEdgeType() << 3); |
| 573 } | 574 } |
| 574 | 575 |
| 575 void GLEllipticalRRectEffect::onSetData(const GrGLProgramDataManager& pdman, | 576 void GLEllipticalRRectEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
| 576 const GrProcessor& effect) { | 577 const GrProcessor& effect) { |
| 577 const EllipticalRRectEffect& erre = effect.cast<EllipticalRRectEffect>(); | 578 const EllipticalRRectEffect& erre = effect.cast<EllipticalRRectEffect>(); |
| 578 const SkRRect& rrect = erre.getRRect(); | 579 const SkRRect& rrect = erre.getRRect(); |
| 579 if (rrect != fPrevRRect) { | 580 if (rrect != fPrevRRect) { |
| 580 SkRect rect = rrect.getBounds(); | 581 SkRect rect = rrect.getBounds(); |
| 581 const SkVector& r0 = rrect.radii(SkRRect::kUpperLeft_Corner); | 582 const SkVector& r0 = rrect.radii(SkRRect::kUpperLeft_Corner); |
| 582 SkASSERT(r0.fX >= kRadiusMin); | 583 SkASSERT(r0.fX >= kRadiusMin); |
| 583 SkASSERT(r0.fY >= kRadiusMin); | 584 SkASSERT(r0.fY >= kRadiusMin); |
| 584 switch (erre.getRRect().getType()) { | 585 switch (erre.getRRect().getType()) { |
| 585 case SkRRect::kSimple_Type: | 586 case SkRRect::kSimple_Type: |
| 586 rect.inset(r0.fX, r0.fY); | 587 rect.inset(r0.fX, r0.fY); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 if (rrect.isNinePatch()) { | 712 if (rrect.isNinePatch()) { |
| 712 return EllipticalRRectEffect::Create(edgeType, rrect); | 713 return EllipticalRRectEffect::Create(edgeType, rrect); |
| 713 } | 714 } |
| 714 return nullptr; | 715 return nullptr; |
| 715 } | 716 } |
| 716 } | 717 } |
| 717 } | 718 } |
| 718 | 719 |
| 719 return nullptr; | 720 return nullptr; |
| 720 } | 721 } |
| OLD | NEW |