commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrOvalEffect.h" |
| 9 | |
| 10 | #include "gl/GrGLEffect.h" |
bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 11 | #include "gl/GrGLShaderBuilder.h" |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 12 | #include "gl/GrGLSL.h" |
| 13 | #include "GrTBackendEffectFactory.h" |
| 14 | |
| 15 | #include "SkRect.h" |
| 16 | |
| 17 | ////////////////////////////////////////////////////////////////////////////// |
| 18 | |
| 19 | class GLCircleEffect; |
| 20 | |
| 21 | class CircleEffect : public GrEffect { |
| 22 | public: |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 23 | static GrEffect* Create(GrEffectEdgeType, const SkPoint& center, SkScalar radius); |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 24 | |
| 25 | virtual ~CircleEffect() {}; |
| 26 | static const char* Name() { return "Circle"; } |
| 27 | |
| 28 | const SkPoint& getCenter() const { return fCenter; } |
| 29 | SkScalar getRadius() const { return fRadius; } |
| 30 | |
| 31 | GrEffectEdgeType getEdgeType() const { return fEdgeType; } |
| 32 | |
| 33 | typedef GLCircleEffect GLEffect; |
| 34 | |
| 35 | virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; |
| 36 | |
| 37 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| 38 | |
| 39 | private: |
| 40 | CircleEffect(GrEffectEdgeType, const SkPoint& center, SkScalar radius); |
| 41 | |
| 42 | virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; |
| 43 | |
| 44 | SkPoint fCenter; |
| 45 | SkScalar fRadius; |
| 46 | GrEffectEdgeType fEdgeType; |
| 47 | |
| 48 | GR_DECLARE_EFFECT_TEST; |
| 49 | |
| 50 | typedef GrEffect INHERITED; |
| 51 | }; |
| 52 | |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 53 | GrEffect* CircleEffect::Create(GrEffectEdgeType edgeType, const SkPoint& center, SkScalar radius) { |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 54 | SkASSERT(radius >= 0); |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 55 | return SkNEW_ARGS(CircleEffect, (edgeType, center, radius)); |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void CircleEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const { |
| 59 | *validFlags = 0; |
| 60 | } |
| 61 | |
| 62 | const GrBackendEffectFactory& CircleEffect::getFactory() const { |
| 63 | return GrTBackendEffectFactory<CircleEffect>::getInstance(); |
| 64 | } |
| 65 | |
| 66 | CircleEffect::CircleEffect(GrEffectEdgeType edgeType, const SkPoint& c, SkScalar r) |
| 67 | : fCenter(c) |
| 68 | , fRadius(r) |
| 69 | , fEdgeType(edgeType) { |
| 70 | this->setWillReadFragmentPosition(); |
| 71 | } |
| 72 | |
| 73 | bool CircleEffect::onIsEqual(const GrEffect& other) const { |
commit-bot@chromium.org | d0a5029 | 2014-04-02 15:00:39 +0000 | [diff] [blame] | 74 | const CircleEffect& ce = CastEffect<CircleEffect>(other); |
| 75 | return fEdgeType == ce.fEdgeType && fCenter == ce.fCenter && fRadius == ce.fRadius; |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | ////////////////////////////////////////////////////////////////////////////// |
| 79 | |
| 80 | GR_DEFINE_EFFECT_TEST(CircleEffect); |
| 81 | |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 82 | GrEffect* CircleEffect::TestCreate(SkRandom* random, |
| 83 | GrContext*, |
| 84 | const GrDrawTargetCaps& caps, |
| 85 | GrTexture*[]) { |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 86 | SkPoint center; |
| 87 | center.fX = random->nextRangeScalar(0.f, 1000.f); |
| 88 | center.fY = random->nextRangeScalar(0.f, 1000.f); |
| 89 | SkScalar radius = random->nextRangeF(0.f, 1000.f); |
| 90 | GrEffectEdgeType et; |
| 91 | do { |
| 92 | et = (GrEffectEdgeType)random->nextULessThan(kGrEffectEdgeTypeCnt); |
| 93 | } while (kHairlineAA_GrEffectEdgeType == et); |
| 94 | return CircleEffect::Create(et, center, radius); |
| 95 | } |
| 96 | |
| 97 | ////////////////////////////////////////////////////////////////////////////// |
| 98 | |
| 99 | class GLCircleEffect : public GrGLEffect { |
| 100 | public: |
| 101 | GLCircleEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
| 102 | |
| 103 | virtual void emitCode(GrGLShaderBuilder* builder, |
| 104 | const GrDrawEffect& drawEffect, |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame^] | 105 | const GrEffectKey& key, |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 106 | const char* outputColor, |
| 107 | const char* inputColor, |
| 108 | const TransformedCoordsArray&, |
| 109 | const TextureSamplerArray&) SK_OVERRIDE; |
| 110 | |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame^] | 111 | static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyBuilder*); |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 112 | |
| 113 | virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE; |
| 114 | |
| 115 | private: |
| 116 | GrGLUniformManager::UniformHandle fCircleUniform; |
| 117 | SkPoint fPrevCenter; |
| 118 | SkScalar fPrevRadius; |
| 119 | |
| 120 | typedef GrGLEffect INHERITED; |
| 121 | }; |
| 122 | |
| 123 | GLCircleEffect::GLCircleEffect(const GrBackendEffectFactory& factory, |
| 124 | const GrDrawEffect& drawEffect) |
| 125 | : INHERITED (factory) { |
| 126 | fPrevRadius = -1.f; |
| 127 | } |
| 128 | |
| 129 | void GLCircleEffect::emitCode(GrGLShaderBuilder* builder, |
| 130 | const GrDrawEffect& drawEffect, |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame^] | 131 | const GrEffectKey& key, |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 132 | const char* outputColor, |
| 133 | const char* inputColor, |
| 134 | const TransformedCoordsArray&, |
| 135 | const TextureSamplerArray& samplers) { |
| 136 | const CircleEffect& ce = drawEffect.castEffect<CircleEffect>(); |
| 137 | const char *circleName; |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 138 | // The circle uniform is (center.x, center.y, radius + 0.5) for regular fills and |
| 139 | // (... ,radius - 0.5) for inverse fills. |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 140 | fCircleUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
| 141 | kVec3f_GrSLType, |
| 142 | "circle", |
| 143 | &circleName); |
| 144 | const char* fragmentPos = builder->fragmentPosition(); |
| 145 | |
| 146 | SkASSERT(kHairlineAA_GrEffectEdgeType != ce.getEdgeType()); |
| 147 | if (GrEffectEdgeTypeIsInverseFill(ce.getEdgeType())) { |
bsalomon | 2290000 | 2014-06-24 11:16:52 -0700 | [diff] [blame] | 148 | builder->fsCodeAppendf("\t\tfloat d = length(%s.xy - %s.xy) - %s.z;\n", |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 149 | circleName, fragmentPos, circleName); |
| 150 | } else { |
bsalomon | 2290000 | 2014-06-24 11:16:52 -0700 | [diff] [blame] | 151 | builder->fsCodeAppendf("\t\tfloat d = %s.z - length(%s.xy - %s.xy);\n", |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 152 | circleName, fragmentPos, circleName); |
| 153 | } |
| 154 | if (GrEffectEdgeTypeIsAA(ce.getEdgeType())) { |
| 155 | builder->fsCodeAppend("\t\td = clamp(d, 0.0, 1.0);\n"); |
| 156 | } else { |
| 157 | builder->fsCodeAppend("\t\td = d > 0.5 ? 1.0 : 0.0;\n"); |
| 158 | } |
| 159 | |
| 160 | builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, |
| 161 | (GrGLSLExpr4(inputColor) * GrGLSLExpr1("d")).c_str()); |
| 162 | } |
| 163 | |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame^] | 164 | void GLCircleEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
| 165 | GrEffectKeyBuilder* b) { |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 166 | const CircleEffect& ce = drawEffect.castEffect<CircleEffect>(); |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame^] | 167 | b->add32(ce.getEdgeType()); |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | void GLCircleEffect::setData(const GrGLUniformManager& uman, const GrDrawEffect& drawEffect) { |
| 171 | const CircleEffect& ce = drawEffect.castEffect<CircleEffect>(); |
| 172 | if (ce.getRadius() != fPrevRadius || ce.getCenter() != fPrevCenter) { |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 173 | SkScalar radius = ce.getRadius(); |
| 174 | if (GrEffectEdgeTypeIsInverseFill(ce.getEdgeType())) { |
| 175 | radius -= 0.5f; |
| 176 | } else { |
| 177 | radius += 0.5f; |
| 178 | } |
| 179 | uman.set3f(fCircleUniform, ce.getCenter().fX, ce.getCenter().fY, radius); |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 180 | fPrevCenter = ce.getCenter(); |
| 181 | fPrevRadius = ce.getRadius(); |
| 182 | } |
| 183 | } |
commit-bot@chromium.org | d0a5029 | 2014-04-02 15:00:39 +0000 | [diff] [blame] | 184 | |
| 185 | ////////////////////////////////////////////////////////////////////////////// |
| 186 | |
| 187 | class GLEllipseEffect; |
| 188 | |
| 189 | class EllipseEffect : public GrEffect { |
| 190 | public: |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 191 | static GrEffect* Create(GrEffectEdgeType, const SkPoint& center, SkScalar rx, SkScalar ry); |
commit-bot@chromium.org | d0a5029 | 2014-04-02 15:00:39 +0000 | [diff] [blame] | 192 | |
| 193 | virtual ~EllipseEffect() {}; |
| 194 | static const char* Name() { return "Ellipse"; } |
| 195 | |
| 196 | const SkPoint& getCenter() const { return fCenter; } |
| 197 | SkVector getRadii() const { return fRadii; } |
| 198 | |
| 199 | GrEffectEdgeType getEdgeType() const { return fEdgeType; } |
| 200 | |
| 201 | typedef GLEllipseEffect GLEffect; |
| 202 | |
| 203 | virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; |
| 204 | |
| 205 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| 206 | |
| 207 | private: |
| 208 | EllipseEffect(GrEffectEdgeType, const SkPoint& center, SkScalar rx, SkScalar ry); |
| 209 | |
| 210 | virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; |
| 211 | |
| 212 | SkPoint fCenter; |
| 213 | SkVector fRadii; |
| 214 | GrEffectEdgeType fEdgeType; |
| 215 | |
| 216 | GR_DECLARE_EFFECT_TEST; |
| 217 | |
| 218 | typedef GrEffect INHERITED; |
| 219 | }; |
| 220 | |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 221 | GrEffect* EllipseEffect::Create(GrEffectEdgeType edgeType, |
| 222 | const SkPoint& center, |
| 223 | SkScalar rx, |
| 224 | SkScalar ry) { |
commit-bot@chromium.org | d0a5029 | 2014-04-02 15:00:39 +0000 | [diff] [blame] | 225 | SkASSERT(rx >= 0 && ry >= 0); |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 226 | return SkNEW_ARGS(EllipseEffect, (edgeType, center, rx, ry)); |
commit-bot@chromium.org | d0a5029 | 2014-04-02 15:00:39 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | void EllipseEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const { |
| 230 | *validFlags = 0; |
| 231 | } |
| 232 | |
| 233 | const GrBackendEffectFactory& EllipseEffect::getFactory() const { |
| 234 | return GrTBackendEffectFactory<EllipseEffect>::getInstance(); |
| 235 | } |
| 236 | |
| 237 | EllipseEffect::EllipseEffect(GrEffectEdgeType edgeType, const SkPoint& c, SkScalar rx, SkScalar ry) |
| 238 | : fCenter(c) |
| 239 | , fRadii(SkVector::Make(rx, ry)) |
| 240 | , fEdgeType(edgeType) { |
| 241 | this->setWillReadFragmentPosition(); |
| 242 | } |
| 243 | |
| 244 | bool EllipseEffect::onIsEqual(const GrEffect& other) const { |
| 245 | const EllipseEffect& ee = CastEffect<EllipseEffect>(other); |
| 246 | return fEdgeType == ee.fEdgeType && fCenter == ee.fCenter && fRadii == ee.fRadii; |
| 247 | } |
| 248 | |
| 249 | ////////////////////////////////////////////////////////////////////////////// |
| 250 | |
| 251 | GR_DEFINE_EFFECT_TEST(EllipseEffect); |
| 252 | |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 253 | GrEffect* EllipseEffect::TestCreate(SkRandom* random, |
| 254 | GrContext*, |
| 255 | const GrDrawTargetCaps& caps, |
| 256 | GrTexture*[]) { |
commit-bot@chromium.org | d0a5029 | 2014-04-02 15:00:39 +0000 | [diff] [blame] | 257 | SkPoint center; |
| 258 | center.fX = random->nextRangeScalar(0.f, 1000.f); |
| 259 | center.fY = random->nextRangeScalar(0.f, 1000.f); |
| 260 | SkScalar rx = random->nextRangeF(0.f, 1000.f); |
| 261 | SkScalar ry = random->nextRangeF(0.f, 1000.f); |
| 262 | GrEffectEdgeType et; |
| 263 | do { |
| 264 | et = (GrEffectEdgeType)random->nextULessThan(kGrEffectEdgeTypeCnt); |
| 265 | } while (kHairlineAA_GrEffectEdgeType == et); |
| 266 | return EllipseEffect::Create(et, center, rx, ry); |
| 267 | } |
| 268 | |
| 269 | ////////////////////////////////////////////////////////////////////////////// |
| 270 | |
| 271 | class GLEllipseEffect : public GrGLEffect { |
| 272 | public: |
| 273 | GLEllipseEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
| 274 | |
| 275 | virtual void emitCode(GrGLShaderBuilder* builder, |
| 276 | const GrDrawEffect& drawEffect, |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame^] | 277 | const GrEffectKey& key, |
commit-bot@chromium.org | d0a5029 | 2014-04-02 15:00:39 +0000 | [diff] [blame] | 278 | const char* outputColor, |
| 279 | const char* inputColor, |
| 280 | const TransformedCoordsArray&, |
| 281 | const TextureSamplerArray&) SK_OVERRIDE; |
| 282 | |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame^] | 283 | static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyBuilder*); |
commit-bot@chromium.org | d0a5029 | 2014-04-02 15:00:39 +0000 | [diff] [blame] | 284 | |
| 285 | virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE; |
| 286 | |
| 287 | private: |
| 288 | GrGLUniformManager::UniformHandle fEllipseUniform; |
| 289 | SkPoint fPrevCenter; |
| 290 | SkVector fPrevRadii; |
| 291 | |
| 292 | typedef GrGLEffect INHERITED; |
| 293 | }; |
| 294 | |
| 295 | GLEllipseEffect::GLEllipseEffect(const GrBackendEffectFactory& factory, |
| 296 | const GrDrawEffect& drawEffect) |
| 297 | : INHERITED (factory) { |
| 298 | fPrevRadii.fX = -1.f; |
| 299 | } |
| 300 | |
| 301 | void GLEllipseEffect::emitCode(GrGLShaderBuilder* builder, |
| 302 | const GrDrawEffect& drawEffect, |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame^] | 303 | const GrEffectKey& key, |
commit-bot@chromium.org | d0a5029 | 2014-04-02 15:00:39 +0000 | [diff] [blame] | 304 | const char* outputColor, |
| 305 | const char* inputColor, |
| 306 | const TransformedCoordsArray&, |
| 307 | const TextureSamplerArray& samplers) { |
| 308 | const EllipseEffect& ee = drawEffect.castEffect<EllipseEffect>(); |
| 309 | const char *ellipseName; |
| 310 | // The ellipse uniform is (center.x, center.y, 1 / rx^2, 1 / ry^2) |
| 311 | fEllipseUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
| 312 | kVec4f_GrSLType, |
| 313 | "ellipse", |
| 314 | &ellipseName); |
| 315 | const char* fragmentPos = builder->fragmentPosition(); |
| 316 | |
| 317 | // d is the offset to the ellipse center |
bsalomon | 2290000 | 2014-06-24 11:16:52 -0700 | [diff] [blame] | 318 | builder->fsCodeAppendf("\t\tvec2 d = %s.xy - %s.xy;\n", fragmentPos, ellipseName); |
commit-bot@chromium.org | d0a5029 | 2014-04-02 15:00:39 +0000 | [diff] [blame] | 319 | builder->fsCodeAppendf("\t\tvec2 Z = d * %s.zw;\n", ellipseName); |
| 320 | // implicit is the evaluation of (x/rx)^2 + (y/ry)^2 - 1. |
| 321 | builder->fsCodeAppend("\t\tfloat implicit = dot(Z, d) - 1.0;\n"); |
| 322 | // grad_dot is the squared length of the gradient of the implicit. |
| 323 | builder->fsCodeAppendf("\t\tfloat grad_dot = 4.0 * dot(Z, Z);\n"); |
commit-bot@chromium.org | 1b035d8 | 2014-04-09 17:11:09 +0000 | [diff] [blame] | 324 | // avoid calling inversesqrt on zero. |
| 325 | builder->fsCodeAppend("\t\tgrad_dot = max(grad_dot, 1.0e-4);\n"); |
commit-bot@chromium.org | d0a5029 | 2014-04-02 15:00:39 +0000 | [diff] [blame] | 326 | builder->fsCodeAppendf("\t\tfloat approx_dist = implicit * inversesqrt(grad_dot);\n"); |
| 327 | |
| 328 | switch (ee.getEdgeType()) { |
| 329 | case kFillAA_GrEffectEdgeType: |
| 330 | builder->fsCodeAppend("\t\tfloat alpha = clamp(0.5 - approx_dist, 0.0, 1.0);\n"); |
| 331 | break; |
| 332 | case kInverseFillAA_GrEffectEdgeType: |
| 333 | builder->fsCodeAppend("\t\tfloat alpha = clamp(0.5 + approx_dist, 0.0, 1.0);\n"); |
| 334 | break; |
| 335 | case kFillBW_GrEffectEdgeType: |
| 336 | builder->fsCodeAppend("\t\tfloat alpha = approx_dist > 0.0 ? 0.0 : 1.0;\n"); |
| 337 | break; |
| 338 | case kInverseFillBW_GrEffectEdgeType: |
| 339 | builder->fsCodeAppend("\t\tfloat alpha = approx_dist > 0.0 ? 1.0 : 0.0;\n"); |
| 340 | break; |
| 341 | case kHairlineAA_GrEffectEdgeType: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 342 | SkFAIL("Hairline not expected here."); |
commit-bot@chromium.org | d0a5029 | 2014-04-02 15:00:39 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, |
| 346 | (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_str()); |
| 347 | } |
| 348 | |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame^] | 349 | void GLEllipseEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
| 350 | GrEffectKeyBuilder* b) { |
commit-bot@chromium.org | d0a5029 | 2014-04-02 15:00:39 +0000 | [diff] [blame] | 351 | const EllipseEffect& ee = drawEffect.castEffect<EllipseEffect>(); |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame^] | 352 | b->add32(ee.getEdgeType()); |
commit-bot@chromium.org | d0a5029 | 2014-04-02 15:00:39 +0000 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | void GLEllipseEffect::setData(const GrGLUniformManager& uman, const GrDrawEffect& drawEffect) { |
| 356 | const EllipseEffect& ee = drawEffect.castEffect<EllipseEffect>(); |
| 357 | if (ee.getRadii() != fPrevRadii || ee.getCenter() != fPrevCenter) { |
| 358 | SkScalar invRXSqd = 1.f / (ee.getRadii().fX * ee.getRadii().fX); |
| 359 | SkScalar invRYSqd = 1.f / (ee.getRadii().fY * ee.getRadii().fY); |
| 360 | uman.set4f(fEllipseUniform, ee.getCenter().fX, ee.getCenter().fY, invRXSqd, invRYSqd); |
| 361 | fPrevCenter = ee.getCenter(); |
| 362 | fPrevRadii = ee.getRadii(); |
| 363 | } |
| 364 | } |
| 365 | |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 366 | ////////////////////////////////////////////////////////////////////////////// |
| 367 | |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 368 | GrEffect* GrOvalEffect::Create(GrEffectEdgeType edgeType, const SkRect& oval) { |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 369 | if (kHairlineAA_GrEffectEdgeType == edgeType) { |
| 370 | return NULL; |
| 371 | } |
| 372 | SkScalar w = oval.width(); |
| 373 | SkScalar h = oval.height(); |
| 374 | if (SkScalarNearlyEqual(w, h)) { |
| 375 | w /= 2; |
| 376 | return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval.fTop + w), w); |
commit-bot@chromium.org | d0a5029 | 2014-04-02 15:00:39 +0000 | [diff] [blame] | 377 | } else { |
| 378 | w /= 2; |
| 379 | h /= 2; |
| 380 | return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval.fTop + h), w, h); |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | return NULL; |
| 384 | } |