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