Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(689)

Side by Side Diff: src/gpu/effects/GrRRectEffect.cpp

Issue 1287023009: Added tree structure to GrGLFragmentProcessor, i.e. GL instances (Closed) Base URL: https://skia.googlesource.com/skia@cs3_isequal_nonrecursive
Patch Set: moved onSetData from public to protected, onCreateGLInstance from public to private in subclasses Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/effects/GrOvalEffect.cpp ('k') | src/gpu/effects/GrSimpleTextureEffect.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 // The flags are used to indicate which corners are circluar (unflagged corn ers are assumed to 43 // The flags are used to indicate which corners are circluar (unflagged corn ers are assumed to
44 // be square). 44 // be square).
45 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, uint32_t circularCor nerFlags, 45 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, uint32_t circularCor nerFlags,
46 const SkRRect&); 46 const SkRRect&);
47 47
48 virtual ~CircularRRectEffect() {}; 48 virtual ~CircularRRectEffect() {};
49 49
50 const char* name() const override { return "CircularRRect"; } 50 const char* name() const override { return "CircularRRect"; }
51 51
52 GrGLFragmentProcessor* createGLInstance() const override;
53
54 const SkRRect& getRRect() const { return fRRect; } 52 const SkRRect& getRRect() const { return fRRect; }
55 53
56 uint32_t getCircularCornerFlags() const { return fCircularCornerFlags; } 54 uint32_t getCircularCornerFlags() const { return fCircularCornerFlags; }
57 55
58 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } 56 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; }
59 57
60 private: 58 private:
61 CircularRRectEffect(GrPrimitiveEdgeType, uint32_t circularCornerFlags, const SkRRect&); 59 CircularRRectEffect(GrPrimitiveEdgeType, uint32_t circularCornerFlags, const SkRRect&);
62 60
61 GrGLFragmentProcessor* onCreateGLInstance() const override;
62
63 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride; 63 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride;
64 64
65 bool onIsEqual(const GrFragmentProcessor& other) const override; 65 bool onIsEqual(const GrFragmentProcessor& other) const override;
66 66
67 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; 67 void onComputeInvariantOutput(GrInvariantOutput* inout) const override;
68 68
69 SkRRect fRRect; 69 SkRRect fRRect;
70 GrPrimitiveEdgeType fEdgeType; 70 GrPrimitiveEdgeType fEdgeType;
71 uint32_t fCircularCornerFlags; 71 uint32_t fCircularCornerFlags;
72 72
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 ////////////////////////////////////////////////////////////////////////////// 125 //////////////////////////////////////////////////////////////////////////////
126 126
127 class GLCircularRRectEffect : public GrGLFragmentProcessor { 127 class GLCircularRRectEffect : public GrGLFragmentProcessor {
128 public: 128 public:
129 GLCircularRRectEffect(const GrProcessor&); 129 GLCircularRRectEffect(const GrProcessor&);
130 130
131 virtual void emitCode(EmitArgs&) override; 131 virtual void emitCode(EmitArgs&) override;
132 132
133 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*); 133 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*);
134 134
135 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; 135 protected:
136 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override;
136 137
137 private: 138 private:
138 GrGLProgramDataManager::UniformHandle fInnerRectUniform; 139 GrGLProgramDataManager::UniformHandle fInnerRectUniform;
139 GrGLProgramDataManager::UniformHandle fRadiusPlusHalfUniform; 140 GrGLProgramDataManager::UniformHandle fRadiusPlusHalfUniform;
140 SkRRect fPrevRRect; 141 SkRRect fPrevRRect;
141 typedef GrGLFragmentProcessor INHERITED; 142 typedef GrGLFragmentProcessor INHERITED;
142 }; 143 };
143 144
144 GLCircularRRectEffect::GLCircularRRectEffect(const GrProcessor& ) { 145 GLCircularRRectEffect::GLCircularRRectEffect(const GrProcessor& ) {
145 fPrevRRect.setEmpty(); 146 fPrevRRect.setEmpty();
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha") ).c_str()); 274 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha") ).c_str());
274 } 275 }
275 276
276 void GLCircularRRectEffect::GenKey(const GrProcessor& processor, const GrGLSLCap s&, 277 void GLCircularRRectEffect::GenKey(const GrProcessor& processor, const GrGLSLCap s&,
277 GrProcessorKeyBuilder* b) { 278 GrProcessorKeyBuilder* b) {
278 const CircularRRectEffect& crre = processor.cast<CircularRRectEffect>(); 279 const CircularRRectEffect& crre = processor.cast<CircularRRectEffect>();
279 GR_STATIC_ASSERT(kGrProcessorEdgeTypeCnt <= 8); 280 GR_STATIC_ASSERT(kGrProcessorEdgeTypeCnt <= 8);
280 b->add32((crre.getCircularCornerFlags() << 3) | crre.getEdgeType()); 281 b->add32((crre.getCircularCornerFlags() << 3) | crre.getEdgeType());
281 } 282 }
282 283
283 void GLCircularRRectEffect::setData(const GrGLProgramDataManager& pdman, 284 void GLCircularRRectEffect::onSetData(const GrGLProgramDataManager& pdman,
284 const GrProcessor& processor) { 285 const GrProcessor& processor) {
285 const CircularRRectEffect& crre = processor.cast<CircularRRectEffect>(); 286 const CircularRRectEffect& crre = processor.cast<CircularRRectEffect>();
286 const SkRRect& rrect = crre.getRRect(); 287 const SkRRect& rrect = crre.getRRect();
287 if (rrect != fPrevRRect) { 288 if (rrect != fPrevRRect) {
288 SkRect rect = rrect.getBounds(); 289 SkRect rect = rrect.getBounds();
289 SkScalar radius = 0; 290 SkScalar radius = 0;
290 switch (crre.getCircularCornerFlags()) { 291 switch (crre.getCircularCornerFlags()) {
291 case CircularRRectEffect::kAll_CornerFlags: 292 case CircularRRectEffect::kAll_CornerFlags:
292 SkASSERT(rrect.isSimpleCircular()); 293 SkASSERT(rrect.isSimpleCircular());
293 radius = rrect.getSimpleRadii().fX; 294 radius = rrect.getSimpleRadii().fX;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 } 360 }
360 } 361 }
361 362
362 //////////////////////////////////////////////////////////////////////////////// //////////////////// 363 //////////////////////////////////////////////////////////////////////////////// ////////////////////
363 364
364 void CircularRRectEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, 365 void CircularRRectEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
365 GrProcessorKeyBuilder* b) const { 366 GrProcessorKeyBuilder* b) const {
366 GLCircularRRectEffect::GenKey(*this, caps, b); 367 GLCircularRRectEffect::GenKey(*this, caps, b);
367 } 368 }
368 369
369 GrGLFragmentProcessor* CircularRRectEffect::createGLInstance() const { 370 GrGLFragmentProcessor* CircularRRectEffect::onCreateGLInstance() const {
370 return SkNEW_ARGS(GLCircularRRectEffect, (*this)); 371 return SkNEW_ARGS(GLCircularRRectEffect, (*this));
371 } 372 }
372 373
373 ////////////////////////////////////////////////////////////////////////////// 374 //////////////////////////////////////////////////////////////////////////////
374 375
375 class EllipticalRRectEffect : public GrFragmentProcessor { 376 class EllipticalRRectEffect : public GrFragmentProcessor {
376 public: 377 public:
377 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkRRect&); 378 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkRRect&);
378 379
379 virtual ~EllipticalRRectEffect() {}; 380 virtual ~EllipticalRRectEffect() {};
380 381
381 const char* name() const override { return "EllipticalRRect"; } 382 const char* name() const override { return "EllipticalRRect"; }
382 383
383 GrGLFragmentProcessor* createGLInstance() const override;
384
385 const SkRRect& getRRect() const { return fRRect; } 384 const SkRRect& getRRect() const { return fRRect; }
386 385
387 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } 386 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; }
388 387
389 private: 388 private:
390 EllipticalRRectEffect(GrPrimitiveEdgeType, const SkRRect&); 389 EllipticalRRectEffect(GrPrimitiveEdgeType, const SkRRect&);
391 390
391 GrGLFragmentProcessor* onCreateGLInstance() const override;
392
392 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride; 393 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride;
393 394
394 bool onIsEqual(const GrFragmentProcessor& other) const override; 395 bool onIsEqual(const GrFragmentProcessor& other) const override;
395 396
396 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; 397 void onComputeInvariantOutput(GrInvariantOutput* inout) const override;
397 398
398 SkRRect fRRect; 399 SkRRect fRRect;
399 GrPrimitiveEdgeType fEdgeType; 400 GrPrimitiveEdgeType fEdgeType;
400 401
401 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 402 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 ////////////////////////////////////////////////////////////////////////////// 471 //////////////////////////////////////////////////////////////////////////////
471 472
472 class GLEllipticalRRectEffect : public GrGLFragmentProcessor { 473 class GLEllipticalRRectEffect : public GrGLFragmentProcessor {
473 public: 474 public:
474 GLEllipticalRRectEffect(const GrProcessor&); 475 GLEllipticalRRectEffect(const GrProcessor&);
475 476
476 virtual void emitCode(EmitArgs&) override; 477 virtual void emitCode(EmitArgs&) override;
477 478
478 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*); 479 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*);
479 480
480 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; 481 protected:
482 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override;
481 483
482 private: 484 private:
483 GrGLProgramDataManager::UniformHandle fInnerRectUniform; 485 GrGLProgramDataManager::UniformHandle fInnerRectUniform;
484 GrGLProgramDataManager::UniformHandle fInvRadiiSqdUniform; 486 GrGLProgramDataManager::UniformHandle fInvRadiiSqdUniform;
485 SkRRect fPrevRRect; 487 SkRRect fPrevRRect;
486 typedef GrGLFragmentProcessor INHERITED; 488 typedef GrGLFragmentProcessor INHERITED;
487 }; 489 };
488 490
489 GLEllipticalRRectEffect::GLEllipticalRRectEffect(const GrProcessor& effect) { 491 GLEllipticalRRectEffect::GLEllipticalRRectEffect(const GrProcessor& effect) {
490 fPrevRRect.setEmpty(); 492 fPrevRRect.setEmpty();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha") ).c_str()); 565 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha") ).c_str());
564 } 566 }
565 567
566 void GLEllipticalRRectEffect::GenKey(const GrProcessor& effect, const GrGLSLCaps &, 568 void GLEllipticalRRectEffect::GenKey(const GrProcessor& effect, const GrGLSLCaps &,
567 GrProcessorKeyBuilder* b) { 569 GrProcessorKeyBuilder* b) {
568 const EllipticalRRectEffect& erre = effect.cast<EllipticalRRectEffect>(); 570 const EllipticalRRectEffect& erre = effect.cast<EllipticalRRectEffect>();
569 GR_STATIC_ASSERT(kLast_GrProcessorEdgeType < (1 << 3)); 571 GR_STATIC_ASSERT(kLast_GrProcessorEdgeType < (1 << 3));
570 b->add32(erre.getRRect().getType() | erre.getEdgeType() << 3); 572 b->add32(erre.getRRect().getType() | erre.getEdgeType() << 3);
571 } 573 }
572 574
573 void GLEllipticalRRectEffect::setData(const GrGLProgramDataManager& pdman, 575 void GLEllipticalRRectEffect::onSetData(const GrGLProgramDataManager& pdman,
574 const GrProcessor& effect) { 576 const GrProcessor& effect) {
575 const EllipticalRRectEffect& erre = effect.cast<EllipticalRRectEffect>(); 577 const EllipticalRRectEffect& erre = effect.cast<EllipticalRRectEffect>();
576 const SkRRect& rrect = erre.getRRect(); 578 const SkRRect& rrect = erre.getRRect();
577 if (rrect != fPrevRRect) { 579 if (rrect != fPrevRRect) {
578 SkRect rect = rrect.getBounds(); 580 SkRect rect = rrect.getBounds();
579 const SkVector& r0 = rrect.radii(SkRRect::kUpperLeft_Corner); 581 const SkVector& r0 = rrect.radii(SkRRect::kUpperLeft_Corner);
580 SkASSERT(r0.fX >= kRadiusMin); 582 SkASSERT(r0.fX >= kRadiusMin);
581 SkASSERT(r0.fY >= kRadiusMin); 583 SkASSERT(r0.fY >= kRadiusMin);
582 switch (erre.getRRect().getType()) { 584 switch (erre.getRRect().getType()) {
583 case SkRRect::kSimple_Type: 585 case SkRRect::kSimple_Type:
(...skipping 23 matching lines...) Expand all
607 } 609 }
608 } 610 }
609 611
610 //////////////////////////////////////////////////////////////////////////////// //////////////////// 612 //////////////////////////////////////////////////////////////////////////////// ////////////////////
611 613
612 void EllipticalRRectEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, 614 void EllipticalRRectEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
613 GrProcessorKeyBuilder* b) const { 615 GrProcessorKeyBuilder* b) const {
614 GLEllipticalRRectEffect::GenKey(*this, caps, b); 616 GLEllipticalRRectEffect::GenKey(*this, caps, b);
615 } 617 }
616 618
617 GrGLFragmentProcessor* EllipticalRRectEffect::createGLInstance() const { 619 GrGLFragmentProcessor* EllipticalRRectEffect::onCreateGLInstance() const {
618 return SkNEW_ARGS(GLEllipticalRRectEffect, (*this)); 620 return SkNEW_ARGS(GLEllipticalRRectEffect, (*this));
619 } 621 }
620 622
621 ////////////////////////////////////////////////////////////////////////////// 623 //////////////////////////////////////////////////////////////////////////////
622 624
623 GrFragmentProcessor* GrRRectEffect::Create(GrPrimitiveEdgeType edgeType, const S kRRect& rrect) { 625 GrFragmentProcessor* GrRRectEffect::Create(GrPrimitiveEdgeType edgeType, const S kRRect& rrect) {
624 if (rrect.isRect()) { 626 if (rrect.isRect()) {
625 return GrConvexPolyEffect::Create(edgeType, rrect.getBounds()); 627 return GrConvexPolyEffect::Create(edgeType, rrect.getBounds());
626 } 628 }
627 629
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 if (rrect.isNinePatch()) { 711 if (rrect.isNinePatch()) {
710 return EllipticalRRectEffect::Create(edgeType, rrect); 712 return EllipticalRRectEffect::Create(edgeType, rrect);
711 } 713 }
712 return NULL; 714 return NULL;
713 } 715 }
714 } 716 }
715 } 717 }
716 718
717 return NULL; 719 return NULL;
718 } 720 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrOvalEffect.cpp ('k') | src/gpu/effects/GrSimpleTextureEffect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698