| 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/GrGLProcessor.h" | 13 #include "gl/GrGLProcessor.h" |
| 14 #include "gl/GrGLSL.h" | 14 #include "gl/GrGLSL.h" |
| 15 #include "gl/builders/GrGLProgramBuilder.h" | 15 #include "gl/builders/GrGLProgramBuilder.h" |
| 16 | 16 |
| 17 ////////////////////////////////////////////////////////////////////////////// | 17 ////////////////////////////////////////////////////////////////////////////// |
| 18 | 18 |
| 19 class CircleEffect : public GrFragmentProcessor { | 19 class CircleEffect : public GrFragmentProcessor { |
| 20 public: | 20 public: |
| 21 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkPoint& cente
r, SkScalar radius); | 21 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkPoint& cente
r, SkScalar radius); |
| 22 | 22 |
| 23 virtual ~CircleEffect() {}; | 23 virtual ~CircleEffect() {}; |
| 24 | 24 |
| 25 const char* name() const override { return "Circle"; } | 25 const char* name() const override { return "Circle"; } |
| 26 | 26 |
| 27 void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) const overri
de; | 27 void getGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const over
ride; |
| 28 | 28 |
| 29 GrGLFragmentProcessor* createGLInstance() const override; | 29 GrGLFragmentProcessor* createGLInstance() const override; |
| 30 | 30 |
| 31 const SkPoint& getCenter() const { return fCenter; } | 31 const SkPoint& getCenter() const { return fCenter; } |
| 32 SkScalar getRadius() const { return fRadius; } | 32 SkScalar getRadius() const { return fRadius; } |
| 33 | 33 |
| 34 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } | 34 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 CircleEffect(GrPrimitiveEdgeType, const SkPoint& center, SkScalar radius); | 37 CircleEffect(GrPrimitiveEdgeType, const SkPoint& center, SkScalar radius); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 public: | 97 public: |
| 98 GLCircleEffect(const GrProcessor&); | 98 GLCircleEffect(const GrProcessor&); |
| 99 | 99 |
| 100 virtual void emitCode(GrGLFPBuilder* builder, | 100 virtual void emitCode(GrGLFPBuilder* builder, |
| 101 const GrFragmentProcessor& fp, | 101 const GrFragmentProcessor& fp, |
| 102 const char* outputColor, | 102 const char* outputColor, |
| 103 const char* inputColor, | 103 const char* inputColor, |
| 104 const TransformedCoordsArray&, | 104 const TransformedCoordsArray&, |
| 105 const TextureSamplerArray&) override; | 105 const TextureSamplerArray&) override; |
| 106 | 106 |
| 107 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); | 107 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); |
| 108 | 108 |
| 109 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; | 109 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; |
| 110 | 110 |
| 111 private: | 111 private: |
| 112 GrGLProgramDataManager::UniformHandle fCircleUniform; | 112 GrGLProgramDataManager::UniformHandle fCircleUniform; |
| 113 SkPoint fPrevCenter; | 113 SkPoint fPrevCenter; |
| 114 SkScalar fPrevRadius; | 114 SkScalar fPrevRadius; |
| 115 | 115 |
| 116 typedef GrGLFragmentProcessor INHERITED; | 116 typedef GrGLFragmentProcessor INHERITED; |
| 117 }; | 117 }; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 if (GrProcessorEdgeTypeIsAA(ce.getEdgeType())) { | 149 if (GrProcessorEdgeTypeIsAA(ce.getEdgeType())) { |
| 150 fsBuilder->codeAppend("\t\td = clamp(d, 0.0, 1.0);\n"); | 150 fsBuilder->codeAppend("\t\td = clamp(d, 0.0, 1.0);\n"); |
| 151 } else { | 151 } else { |
| 152 fsBuilder->codeAppend("\t\td = d > 0.5 ? 1.0 : 0.0;\n"); | 152 fsBuilder->codeAppend("\t\td = d > 0.5 ? 1.0 : 0.0;\n"); |
| 153 } | 153 } |
| 154 | 154 |
| 155 fsBuilder->codeAppendf("\t\t%s = %s;\n", outputColor, | 155 fsBuilder->codeAppendf("\t\t%s = %s;\n", outputColor, |
| 156 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("d")).c_str())
; | 156 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("d")).c_str())
; |
| 157 } | 157 } |
| 158 | 158 |
| 159 void GLCircleEffect::GenKey(const GrProcessor& processor, const GrGLCaps&, | 159 void GLCircleEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps&, |
| 160 GrProcessorKeyBuilder* b) { | 160 GrProcessorKeyBuilder* b) { |
| 161 const CircleEffect& ce = processor.cast<CircleEffect>(); | 161 const CircleEffect& ce = processor.cast<CircleEffect>(); |
| 162 b->add32(ce.getEdgeType()); | 162 b->add32(ce.getEdgeType()); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void GLCircleEffect::setData(const GrGLProgramDataManager& pdman, const GrProces
sor& processor) { | 165 void GLCircleEffect::setData(const GrGLProgramDataManager& pdman, const GrProces
sor& processor) { |
| 166 const CircleEffect& ce = processor.cast<CircleEffect>(); | 166 const CircleEffect& ce = processor.cast<CircleEffect>(); |
| 167 if (ce.getRadius() != fPrevRadius || ce.getCenter() != fPrevCenter) { | 167 if (ce.getRadius() != fPrevRadius || ce.getCenter() != fPrevCenter) { |
| 168 SkScalar radius = ce.getRadius(); | 168 SkScalar radius = ce.getRadius(); |
| 169 if (GrProcessorEdgeTypeIsInverseFill(ce.getEdgeType())) { | 169 if (GrProcessorEdgeTypeIsInverseFill(ce.getEdgeType())) { |
| 170 radius -= 0.5f; | 170 radius -= 0.5f; |
| 171 } else { | 171 } else { |
| 172 radius += 0.5f; | 172 radius += 0.5f; |
| 173 } | 173 } |
| 174 pdman.set3f(fCircleUniform, ce.getCenter().fX, ce.getCenter().fY, radius
); | 174 pdman.set3f(fCircleUniform, ce.getCenter().fX, ce.getCenter().fY, radius
); |
| 175 fPrevCenter = ce.getCenter(); | 175 fPrevCenter = ce.getCenter(); |
| 176 fPrevRadius = ce.getRadius(); | 176 fPrevRadius = ce.getRadius(); |
| 177 } | 177 } |
| 178 } | 178 } |
| 179 | 179 |
| 180 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 180 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 181 | 181 |
| 182 void CircleEffect::getGLProcessorKey(const GrGLCaps& caps, | 182 void CircleEffect::getGLProcessorKey(const GrGLSLCaps& caps, |
| 183 GrProcessorKeyBuilder* b) const { | 183 GrProcessorKeyBuilder* b) const { |
| 184 GLCircleEffect::GenKey(*this, caps, b); | 184 GLCircleEffect::GenKey(*this, caps, b); |
| 185 } | 185 } |
| 186 | 186 |
| 187 GrGLFragmentProcessor* CircleEffect::createGLInstance() const { | 187 GrGLFragmentProcessor* CircleEffect::createGLInstance() const { |
| 188 return SkNEW_ARGS(GLCircleEffect, (*this)); | 188 return SkNEW_ARGS(GLCircleEffect, (*this)); |
| 189 } | 189 } |
| 190 | 190 |
| 191 ////////////////////////////////////////////////////////////////////////////// | 191 ////////////////////////////////////////////////////////////////////////////// |
| 192 | 192 |
| 193 class EllipseEffect : public GrFragmentProcessor { | 193 class EllipseEffect : public GrFragmentProcessor { |
| 194 public: | 194 public: |
| 195 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkPoint& cente
r, SkScalar rx, | 195 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkPoint& cente
r, SkScalar rx, |
| 196 SkScalar ry); | 196 SkScalar ry); |
| 197 | 197 |
| 198 virtual ~EllipseEffect() {}; | 198 virtual ~EllipseEffect() {}; |
| 199 | 199 |
| 200 const char* name() const override { return "Ellipse"; } | 200 const char* name() const override { return "Ellipse"; } |
| 201 | 201 |
| 202 void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) const overri
de; | 202 void getGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const over
ride; |
| 203 | 203 |
| 204 GrGLFragmentProcessor* createGLInstance() const override; | 204 GrGLFragmentProcessor* createGLInstance() const override; |
| 205 | 205 |
| 206 const SkPoint& getCenter() const { return fCenter; } | 206 const SkPoint& getCenter() const { return fCenter; } |
| 207 SkVector getRadii() const { return fRadii; } | 207 SkVector getRadii() const { return fRadii; } |
| 208 | 208 |
| 209 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } | 209 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
| 210 | 210 |
| 211 private: | 211 private: |
| 212 EllipseEffect(GrPrimitiveEdgeType, const SkPoint& center, SkScalar rx, SkSca
lar ry); | 212 EllipseEffect(GrPrimitiveEdgeType, const SkPoint& center, SkScalar rx, SkSca
lar ry); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 public: | 275 public: |
| 276 GLEllipseEffect(const GrProcessor&); | 276 GLEllipseEffect(const GrProcessor&); |
| 277 | 277 |
| 278 virtual void emitCode(GrGLFPBuilder* builder, | 278 virtual void emitCode(GrGLFPBuilder* builder, |
| 279 const GrFragmentProcessor& fp, | 279 const GrFragmentProcessor& fp, |
| 280 const char* outputColor, | 280 const char* outputColor, |
| 281 const char* inputColor, | 281 const char* inputColor, |
| 282 const TransformedCoordsArray&, | 282 const TransformedCoordsArray&, |
| 283 const TextureSamplerArray&) override; | 283 const TextureSamplerArray&) override; |
| 284 | 284 |
| 285 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); | 285 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); |
| 286 | 286 |
| 287 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; | 287 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; |
| 288 | 288 |
| 289 private: | 289 private: |
| 290 GrGLProgramDataManager::UniformHandle fEllipseUniform; | 290 GrGLProgramDataManager::UniformHandle fEllipseUniform; |
| 291 SkPoint fPrevCenter; | 291 SkPoint fPrevCenter; |
| 292 SkVector fPrevRadii; | 292 SkVector fPrevRadii; |
| 293 | 293 |
| 294 typedef GrGLFragmentProcessor INHERITED; | 294 typedef GrGLFragmentProcessor INHERITED; |
| 295 }; | 295 }; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 fsBuilder->codeAppend("\t\tfloat alpha = approx_dist > 0.0 ? 1.0 : 0
.0;\n"); | 340 fsBuilder->codeAppend("\t\tfloat alpha = approx_dist > 0.0 ? 1.0 : 0
.0;\n"); |
| 341 break; | 341 break; |
| 342 case kHairlineAA_GrProcessorEdgeType: | 342 case kHairlineAA_GrProcessorEdgeType: |
| 343 SkFAIL("Hairline not expected here."); | 343 SkFAIL("Hairline not expected here."); |
| 344 } | 344 } |
| 345 | 345 |
| 346 fsBuilder->codeAppendf("\t\t%s = %s;\n", outputColor, | 346 fsBuilder->codeAppendf("\t\t%s = %s;\n", outputColor, |
| 347 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st
r()); | 347 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st
r()); |
| 348 } | 348 } |
| 349 | 349 |
| 350 void GLEllipseEffect::GenKey(const GrProcessor& effect, const GrGLCaps&, | 350 void GLEllipseEffect::GenKey(const GrProcessor& effect, const GrGLSLCaps&, |
| 351 GrProcessorKeyBuilder* b) { | 351 GrProcessorKeyBuilder* b) { |
| 352 const EllipseEffect& ee = effect.cast<EllipseEffect>(); | 352 const EllipseEffect& ee = effect.cast<EllipseEffect>(); |
| 353 b->add32(ee.getEdgeType()); | 353 b->add32(ee.getEdgeType()); |
| 354 } | 354 } |
| 355 | 355 |
| 356 void GLEllipseEffect::setData(const GrGLProgramDataManager& pdman, const GrProce
ssor& effect) { | 356 void GLEllipseEffect::setData(const GrGLProgramDataManager& pdman, const GrProce
ssor& effect) { |
| 357 const EllipseEffect& ee = effect.cast<EllipseEffect>(); | 357 const EllipseEffect& ee = effect.cast<EllipseEffect>(); |
| 358 if (ee.getRadii() != fPrevRadii || ee.getCenter() != fPrevCenter) { | 358 if (ee.getRadii() != fPrevRadii || ee.getCenter() != fPrevCenter) { |
| 359 SkScalar invRXSqd = 1.f / (ee.getRadii().fX * ee.getRadii().fX); | 359 SkScalar invRXSqd = 1.f / (ee.getRadii().fX * ee.getRadii().fX); |
| 360 SkScalar invRYSqd = 1.f / (ee.getRadii().fY * ee.getRadii().fY); | 360 SkScalar invRYSqd = 1.f / (ee.getRadii().fY * ee.getRadii().fY); |
| 361 pdman.set4f(fEllipseUniform, ee.getCenter().fX, ee.getCenter().fY, invRX
Sqd, invRYSqd); | 361 pdman.set4f(fEllipseUniform, ee.getCenter().fX, ee.getCenter().fY, invRX
Sqd, invRYSqd); |
| 362 fPrevCenter = ee.getCenter(); | 362 fPrevCenter = ee.getCenter(); |
| 363 fPrevRadii = ee.getRadii(); | 363 fPrevRadii = ee.getRadii(); |
| 364 } | 364 } |
| 365 } | 365 } |
| 366 | 366 |
| 367 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 367 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 368 | 368 |
| 369 void EllipseEffect::getGLProcessorKey(const GrGLCaps& caps, | 369 void EllipseEffect::getGLProcessorKey(const GrGLSLCaps& caps, |
| 370 GrProcessorKeyBuilder* b) const { | 370 GrProcessorKeyBuilder* b) const { |
| 371 GLEllipseEffect::GenKey(*this, caps, b); | 371 GLEllipseEffect::GenKey(*this, caps, b); |
| 372 } | 372 } |
| 373 | 373 |
| 374 GrGLFragmentProcessor* EllipseEffect::createGLInstance() const { | 374 GrGLFragmentProcessor* EllipseEffect::createGLInstance() const { |
| 375 return SkNEW_ARGS(GLEllipseEffect, (*this)); | 375 return SkNEW_ARGS(GLEllipseEffect, (*this)); |
| 376 } | 376 } |
| 377 | 377 |
| 378 ////////////////////////////////////////////////////////////////////////////// | 378 ////////////////////////////////////////////////////////////////////////////// |
| 379 | 379 |
| 380 GrFragmentProcessor* GrOvalEffect::Create(GrPrimitiveEdgeType edgeType, const Sk
Rect& oval) { | 380 GrFragmentProcessor* GrOvalEffect::Create(GrPrimitiveEdgeType edgeType, const Sk
Rect& oval) { |
| 381 if (kHairlineAA_GrProcessorEdgeType == edgeType) { | 381 if (kHairlineAA_GrProcessorEdgeType == edgeType) { |
| 382 return NULL; | 382 return NULL; |
| 383 } | 383 } |
| 384 SkScalar w = oval.width(); | 384 SkScalar w = oval.width(); |
| 385 SkScalar h = oval.height(); | 385 SkScalar h = oval.height(); |
| 386 if (SkScalarNearlyEqual(w, h)) { | 386 if (SkScalarNearlyEqual(w, h)) { |
| 387 w /= 2; | 387 w /= 2; |
| 388 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval
.fTop + w), w); | 388 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval
.fTop + w), w); |
| 389 } else { | 389 } else { |
| 390 w /= 2; | 390 w /= 2; |
| 391 h /= 2; | 391 h /= 2; |
| 392 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova
l.fTop + h), w, h); | 392 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova
l.fTop + h), w, h); |
| 393 } | 393 } |
| 394 | 394 |
| 395 return NULL; | 395 return NULL; |
| 396 } | 396 } |
| OLD | NEW |