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 void getGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const over
ride; | |
27 | |
28 GrGLFragmentProcessor* createGLInstance() const override; | 26 GrGLFragmentProcessor* createGLInstance() const override; |
29 | 27 |
30 const SkPoint& getCenter() const { return fCenter; } | 28 const SkPoint& getCenter() const { return fCenter; } |
31 SkScalar getRadius() const { return fRadius; } | 29 SkScalar getRadius() const { return fRadius; } |
32 | 30 |
33 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } | 31 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
34 | 32 |
35 private: | 33 private: |
36 CircleEffect(GrPrimitiveEdgeType, const SkPoint& center, SkScalar radius); | 34 CircleEffect(GrPrimitiveEdgeType, const SkPoint& center, SkScalar radius); |
37 | 35 |
| 36 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; |
| 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 |
46 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 46 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
47 | 47 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 } | 163 } |
164 pdman.set4f(fCircleUniform, ce.getCenter().fX, ce.getCenter().fY, radius
, | 164 pdman.set4f(fCircleUniform, ce.getCenter().fX, ce.getCenter().fY, radius
, |
165 SkScalarInvert(radius)); | 165 SkScalarInvert(radius)); |
166 fPrevCenter = ce.getCenter(); | 166 fPrevCenter = ce.getCenter(); |
167 fPrevRadius = ce.getRadius(); | 167 fPrevRadius = ce.getRadius(); |
168 } | 168 } |
169 } | 169 } |
170 | 170 |
171 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 171 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
172 | 172 |
173 void CircleEffect::getGLProcessorKey(const GrGLSLCaps& caps, | 173 void CircleEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
174 GrProcessorKeyBuilder* b) const { | 174 GrProcessorKeyBuilder* b) const { |
175 GLCircleEffect::GenKey(*this, caps, b); | 175 GLCircleEffect::GenKey(*this, caps, b); |
176 } | 176 } |
177 | 177 |
178 GrGLFragmentProcessor* CircleEffect::createGLInstance() const { | 178 GrGLFragmentProcessor* CircleEffect::createGLInstance() const { |
179 return SkNEW_ARGS(GLCircleEffect, (*this)); | 179 return SkNEW_ARGS(GLCircleEffect, (*this)); |
180 } | 180 } |
181 | 181 |
182 ////////////////////////////////////////////////////////////////////////////// | 182 ////////////////////////////////////////////////////////////////////////////// |
183 | 183 |
184 class EllipseEffect : public GrFragmentProcessor { | 184 class EllipseEffect : public GrFragmentProcessor { |
185 public: | 185 public: |
186 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkPoint& cente
r, SkScalar rx, | 186 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkPoint& cente
r, SkScalar rx, |
187 SkScalar ry); | 187 SkScalar ry); |
188 | 188 |
189 virtual ~EllipseEffect() {}; | 189 virtual ~EllipseEffect() {}; |
190 | 190 |
191 const char* name() const override { return "Ellipse"; } | 191 const char* name() const override { return "Ellipse"; } |
192 | 192 |
193 void getGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const over
ride; | |
194 | |
195 GrGLFragmentProcessor* createGLInstance() const override; | 193 GrGLFragmentProcessor* createGLInstance() const override; |
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 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } | 198 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
201 | 199 |
202 private: | 200 private: |
203 EllipseEffect(GrPrimitiveEdgeType, const SkPoint& center, SkScalar rx, SkSca
lar ry); | 201 EllipseEffect(GrPrimitiveEdgeType, const SkPoint& center, SkScalar rx, SkSca
lar ry); |
204 | 202 |
| 203 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; |
| 204 |
205 bool onIsEqual(const GrFragmentProcessor&) const override; | 205 bool onIsEqual(const GrFragmentProcessor&) const override; |
206 | 206 |
207 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | 207 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
208 | 208 |
209 SkPoint fCenter; | 209 SkPoint fCenter; |
210 SkVector fRadii; | 210 SkVector fRadii; |
211 GrPrimitiveEdgeType fEdgeType; | 211 GrPrimitiveEdgeType fEdgeType; |
212 | 212 |
213 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 213 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
214 | 214 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 SkScalar invRXSqd = 1.f / (ee.getRadii().fX * ee.getRadii().fX); | 337 SkScalar invRXSqd = 1.f / (ee.getRadii().fX * ee.getRadii().fX); |
338 SkScalar invRYSqd = 1.f / (ee.getRadii().fY * ee.getRadii().fY); | 338 SkScalar invRYSqd = 1.f / (ee.getRadii().fY * ee.getRadii().fY); |
339 pdman.set4f(fEllipseUniform, ee.getCenter().fX, ee.getCenter().fY, invRX
Sqd, invRYSqd); | 339 pdman.set4f(fEllipseUniform, ee.getCenter().fX, ee.getCenter().fY, invRX
Sqd, invRYSqd); |
340 fPrevCenter = ee.getCenter(); | 340 fPrevCenter = ee.getCenter(); |
341 fPrevRadii = ee.getRadii(); | 341 fPrevRadii = ee.getRadii(); |
342 } | 342 } |
343 } | 343 } |
344 | 344 |
345 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 345 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
346 | 346 |
347 void EllipseEffect::getGLProcessorKey(const GrGLSLCaps& caps, | 347 void EllipseEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
348 GrProcessorKeyBuilder* b) const { | 348 GrProcessorKeyBuilder* b) const { |
349 GLEllipseEffect::GenKey(*this, caps, b); | 349 GLEllipseEffect::GenKey(*this, caps, b); |
350 } | 350 } |
351 | 351 |
352 GrGLFragmentProcessor* EllipseEffect::createGLInstance() const { | 352 GrGLFragmentProcessor* EllipseEffect::createGLInstance() const { |
353 return SkNEW_ARGS(GLEllipseEffect, (*this)); | 353 return SkNEW_ARGS(GLEllipseEffect, (*this)); |
354 } | 354 } |
355 | 355 |
356 ////////////////////////////////////////////////////////////////////////////// | 356 ////////////////////////////////////////////////////////////////////////////// |
357 | 357 |
358 GrFragmentProcessor* GrOvalEffect::Create(GrPrimitiveEdgeType edgeType, const Sk
Rect& oval) { | 358 GrFragmentProcessor* GrOvalEffect::Create(GrPrimitiveEdgeType edgeType, const Sk
Rect& oval) { |
359 if (kHairlineAA_GrProcessorEdgeType == edgeType) { | 359 if (kHairlineAA_GrProcessorEdgeType == edgeType) { |
360 return NULL; | 360 return NULL; |
361 } | 361 } |
362 SkScalar w = oval.width(); | 362 SkScalar w = oval.width(); |
363 SkScalar h = oval.height(); | 363 SkScalar h = oval.height(); |
364 if (SkScalarNearlyEqual(w, h)) { | 364 if (SkScalarNearlyEqual(w, h)) { |
365 w /= 2; | 365 w /= 2; |
366 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval
.fTop + w), w); | 366 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval
.fTop + w), w); |
367 } else { | 367 } else { |
368 w /= 2; | 368 w /= 2; |
369 h /= 2; | 369 h /= 2; |
370 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova
l.fTop + h), w, h); | 370 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova
l.fTop + h), w, h); |
371 } | 371 } |
372 | 372 |
373 return NULL; | 373 return NULL; |
374 } | 374 } |
OLD | NEW |