| 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 "glsl/GrGLSLFragmentProcessor.h" | 13 #include "glsl/GrGLSLFragmentProcessor.h" |
| 14 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 14 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 15 #include "glsl/GrGLSLProgramDataManager.h" | 15 #include "glsl/GrGLSLProgramDataManager.h" |
| 16 #include "glsl/GrGLSLUniformHandler.h" | 16 #include "glsl/GrGLSLUniformHandler.h" |
| 17 | 17 |
| 18 ////////////////////////////////////////////////////////////////////////////// | 18 ////////////////////////////////////////////////////////////////////////////// |
| 19 | 19 |
| 20 class CircleEffect : public GrFragmentProcessor { | 20 class CircleEffect : public GrFragmentProcessor { |
| 21 public: | 21 public: |
| 22 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkPoint& cente
r, SkScalar radius); | 22 static sk_sp<GrFragmentProcessor> Make(GrPrimitiveEdgeType, const SkPoint& c
enter, |
| 23 SkScalar radius); |
| 23 | 24 |
| 24 virtual ~CircleEffect() {}; | 25 virtual ~CircleEffect() {}; |
| 25 | 26 |
| 26 const char* name() const override { return "Circle"; } | 27 const char* name() const override { return "Circle"; } |
| 27 | 28 |
| 28 const SkPoint& getCenter() const { return fCenter; } | 29 const SkPoint& getCenter() const { return fCenter; } |
| 29 SkScalar getRadius() const { return fRadius; } | 30 SkScalar getRadius() const { return fRadius; } |
| 30 | 31 |
| 31 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } | 32 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
| 32 | 33 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 43 | 44 |
| 44 SkPoint fCenter; | 45 SkPoint fCenter; |
| 45 SkScalar fRadius; | 46 SkScalar fRadius; |
| 46 GrPrimitiveEdgeType fEdgeType; | 47 GrPrimitiveEdgeType fEdgeType; |
| 47 | 48 |
| 48 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 49 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 49 | 50 |
| 50 typedef GrFragmentProcessor INHERITED; | 51 typedef GrFragmentProcessor INHERITED; |
| 51 }; | 52 }; |
| 52 | 53 |
| 53 GrFragmentProcessor* CircleEffect::Create(GrPrimitiveEdgeType edgeType, const Sk
Point& center, | 54 sk_sp<GrFragmentProcessor> CircleEffect::Make(GrPrimitiveEdgeType edgeType, cons
t SkPoint& center, |
| 54 SkScalar radius) { | 55 SkScalar radius) { |
| 55 SkASSERT(radius >= 0); | 56 SkASSERT(radius >= 0); |
| 56 return new CircleEffect(edgeType, center, radius); | 57 return sk_sp<GrFragmentProcessor>(new CircleEffect(edgeType, center, radius)
); |
| 57 } | 58 } |
| 58 | 59 |
| 59 void CircleEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { | 60 void CircleEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { |
| 60 inout->mulByUnknownSingleComponent(); | 61 inout->mulByUnknownSingleComponent(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 CircleEffect::CircleEffect(GrPrimitiveEdgeType edgeType, const SkPoint& c, SkSca
lar r) | 64 CircleEffect::CircleEffect(GrPrimitiveEdgeType edgeType, const SkPoint& c, SkSca
lar r) |
| 64 : fCenter(c) | 65 : fCenter(c) |
| 65 , fRadius(r) | 66 , fRadius(r) |
| 66 , fEdgeType(edgeType) { | 67 , fEdgeType(edgeType) { |
| 67 this->initClassID<CircleEffect>(); | 68 this->initClassID<CircleEffect>(); |
| 68 this->setWillReadFragmentPosition(); | 69 this->setWillReadFragmentPosition(); |
| 69 } | 70 } |
| 70 | 71 |
| 71 bool CircleEffect::onIsEqual(const GrFragmentProcessor& other) const { | 72 bool CircleEffect::onIsEqual(const GrFragmentProcessor& other) const { |
| 72 const CircleEffect& ce = other.cast<CircleEffect>(); | 73 const CircleEffect& ce = other.cast<CircleEffect>(); |
| 73 return fEdgeType == ce.fEdgeType && fCenter == ce.fCenter && fRadius == ce.f
Radius; | 74 return fEdgeType == ce.fEdgeType && fCenter == ce.fCenter && fRadius == ce.f
Radius; |
| 74 } | 75 } |
| 75 | 76 |
| 76 ////////////////////////////////////////////////////////////////////////////// | 77 ////////////////////////////////////////////////////////////////////////////// |
| 77 | 78 |
| 78 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(CircleEffect); | 79 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(CircleEffect); |
| 79 | 80 |
| 80 const GrFragmentProcessor* CircleEffect::TestCreate(GrProcessorTestData* d) { | 81 sk_sp<GrFragmentProcessor> CircleEffect::TestCreate(GrProcessorTestData* d) { |
| 81 SkPoint center; | 82 SkPoint center; |
| 82 center.fX = d->fRandom->nextRangeScalar(0.f, 1000.f); | 83 center.fX = d->fRandom->nextRangeScalar(0.f, 1000.f); |
| 83 center.fY = d->fRandom->nextRangeScalar(0.f, 1000.f); | 84 center.fY = d->fRandom->nextRangeScalar(0.f, 1000.f); |
| 84 SkScalar radius = d->fRandom->nextRangeF(0.f, 1000.f); | 85 SkScalar radius = d->fRandom->nextRangeF(0.f, 1000.f); |
| 85 GrPrimitiveEdgeType et; | 86 GrPrimitiveEdgeType et; |
| 86 do { | 87 do { |
| 87 et = (GrPrimitiveEdgeType)d->fRandom->nextULessThan(kGrProcessorEdgeType
Cnt); | 88 et = (GrPrimitiveEdgeType)d->fRandom->nextULessThan(kGrProcessorEdgeType
Cnt); |
| 88 } while (kHairlineAA_GrProcessorEdgeType == et); | 89 } while (kHairlineAA_GrProcessorEdgeType == et); |
| 89 return CircleEffect::Create(et, center, radius); | 90 return CircleEffect::Make(et, center, radius); |
| 90 } | 91 } |
| 91 | 92 |
| 92 ////////////////////////////////////////////////////////////////////////////// | 93 ////////////////////////////////////////////////////////////////////////////// |
| 93 | 94 |
| 94 class GLCircleEffect : public GrGLSLFragmentProcessor { | 95 class GLCircleEffect : public GrGLSLFragmentProcessor { |
| 95 public: | 96 public: |
| 96 GLCircleEffect() : fPrevRadius(-1.0f) { } | 97 GLCircleEffect() : fPrevRadius(-1.0f) { } |
| 97 | 98 |
| 98 virtual void emitCode(EmitArgs&) override; | 99 virtual void emitCode(EmitArgs&) override; |
| 99 | 100 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 } | 177 } |
| 177 | 178 |
| 178 GrGLSLFragmentProcessor* CircleEffect::onCreateGLSLInstance() const { | 179 GrGLSLFragmentProcessor* CircleEffect::onCreateGLSLInstance() const { |
| 179 return new GLCircleEffect; | 180 return new GLCircleEffect; |
| 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 sk_sp<GrFragmentProcessor> Make(GrPrimitiveEdgeType, const SkPoint& c
enter, |
| 187 SkScalar ry); | 188 SkScalar rx, 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 const SkPoint& getCenter() const { return fCenter; } | 194 const SkPoint& getCenter() const { return fCenter; } |
| 194 SkVector getRadii() const { return fRadii; } | 195 SkVector getRadii() const { return fRadii; } |
| 195 | 196 |
| 196 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } | 197 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
| 197 | 198 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 208 | 209 |
| 209 SkPoint fCenter; | 210 SkPoint fCenter; |
| 210 SkVector fRadii; | 211 SkVector fRadii; |
| 211 GrPrimitiveEdgeType fEdgeType; | 212 GrPrimitiveEdgeType fEdgeType; |
| 212 | 213 |
| 213 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 214 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 214 | 215 |
| 215 typedef GrFragmentProcessor INHERITED; | 216 typedef GrFragmentProcessor INHERITED; |
| 216 }; | 217 }; |
| 217 | 218 |
| 218 GrFragmentProcessor* EllipseEffect::Create(GrPrimitiveEdgeType edgeType, | 219 sk_sp<GrFragmentProcessor> EllipseEffect::Make(GrPrimitiveEdgeType edgeType, |
| 219 const SkPoint& center, | 220 const SkPoint& center, |
| 220 SkScalar rx, | 221 SkScalar rx, |
| 221 SkScalar ry) { | 222 SkScalar ry) { |
| 222 SkASSERT(rx >= 0 && ry >= 0); | 223 SkASSERT(rx >= 0 && ry >= 0); |
| 223 return new EllipseEffect(edgeType, center, rx, ry); | 224 return sk_sp<GrFragmentProcessor>(new EllipseEffect(edgeType, center, rx, ry
)); |
| 224 } | 225 } |
| 225 | 226 |
| 226 void EllipseEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { | 227 void EllipseEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { |
| 227 inout->mulByUnknownSingleComponent(); | 228 inout->mulByUnknownSingleComponent(); |
| 228 } | 229 } |
| 229 | 230 |
| 230 EllipseEffect::EllipseEffect(GrPrimitiveEdgeType edgeType, const SkPoint& c, SkS
calar rx, SkScalar ry) | 231 EllipseEffect::EllipseEffect(GrPrimitiveEdgeType edgeType, const SkPoint& c, SkS
calar rx, SkScalar ry) |
| 231 : fCenter(c) | 232 : fCenter(c) |
| 232 , fRadii(SkVector::Make(rx, ry)) | 233 , fRadii(SkVector::Make(rx, ry)) |
| 233 , fEdgeType(edgeType) { | 234 , fEdgeType(edgeType) { |
| 234 this->initClassID<EllipseEffect>(); | 235 this->initClassID<EllipseEffect>(); |
| 235 this->setWillReadFragmentPosition(); | 236 this->setWillReadFragmentPosition(); |
| 236 } | 237 } |
| 237 | 238 |
| 238 bool EllipseEffect::onIsEqual(const GrFragmentProcessor& other) const { | 239 bool EllipseEffect::onIsEqual(const GrFragmentProcessor& other) const { |
| 239 const EllipseEffect& ee = other.cast<EllipseEffect>(); | 240 const EllipseEffect& ee = other.cast<EllipseEffect>(); |
| 240 return fEdgeType == ee.fEdgeType && fCenter == ee.fCenter && fRadii == ee.fR
adii; | 241 return fEdgeType == ee.fEdgeType && fCenter == ee.fCenter && fRadii == ee.fR
adii; |
| 241 } | 242 } |
| 242 | 243 |
| 243 ////////////////////////////////////////////////////////////////////////////// | 244 ////////////////////////////////////////////////////////////////////////////// |
| 244 | 245 |
| 245 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(EllipseEffect); | 246 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(EllipseEffect); |
| 246 | 247 |
| 247 const GrFragmentProcessor* EllipseEffect::TestCreate(GrProcessorTestData* d) { | 248 sk_sp<GrFragmentProcessor> EllipseEffect::TestCreate(GrProcessorTestData* d) { |
| 248 SkPoint center; | 249 SkPoint center; |
| 249 center.fX = d->fRandom->nextRangeScalar(0.f, 1000.f); | 250 center.fX = d->fRandom->nextRangeScalar(0.f, 1000.f); |
| 250 center.fY = d->fRandom->nextRangeScalar(0.f, 1000.f); | 251 center.fY = d->fRandom->nextRangeScalar(0.f, 1000.f); |
| 251 SkScalar rx = d->fRandom->nextRangeF(0.f, 1000.f); | 252 SkScalar rx = d->fRandom->nextRangeF(0.f, 1000.f); |
| 252 SkScalar ry = d->fRandom->nextRangeF(0.f, 1000.f); | 253 SkScalar ry = d->fRandom->nextRangeF(0.f, 1000.f); |
| 253 GrPrimitiveEdgeType et; | 254 GrPrimitiveEdgeType et; |
| 254 do { | 255 do { |
| 255 et = (GrPrimitiveEdgeType)d->fRandom->nextULessThan(kGrProcessorEdgeType
Cnt); | 256 et = (GrPrimitiveEdgeType)d->fRandom->nextULessThan(kGrProcessorEdgeType
Cnt); |
| 256 } while (kHairlineAA_GrProcessorEdgeType == et); | 257 } while (kHairlineAA_GrProcessorEdgeType == et); |
| 257 return EllipseEffect::Create(et, center, rx, ry); | 258 return EllipseEffect::Make(et, center, rx, ry); |
| 258 } | 259 } |
| 259 | 260 |
| 260 ////////////////////////////////////////////////////////////////////////////// | 261 ////////////////////////////////////////////////////////////////////////////// |
| 261 | 262 |
| 262 class GLEllipseEffect : public GrGLSLFragmentProcessor { | 263 class GLEllipseEffect : public GrGLSLFragmentProcessor { |
| 263 public: | 264 public: |
| 264 GLEllipseEffect() { | 265 GLEllipseEffect() { |
| 265 fPrevRadii.fX = -1.0f; | 266 fPrevRadii.fX = -1.0f; |
| 266 } | 267 } |
| 267 | 268 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 GrProcessorKeyBuilder* b) const { | 385 GrProcessorKeyBuilder* b) const { |
| 385 GLEllipseEffect::GenKey(*this, caps, b); | 386 GLEllipseEffect::GenKey(*this, caps, b); |
| 386 } | 387 } |
| 387 | 388 |
| 388 GrGLSLFragmentProcessor* EllipseEffect::onCreateGLSLInstance() const { | 389 GrGLSLFragmentProcessor* EllipseEffect::onCreateGLSLInstance() const { |
| 389 return new GLEllipseEffect; | 390 return new GLEllipseEffect; |
| 390 } | 391 } |
| 391 | 392 |
| 392 ////////////////////////////////////////////////////////////////////////////// | 393 ////////////////////////////////////////////////////////////////////////////// |
| 393 | 394 |
| 394 GrFragmentProcessor* GrOvalEffect::Create(GrPrimitiveEdgeType edgeType, const Sk
Rect& oval) { | 395 sk_sp<GrFragmentProcessor> GrOvalEffect::Make(GrPrimitiveEdgeType edgeType, cons
t SkRect& oval) { |
| 395 if (kHairlineAA_GrProcessorEdgeType == edgeType) { | 396 if (kHairlineAA_GrProcessorEdgeType == edgeType) { |
| 396 return nullptr; | 397 return nullptr; |
| 397 } | 398 } |
| 398 SkScalar w = oval.width(); | 399 SkScalar w = oval.width(); |
| 399 SkScalar h = oval.height(); | 400 SkScalar h = oval.height(); |
| 400 if (SkScalarNearlyEqual(w, h)) { | 401 if (SkScalarNearlyEqual(w, h)) { |
| 401 w /= 2; | 402 w /= 2; |
| 402 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval
.fTop + w), w); | 403 return CircleEffect::Make(edgeType, SkPoint::Make(oval.fLeft + w, oval.f
Top + w), w); |
| 403 } else { | 404 } else { |
| 404 w /= 2; | 405 w /= 2; |
| 405 h /= 2; | 406 h /= 2; |
| 406 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova
l.fTop + h), w, h); | 407 return EllipseEffect::Make(edgeType, SkPoint::Make(oval.fLeft + w, oval.
fTop + h), w, h); |
| 407 } | 408 } |
| 408 | 409 |
| 409 return nullptr; | 410 return nullptr; |
| 410 } | 411 } |
| OLD | NEW |