| 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" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 (GrPrimitiveEdgeType)d->fRandom->nextULessThan(kGrProcessorEdgeT
ypeCnt); | 122 (GrPrimitiveEdgeType)d->fRandom->nextULessThan(kGrProcessorEdgeT
ypeCnt); |
| 123 fp = GrRRectEffect::Create(et, rrect); | 123 fp = GrRRectEffect::Create(et, rrect); |
| 124 } while (nullptr == fp); | 124 } while (nullptr == fp); |
| 125 return fp; | 125 return fp; |
| 126 } | 126 } |
| 127 | 127 |
| 128 ////////////////////////////////////////////////////////////////////////////// | 128 ////////////////////////////////////////////////////////////////////////////// |
| 129 | 129 |
| 130 class GLCircularRRectEffect : public GrGLSLFragmentProcessor { | 130 class GLCircularRRectEffect : public GrGLSLFragmentProcessor { |
| 131 public: | 131 public: |
| 132 GLCircularRRectEffect(const GrProcessor&); | 132 GLCircularRRectEffect() { |
| 133 fPrevRRect.setEmpty(); |
| 134 } |
| 133 | 135 |
| 134 virtual void emitCode(EmitArgs&) override; | 136 virtual void emitCode(EmitArgs&) override; |
| 135 | 137 |
| 136 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); | 138 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); |
| 137 | 139 |
| 138 protected: | 140 protected: |
| 139 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; | 141 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
| 140 | 142 |
| 141 private: | 143 private: |
| 142 GrGLSLProgramDataManager::UniformHandle fInnerRectUniform; | 144 GrGLSLProgramDataManager::UniformHandle fInnerRectUniform; |
| 143 GrGLSLProgramDataManager::UniformHandle fRadiusPlusHalfUniform; | 145 GrGLSLProgramDataManager::UniformHandle fRadiusPlusHalfUniform; |
| 144 SkRRect fPrevRRect; | 146 SkRRect fPrevRRect; |
| 145 typedef GrGLSLFragmentProcessor INHERITED; | 147 typedef GrGLSLFragmentProcessor INHERITED; |
| 146 }; | 148 }; |
| 147 | 149 |
| 148 GLCircularRRectEffect::GLCircularRRectEffect(const GrProcessor& ) { | |
| 149 fPrevRRect.setEmpty(); | |
| 150 } | |
| 151 | |
| 152 void GLCircularRRectEffect::emitCode(EmitArgs& args) { | 150 void GLCircularRRectEffect::emitCode(EmitArgs& args) { |
| 153 const CircularRRectEffect& crre = args.fFp.cast<CircularRRectEffect>(); | 151 const CircularRRectEffect& crre = args.fFp.cast<CircularRRectEffect>(); |
| 154 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; | 152 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
| 155 const char *rectName; | 153 const char *rectName; |
| 156 const char *radiusPlusHalfName; | 154 const char *radiusPlusHalfName; |
| 157 // The inner rect is the rrect bounds inset by the radius. Its left, top, ri
ght, and bottom | 155 // The inner rect is the rrect bounds inset by the radius. Its left, top, ri
ght, and bottom |
| 158 // edges correspond to components x, y, z, and w, respectively. When a side
of the rrect has | 156 // edges correspond to components x, y, z, and w, respectively. When a side
of the rrect has |
| 159 // only rectangular corners, that side's value corresponds to the rect edge'
s value outset by | 157 // only rectangular corners, that side's value corresponds to the rect edge'
s value outset by |
| 160 // half a pixel. | 158 // half a pixel. |
| 161 fInnerRectUniform = uniformHandler->addUniform(GrGLSLUniformHandler::kFragme
nt_Visibility, | 159 fInnerRectUniform = uniformHandler->addUniform(GrGLSLUniformHandler::kFragme
nt_Visibility, |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 } | 373 } |
| 376 | 374 |
| 377 ////////////////////////////////////////////////////////////////////////////////
//////////////////// | 375 ////////////////////////////////////////////////////////////////////////////////
//////////////////// |
| 378 | 376 |
| 379 void CircularRRectEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, | 377 void CircularRRectEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, |
| 380 GrProcessorKeyBuilder* b) const
{ | 378 GrProcessorKeyBuilder* b) const
{ |
| 381 GLCircularRRectEffect::GenKey(*this, caps, b); | 379 GLCircularRRectEffect::GenKey(*this, caps, b); |
| 382 } | 380 } |
| 383 | 381 |
| 384 GrGLSLFragmentProcessor* CircularRRectEffect::onCreateGLSLInstance() const { | 382 GrGLSLFragmentProcessor* CircularRRectEffect::onCreateGLSLInstance() const { |
| 385 return new GLCircularRRectEffect(*this); | 383 return new GLCircularRRectEffect; |
| 386 } | 384 } |
| 387 | 385 |
| 388 ////////////////////////////////////////////////////////////////////////////// | 386 ////////////////////////////////////////////////////////////////////////////// |
| 389 | 387 |
| 390 class EllipticalRRectEffect : public GrFragmentProcessor { | 388 class EllipticalRRectEffect : public GrFragmentProcessor { |
| 391 public: | 389 public: |
| 392 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkRRect&); | 390 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkRRect&); |
| 393 | 391 |
| 394 virtual ~EllipticalRRectEffect() {}; | 392 virtual ~EllipticalRRectEffect() {}; |
| 395 | 393 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 (GrPrimitiveEdgeType)d->fRandom->nextULessThan(kGrProcessorEdgeT
ypeCnt); | 477 (GrPrimitiveEdgeType)d->fRandom->nextULessThan(kGrProcessorEdgeT
ypeCnt); |
| 480 fp = GrRRectEffect::Create(et, rrect); | 478 fp = GrRRectEffect::Create(et, rrect); |
| 481 } while (nullptr == fp); | 479 } while (nullptr == fp); |
| 482 return fp; | 480 return fp; |
| 483 } | 481 } |
| 484 | 482 |
| 485 ////////////////////////////////////////////////////////////////////////////// | 483 ////////////////////////////////////////////////////////////////////////////// |
| 486 | 484 |
| 487 class GLEllipticalRRectEffect : public GrGLSLFragmentProcessor { | 485 class GLEllipticalRRectEffect : public GrGLSLFragmentProcessor { |
| 488 public: | 486 public: |
| 489 GLEllipticalRRectEffect(const GrProcessor&); | 487 GLEllipticalRRectEffect() { |
| 488 fPrevRRect.setEmpty(); |
| 489 } |
| 490 | 490 |
| 491 virtual void emitCode(EmitArgs&) override; | 491 void emitCode(EmitArgs&) override; |
| 492 | 492 |
| 493 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); | 493 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); |
| 494 | 494 |
| 495 protected: | 495 protected: |
| 496 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; | 496 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
| 497 | 497 |
| 498 private: | 498 private: |
| 499 GrGLSLProgramDataManager::UniformHandle fInnerRectUniform; | 499 GrGLSLProgramDataManager::UniformHandle fInnerRectUniform; |
| 500 GrGLSLProgramDataManager::UniformHandle fInvRadiiSqdUniform; | 500 GrGLSLProgramDataManager::UniformHandle fInvRadiiSqdUniform; |
| 501 GrGLSLProgramDataManager::UniformHandle fScaleUniform; | 501 GrGLSLProgramDataManager::UniformHandle fScaleUniform; |
| 502 SkRRect fPrevRRect; | 502 SkRRect fPrevRRect; |
| 503 typedef GrGLSLFragmentProcessor INHERITED; | 503 typedef GrGLSLFragmentProcessor INHERITED; |
| 504 }; | 504 }; |
| 505 | 505 |
| 506 GLEllipticalRRectEffect::GLEllipticalRRectEffect(const GrProcessor& effect) { | |
| 507 fPrevRRect.setEmpty(); | |
| 508 } | |
| 509 | |
| 510 void GLEllipticalRRectEffect::emitCode(EmitArgs& args) { | 506 void GLEllipticalRRectEffect::emitCode(EmitArgs& args) { |
| 511 const EllipticalRRectEffect& erre = args.fFp.cast<EllipticalRRectEffect>(); | 507 const EllipticalRRectEffect& erre = args.fFp.cast<EllipticalRRectEffect>(); |
| 512 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; | 508 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
| 513 const char *rectName; | 509 const char *rectName; |
| 514 // The inner rect is the rrect bounds inset by the x/y radii | 510 // The inner rect is the rrect bounds inset by the x/y radii |
| 515 fInnerRectUniform = uniformHandler->addUniform(GrGLSLUniformHandler::kFragme
nt_Visibility, | 511 fInnerRectUniform = uniformHandler->addUniform(GrGLSLUniformHandler::kFragme
nt_Visibility, |
| 516 kVec4f_GrSLType, kDefault_GrS
LPrecision, | 512 kVec4f_GrSLType, kDefault_GrS
LPrecision, |
| 517 "innerRect", | 513 "innerRect", |
| 518 &rectName); | 514 &rectName); |
| 519 | 515 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 } | 668 } |
| 673 | 669 |
| 674 ////////////////////////////////////////////////////////////////////////////////
//////////////////// | 670 ////////////////////////////////////////////////////////////////////////////////
//////////////////// |
| 675 | 671 |
| 676 void EllipticalRRectEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, | 672 void EllipticalRRectEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, |
| 677 GrProcessorKeyBuilder* b) cons
t { | 673 GrProcessorKeyBuilder* b) cons
t { |
| 678 GLEllipticalRRectEffect::GenKey(*this, caps, b); | 674 GLEllipticalRRectEffect::GenKey(*this, caps, b); |
| 679 } | 675 } |
| 680 | 676 |
| 681 GrGLSLFragmentProcessor* EllipticalRRectEffect::onCreateGLSLInstance() const { | 677 GrGLSLFragmentProcessor* EllipticalRRectEffect::onCreateGLSLInstance() const { |
| 682 return new GLEllipticalRRectEffect(*this); | 678 return new GLEllipticalRRectEffect; |
| 683 } | 679 } |
| 684 | 680 |
| 685 ////////////////////////////////////////////////////////////////////////////// | 681 ////////////////////////////////////////////////////////////////////////////// |
| 686 | 682 |
| 687 GrFragmentProcessor* GrRRectEffect::Create(GrPrimitiveEdgeType edgeType, const S
kRRect& rrect) { | 683 GrFragmentProcessor* GrRRectEffect::Create(GrPrimitiveEdgeType edgeType, const S
kRRect& rrect) { |
| 688 if (rrect.isRect()) { | 684 if (rrect.isRect()) { |
| 689 return GrConvexPolyEffect::Create(edgeType, rrect.getBounds()); | 685 return GrConvexPolyEffect::Create(edgeType, rrect.getBounds()); |
| 690 } | 686 } |
| 691 | 687 |
| 692 if (rrect.isOval()) { | 688 if (rrect.isOval()) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 if (rrect.isNinePatch()) { | 769 if (rrect.isNinePatch()) { |
| 774 return EllipticalRRectEffect::Create(edgeType, rrect); | 770 return EllipticalRRectEffect::Create(edgeType, rrect); |
| 775 } | 771 } |
| 776 return nullptr; | 772 return nullptr; |
| 777 } | 773 } |
| 778 } | 774 } |
| 779 } | 775 } |
| 780 | 776 |
| 781 return nullptr; | 777 return nullptr; |
| 782 } | 778 } |
| OLD | NEW |