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

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

Issue 1428543003: Create GLSL base class for ProgramDataManager (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add space Created 5 years, 1 month 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
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"
11 #include "GrInvariantOutput.h" 11 #include "GrInvariantOutput.h"
12 #include "SkRect.h" 12 #include "SkRect.h"
13 #include "gl/GrGLFragmentProcessor.h" 13 #include "gl/GrGLFragmentProcessor.h"
14 #include "gl/builders/GrGLProgramBuilder.h" 14 #include "gl/builders/GrGLProgramBuilder.h"
15 #include "glsl/GrGLSLProgramDataManager.h"
15 16
16 ////////////////////////////////////////////////////////////////////////////// 17 //////////////////////////////////////////////////////////////////////////////
17 18
18 class CircleEffect : public GrFragmentProcessor { 19 class CircleEffect : public GrFragmentProcessor {
19 public: 20 public:
20 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkPoint& cente r, SkScalar radius); 21 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkPoint& cente r, SkScalar radius);
21 22
22 virtual ~CircleEffect() {}; 23 virtual ~CircleEffect() {};
23 24
24 const char* name() const override { return "Circle"; } 25 const char* name() const override { return "Circle"; }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 92
92 class GLCircleEffect : public GrGLFragmentProcessor { 93 class GLCircleEffect : public GrGLFragmentProcessor {
93 public: 94 public:
94 GLCircleEffect(const GrProcessor&); 95 GLCircleEffect(const GrProcessor&);
95 96
96 virtual void emitCode(EmitArgs&) override; 97 virtual void emitCode(EmitArgs&) override;
97 98
98 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*); 99 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*);
99 100
100 protected: 101 protected:
101 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; 102 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ;
102 103
103 private: 104 private:
104 GrGLProgramDataManager::UniformHandle fCircleUniform; 105 GrGLSLProgramDataManager::UniformHandle fCircleUniform;
105 SkPoint fPrevCenter; 106 SkPoint fPrevCenter;
106 SkScalar fPrevRadius; 107 SkScalar fPrevRadius;
107 108
108 typedef GrGLFragmentProcessor INHERITED; 109 typedef GrGLFragmentProcessor INHERITED;
109 }; 110 };
110 111
111 GLCircleEffect::GLCircleEffect(const GrProcessor&) { 112 GLCircleEffect::GLCircleEffect(const GrProcessor&) {
112 fPrevRadius = -1.f; 113 fPrevRadius = -1.f;
113 } 114 }
114 115
115 void GLCircleEffect::emitCode(EmitArgs& args) { 116 void GLCircleEffect::emitCode(EmitArgs& args) {
116 const CircleEffect& ce = args.fFp.cast<CircleEffect>(); 117 const CircleEffect& ce = args.fFp.cast<CircleEffect>();
(...skipping 29 matching lines...) Expand all
146 fsBuilder->codeAppendf("\t\t%s = %s;\n", args.fOutputColor, 147 fsBuilder->codeAppendf("\t\t%s = %s;\n", args.fOutputColor,
147 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("d")).c_ str()); 148 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("d")).c_ str());
148 } 149 }
149 150
150 void GLCircleEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps&, 151 void GLCircleEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps&,
151 GrProcessorKeyBuilder* b) { 152 GrProcessorKeyBuilder* b) {
152 const CircleEffect& ce = processor.cast<CircleEffect>(); 153 const CircleEffect& ce = processor.cast<CircleEffect>();
153 b->add32(ce.getEdgeType()); 154 b->add32(ce.getEdgeType());
154 } 155 }
155 156
156 void GLCircleEffect::onSetData(const GrGLProgramDataManager& pdman, const GrProc essor& processor) { 157 void GLCircleEffect::onSetData(const GrGLSLProgramDataManager& pdman,
158 const GrProcessor& processor) {
157 const CircleEffect& ce = processor.cast<CircleEffect>(); 159 const CircleEffect& ce = processor.cast<CircleEffect>();
158 if (ce.getRadius() != fPrevRadius || ce.getCenter() != fPrevCenter) { 160 if (ce.getRadius() != fPrevRadius || ce.getCenter() != fPrevCenter) {
159 SkScalar radius = ce.getRadius(); 161 SkScalar radius = ce.getRadius();
160 if (GrProcessorEdgeTypeIsInverseFill(ce.getEdgeType())) { 162 if (GrProcessorEdgeTypeIsInverseFill(ce.getEdgeType())) {
161 radius -= 0.5f; 163 radius -= 0.5f;
162 } else { 164 } else {
163 radius += 0.5f; 165 radius += 0.5f;
164 } 166 }
165 pdman.set4f(fCircleUniform, ce.getCenter().fX, ce.getCenter().fY, radius , 167 pdman.set4f(fCircleUniform, ce.getCenter().fX, ce.getCenter().fY, radius ,
166 SkScalarInvert(radius)); 168 SkScalarInvert(radius));
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 264
263 class GLEllipseEffect : public GrGLFragmentProcessor { 265 class GLEllipseEffect : public GrGLFragmentProcessor {
264 public: 266 public:
265 GLEllipseEffect(const GrProcessor&); 267 GLEllipseEffect(const GrProcessor&);
266 268
267 virtual void emitCode(EmitArgs&) override; 269 virtual void emitCode(EmitArgs&) override;
268 270
269 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*); 271 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*);
270 272
271 protected: 273 protected:
272 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; 274 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ;
273 275
274 private: 276 private:
275 GrGLProgramDataManager::UniformHandle fEllipseUniform; 277 GrGLSLProgramDataManager::UniformHandle fEllipseUniform;
276 SkPoint fPrevCenter; 278 SkPoint fPrevCenter;
277 SkVector fPrevRadii; 279 SkVector fPrevRadii;
278 280
279 typedef GrGLFragmentProcessor INHERITED; 281 typedef GrGLFragmentProcessor INHERITED;
280 }; 282 };
281 283
282 GLEllipseEffect::GLEllipseEffect(const GrProcessor& effect) { 284 GLEllipseEffect::GLEllipseEffect(const GrProcessor& effect) {
283 fPrevRadii.fX = -1.f; 285 fPrevRadii.fX = -1.f;
284 } 286 }
285 287
286 void GLEllipseEffect::emitCode(EmitArgs& args) { 288 void GLEllipseEffect::emitCode(EmitArgs& args) {
287 const EllipseEffect& ee = args.fFp.cast<EllipseEffect>(); 289 const EllipseEffect& ee = args.fFp.cast<EllipseEffect>();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 fsBuilder->codeAppendf("\t\t%s = %s;\n", args.fOutputColor, 329 fsBuilder->codeAppendf("\t\t%s = %s;\n", args.fOutputColor,
328 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha") ).c_str()); 330 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha") ).c_str());
329 } 331 }
330 332
331 void GLEllipseEffect::GenKey(const GrProcessor& effect, const GrGLSLCaps&, 333 void GLEllipseEffect::GenKey(const GrProcessor& effect, const GrGLSLCaps&,
332 GrProcessorKeyBuilder* b) { 334 GrProcessorKeyBuilder* b) {
333 const EllipseEffect& ee = effect.cast<EllipseEffect>(); 335 const EllipseEffect& ee = effect.cast<EllipseEffect>();
334 b->add32(ee.getEdgeType()); 336 b->add32(ee.getEdgeType());
335 } 337 }
336 338
337 void GLEllipseEffect::onSetData(const GrGLProgramDataManager& pdman, const GrPro cessor& effect) { 339 void GLEllipseEffect::onSetData(const GrGLSLProgramDataManager& pdman,
340 const GrProcessor& effect) {
338 const EllipseEffect& ee = effect.cast<EllipseEffect>(); 341 const EllipseEffect& ee = effect.cast<EllipseEffect>();
339 if (ee.getRadii() != fPrevRadii || ee.getCenter() != fPrevCenter) { 342 if (ee.getRadii() != fPrevRadii || ee.getCenter() != fPrevCenter) {
340 SkScalar invRXSqd = 1.f / (ee.getRadii().fX * ee.getRadii().fX); 343 SkScalar invRXSqd = 1.f / (ee.getRadii().fX * ee.getRadii().fX);
341 SkScalar invRYSqd = 1.f / (ee.getRadii().fY * ee.getRadii().fY); 344 SkScalar invRYSqd = 1.f / (ee.getRadii().fY * ee.getRadii().fY);
342 pdman.set4f(fEllipseUniform, ee.getCenter().fX, ee.getCenter().fY, invRX Sqd, invRYSqd); 345 pdman.set4f(fEllipseUniform, ee.getCenter().fX, ee.getCenter().fY, invRX Sqd, invRYSqd);
343 fPrevCenter = ee.getCenter(); 346 fPrevCenter = ee.getCenter();
344 fPrevRadii = ee.getRadii(); 347 fPrevRadii = ee.getRadii();
345 } 348 }
346 } 349 }
347 350
(...skipping 20 matching lines...) Expand all
368 w /= 2; 371 w /= 2;
369 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval .fTop + w), w); 372 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval .fTop + w), w);
370 } else { 373 } else {
371 w /= 2; 374 w /= 2;
372 h /= 2; 375 h /= 2;
373 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova l.fTop + h), w, h); 376 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova l.fTop + h), w, h);
374 } 377 }
375 378
376 return nullptr; 379 return nullptr;
377 } 380 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrMatrixConvolutionEffect.cpp ('k') | src/gpu/effects/GrPorterDuffXferProcessor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698