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

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

Issue 385713005: Allow GrGLEffects to produce variable length keys. (Closed) Base URL: https://skia.googlesource.com/skia.git@key
Patch Set: rebase Created 6 years, 5 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.cpp » ('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 "gl/GrGLEffect.h" 10 #include "gl/GrGLEffect.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 129 }
130 130
131 ////////////////////////////////////////////////////////////////////////////// 131 //////////////////////////////////////////////////////////////////////////////
132 132
133 class GLCircularRRectEffect : public GrGLEffect { 133 class GLCircularRRectEffect : public GrGLEffect {
134 public: 134 public:
135 GLCircularRRectEffect(const GrBackendEffectFactory&, const GrDrawEffect&); 135 GLCircularRRectEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
136 136
137 virtual void emitCode(GrGLShaderBuilder* builder, 137 virtual void emitCode(GrGLShaderBuilder* builder,
138 const GrDrawEffect& drawEffect, 138 const GrDrawEffect& drawEffect,
139 EffectKey key, 139 const GrEffectKey& key,
140 const char* outputColor, 140 const char* outputColor,
141 const char* inputColor, 141 const char* inputColor,
142 const TransformedCoordsArray&, 142 const TransformedCoordsArray&,
143 const TextureSamplerArray&) SK_OVERRIDE; 143 const TextureSamplerArray&) SK_OVERRIDE;
144 144
145 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); 145 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB uilder*);
146 146
147 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE; 147 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE;
148 148
149 private: 149 private:
150 GrGLUniformManager::UniformHandle fInnerRectUniform; 150 GrGLUniformManager::UniformHandle fInnerRectUniform;
151 GrGLUniformManager::UniformHandle fRadiusPlusHalfUniform; 151 GrGLUniformManager::UniformHandle fRadiusPlusHalfUniform;
152 SkRRect fPrevRRect; 152 SkRRect fPrevRRect;
153 typedef GrGLEffect INHERITED; 153 typedef GrGLEffect INHERITED;
154 }; 154 };
155 155
156 GLCircularRRectEffect::GLCircularRRectEffect(const GrBackendEffectFactory& facto ry, 156 GLCircularRRectEffect::GLCircularRRectEffect(const GrBackendEffectFactory& facto ry,
157 const GrDrawEffect& drawEffect) 157 const GrDrawEffect& drawEffect)
158 : INHERITED (factory) { 158 : INHERITED (factory) {
159 fPrevRRect.setEmpty(); 159 fPrevRRect.setEmpty();
160 } 160 }
161 161
162 void GLCircularRRectEffect::emitCode(GrGLShaderBuilder* builder, 162 void GLCircularRRectEffect::emitCode(GrGLShaderBuilder* builder,
163 const GrDrawEffect& drawEffect, 163 const GrDrawEffect& drawEffect,
164 EffectKey key, 164 const GrEffectKey& key,
165 const char* outputColor, 165 const char* outputColor,
166 const char* inputColor, 166 const char* inputColor,
167 const TransformedCoordsArray&, 167 const TransformedCoordsArray&,
168 const TextureSamplerArray& samplers) { 168 const TextureSamplerArray& samplers) {
169 const CircularRRectEffect& crre = drawEffect.castEffect<CircularRRectEffect> (); 169 const CircularRRectEffect& crre = drawEffect.castEffect<CircularRRectEffect> ();
170 const char *rectName; 170 const char *rectName;
171 const char *radiusPlusHalfName; 171 const char *radiusPlusHalfName;
172 // The inner rect is the rrect bounds inset by the radius. Its left, top, ri ght, and bottom 172 // The inner rect is the rrect bounds inset by the radius. Its left, top, ri ght, and bottom
173 // edges correspond to components x, y, z, and w, respectively. When a side of the rrect has 173 // edges correspond to components x, y, z, and w, respectively. When a side of the rrect has
174 // only rectangular corners, that side's value corresponds to the rect edge' s value outset by 174 // only rectangular corners, that side's value corresponds to the rect edge' s value outset by
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 } 284 }
285 285
286 if (kInverseFillAA_GrEffectEdgeType == crre.getEdgeType()) { 286 if (kInverseFillAA_GrEffectEdgeType == crre.getEdgeType()) {
287 builder->fsCodeAppend("\t\talpha = 1.0 - alpha;\n"); 287 builder->fsCodeAppend("\t\talpha = 1.0 - alpha;\n");
288 } 288 }
289 289
290 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, 290 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor,
291 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st r()); 291 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st r());
292 } 292 }
293 293
294 GrGLEffect::EffectKey GLCircularRRectEffect::GenKey(const GrDrawEffect& drawEffe ct, 294 void GLCircularRRectEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCap s&,
295 const GrGLCaps&) { 295 GrEffectKeyBuilder* b) {
296 const CircularRRectEffect& crre = drawEffect.castEffect<CircularRRectEffect> (); 296 const CircularRRectEffect& crre = drawEffect.castEffect<CircularRRectEffect> ();
297 GR_STATIC_ASSERT(kGrEffectEdgeTypeCnt <= 8); 297 GR_STATIC_ASSERT(kGrEffectEdgeTypeCnt <= 8);
298 return (crre.getCircularCornerFlags() << 3) | crre.getEdgeType(); 298 b->add32((crre.getCircularCornerFlags() << 3) | crre.getEdgeType());
299 } 299 }
300 300
301 void GLCircularRRectEffect::setData(const GrGLUniformManager& uman, 301 void GLCircularRRectEffect::setData(const GrGLUniformManager& uman,
302 const GrDrawEffect& drawEffect) { 302 const GrDrawEffect& drawEffect) {
303 const CircularRRectEffect& crre = drawEffect.castEffect<CircularRRectEffect> (); 303 const CircularRRectEffect& crre = drawEffect.castEffect<CircularRRectEffect> ();
304 const SkRRect& rrect = crre.getRRect(); 304 const SkRRect& rrect = crre.getRRect();
305 if (rrect != fPrevRRect) { 305 if (rrect != fPrevRRect) {
306 SkRect rect = rrect.getBounds(); 306 SkRect rect = rrect.getBounds();
307 SkScalar radius = 0; 307 SkScalar radius = 0;
308 switch (crre.getCircularCornerFlags()) { 308 switch (crre.getCircularCornerFlags()) {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 } 481 }
482 482
483 ////////////////////////////////////////////////////////////////////////////// 483 //////////////////////////////////////////////////////////////////////////////
484 484
485 class GLEllipticalRRectEffect : public GrGLEffect { 485 class GLEllipticalRRectEffect : public GrGLEffect {
486 public: 486 public:
487 GLEllipticalRRectEffect(const GrBackendEffectFactory&, const GrDrawEffect&); 487 GLEllipticalRRectEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
488 488
489 virtual void emitCode(GrGLShaderBuilder* builder, 489 virtual void emitCode(GrGLShaderBuilder* builder,
490 const GrDrawEffect& drawEffect, 490 const GrDrawEffect& drawEffect,
491 EffectKey key, 491 const GrEffectKey& key,
492 const char* outputColor, 492 const char* outputColor,
493 const char* inputColor, 493 const char* inputColor,
494 const TransformedCoordsArray&, 494 const TransformedCoordsArray&,
495 const TextureSamplerArray&) SK_OVERRIDE; 495 const TextureSamplerArray&) SK_OVERRIDE;
496 496
497 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); 497 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB uilder*);
498 498
499 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE; 499 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE;
500 500
501 private: 501 private:
502 GrGLUniformManager::UniformHandle fInnerRectUniform; 502 GrGLUniformManager::UniformHandle fInnerRectUniform;
503 GrGLUniformManager::UniformHandle fInvRadiiSqdUniform; 503 GrGLUniformManager::UniformHandle fInvRadiiSqdUniform;
504 SkRRect fPrevRRect; 504 SkRRect fPrevRRect;
505 typedef GrGLEffect INHERITED; 505 typedef GrGLEffect INHERITED;
506 }; 506 };
507 507
508 GLEllipticalRRectEffect::GLEllipticalRRectEffect(const GrBackendEffectFactory& f actory, 508 GLEllipticalRRectEffect::GLEllipticalRRectEffect(const GrBackendEffectFactory& f actory,
509 const GrDrawEffect& drawEffect) 509 const GrDrawEffect& drawEffect)
510 : INHERITED (factory) { 510 : INHERITED (factory) {
511 fPrevRRect.setEmpty(); 511 fPrevRRect.setEmpty();
512 } 512 }
513 513
514 void GLEllipticalRRectEffect::emitCode(GrGLShaderBuilder* builder, 514 void GLEllipticalRRectEffect::emitCode(GrGLShaderBuilder* builder,
515 const GrDrawEffect& drawEffect, 515 const GrDrawEffect& drawEffect,
516 EffectKey key, 516 const GrEffectKey& key,
517 const char* outputColor, 517 const char* outputColor,
518 const char* inputColor, 518 const char* inputColor,
519 const TransformedCoordsArray&, 519 const TransformedCoordsArray&,
520 const TextureSamplerArray& samplers) { 520 const TextureSamplerArray& samplers) {
521 const EllipticalRRectEffect& erre = drawEffect.castEffect<EllipticalRRectEff ect>(); 521 const EllipticalRRectEffect& erre = drawEffect.castEffect<EllipticalRRectEff ect>();
522 const char *rectName; 522 const char *rectName;
523 // The inner rect is the rrect bounds inset by the x/y radii 523 // The inner rect is the rrect bounds inset by the x/y radii
524 fInnerRectUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibil ity, 524 fInnerRectUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibil ity,
525 kVec4f_GrSLType, 525 kVec4f_GrSLType,
526 "innerRect", 526 "innerRect",
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 if (kFillAA_GrEffectEdgeType == erre.getEdgeType()) { 579 if (kFillAA_GrEffectEdgeType == erre.getEdgeType()) {
580 builder->fsCodeAppend("\t\tfloat alpha = clamp(0.5 - approx_dist, 0.0, 1 .0);\n"); 580 builder->fsCodeAppend("\t\tfloat alpha = clamp(0.5 - approx_dist, 0.0, 1 .0);\n");
581 } else { 581 } else {
582 builder->fsCodeAppend("\t\tfloat alpha = clamp(0.5 + approx_dist, 0.0, 1 .0);\n"); 582 builder->fsCodeAppend("\t\tfloat alpha = clamp(0.5 + approx_dist, 0.0, 1 .0);\n");
583 } 583 }
584 584
585 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, 585 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor,
586 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st r()); 586 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st r());
587 } 587 }
588 588
589 GrGLEffect::EffectKey GLEllipticalRRectEffect::GenKey(const GrDrawEffect& drawEf fect, 589 void GLEllipticalRRectEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLC aps&,
590 const GrGLCaps&) { 590 GrEffectKeyBuilder* b) {
591 const EllipticalRRectEffect& erre = drawEffect.castEffect<EllipticalRRectEff ect>(); 591 const EllipticalRRectEffect& erre = drawEffect.castEffect<EllipticalRRectEff ect>();
592 GR_STATIC_ASSERT(kLast_GrEffectEdgeType < (1 << 3)); 592 GR_STATIC_ASSERT(kLast_GrEffectEdgeType < (1 << 3));
593 return erre.getRRect().getType() | erre.getEdgeType() << 3; 593 b->add32(erre.getRRect().getType() | erre.getEdgeType() << 3);
594 } 594 }
595 595
596 void GLEllipticalRRectEffect::setData(const GrGLUniformManager& uman, 596 void GLEllipticalRRectEffect::setData(const GrGLUniformManager& uman,
597 const GrDrawEffect& drawEffect) { 597 const GrDrawEffect& drawEffect) {
598 const EllipticalRRectEffect& erre = drawEffect.castEffect<EllipticalRRectEff ect>(); 598 const EllipticalRRectEffect& erre = drawEffect.castEffect<EllipticalRRectEff ect>();
599 const SkRRect& rrect = erre.getRRect(); 599 const SkRRect& rrect = erre.getRRect();
600 if (rrect != fPrevRRect) { 600 if (rrect != fPrevRRect) {
601 SkRect rect = rrect.getBounds(); 601 SkRect rect = rrect.getBounds();
602 const SkVector& r0 = rrect.radii(SkRRect::kUpperLeft_Corner); 602 const SkVector& r0 = rrect.radii(SkRRect::kUpperLeft_Corner);
603 SkASSERT(r0.fX >= kRadiusMin); 603 SkASSERT(r0.fX >= kRadiusMin);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 if (rrect.isNinePatch()) { 721 if (rrect.isNinePatch()) {
722 return EllipticalRRectEffect::Create(edgeType, rrect); 722 return EllipticalRRectEffect::Create(edgeType, rrect);
723 } 723 }
724 return NULL; 724 return NULL;
725 } 725 }
726 } 726 }
727 } 727 }
728 728
729 return NULL; 729 return NULL;
730 } 730 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrOvalEffect.cpp ('k') | src/gpu/effects/GrSimpleTextureEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698