| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "GrOvalRenderer.h" | 8 #include "GrOvalRenderer.h" |
| 9 | 9 |
| 10 #include "GrEffect.h" | 10 #include "GrEffect.h" |
| 11 #include "gl/GrGLEffect.h" | 11 #include "gl/GrGLEffect.h" |
| 12 #include "gl/GrGLSL.h" | 12 #include "gl/GrGLSL.h" |
| 13 #include "GrTBackendEffectFactory.h" | 13 #include "GrTBackendEffectFactory.h" |
| 14 | 14 |
| 15 #include "GrDrawState.h" | 15 #include "GrDrawState.h" |
| 16 #include "GrDrawTarget.h" | 16 #include "GrDrawTarget.h" |
| 17 #include "GrGpu.h" | 17 #include "GrGpu.h" |
| 18 | 18 |
| 19 #include "SkRRect.h" | 19 #include "SkRRect.h" |
| 20 #include "SkStrokeRec.h" | 20 #include "SkStrokeRec.h" |
| 21 | 21 |
| 22 #include "effects/GrVertexEffect.h" |
| 23 |
| 22 SK_DEFINE_INST_COUNT(GrOvalRenderer) | 24 SK_DEFINE_INST_COUNT(GrOvalRenderer) |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 struct CircleVertex { | 28 struct CircleVertex { |
| 27 GrPoint fPos; | 29 GrPoint fPos; |
| 28 GrPoint fOffset; | 30 GrPoint fOffset; |
| 29 SkScalar fOuterRadius; | 31 SkScalar fOuterRadius; |
| 30 SkScalar fInnerRadius; | 32 SkScalar fInnerRadius; |
| 31 }; | 33 }; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 49 | 51 |
| 50 } | 52 } |
| 51 | 53 |
| 52 /////////////////////////////////////////////////////////////////////////////// | 54 /////////////////////////////////////////////////////////////////////////////// |
| 53 | 55 |
| 54 /** | 56 /** |
| 55 * The output of this effect is a modulation of the input color and coverage for
a circle, | 57 * The output of this effect is a modulation of the input color and coverage for
a circle, |
| 56 * specified as offset_x, offset_y (both from center point), outer radius and in
ner radius. | 58 * specified as offset_x, offset_y (both from center point), outer radius and in
ner radius. |
| 57 */ | 59 */ |
| 58 | 60 |
| 59 class CircleEdgeEffect : public GrEffect { | 61 class CircleEdgeEffect : public GrVertexEffect { |
| 60 public: | 62 public: |
| 61 static GrEffectRef* Create(bool stroke) { | 63 static GrEffectRef* Create(bool stroke) { |
| 62 GR_CREATE_STATIC_EFFECT(gCircleStrokeEdge, CircleEdgeEffect, (true)); | 64 GR_CREATE_STATIC_EFFECT(gCircleStrokeEdge, CircleEdgeEffect, (true)); |
| 63 GR_CREATE_STATIC_EFFECT(gCircleFillEdge, CircleEdgeEffect, (false)); | 65 GR_CREATE_STATIC_EFFECT(gCircleFillEdge, CircleEdgeEffect, (false)); |
| 64 | 66 |
| 65 if (stroke) { | 67 if (stroke) { |
| 66 gCircleStrokeEdge->ref(); | 68 gCircleStrokeEdge->ref(); |
| 67 return gCircleStrokeEdge; | 69 return gCircleStrokeEdge; |
| 68 } else { | 70 } else { |
| 69 gCircleFillEdge->ref(); | 71 gCircleFillEdge->ref(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 } | 129 } |
| 128 | 130 |
| 129 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE {} | 131 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE {} |
| 130 | 132 |
| 131 private: | 133 private: |
| 132 typedef GrGLEffect INHERITED; | 134 typedef GrGLEffect INHERITED; |
| 133 }; | 135 }; |
| 134 | 136 |
| 135 | 137 |
| 136 private: | 138 private: |
| 137 CircleEdgeEffect(bool stroke) : GrEffect() { | 139 CircleEdgeEffect(bool stroke) : GrVertexEffect() { |
| 138 this->addVertexAttrib(kVec4f_GrSLType); | 140 this->addVertexAttrib(kVec4f_GrSLType); |
| 139 fStroke = stroke; | 141 fStroke = stroke; |
| 140 } | 142 } |
| 141 | 143 |
| 142 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { | 144 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { |
| 143 const CircleEdgeEffect& cee = CastEffect<CircleEdgeEffect>(other); | 145 const CircleEdgeEffect& cee = CastEffect<CircleEdgeEffect>(other); |
| 144 return cee.fStroke == fStroke; | 146 return cee.fStroke == fStroke; |
| 145 } | 147 } |
| 146 | 148 |
| 147 bool fStroke; | 149 bool fStroke; |
| 148 | 150 |
| 149 GR_DECLARE_EFFECT_TEST; | 151 GR_DECLARE_EFFECT_TEST; |
| 150 | 152 |
| 151 typedef GrEffect INHERITED; | 153 typedef GrVertexEffect INHERITED; |
| 152 }; | 154 }; |
| 153 | 155 |
| 154 GR_DEFINE_EFFECT_TEST(CircleEdgeEffect); | 156 GR_DEFINE_EFFECT_TEST(CircleEdgeEffect); |
| 155 | 157 |
| 156 GrEffectRef* CircleEdgeEffect::TestCreate(SkRandom* random, | 158 GrEffectRef* CircleEdgeEffect::TestCreate(SkRandom* random, |
| 157 GrContext* context, | 159 GrContext* context, |
| 158 const GrDrawTargetCaps&, | 160 const GrDrawTargetCaps&, |
| 159 GrTexture* textures[]) { | 161 GrTexture* textures[]) { |
| 160 return CircleEdgeEffect::Create(random->nextBool()); | 162 return CircleEdgeEffect::Create(random->nextBool()); |
| 161 } | 163 } |
| 162 | 164 |
| 163 /////////////////////////////////////////////////////////////////////////////// | 165 /////////////////////////////////////////////////////////////////////////////// |
| 164 | 166 |
| 165 /** | 167 /** |
| 166 * The output of this effect is a modulation of the input color and coverage for
an axis-aligned | 168 * The output of this effect is a modulation of the input color and coverage for
an axis-aligned |
| 167 * ellipse, specified as a 2D offset from center, and the reciprocals of the out
er and inner radii, | 169 * ellipse, specified as a 2D offset from center, and the reciprocals of the out
er and inner radii, |
| 168 * in both x and y directions. | 170 * in both x and y directions. |
| 169 * | 171 * |
| 170 * We are using an implicit function of x^2/a^2 + y^2/b^2 - 1 = 0. | 172 * We are using an implicit function of x^2/a^2 + y^2/b^2 - 1 = 0. |
| 171 */ | 173 */ |
| 172 | 174 |
| 173 class EllipseEdgeEffect : public GrEffect { | 175 class EllipseEdgeEffect : public GrVertexEffect { |
| 174 public: | 176 public: |
| 175 static GrEffectRef* Create(bool stroke) { | 177 static GrEffectRef* Create(bool stroke) { |
| 176 GR_CREATE_STATIC_EFFECT(gEllipseStrokeEdge, EllipseEdgeEffect, (true)); | 178 GR_CREATE_STATIC_EFFECT(gEllipseStrokeEdge, EllipseEdgeEffect, (true)); |
| 177 GR_CREATE_STATIC_EFFECT(gEllipseFillEdge, EllipseEdgeEffect, (false)); | 179 GR_CREATE_STATIC_EFFECT(gEllipseFillEdge, EllipseEdgeEffect, (false)); |
| 178 | 180 |
| 179 if (stroke) { | 181 if (stroke) { |
| 180 gEllipseStrokeEdge->ref(); | 182 gEllipseStrokeEdge->ref(); |
| 181 return gEllipseStrokeEdge; | 183 return gEllipseStrokeEdge; |
| 182 } else { | 184 } else { |
| 183 gEllipseFillEdge->ref(); | 185 gEllipseFillEdge->ref(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 264 } |
| 263 | 265 |
| 264 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE { | 266 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE { |
| 265 } | 267 } |
| 266 | 268 |
| 267 private: | 269 private: |
| 268 typedef GrGLEffect INHERITED; | 270 typedef GrGLEffect INHERITED; |
| 269 }; | 271 }; |
| 270 | 272 |
| 271 private: | 273 private: |
| 272 EllipseEdgeEffect(bool stroke) : GrEffect() { | 274 EllipseEdgeEffect(bool stroke) : GrVertexEffect() { |
| 273 this->addVertexAttrib(kVec2f_GrSLType); | 275 this->addVertexAttrib(kVec2f_GrSLType); |
| 274 this->addVertexAttrib(kVec4f_GrSLType); | 276 this->addVertexAttrib(kVec4f_GrSLType); |
| 275 fStroke = stroke; | 277 fStroke = stroke; |
| 276 } | 278 } |
| 277 | 279 |
| 278 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { | 280 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { |
| 279 const EllipseEdgeEffect& eee = CastEffect<EllipseEdgeEffect>(other); | 281 const EllipseEdgeEffect& eee = CastEffect<EllipseEdgeEffect>(other); |
| 280 return eee.fStroke == fStroke; | 282 return eee.fStroke == fStroke; |
| 281 } | 283 } |
| 282 | 284 |
| 283 bool fStroke; | 285 bool fStroke; |
| 284 | 286 |
| 285 GR_DECLARE_EFFECT_TEST; | 287 GR_DECLARE_EFFECT_TEST; |
| 286 | 288 |
| 287 typedef GrEffect INHERITED; | 289 typedef GrVertexEffect INHERITED; |
| 288 }; | 290 }; |
| 289 | 291 |
| 290 GR_DEFINE_EFFECT_TEST(EllipseEdgeEffect); | 292 GR_DEFINE_EFFECT_TEST(EllipseEdgeEffect); |
| 291 | 293 |
| 292 GrEffectRef* EllipseEdgeEffect::TestCreate(SkRandom* random, | 294 GrEffectRef* EllipseEdgeEffect::TestCreate(SkRandom* random, |
| 293 GrContext* context, | 295 GrContext* context, |
| 294 const GrDrawTargetCaps&, | 296 const GrDrawTargetCaps&, |
| 295 GrTexture* textures[]) { | 297 GrTexture* textures[]) { |
| 296 return EllipseEdgeEffect::Create(random->nextBool()); | 298 return EllipseEdgeEffect::Create(random->nextBool()); |
| 297 } | 299 } |
| 298 | 300 |
| 299 /////////////////////////////////////////////////////////////////////////////// | 301 /////////////////////////////////////////////////////////////////////////////// |
| 300 | 302 |
| 301 /** | 303 /** |
| 302 * The output of this effect is a modulation of the input color and coverage for
an ellipse, | 304 * The output of this effect is a modulation of the input color and coverage for
an ellipse, |
| 303 * specified as a 2D offset from center for both the outer and inner paths (if s
troked). The | 305 * specified as a 2D offset from center for both the outer and inner paths (if s
troked). The |
| 304 * implict equation used is for a unit circle (x^2 + y^2 - 1 = 0) and the edge c
orrected by | 306 * implict equation used is for a unit circle (x^2 + y^2 - 1 = 0) and the edge c
orrected by |
| 305 * using differentials. | 307 * using differentials. |
| 306 * | 308 * |
| 307 * The result is device-independent and can be used with any affine matrix. | 309 * The result is device-independent and can be used with any affine matrix. |
| 308 */ | 310 */ |
| 309 | 311 |
| 310 class DIEllipseEdgeEffect : public GrEffect { | 312 class DIEllipseEdgeEffect : public GrVertexEffect { |
| 311 public: | 313 public: |
| 312 enum Mode { kStroke = 0, kHairline, kFill }; | 314 enum Mode { kStroke = 0, kHairline, kFill }; |
| 313 | 315 |
| 314 static GrEffectRef* Create(Mode mode) { | 316 static GrEffectRef* Create(Mode mode) { |
| 315 GR_CREATE_STATIC_EFFECT(gEllipseStrokeEdge, DIEllipseEdgeEffect, (kStrok
e)); | 317 GR_CREATE_STATIC_EFFECT(gEllipseStrokeEdge, DIEllipseEdgeEffect, (kStrok
e)); |
| 316 GR_CREATE_STATIC_EFFECT(gEllipseHairlineEdge, DIEllipseEdgeEffect, (kHai
rline)); | 318 GR_CREATE_STATIC_EFFECT(gEllipseHairlineEdge, DIEllipseEdgeEffect, (kHai
rline)); |
| 317 GR_CREATE_STATIC_EFFECT(gEllipseFillEdge, DIEllipseEdgeEffect, (kFill)); | 319 GR_CREATE_STATIC_EFFECT(gEllipseFillEdge, DIEllipseEdgeEffect, (kFill)); |
| 318 | 320 |
| 319 if (kStroke == mode) { | 321 if (kStroke == mode) { |
| 320 gEllipseStrokeEdge->ref(); | 322 gEllipseStrokeEdge->ref(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 } | 425 } |
| 424 | 426 |
| 425 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE { | 427 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE { |
| 426 } | 428 } |
| 427 | 429 |
| 428 private: | 430 private: |
| 429 typedef GrGLEffect INHERITED; | 431 typedef GrGLEffect INHERITED; |
| 430 }; | 432 }; |
| 431 | 433 |
| 432 private: | 434 private: |
| 433 DIEllipseEdgeEffect(Mode mode) : GrEffect() { | 435 DIEllipseEdgeEffect(Mode mode) : GrVertexEffect() { |
| 434 this->addVertexAttrib(kVec2f_GrSLType); | 436 this->addVertexAttrib(kVec2f_GrSLType); |
| 435 this->addVertexAttrib(kVec2f_GrSLType); | 437 this->addVertexAttrib(kVec2f_GrSLType); |
| 436 fMode = mode; | 438 fMode = mode; |
| 437 } | 439 } |
| 438 | 440 |
| 439 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { | 441 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { |
| 440 const DIEllipseEdgeEffect& eee = CastEffect<DIEllipseEdgeEffect>(other); | 442 const DIEllipseEdgeEffect& eee = CastEffect<DIEllipseEdgeEffect>(other); |
| 441 return eee.fMode == fMode; | 443 return eee.fMode == fMode; |
| 442 } | 444 } |
| 443 | 445 |
| 444 Mode fMode; | 446 Mode fMode; |
| 445 | 447 |
| 446 GR_DECLARE_EFFECT_TEST; | 448 GR_DECLARE_EFFECT_TEST; |
| 447 | 449 |
| 448 typedef GrEffect INHERITED; | 450 typedef GrVertexEffect INHERITED; |
| 449 }; | 451 }; |
| 450 | 452 |
| 451 GR_DEFINE_EFFECT_TEST(DIEllipseEdgeEffect); | 453 GR_DEFINE_EFFECT_TEST(DIEllipseEdgeEffect); |
| 452 | 454 |
| 453 GrEffectRef* DIEllipseEdgeEffect::TestCreate(SkRandom* random, | 455 GrEffectRef* DIEllipseEdgeEffect::TestCreate(SkRandom* random, |
| 454 GrContext* context, | 456 GrContext* context, |
| 455 const GrDrawTargetCaps&, | 457 const GrDrawTargetCaps&, |
| 456 GrTexture* textures[]) { | 458 GrTexture* textures[]) { |
| 457 return DIEllipseEdgeEffect::Create((Mode)(random->nextRangeU(0,2))); | 459 return DIEllipseEdgeEffect::Create((Mode)(random->nextRangeU(0,2))); |
| 458 } | 460 } |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1138 } | 1140 } |
| 1139 | 1141 |
| 1140 // drop out the middle quad if we're stroked | 1142 // drop out the middle quad if we're stroked |
| 1141 int indexCnt = isStroked ? GR_ARRAY_COUNT(gRRectIndices)-6 : GR_ARRAY_CO
UNT(gRRectIndices); | 1143 int indexCnt = isStroked ? GR_ARRAY_COUNT(gRRectIndices)-6 : GR_ARRAY_CO
UNT(gRRectIndices); |
| 1142 target->setIndexSourceToBuffer(indexBuffer); | 1144 target->setIndexSourceToBuffer(indexBuffer); |
| 1143 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); | 1145 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); |
| 1144 } | 1146 } |
| 1145 | 1147 |
| 1146 return true; | 1148 return true; |
| 1147 } | 1149 } |
| OLD | NEW |