OLD | NEW |
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 | 15 |
16 ////////////////////////////////////////////////////////////////////////////// | 16 ////////////////////////////////////////////////////////////////////////////// |
17 | 17 |
18 class CircleEffect : public GrFragmentProcessor { | 18 class CircleEffect : public GrFragmentProcessor { |
19 public: | 19 public: |
20 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkPoint& cente
r, SkScalar radius); | 20 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkPoint& cente
r, SkScalar radius); |
21 | 21 |
22 virtual ~CircleEffect() {}; | 22 virtual ~CircleEffect() {}; |
23 | 23 |
24 const char* name() const override { return "Circle"; } | 24 const char* name() const override { return "Circle"; } |
25 | 25 |
26 GrGLFragmentProcessor* createGLInstance() const override; | |
27 | |
28 const SkPoint& getCenter() const { return fCenter; } | 26 const SkPoint& getCenter() const { return fCenter; } |
29 SkScalar getRadius() const { return fRadius; } | 27 SkScalar getRadius() const { return fRadius; } |
30 | 28 |
31 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } | 29 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
32 | 30 |
33 private: | 31 private: |
34 CircleEffect(GrPrimitiveEdgeType, const SkPoint& center, SkScalar radius); | 32 CircleEffect(GrPrimitiveEdgeType, const SkPoint& center, SkScalar radius); |
35 | 33 |
| 34 GrGLFragmentProcessor* onCreateGLInstance() const override; |
| 35 |
36 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; | 36 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; |
37 | 37 |
38 bool onIsEqual(const GrFragmentProcessor&) const override; | 38 bool onIsEqual(const GrFragmentProcessor&) const override; |
39 | 39 |
40 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | 40 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
41 | 41 |
42 SkPoint fCenter; | 42 SkPoint fCenter; |
43 SkScalar fRadius; | 43 SkScalar fRadius; |
44 GrPrimitiveEdgeType fEdgeType; | 44 GrPrimitiveEdgeType fEdgeType; |
45 | 45 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 ////////////////////////////////////////////////////////////////////////////// | 90 ////////////////////////////////////////////////////////////////////////////// |
91 | 91 |
92 class GLCircleEffect : public GrGLFragmentProcessor { | 92 class GLCircleEffect : public GrGLFragmentProcessor { |
93 public: | 93 public: |
94 GLCircleEffect(const GrProcessor&); | 94 GLCircleEffect(const GrProcessor&); |
95 | 95 |
96 virtual void emitCode(EmitArgs&) override; | 96 virtual void emitCode(EmitArgs&) override; |
97 | 97 |
98 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); | 98 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); |
99 | 99 |
100 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; | 100 protected: |
| 101 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; |
101 | 102 |
102 private: | 103 private: |
103 GrGLProgramDataManager::UniformHandle fCircleUniform; | 104 GrGLProgramDataManager::UniformHandle fCircleUniform; |
104 SkPoint fPrevCenter; | 105 SkPoint fPrevCenter; |
105 SkScalar fPrevRadius; | 106 SkScalar fPrevRadius; |
106 | 107 |
107 typedef GrGLFragmentProcessor INHERITED; | 108 typedef GrGLFragmentProcessor INHERITED; |
108 }; | 109 }; |
109 | 110 |
110 GLCircleEffect::GLCircleEffect(const GrProcessor&) { | 111 GLCircleEffect::GLCircleEffect(const GrProcessor&) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 fsBuilder->codeAppendf("\t\t%s = %s;\n", args.fOutputColor, | 146 fsBuilder->codeAppendf("\t\t%s = %s;\n", args.fOutputColor, |
146 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("d")).c_
str()); | 147 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("d")).c_
str()); |
147 } | 148 } |
148 | 149 |
149 void GLCircleEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps&, | 150 void GLCircleEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps&, |
150 GrProcessorKeyBuilder* b) { | 151 GrProcessorKeyBuilder* b) { |
151 const CircleEffect& ce = processor.cast<CircleEffect>(); | 152 const CircleEffect& ce = processor.cast<CircleEffect>(); |
152 b->add32(ce.getEdgeType()); | 153 b->add32(ce.getEdgeType()); |
153 } | 154 } |
154 | 155 |
155 void GLCircleEffect::setData(const GrGLProgramDataManager& pdman, const GrProces
sor& processor) { | 156 void GLCircleEffect::onSetData(const GrGLProgramDataManager& pdman, const GrProc
essor& processor) { |
156 const CircleEffect& ce = processor.cast<CircleEffect>(); | 157 const CircleEffect& ce = processor.cast<CircleEffect>(); |
157 if (ce.getRadius() != fPrevRadius || ce.getCenter() != fPrevCenter) { | 158 if (ce.getRadius() != fPrevRadius || ce.getCenter() != fPrevCenter) { |
158 SkScalar radius = ce.getRadius(); | 159 SkScalar radius = ce.getRadius(); |
159 if (GrProcessorEdgeTypeIsInverseFill(ce.getEdgeType())) { | 160 if (GrProcessorEdgeTypeIsInverseFill(ce.getEdgeType())) { |
160 radius -= 0.5f; | 161 radius -= 0.5f; |
161 } else { | 162 } else { |
162 radius += 0.5f; | 163 radius += 0.5f; |
163 } | 164 } |
164 pdman.set4f(fCircleUniform, ce.getCenter().fX, ce.getCenter().fY, radius
, | 165 pdman.set4f(fCircleUniform, ce.getCenter().fX, ce.getCenter().fY, radius
, |
165 SkScalarInvert(radius)); | 166 SkScalarInvert(radius)); |
166 fPrevCenter = ce.getCenter(); | 167 fPrevCenter = ce.getCenter(); |
167 fPrevRadius = ce.getRadius(); | 168 fPrevRadius = ce.getRadius(); |
168 } | 169 } |
169 } | 170 } |
170 | 171 |
171 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 172 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
172 | 173 |
173 void CircleEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 174 void CircleEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
174 GrProcessorKeyBuilder* b) const { | 175 GrProcessorKeyBuilder* b) const { |
175 GLCircleEffect::GenKey(*this, caps, b); | 176 GLCircleEffect::GenKey(*this, caps, b); |
176 } | 177 } |
177 | 178 |
178 GrGLFragmentProcessor* CircleEffect::createGLInstance() const { | 179 GrGLFragmentProcessor* CircleEffect::onCreateGLInstance() const { |
179 return SkNEW_ARGS(GLCircleEffect, (*this)); | 180 return SkNEW_ARGS(GLCircleEffect, (*this)); |
180 } | 181 } |
181 | 182 |
182 ////////////////////////////////////////////////////////////////////////////// | 183 ////////////////////////////////////////////////////////////////////////////// |
183 | 184 |
184 class EllipseEffect : public GrFragmentProcessor { | 185 class EllipseEffect : public GrFragmentProcessor { |
185 public: | 186 public: |
186 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkPoint& cente
r, SkScalar rx, | 187 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkPoint& cente
r, SkScalar rx, |
187 SkScalar ry); | 188 SkScalar ry); |
188 | 189 |
189 virtual ~EllipseEffect() {}; | 190 virtual ~EllipseEffect() {}; |
190 | 191 |
191 const char* name() const override { return "Ellipse"; } | 192 const char* name() const override { return "Ellipse"; } |
192 | 193 |
193 GrGLFragmentProcessor* createGLInstance() const override; | |
194 | |
195 const SkPoint& getCenter() const { return fCenter; } | 194 const SkPoint& getCenter() const { return fCenter; } |
196 SkVector getRadii() const { return fRadii; } | 195 SkVector getRadii() const { return fRadii; } |
197 | 196 |
198 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } | 197 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
199 | 198 |
200 private: | 199 private: |
201 EllipseEffect(GrPrimitiveEdgeType, const SkPoint& center, SkScalar rx, SkSca
lar ry); | 200 EllipseEffect(GrPrimitiveEdgeType, const SkPoint& center, SkScalar rx, SkSca
lar ry); |
202 | 201 |
| 202 GrGLFragmentProcessor* onCreateGLInstance() const override; |
| 203 |
203 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; | 204 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; |
204 | 205 |
205 bool onIsEqual(const GrFragmentProcessor&) const override; | 206 bool onIsEqual(const GrFragmentProcessor&) const override; |
206 | 207 |
207 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | 208 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
208 | 209 |
209 SkPoint fCenter; | 210 SkPoint fCenter; |
210 SkVector fRadii; | 211 SkVector fRadii; |
211 GrPrimitiveEdgeType fEdgeType; | 212 GrPrimitiveEdgeType fEdgeType; |
212 | 213 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 ////////////////////////////////////////////////////////////////////////////// | 261 ////////////////////////////////////////////////////////////////////////////// |
261 | 262 |
262 class GLEllipseEffect : public GrGLFragmentProcessor { | 263 class GLEllipseEffect : public GrGLFragmentProcessor { |
263 public: | 264 public: |
264 GLEllipseEffect(const GrProcessor&); | 265 GLEllipseEffect(const GrProcessor&); |
265 | 266 |
266 virtual void emitCode(EmitArgs&) override; | 267 virtual void emitCode(EmitArgs&) override; |
267 | 268 |
268 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); | 269 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); |
269 | 270 |
270 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; | 271 protected: |
| 272 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; |
271 | 273 |
272 private: | 274 private: |
273 GrGLProgramDataManager::UniformHandle fEllipseUniform; | 275 GrGLProgramDataManager::UniformHandle fEllipseUniform; |
274 SkPoint fPrevCenter; | 276 SkPoint fPrevCenter; |
275 SkVector fPrevRadii; | 277 SkVector fPrevRadii; |
276 | 278 |
277 typedef GrGLFragmentProcessor INHERITED; | 279 typedef GrGLFragmentProcessor INHERITED; |
278 }; | 280 }; |
279 | 281 |
280 GLEllipseEffect::GLEllipseEffect(const GrProcessor& effect) { | 282 GLEllipseEffect::GLEllipseEffect(const GrProcessor& effect) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 fsBuilder->codeAppendf("\t\t%s = %s;\n", args.fOutputColor, | 327 fsBuilder->codeAppendf("\t\t%s = %s;\n", args.fOutputColor, |
326 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha")
).c_str()); | 328 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha")
).c_str()); |
327 } | 329 } |
328 | 330 |
329 void GLEllipseEffect::GenKey(const GrProcessor& effect, const GrGLSLCaps&, | 331 void GLEllipseEffect::GenKey(const GrProcessor& effect, const GrGLSLCaps&, |
330 GrProcessorKeyBuilder* b) { | 332 GrProcessorKeyBuilder* b) { |
331 const EllipseEffect& ee = effect.cast<EllipseEffect>(); | 333 const EllipseEffect& ee = effect.cast<EllipseEffect>(); |
332 b->add32(ee.getEdgeType()); | 334 b->add32(ee.getEdgeType()); |
333 } | 335 } |
334 | 336 |
335 void GLEllipseEffect::setData(const GrGLProgramDataManager& pdman, const GrProce
ssor& effect) { | 337 void GLEllipseEffect::onSetData(const GrGLProgramDataManager& pdman, const GrPro
cessor& effect) { |
336 const EllipseEffect& ee = effect.cast<EllipseEffect>(); | 338 const EllipseEffect& ee = effect.cast<EllipseEffect>(); |
337 if (ee.getRadii() != fPrevRadii || ee.getCenter() != fPrevCenter) { | 339 if (ee.getRadii() != fPrevRadii || ee.getCenter() != fPrevCenter) { |
338 SkScalar invRXSqd = 1.f / (ee.getRadii().fX * ee.getRadii().fX); | 340 SkScalar invRXSqd = 1.f / (ee.getRadii().fX * ee.getRadii().fX); |
339 SkScalar invRYSqd = 1.f / (ee.getRadii().fY * ee.getRadii().fY); | 341 SkScalar invRYSqd = 1.f / (ee.getRadii().fY * ee.getRadii().fY); |
340 pdman.set4f(fEllipseUniform, ee.getCenter().fX, ee.getCenter().fY, invRX
Sqd, invRYSqd); | 342 pdman.set4f(fEllipseUniform, ee.getCenter().fX, ee.getCenter().fY, invRX
Sqd, invRYSqd); |
341 fPrevCenter = ee.getCenter(); | 343 fPrevCenter = ee.getCenter(); |
342 fPrevRadii = ee.getRadii(); | 344 fPrevRadii = ee.getRadii(); |
343 } | 345 } |
344 } | 346 } |
345 | 347 |
346 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 348 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
347 | 349 |
348 void EllipseEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 350 void EllipseEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
349 GrProcessorKeyBuilder* b) const { | 351 GrProcessorKeyBuilder* b) const { |
350 GLEllipseEffect::GenKey(*this, caps, b); | 352 GLEllipseEffect::GenKey(*this, caps, b); |
351 } | 353 } |
352 | 354 |
353 GrGLFragmentProcessor* EllipseEffect::createGLInstance() const { | 355 GrGLFragmentProcessor* EllipseEffect::onCreateGLInstance() const { |
354 return SkNEW_ARGS(GLEllipseEffect, (*this)); | 356 return SkNEW_ARGS(GLEllipseEffect, (*this)); |
355 } | 357 } |
356 | 358 |
357 ////////////////////////////////////////////////////////////////////////////// | 359 ////////////////////////////////////////////////////////////////////////////// |
358 | 360 |
359 GrFragmentProcessor* GrOvalEffect::Create(GrPrimitiveEdgeType edgeType, const Sk
Rect& oval) { | 361 GrFragmentProcessor* GrOvalEffect::Create(GrPrimitiveEdgeType edgeType, const Sk
Rect& oval) { |
360 if (kHairlineAA_GrProcessorEdgeType == edgeType) { | 362 if (kHairlineAA_GrProcessorEdgeType == edgeType) { |
361 return NULL; | 363 return NULL; |
362 } | 364 } |
363 SkScalar w = oval.width(); | 365 SkScalar w = oval.width(); |
364 SkScalar h = oval.height(); | 366 SkScalar h = oval.height(); |
365 if (SkScalarNearlyEqual(w, h)) { | 367 if (SkScalarNearlyEqual(w, h)) { |
366 w /= 2; | 368 w /= 2; |
367 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval
.fTop + w), w); | 369 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval
.fTop + w), w); |
368 } else { | 370 } else { |
369 w /= 2; | 371 w /= 2; |
370 h /= 2; | 372 h /= 2; |
371 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova
l.fTop + h), w, h); | 373 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova
l.fTop + h), w, h); |
372 } | 374 } |
373 | 375 |
374 return NULL; | 376 return NULL; |
375 } | 377 } |
OLD | NEW |