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

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

Issue 1666773002: Clean up GrGLSLFragmentProcessor-derived classes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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/GrMatrixConvolutionEffect.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 "GrFragmentProcessor.h" 10 #include "GrFragmentProcessor.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 do { 86 do {
87 et = (GrPrimitiveEdgeType)d->fRandom->nextULessThan(kGrProcessorEdgeType Cnt); 87 et = (GrPrimitiveEdgeType)d->fRandom->nextULessThan(kGrProcessorEdgeType Cnt);
88 } while (kHairlineAA_GrProcessorEdgeType == et); 88 } while (kHairlineAA_GrProcessorEdgeType == et);
89 return CircleEffect::Create(et, center, radius); 89 return CircleEffect::Create(et, center, radius);
90 } 90 }
91 91
92 ////////////////////////////////////////////////////////////////////////////// 92 //////////////////////////////////////////////////////////////////////////////
93 93
94 class GLCircleEffect : public GrGLSLFragmentProcessor { 94 class GLCircleEffect : public GrGLSLFragmentProcessor {
95 public: 95 public:
96 GLCircleEffect(const GrProcessor&); 96 GLCircleEffect() : fPrevRadius(-1.0f) { }
97 97
98 virtual void emitCode(EmitArgs&) override; 98 virtual void emitCode(EmitArgs&) override;
99 99
100 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*); 100 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*);
101 101
102 protected: 102 protected:
103 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ; 103 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ;
104 104
105 private: 105 private:
106 GrGLSLProgramDataManager::UniformHandle fCircleUniform; 106 GrGLSLProgramDataManager::UniformHandle fCircleUniform;
107 SkPoint fPrevCenter; 107 SkPoint fPrevCenter;
108 SkScalar fPrevRadius; 108 SkScalar fPrevRadius;
109 109
110 typedef GrGLSLFragmentProcessor INHERITED; 110 typedef GrGLSLFragmentProcessor INHERITED;
111 }; 111 };
112 112
113 GLCircleEffect::GLCircleEffect(const GrProcessor&) {
114 fPrevRadius = -1.f;
115 }
116
117 void GLCircleEffect::emitCode(EmitArgs& args) { 113 void GLCircleEffect::emitCode(EmitArgs& args) {
118 const CircleEffect& ce = args.fFp.cast<CircleEffect>(); 114 const CircleEffect& ce = args.fFp.cast<CircleEffect>();
119 const char *circleName; 115 const char *circleName;
120 // The circle uniform is (center.x, center.y, radius + 0.5, 1 / (radius + 0. 5)) for regular 116 // The circle uniform is (center.x, center.y, radius + 0.5, 1 / (radius + 0. 5)) for regular
121 // fills and (..., radius - 0.5, 1 / (radius - 0.5)) for inverse fills. 117 // fills and (..., radius - 0.5, 1 / (radius - 0.5)) for inverse fills.
122 fCircleUniform = args.fUniformHandler->addUniform(GrGLSLUniformHandler::kFra gment_Visibility, 118 fCircleUniform = args.fUniformHandler->addUniform(GrGLSLUniformHandler::kFra gment_Visibility,
123 kVec4f_GrSLType, kDefault_ GrSLPrecision, 119 kVec4f_GrSLType, kDefault_ GrSLPrecision,
124 "circle", 120 "circle",
125 &circleName); 121 &circleName);
126 122
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 169 }
174 170
175 //////////////////////////////////////////////////////////////////////////////// /////////////////// 171 //////////////////////////////////////////////////////////////////////////////// ///////////////////
176 172
177 void CircleEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, 173 void CircleEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps,
178 GrProcessorKeyBuilder* b) const { 174 GrProcessorKeyBuilder* b) const {
179 GLCircleEffect::GenKey(*this, caps, b); 175 GLCircleEffect::GenKey(*this, caps, b);
180 } 176 }
181 177
182 GrGLSLFragmentProcessor* CircleEffect::onCreateGLSLInstance() const { 178 GrGLSLFragmentProcessor* CircleEffect::onCreateGLSLInstance() const {
183 return new GLCircleEffect(*this); 179 return new GLCircleEffect;
184 } 180 }
185 181
186 ////////////////////////////////////////////////////////////////////////////// 182 //////////////////////////////////////////////////////////////////////////////
187 183
188 class EllipseEffect : public GrFragmentProcessor { 184 class EllipseEffect : public GrFragmentProcessor {
189 public: 185 public:
190 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkPoint& cente r, SkScalar rx, 186 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkPoint& cente r, SkScalar rx,
191 SkScalar ry); 187 SkScalar ry);
192 188
193 virtual ~EllipseEffect() {}; 189 virtual ~EllipseEffect() {};
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 do { 254 do {
259 et = (GrPrimitiveEdgeType)d->fRandom->nextULessThan(kGrProcessorEdgeType Cnt); 255 et = (GrPrimitiveEdgeType)d->fRandom->nextULessThan(kGrProcessorEdgeType Cnt);
260 } while (kHairlineAA_GrProcessorEdgeType == et); 256 } while (kHairlineAA_GrProcessorEdgeType == et);
261 return EllipseEffect::Create(et, center, rx, ry); 257 return EllipseEffect::Create(et, center, rx, ry);
262 } 258 }
263 259
264 ////////////////////////////////////////////////////////////////////////////// 260 //////////////////////////////////////////////////////////////////////////////
265 261
266 class GLEllipseEffect : public GrGLSLFragmentProcessor { 262 class GLEllipseEffect : public GrGLSLFragmentProcessor {
267 public: 263 public:
268 GLEllipseEffect(const GrProcessor&); 264 GLEllipseEffect() {
265 fPrevRadii.fX = -1.0f;
266 }
269 267
270 virtual void emitCode(EmitArgs&) override; 268 void emitCode(EmitArgs&) override;
271 269
272 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*); 270 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*);
273 271
274 protected: 272 protected:
275 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ; 273 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ;
276 274
277 private: 275 private:
278 GrGLSLProgramDataManager::UniformHandle fEllipseUniform; 276 GrGLSLProgramDataManager::UniformHandle fEllipseUniform;
279 GrGLSLProgramDataManager::UniformHandle fScaleUniform; 277 GrGLSLProgramDataManager::UniformHandle fScaleUniform;
280 SkPoint fPrevCenter; 278 SkPoint fPrevCenter;
281 SkVector fPrevRadii; 279 SkVector fPrevRadii;
282 280
283 typedef GrGLSLFragmentProcessor INHERITED; 281 typedef GrGLSLFragmentProcessor INHERITED;
284 }; 282 };
285 283
286 GLEllipseEffect::GLEllipseEffect(const GrProcessor& effect) {
287 fPrevRadii.fX = -1.f;
288 }
289
290 void GLEllipseEffect::emitCode(EmitArgs& args) { 284 void GLEllipseEffect::emitCode(EmitArgs& args) {
291 const EllipseEffect& ee = args.fFp.cast<EllipseEffect>(); 285 const EllipseEffect& ee = args.fFp.cast<EllipseEffect>();
292 const char *ellipseName; 286 const char *ellipseName;
293 // The ellipse uniform is (center.x, center.y, 1 / rx^2, 1 / ry^2) 287 // The ellipse uniform is (center.x, center.y, 1 / rx^2, 1 / ry^2)
294 // The last two terms can underflow on mediump, so we use highp. 288 // The last two terms can underflow on mediump, so we use highp.
295 fEllipseUniform = args.fUniformHandler->addUniform(GrGLSLUniformHandler::kFr agment_Visibility, 289 fEllipseUniform = args.fUniformHandler->addUniform(GrGLSLUniformHandler::kFr agment_Visibility,
296 kVec4f_GrSLType, kHigh_Gr SLPrecision, 290 kVec4f_GrSLType, kHigh_Gr SLPrecision,
297 "ellipse", 291 "ellipse",
298 &ellipseName); 292 &ellipseName);
299 // If we're on a device with a "real" mediump then we'll do the distance com putation in a space 293 // If we're on a device with a "real" mediump then we'll do the distance com putation in a space
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 379 }
386 380
387 //////////////////////////////////////////////////////////////////////////////// /////////////////// 381 //////////////////////////////////////////////////////////////////////////////// ///////////////////
388 382
389 void EllipseEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, 383 void EllipseEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps,
390 GrProcessorKeyBuilder* b) const { 384 GrProcessorKeyBuilder* b) const {
391 GLEllipseEffect::GenKey(*this, caps, b); 385 GLEllipseEffect::GenKey(*this, caps, b);
392 } 386 }
393 387
394 GrGLSLFragmentProcessor* EllipseEffect::onCreateGLSLInstance() const { 388 GrGLSLFragmentProcessor* EllipseEffect::onCreateGLSLInstance() const {
395 return new GLEllipseEffect(*this); 389 return new GLEllipseEffect;
396 } 390 }
397 391
398 ////////////////////////////////////////////////////////////////////////////// 392 //////////////////////////////////////////////////////////////////////////////
399 393
400 GrFragmentProcessor* GrOvalEffect::Create(GrPrimitiveEdgeType edgeType, const Sk Rect& oval) { 394 GrFragmentProcessor* GrOvalEffect::Create(GrPrimitiveEdgeType edgeType, const Sk Rect& oval) {
401 if (kHairlineAA_GrProcessorEdgeType == edgeType) { 395 if (kHairlineAA_GrProcessorEdgeType == edgeType) {
402 return nullptr; 396 return nullptr;
403 } 397 }
404 SkScalar w = oval.width(); 398 SkScalar w = oval.width();
405 SkScalar h = oval.height(); 399 SkScalar h = oval.height();
406 if (SkScalarNearlyEqual(w, h)) { 400 if (SkScalarNearlyEqual(w, h)) {
407 w /= 2; 401 w /= 2;
408 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval .fTop + w), w); 402 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval .fTop + w), w);
409 } else { 403 } else {
410 w /= 2; 404 w /= 2;
411 h /= 2; 405 h /= 2;
412 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova l.fTop + h), w, h); 406 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova l.fTop + h), w, h);
413 } 407 }
414 408
415 return nullptr; 409 return nullptr;
416 } 410 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrMatrixConvolutionEffect.cpp ('k') | src/gpu/effects/GrRRectEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698