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

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

Issue 183893023: Unify edge type enums across GrEffect subclasses that clip rendering to a geometry. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: tot again Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/effects/GrRRectEffect.h ('k') | no next file » | 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 13 matching lines...) Expand all
24 24
25 /// The types of circular corner rrects supported 25 /// The types of circular corner rrects supported
26 enum RRectType { 26 enum RRectType {
27 kCircleCorner_RRectType, //<! All four corners have the same circula r radius. 27 kCircleCorner_RRectType, //<! All four corners have the same circula r radius.
28 kLeftCircleTab_RRectType, //<! The left side has circular corners, th e right is a rect. 28 kLeftCircleTab_RRectType, //<! The left side has circular corners, th e right is a rect.
29 kTopCircleTab_RRectType, //<! etc 29 kTopCircleTab_RRectType, //<! etc
30 kRightCircleTab_RRectType, 30 kRightCircleTab_RRectType,
31 kBottomCircleTab_RRectType, 31 kBottomCircleTab_RRectType,
32 }; 32 };
33 33
34 static GrEffectRef* Create(EdgeType, const SkRRect&, RRectType); 34 static GrEffectRef* Create(GrEffectEdgeType, RRectType, const SkRRect&);
35 35
36 virtual ~RRectEffect() {}; 36 virtual ~RRectEffect() {};
37 static const char* Name() { return "RRect"; } 37 static const char* Name() { return "RRect"; }
38 38
39 const SkRRect& getRRect() const { return fRRect; } 39 const SkRRect& getRRect() const { return fRRect; }
40 40
41 RRectType getType() const { return fRRectType; } 41 RRectType getType() const { return fRRectType; }
42 42
43 EdgeType getEdgeType() const { return fEdgeType; } 43 GrEffectEdgeType getEdgeType() const { return fEdgeType; }
44 44
45 typedef GLRRectEffect GLEffect; 45 typedef GLRRectEffect GLEffect;
46 46
47 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE; 47 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE;
48 48
49 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; 49 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
50 50
51 private: 51 private:
52 RRectEffect(EdgeType, const SkRRect&, RRectType); 52 RRectEffect(GrEffectEdgeType, RRectType, const SkRRect&);
53 53
54 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; 54 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE;
55 55
56 SkRRect fRRect; 56 SkRRect fRRect;
57 EdgeType fEdgeType; 57 GrEffectEdgeType fEdgeType;
58 RRectType fRRectType; 58 RRectType fRRectType;
59 59
60 GR_DECLARE_EFFECT_TEST; 60 GR_DECLARE_EFFECT_TEST;
61 61
62 typedef GrEffect INHERITED; 62 typedef GrEffect INHERITED;
63 }; 63 };
64 64
65 const SkScalar RRectEffect::kRadiusMin = 0.5f; 65 const SkScalar RRectEffect::kRadiusMin = 0.5f;
66 66
67 GrEffectRef* RRectEffect::Create(EdgeType edgeType, const SkRRect& rrect, RRectT ype rrtype) { 67 GrEffectRef* RRectEffect::Create(GrEffectEdgeType edgeType,
68 return CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(RRectEffect, (edgeType, rr ect, rrtype)))); 68 RRectType rrType,
69 const SkRRect& rrect) {
70 SkASSERT(kFillAA_GrEffectEdgeType == edgeType || kInverseFillBW_GrEffectEdge Type == edgeType);
71 return CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(RRectEffect, (edgeType, rr Type, rrect))));
69 } 72 }
70 73
71 void RRectEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlag s) const { 74 void RRectEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlag s) const {
72 *validFlags = 0; 75 *validFlags = 0;
73 } 76 }
74 77
75 const GrBackendEffectFactory& RRectEffect::getFactory() const { 78 const GrBackendEffectFactory& RRectEffect::getFactory() const {
76 return GrTBackendEffectFactory<RRectEffect>::getInstance(); 79 return GrTBackendEffectFactory<RRectEffect>::getInstance();
77 } 80 }
78 81
79 RRectEffect::RRectEffect(EdgeType edgeType, const SkRRect& rrect, RRectType rrty pe) 82 RRectEffect::RRectEffect(GrEffectEdgeType edgeType, RRectType rrType, const SkRR ect& rrect)
80 : fRRect(rrect) 83 : fRRect(rrect)
81 , fEdgeType(edgeType) 84 , fEdgeType(edgeType)
82 , fRRectType(rrtype) { 85 , fRRectType(rrType) {
83 this->setWillReadFragmentPosition(); 86 this->setWillReadFragmentPosition();
84 } 87 }
85 88
86 bool RRectEffect::onIsEqual(const GrEffect& other) const { 89 bool RRectEffect::onIsEqual(const GrEffect& other) const {
87 const RRectEffect& rre = CastEffect<RRectEffect>(other); 90 const RRectEffect& rre = CastEffect<RRectEffect>(other);
88 // type is derived from fRRect, so no need to check it. 91 // type is derived from fRRect, so no need to check it.
89 return fEdgeType == rre.fEdgeType && fRRect == rre.fRRect; 92 return fEdgeType == rre.fEdgeType && fRRect == rre.fRRect;
90 } 93 }
91 94
92 ////////////////////////////////////////////////////////////////////////////// 95 //////////////////////////////////////////////////////////////////////////////
93 96
94 GR_DEFINE_EFFECT_TEST(RRectEffect); 97 GR_DEFINE_EFFECT_TEST(RRectEffect);
95 98
96 GrEffectRef* RRectEffect::TestCreate(SkRandom* random, 99 GrEffectRef* RRectEffect::TestCreate(SkRandom* random,
97 GrContext*, 100 GrContext*,
98 const GrDrawTargetCaps& caps, 101 const GrDrawTargetCaps& caps,
99 GrTexture*[]) { 102 GrTexture*[]) {
100 SkScalar w = random->nextRangeScalar(20.f, 1000.f); 103 SkScalar w = random->nextRangeScalar(20.f, 1000.f);
101 SkScalar h = random->nextRangeScalar(20.f, 1000.f); 104 SkScalar h = random->nextRangeScalar(20.f, 1000.f);
102 SkScalar r = random->nextRangeF(kRadiusMin, 9.f); 105 SkScalar r = random->nextRangeF(kRadiusMin, 9.f);
103 EdgeType et = (EdgeType) random->nextULessThan(kEdgeTypeCnt);
104 SkRRect rrect; 106 SkRRect rrect;
105 rrect.setRectXY(SkRect::MakeWH(w, h), r, r); 107 rrect.setRectXY(SkRect::MakeWH(w, h), r, r);
106 108 GrEffectRef* effect;
107 return GrRRectEffect::Create(et, rrect); 109 do {
110 GrEffectEdgeType et = (GrEffectEdgeType)random->nextULessThan(kGrEffectE dgeTypeCnt);
111 effect = GrRRectEffect::Create(et, rrect);
112 } while (NULL == effect);
113 return effect;
108 } 114 }
109 115
110 ////////////////////////////////////////////////////////////////////////////// 116 //////////////////////////////////////////////////////////////////////////////
111 117
112 class GLRRectEffect : public GrGLEffect { 118 class GLRRectEffect : public GrGLEffect {
113 public: 119 public:
114 GLRRectEffect(const GrBackendEffectFactory&, const GrDrawEffect&); 120 GLRRectEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
115 121
116 virtual void emitCode(GrGLShaderBuilder* builder, 122 virtual void emitCode(GrGLShaderBuilder* builder,
117 const GrDrawEffect& drawEffect, 123 const GrDrawEffect& drawEffect,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 case RRectEffect::kBottomCircleTab_RRectType: 220 case RRectEffect::kBottomCircleTab_RRectType:
215 builder->fsCodeAppendf("\t\tfloat dx0 = %s.x - %s.x;\n", rectName, f ragmentPos); 221 builder->fsCodeAppendf("\t\tfloat dx0 = %s.x - %s.x;\n", rectName, f ragmentPos);
216 builder->fsCodeAppendf("\t\tvec2 dxy1 = %s.xy - %s.zw;\n", fragmentP os, rectName); 222 builder->fsCodeAppendf("\t\tvec2 dxy1 = %s.xy - %s.zw;\n", fragmentP os, rectName);
217 builder->fsCodeAppend("\t\tvec2 dxy = max(vec2(max(dx0, dxy1.x), dxy 1.y), 0.0);\n"); 223 builder->fsCodeAppend("\t\tvec2 dxy = max(vec2(max(dx0, dxy1.x), dxy 1.y), 0.0);\n");
218 builder->fsCodeAppendf("\t\tfloat topAlpha = clamp(%s.y - %s.y, 0.0, 1.0);\n", 224 builder->fsCodeAppendf("\t\tfloat topAlpha = clamp(%s.y - %s.y, 0.0, 1.0);\n",
219 fragmentPos, rectName); 225 fragmentPos, rectName);
220 builder->fsCodeAppendf("\t\tfloat alpha = topAlpha * clamp(%s - leng th(dxy), 0.0, 1.0);\n", 226 builder->fsCodeAppendf("\t\tfloat alpha = topAlpha * clamp(%s - leng th(dxy), 0.0, 1.0);\n",
221 radiusPlusHalfName); 227 radiusPlusHalfName);
222 break; 228 break;
223 } 229 }
224 230
225 if (kInverseFillAA_EdgeType == rre.getEdgeType()) { 231 if (kInverseFillBW_GrEffectEdgeType == rre.getEdgeType()) {
226 builder->fsCodeAppend("\t\talpha = 1.0 - alpha;\n"); 232 builder->fsCodeAppend("\t\talpha = 1.0 - alpha;\n");
227 } 233 }
228 234
229 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, 235 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor,
230 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st r()); 236 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st r());
231 } 237 }
232 238
233 GrGLEffect::EffectKey GLRRectEffect::GenKey(const GrDrawEffect& drawEffect, cons t GrGLCaps&) { 239 GrGLEffect::EffectKey GLRRectEffect::GenKey(const GrDrawEffect& drawEffect, cons t GrGLCaps&) {
234 const RRectEffect& rre = drawEffect.castEffect<RRectEffect>(); 240 const RRectEffect& rre = drawEffect.castEffect<RRectEffect>();
235 GR_STATIC_ASSERT(kEdgeTypeCnt <= 4); 241 GR_STATIC_ASSERT(kGrEffectEdgeTypeCnt <= 8);
236 return (rre.getType() << 2) | rre.getEdgeType(); 242 return (rre.getType() << 3) | rre.getEdgeType();
237 } 243 }
238 244
239 void GLRRectEffect::setData(const GrGLUniformManager& uman, const GrDrawEffect& drawEffect) { 245 void GLRRectEffect::setData(const GrGLUniformManager& uman, const GrDrawEffect& drawEffect) {
240 const RRectEffect& rre = drawEffect.castEffect<RRectEffect>(); 246 const RRectEffect& rre = drawEffect.castEffect<RRectEffect>();
241 const SkRRect& rrect = rre.getRRect(); 247 const SkRRect& rrect = rre.getRRect();
242 if (rrect != fPrevRRect) { 248 if (rrect != fPrevRRect) {
243 SkRect rect = rrect.getBounds(); 249 SkRect rect = rrect.getBounds();
244 SkScalar radius = 0; 250 SkScalar radius = 0;
245 switch (rre.getType()) { 251 switch (rre.getType()) {
246 case RRectEffect::kCircleCorner_RRectType: 252 case RRectEffect::kCircleCorner_RRectType:
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 break; 285 break;
280 } 286 }
281 uman.set4f(fInnerRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.f Bottom); 287 uman.set4f(fInnerRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.f Bottom);
282 uman.set1f(fRadiusPlusHalfUniform, radius + 0.5f); 288 uman.set1f(fRadiusPlusHalfUniform, radius + 0.5f);
283 fPrevRRect = rrect; 289 fPrevRRect = rrect;
284 } 290 }
285 } 291 }
286 292
287 ////////////////////////////////////////////////////////////////////////////// 293 //////////////////////////////////////////////////////////////////////////////
288 294
289 GrEffectRef* GrRRectEffect::Create(EdgeType edgeType, const SkRRect& rrect) { 295 GrEffectRef* GrRRectEffect::Create(GrEffectEdgeType edgeType, const SkRRect& rre ct) {
296 if (kFillAA_GrEffectEdgeType != edgeType && kInverseFillBW_GrEffectEdgeType != edgeType) {
297 return NULL;
298 }
290 RRectEffect::RRectType rrtype; 299 RRectEffect::RRectType rrtype;
291 if (rrect.isSimpleCircular()) { 300 if (rrect.isSimpleCircular()) {
292 if (rrect.getSimpleRadii().fX < RRectEffect::kRadiusMin) { 301 if (rrect.getSimpleRadii().fX < RRectEffect::kRadiusMin) {
293 return NULL; 302 return NULL;
294 } 303 }
295 rrtype = RRectEffect::kCircleCorner_RRectType; 304 rrtype = RRectEffect::kCircleCorner_RRectType;
296 } else if (rrect.isComplex()) { 305 } else if (rrect.isComplex()) {
297 // Check for the "tab" cases - two adjacent circular corners and two squ are corners. 306 // Check for the "tab" cases - two adjacent circular corners and two squ are corners.
298 SkScalar radius = 0; 307 SkScalar radius = 0;
299 int circleCornerBitfield = 0; 308 int circleCornerBitfield = 0;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 break; 345 break;
337 case 12: 346 case 12:
338 rrtype = RRectEffect::kBottomCircleTab_RRectType; 347 rrtype = RRectEffect::kBottomCircleTab_RRectType;
339 break; 348 break;
340 default: 349 default:
341 return NULL; 350 return NULL;
342 } 351 }
343 } else { 352 } else {
344 return NULL; 353 return NULL;
345 } 354 }
346 return RRectEffect::Create(edgeType, rrect, rrtype); 355 return RRectEffect::Create(edgeType, rrtype, rrect);
347 } 356 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrRRectEffect.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698