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

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

Issue 374923002: Goodbye GrEffectRef. (Closed) Base URL: https://skia.googlesource.com/skia.git@noref3
Patch Set: Address comments 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/GrDitherEffect.cpp ('k') | src/gpu/effects/GrRRectEffect.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 "GrOvalEffect.h" 8 #include "GrOvalEffect.h"
9 9
10 #include "gl/GrGLEffect.h" 10 #include "gl/GrGLEffect.h"
11 #include "gl/GrGLSL.h" 11 #include "gl/GrGLSL.h"
12 #include "GrTBackendEffectFactory.h" 12 #include "GrTBackendEffectFactory.h"
13 13
14 #include "SkRect.h" 14 #include "SkRect.h"
15 15
16 ////////////////////////////////////////////////////////////////////////////// 16 //////////////////////////////////////////////////////////////////////////////
17 17
18 class GLCircleEffect; 18 class GLCircleEffect;
19 19
20 class CircleEffect : public GrEffect { 20 class CircleEffect : public GrEffect {
21 public: 21 public:
22 static GrEffectRef* Create(GrEffectEdgeType, const SkPoint& center, SkScalar radius); 22 static GrEffect* Create(GrEffectEdgeType, const SkPoint& center, SkScalar ra dius);
23 23
24 virtual ~CircleEffect() {}; 24 virtual ~CircleEffect() {};
25 static const char* Name() { return "Circle"; } 25 static const char* Name() { return "Circle"; }
26 26
27 const SkPoint& getCenter() const { return fCenter; } 27 const SkPoint& getCenter() const { return fCenter; }
28 SkScalar getRadius() const { return fRadius; } 28 SkScalar getRadius() const { return fRadius; }
29 29
30 GrEffectEdgeType getEdgeType() const { return fEdgeType; } 30 GrEffectEdgeType getEdgeType() const { return fEdgeType; }
31 31
32 typedef GLCircleEffect GLEffect; 32 typedef GLCircleEffect GLEffect;
33 33
34 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE; 34 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE;
35 35
36 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; 36 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
37 37
38 private: 38 private:
39 CircleEffect(GrEffectEdgeType, const SkPoint& center, SkScalar radius); 39 CircleEffect(GrEffectEdgeType, const SkPoint& center, SkScalar radius);
40 40
41 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; 41 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE;
42 42
43 SkPoint fCenter; 43 SkPoint fCenter;
44 SkScalar fRadius; 44 SkScalar fRadius;
45 GrEffectEdgeType fEdgeType; 45 GrEffectEdgeType fEdgeType;
46 46
47 GR_DECLARE_EFFECT_TEST; 47 GR_DECLARE_EFFECT_TEST;
48 48
49 typedef GrEffect INHERITED; 49 typedef GrEffect INHERITED;
50 }; 50 };
51 51
52 GrEffectRef* CircleEffect::Create(GrEffectEdgeType edgeType, 52 GrEffect* CircleEffect::Create(GrEffectEdgeType edgeType, const SkPoint& center, SkScalar radius) {
53 const SkPoint& center,
54 SkScalar radius) {
55 SkASSERT(radius >= 0); 53 SkASSERT(radius >= 0);
56 return SkNEW_ARGS(CircleEffect, (edgeType, center, radius)); 54 return SkNEW_ARGS(CircleEffect, (edgeType, center, radius));
57 } 55 }
58 56
59 void CircleEffect::getConstantColorComponents(GrColor* color, uint32_t* validFla gs) const { 57 void CircleEffect::getConstantColorComponents(GrColor* color, uint32_t* validFla gs) const {
60 *validFlags = 0; 58 *validFlags = 0;
61 } 59 }
62 60
63 const GrBackendEffectFactory& CircleEffect::getFactory() const { 61 const GrBackendEffectFactory& CircleEffect::getFactory() const {
64 return GrTBackendEffectFactory<CircleEffect>::getInstance(); 62 return GrTBackendEffectFactory<CircleEffect>::getInstance();
65 } 63 }
66 64
67 CircleEffect::CircleEffect(GrEffectEdgeType edgeType, const SkPoint& c, SkScalar r) 65 CircleEffect::CircleEffect(GrEffectEdgeType edgeType, const SkPoint& c, SkScalar r)
68 : fCenter(c) 66 : fCenter(c)
69 , fRadius(r) 67 , fRadius(r)
70 , fEdgeType(edgeType) { 68 , fEdgeType(edgeType) {
71 this->setWillReadFragmentPosition(); 69 this->setWillReadFragmentPosition();
72 } 70 }
73 71
74 bool CircleEffect::onIsEqual(const GrEffect& other) const { 72 bool CircleEffect::onIsEqual(const GrEffect& other) const {
75 const CircleEffect& ce = CastEffect<CircleEffect>(other); 73 const CircleEffect& ce = CastEffect<CircleEffect>(other);
76 return fEdgeType == ce.fEdgeType && fCenter == ce.fCenter && fRadius == ce.f Radius; 74 return fEdgeType == ce.fEdgeType && fCenter == ce.fCenter && fRadius == ce.f Radius;
77 } 75 }
78 76
79 ////////////////////////////////////////////////////////////////////////////// 77 //////////////////////////////////////////////////////////////////////////////
80 78
81 GR_DEFINE_EFFECT_TEST(CircleEffect); 79 GR_DEFINE_EFFECT_TEST(CircleEffect);
82 80
83 GrEffectRef* CircleEffect::TestCreate(SkRandom* random, 81 GrEffect* CircleEffect::TestCreate(SkRandom* random,
84 GrContext*, 82 GrContext*,
85 const GrDrawTargetCaps& caps, 83 const GrDrawTargetCaps& caps,
86 GrTexture*[]) { 84 GrTexture*[]) {
87 SkPoint center; 85 SkPoint center;
88 center.fX = random->nextRangeScalar(0.f, 1000.f); 86 center.fX = random->nextRangeScalar(0.f, 1000.f);
89 center.fY = random->nextRangeScalar(0.f, 1000.f); 87 center.fY = random->nextRangeScalar(0.f, 1000.f);
90 SkScalar radius = random->nextRangeF(0.f, 1000.f); 88 SkScalar radius = random->nextRangeF(0.f, 1000.f);
91 GrEffectEdgeType et; 89 GrEffectEdgeType et;
92 do { 90 do {
93 et = (GrEffectEdgeType)random->nextULessThan(kGrEffectEdgeTypeCnt); 91 et = (GrEffectEdgeType)random->nextULessThan(kGrEffectEdgeTypeCnt);
94 } while (kHairlineAA_GrEffectEdgeType == et); 92 } while (kHairlineAA_GrEffectEdgeType == et);
95 return CircleEffect::Create(et, center, radius); 93 return CircleEffect::Create(et, center, radius);
96 } 94 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 fPrevRadius = ce.getRadius(); 180 fPrevRadius = ce.getRadius();
183 } 181 }
184 } 182 }
185 183
186 ////////////////////////////////////////////////////////////////////////////// 184 //////////////////////////////////////////////////////////////////////////////
187 185
188 class GLEllipseEffect; 186 class GLEllipseEffect;
189 187
190 class EllipseEffect : public GrEffect { 188 class EllipseEffect : public GrEffect {
191 public: 189 public:
192 static GrEffectRef* Create(GrEffectEdgeType, const SkPoint& center, SkScalar rx, SkScalar ry); 190 static GrEffect* Create(GrEffectEdgeType, const SkPoint& center, SkScalar rx , SkScalar ry);
193 191
194 virtual ~EllipseEffect() {}; 192 virtual ~EllipseEffect() {};
195 static const char* Name() { return "Ellipse"; } 193 static const char* Name() { return "Ellipse"; }
196 194
197 const SkPoint& getCenter() const { return fCenter; } 195 const SkPoint& getCenter() const { return fCenter; }
198 SkVector getRadii() const { return fRadii; } 196 SkVector getRadii() const { return fRadii; }
199 197
200 GrEffectEdgeType getEdgeType() const { return fEdgeType; } 198 GrEffectEdgeType getEdgeType() const { return fEdgeType; }
201 199
202 typedef GLEllipseEffect GLEffect; 200 typedef GLEllipseEffect GLEffect;
203 201
204 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE; 202 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE;
205 203
206 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; 204 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
207 205
208 private: 206 private:
209 EllipseEffect(GrEffectEdgeType, const SkPoint& center, SkScalar rx, SkScalar ry); 207 EllipseEffect(GrEffectEdgeType, const SkPoint& center, SkScalar rx, SkScalar ry);
210 208
211 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; 209 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE;
212 210
213 SkPoint fCenter; 211 SkPoint fCenter;
214 SkVector fRadii; 212 SkVector fRadii;
215 GrEffectEdgeType fEdgeType; 213 GrEffectEdgeType fEdgeType;
216 214
217 GR_DECLARE_EFFECT_TEST; 215 GR_DECLARE_EFFECT_TEST;
218 216
219 typedef GrEffect INHERITED; 217 typedef GrEffect INHERITED;
220 }; 218 };
221 219
222 GrEffectRef* EllipseEffect::Create(GrEffectEdgeType edgeType, 220 GrEffect* EllipseEffect::Create(GrEffectEdgeType edgeType,
223 const SkPoint& center, 221 const SkPoint& center,
224 SkScalar rx, 222 SkScalar rx,
225 SkScalar ry) { 223 SkScalar ry) {
226 SkASSERT(rx >= 0 && ry >= 0); 224 SkASSERT(rx >= 0 && ry >= 0);
227 return SkNEW_ARGS(EllipseEffect, (edgeType, center, rx, ry)); 225 return SkNEW_ARGS(EllipseEffect, (edgeType, center, rx, ry));
228 } 226 }
229 227
230 void EllipseEffect::getConstantColorComponents(GrColor* color, uint32_t* validFl ags) const { 228 void EllipseEffect::getConstantColorComponents(GrColor* color, uint32_t* validFl ags) const {
231 *validFlags = 0; 229 *validFlags = 0;
232 } 230 }
233 231
234 const GrBackendEffectFactory& EllipseEffect::getFactory() const { 232 const GrBackendEffectFactory& EllipseEffect::getFactory() const {
235 return GrTBackendEffectFactory<EllipseEffect>::getInstance(); 233 return GrTBackendEffectFactory<EllipseEffect>::getInstance();
236 } 234 }
237 235
238 EllipseEffect::EllipseEffect(GrEffectEdgeType edgeType, const SkPoint& c, SkScal ar rx, SkScalar ry) 236 EllipseEffect::EllipseEffect(GrEffectEdgeType edgeType, const SkPoint& c, SkScal ar rx, SkScalar ry)
239 : fCenter(c) 237 : fCenter(c)
240 , fRadii(SkVector::Make(rx, ry)) 238 , fRadii(SkVector::Make(rx, ry))
241 , fEdgeType(edgeType) { 239 , fEdgeType(edgeType) {
242 this->setWillReadFragmentPosition(); 240 this->setWillReadFragmentPosition();
243 } 241 }
244 242
245 bool EllipseEffect::onIsEqual(const GrEffect& other) const { 243 bool EllipseEffect::onIsEqual(const GrEffect& other) const {
246 const EllipseEffect& ee = CastEffect<EllipseEffect>(other); 244 const EllipseEffect& ee = CastEffect<EllipseEffect>(other);
247 return fEdgeType == ee.fEdgeType && fCenter == ee.fCenter && fRadii == ee.fR adii; 245 return fEdgeType == ee.fEdgeType && fCenter == ee.fCenter && fRadii == ee.fR adii;
248 } 246 }
249 247
250 ////////////////////////////////////////////////////////////////////////////// 248 //////////////////////////////////////////////////////////////////////////////
251 249
252 GR_DEFINE_EFFECT_TEST(EllipseEffect); 250 GR_DEFINE_EFFECT_TEST(EllipseEffect);
253 251
254 GrEffectRef* EllipseEffect::TestCreate(SkRandom* random, 252 GrEffect* EllipseEffect::TestCreate(SkRandom* random,
255 GrContext*, 253 GrContext*,
256 const GrDrawTargetCaps& caps, 254 const GrDrawTargetCaps& caps,
257 GrTexture*[]) { 255 GrTexture*[]) {
258 SkPoint center; 256 SkPoint center;
259 center.fX = random->nextRangeScalar(0.f, 1000.f); 257 center.fX = random->nextRangeScalar(0.f, 1000.f);
260 center.fY = random->nextRangeScalar(0.f, 1000.f); 258 center.fY = random->nextRangeScalar(0.f, 1000.f);
261 SkScalar rx = random->nextRangeF(0.f, 1000.f); 259 SkScalar rx = random->nextRangeF(0.f, 1000.f);
262 SkScalar ry = random->nextRangeF(0.f, 1000.f); 260 SkScalar ry = random->nextRangeF(0.f, 1000.f);
263 GrEffectEdgeType et; 261 GrEffectEdgeType et;
264 do { 262 do {
265 et = (GrEffectEdgeType)random->nextULessThan(kGrEffectEdgeTypeCnt); 263 et = (GrEffectEdgeType)random->nextULessThan(kGrEffectEdgeTypeCnt);
266 } while (kHairlineAA_GrEffectEdgeType == et); 264 } while (kHairlineAA_GrEffectEdgeType == et);
267 return EllipseEffect::Create(et, center, rx, ry); 265 return EllipseEffect::Create(et, center, rx, ry);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 SkScalar invRXSqd = 1.f / (ee.getRadii().fX * ee.getRadii().fX); 357 SkScalar invRXSqd = 1.f / (ee.getRadii().fX * ee.getRadii().fX);
360 SkScalar invRYSqd = 1.f / (ee.getRadii().fY * ee.getRadii().fY); 358 SkScalar invRYSqd = 1.f / (ee.getRadii().fY * ee.getRadii().fY);
361 uman.set4f(fEllipseUniform, ee.getCenter().fX, ee.getCenter().fY, invRXS qd, invRYSqd); 359 uman.set4f(fEllipseUniform, ee.getCenter().fX, ee.getCenter().fY, invRXS qd, invRYSqd);
362 fPrevCenter = ee.getCenter(); 360 fPrevCenter = ee.getCenter();
363 fPrevRadii = ee.getRadii(); 361 fPrevRadii = ee.getRadii();
364 } 362 }
365 } 363 }
366 364
367 ////////////////////////////////////////////////////////////////////////////// 365 //////////////////////////////////////////////////////////////////////////////
368 366
369 GrEffectRef* GrOvalEffect::Create(GrEffectEdgeType edgeType, const SkRect& oval) { 367 GrEffect* GrOvalEffect::Create(GrEffectEdgeType edgeType, const SkRect& oval) {
370 if (kHairlineAA_GrEffectEdgeType == edgeType) { 368 if (kHairlineAA_GrEffectEdgeType == edgeType) {
371 return NULL; 369 return NULL;
372 } 370 }
373 SkScalar w = oval.width(); 371 SkScalar w = oval.width();
374 SkScalar h = oval.height(); 372 SkScalar h = oval.height();
375 if (SkScalarNearlyEqual(w, h)) { 373 if (SkScalarNearlyEqual(w, h)) {
376 w /= 2; 374 w /= 2;
377 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval .fTop + w), w); 375 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval .fTop + w), w);
378 } else { 376 } else {
379 w /= 2; 377 w /= 2;
380 h /= 2; 378 h /= 2;
381 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova l.fTop + h), w, h); 379 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova l.fTop + h), w, h);
382 } 380 }
383 381
384 return NULL; 382 return NULL;
385 } 383 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrDitherEffect.cpp ('k') | src/gpu/effects/GrRRectEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698