commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 "GrOvalRenderer.h" |
| 9 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 10 | #include "GrEffect.h" |
| 11 | #include "gl/GrGLEffect.h" |
| 12 | #include "gl/GrGLSL.h" |
| 13 | #include "GrTBackendEffectFactory.h" |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 14 | |
| 15 | #include "GrDrawState.h" |
| 16 | #include "GrDrawTarget.h" |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 17 | #include "GrGpu.h" |
| 18 | |
| 19 | #include "SkRRect.h" |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 20 | #include "SkStrokeRec.h" |
| 21 | |
| 22 | SK_DEFINE_INST_COUNT(GrOvalRenderer) |
| 23 | |
| 24 | namespace { |
| 25 | |
| 26 | struct CircleVertex { |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 27 | GrPoint fPos; |
| 28 | GrPoint fOffset; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 29 | SkScalar fOuterRadius; |
| 30 | SkScalar fInnerRadius; |
| 31 | }; |
| 32 | |
| 33 | struct EllipseVertex { |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 34 | GrPoint fPos; |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 35 | GrPoint fOffset; |
| 36 | GrPoint fOuterRadii; |
| 37 | GrPoint fInnerRadii; |
| 38 | }; |
| 39 | |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 40 | inline bool circle_stays_circle(const SkMatrix& m) { |
| 41 | return m.isSimilarity(); |
| 42 | } |
| 43 | |
| 44 | } |
| 45 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 46 | /////////////////////////////////////////////////////////////////////////////// |
| 47 | |
| 48 | /** |
| 49 | * The output of this effect is a modulation of the input color and coverage for a circle, |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 50 | * specified as offset_x, offset_y (both from center point), outer radius and inner radius. |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 51 | */ |
| 52 | |
| 53 | class CircleEdgeEffect : public GrEffect { |
| 54 | public: |
| 55 | static GrEffectRef* Create(bool stroke) { |
bsalomon@google.com | d42aca3 | 2013-04-23 15:37:27 +0000 | [diff] [blame] | 56 | GR_CREATE_STATIC_EFFECT(gCircleStrokeEdge, CircleEdgeEffect, (true)); |
| 57 | GR_CREATE_STATIC_EFFECT(gCircleFillEdge, CircleEdgeEffect, (false)); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 58 | |
| 59 | if (stroke) { |
bsalomon@google.com | d42aca3 | 2013-04-23 15:37:27 +0000 | [diff] [blame] | 60 | gCircleStrokeEdge->ref(); |
| 61 | return gCircleStrokeEdge; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 62 | } else { |
bsalomon@google.com | d42aca3 | 2013-04-23 15:37:27 +0000 | [diff] [blame] | 63 | gCircleFillEdge->ref(); |
| 64 | return gCircleFillEdge; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 65 | } |
| 66 | } |
| 67 | |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 68 | virtual void getConstantColorComponents(GrColor* color, |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 69 | uint32_t* validFlags) const SK_OVERRIDE { |
| 70 | *validFlags = 0; |
| 71 | } |
| 72 | |
| 73 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { |
| 74 | return GrTBackendEffectFactory<CircleEdgeEffect>::getInstance(); |
| 75 | } |
| 76 | |
| 77 | virtual ~CircleEdgeEffect() {} |
| 78 | |
| 79 | static const char* Name() { return "CircleEdge"; } |
| 80 | |
| 81 | inline bool isStroked() const { return fStroke; } |
| 82 | |
| 83 | class GLEffect : public GrGLEffect { |
| 84 | public: |
| 85 | GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
| 86 | : INHERITED (factory) {} |
| 87 | |
| 88 | virtual void emitCode(GrGLShaderBuilder* builder, |
| 89 | const GrDrawEffect& drawEffect, |
| 90 | EffectKey key, |
| 91 | const char* outputColor, |
| 92 | const char* inputColor, |
| 93 | const TextureSamplerArray& samplers) SK_OVERRIDE { |
commit-bot@chromium.org | 5a02cb4 | 2013-08-30 20:17:31 +0000 | [diff] [blame^] | 94 | GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertexBuilder(); |
| 95 | SkASSERT(NULL != vertexBuilder); |
| 96 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 97 | const CircleEdgeEffect& circleEffect = drawEffect.castEffect<CircleEdgeEffect>(); |
| 98 | const char *vsName, *fsName; |
commit-bot@chromium.org | 5a02cb4 | 2013-08-30 20:17:31 +0000 | [diff] [blame^] | 99 | vertexBuilder->addVarying(kVec4f_GrSLType, "CircleEdge", &vsName, &fsName); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 100 | |
| 101 | const SkString* attrName = |
commit-bot@chromium.org | 5a02cb4 | 2013-08-30 20:17:31 +0000 | [diff] [blame^] | 102 | vertexBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); |
| 103 | vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str()); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 104 | |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 105 | builder->fsCodeAppendf("\tfloat d = length(%s.xy);\n", fsName); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 106 | builder->fsCodeAppendf("\tfloat edgeAlpha = clamp(%s.z - d, 0.0, 1.0);\n", fsName); |
| 107 | if (circleEffect.isStroked()) { |
| 108 | builder->fsCodeAppendf("\tfloat innerAlpha = clamp(d - %s.w, 0.0, 1.0);\n", fsName); |
| 109 | builder->fsCodeAppend("\tedgeAlpha *= innerAlpha;\n"); |
| 110 | } |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 111 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 112 | SkString modulate; |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 113 | GrGLSLModulatef<4>(&modulate, inputColor, "edgeAlpha"); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 114 | builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str()); |
| 115 | } |
| 116 | |
| 117 | static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) { |
| 118 | const CircleEdgeEffect& circleEffect = drawEffect.castEffect<CircleEdgeEffect>(); |
| 119 | |
| 120 | return circleEffect.isStroked() ? 0x1 : 0x0; |
| 121 | } |
| 122 | |
| 123 | virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE {} |
| 124 | |
| 125 | private: |
| 126 | typedef GrGLEffect INHERITED; |
| 127 | }; |
| 128 | |
| 129 | |
| 130 | private: |
| 131 | CircleEdgeEffect(bool stroke) : GrEffect() { |
| 132 | this->addVertexAttrib(kVec4f_GrSLType); |
| 133 | fStroke = stroke; |
| 134 | } |
| 135 | |
| 136 | virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { |
| 137 | const CircleEdgeEffect& cee = CastEffect<CircleEdgeEffect>(other); |
| 138 | return cee.fStroke == fStroke; |
| 139 | } |
| 140 | |
| 141 | bool fStroke; |
| 142 | |
| 143 | GR_DECLARE_EFFECT_TEST; |
| 144 | |
| 145 | typedef GrEffect INHERITED; |
| 146 | }; |
| 147 | |
| 148 | GR_DEFINE_EFFECT_TEST(CircleEdgeEffect); |
| 149 | |
| 150 | GrEffectRef* CircleEdgeEffect::TestCreate(SkMWCRandom* random, |
| 151 | GrContext* context, |
| 152 | const GrDrawTargetCaps&, |
| 153 | GrTexture* textures[]) { |
| 154 | return CircleEdgeEffect::Create(random->nextBool()); |
| 155 | } |
| 156 | |
| 157 | /////////////////////////////////////////////////////////////////////////////// |
| 158 | |
| 159 | /** |
| 160 | * The output of this effect is a modulation of the input color and coverage for an axis-aligned |
skia.committer@gmail.com | 8be02fc | 2013-05-17 07:01:11 +0000 | [diff] [blame] | 161 | * ellipse, specified as a 2D offset from center, and the reciprocals of the outer and inner radii, |
| 162 | * in both x and y directions. |
| 163 | * |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 164 | * We are using an implicit function of x^2/a^2 + y^2/b^2 - 1 = 0. |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 165 | */ |
| 166 | |
| 167 | class EllipseEdgeEffect : public GrEffect { |
| 168 | public: |
| 169 | static GrEffectRef* Create(bool stroke) { |
bsalomon@google.com | d42aca3 | 2013-04-23 15:37:27 +0000 | [diff] [blame] | 170 | GR_CREATE_STATIC_EFFECT(gEllipseStrokeEdge, EllipseEdgeEffect, (true)); |
| 171 | GR_CREATE_STATIC_EFFECT(gEllipseFillEdge, EllipseEdgeEffect, (false)); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 172 | |
| 173 | if (stroke) { |
bsalomon@google.com | d42aca3 | 2013-04-23 15:37:27 +0000 | [diff] [blame] | 174 | gEllipseStrokeEdge->ref(); |
| 175 | return gEllipseStrokeEdge; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 176 | } else { |
bsalomon@google.com | d42aca3 | 2013-04-23 15:37:27 +0000 | [diff] [blame] | 177 | gEllipseFillEdge->ref(); |
| 178 | return gEllipseFillEdge; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 182 | virtual void getConstantColorComponents(GrColor* color, |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 183 | uint32_t* validFlags) const SK_OVERRIDE { |
| 184 | *validFlags = 0; |
| 185 | } |
| 186 | |
| 187 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { |
| 188 | return GrTBackendEffectFactory<EllipseEdgeEffect>::getInstance(); |
| 189 | } |
| 190 | |
| 191 | virtual ~EllipseEdgeEffect() {} |
| 192 | |
| 193 | static const char* Name() { return "EllipseEdge"; } |
| 194 | |
| 195 | inline bool isStroked() const { return fStroke; } |
| 196 | |
| 197 | class GLEffect : public GrGLEffect { |
| 198 | public: |
| 199 | GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
| 200 | : INHERITED (factory) {} |
| 201 | |
| 202 | virtual void emitCode(GrGLShaderBuilder* builder, |
| 203 | const GrDrawEffect& drawEffect, |
| 204 | EffectKey key, |
| 205 | const char* outputColor, |
| 206 | const char* inputColor, |
| 207 | const TextureSamplerArray& samplers) SK_OVERRIDE { |
commit-bot@chromium.org | 5a02cb4 | 2013-08-30 20:17:31 +0000 | [diff] [blame^] | 208 | GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertexBuilder(); |
| 209 | SkASSERT(NULL != vertexBuilder); |
| 210 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 211 | const EllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<EllipseEdgeEffect>(); |
| 212 | |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 213 | const char *vsOffsetName, *fsOffsetName; |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 214 | const char *vsRadiiName, *fsRadiiName; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 215 | |
commit-bot@chromium.org | 5a02cb4 | 2013-08-30 20:17:31 +0000 | [diff] [blame^] | 216 | vertexBuilder->addVarying(kVec2f_GrSLType, "EllipseOffsets", &vsOffsetName, &fsOffsetName); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 217 | const SkString* attr0Name = |
commit-bot@chromium.org | 5a02cb4 | 2013-08-30 20:17:31 +0000 | [diff] [blame^] | 218 | vertexBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); |
| 219 | vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsOffsetName, attr0Name->c_str()); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 220 | |
commit-bot@chromium.org | 5a02cb4 | 2013-08-30 20:17:31 +0000 | [diff] [blame^] | 221 | vertexBuilder->addVarying(kVec4f_GrSLType, "EllipseRadii", &vsRadiiName, &fsRadiiName); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 222 | const SkString* attr1Name = |
commit-bot@chromium.org | 5a02cb4 | 2013-08-30 20:17:31 +0000 | [diff] [blame^] | 223 | vertexBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[1]); |
| 224 | vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsRadiiName, attr1Name->c_str()); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 225 | |
skia.committer@gmail.com | 8be02fc | 2013-05-17 07:01:11 +0000 | [diff] [blame] | 226 | // for outer curve |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 227 | builder->fsCodeAppendf("\tvec2 scaledOffset = %s*%s.xy;\n", fsOffsetName, fsRadiiName); |
| 228 | builder->fsCodeAppend("\tfloat test = dot(scaledOffset, scaledOffset) - 1.0;\n"); |
| 229 | builder->fsCodeAppendf("\tvec2 grad = 2.0*scaledOffset*%s.xy;\n", fsRadiiName); |
jvanverth@google.com | d1b5b14 | 2013-07-02 14:46:03 +0000 | [diff] [blame] | 230 | builder->fsCodeAppend("\tfloat grad_dot = dot(grad, grad);\n"); |
| 231 | // we need to clamp the length^2 of the gradiant vector to a non-zero value, because |
| 232 | // on the Nexus 4 the undefined result of inversesqrt(0) drops out an entire tile |
| 233 | // TODO: restrict this to Adreno-only |
| 234 | builder->fsCodeAppend("\tgrad_dot = max(grad_dot, 1.0e-4);\n"); |
| 235 | builder->fsCodeAppend("\tfloat invlen = inversesqrt(grad_dot);\n"); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 236 | builder->fsCodeAppend("\tfloat edgeAlpha = clamp(0.5-test*invlen, 0.0, 1.0);\n"); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 237 | |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 238 | // for inner curve |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 239 | if (ellipseEffect.isStroked()) { |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 240 | builder->fsCodeAppendf("\tscaledOffset = %s*%s.zw;\n", fsOffsetName, fsRadiiName); |
| 241 | builder->fsCodeAppend("\ttest = dot(scaledOffset, scaledOffset) - 1.0;\n"); |
| 242 | builder->fsCodeAppendf("\tgrad = 2.0*scaledOffset*%s.zw;\n", fsRadiiName); |
| 243 | builder->fsCodeAppend("\tinvlen = inversesqrt(dot(grad, grad));\n"); |
| 244 | builder->fsCodeAppend("\tedgeAlpha *= clamp(0.5+test*invlen, 0.0, 1.0);\n"); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | SkString modulate; |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 248 | GrGLSLModulatef<4>(&modulate, inputColor, "edgeAlpha"); |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 249 | builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str()); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) { |
| 253 | const EllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<EllipseEdgeEffect>(); |
| 254 | |
| 255 | return ellipseEffect.isStroked() ? 0x1 : 0x0; |
| 256 | } |
| 257 | |
| 258 | virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE { |
| 259 | } |
| 260 | |
| 261 | private: |
| 262 | typedef GrGLEffect INHERITED; |
| 263 | }; |
| 264 | |
| 265 | private: |
| 266 | EllipseEdgeEffect(bool stroke) : GrEffect() { |
| 267 | this->addVertexAttrib(kVec2f_GrSLType); |
| 268 | this->addVertexAttrib(kVec4f_GrSLType); |
| 269 | fStroke = stroke; |
| 270 | } |
| 271 | |
| 272 | virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { |
| 273 | const EllipseEdgeEffect& eee = CastEffect<EllipseEdgeEffect>(other); |
| 274 | return eee.fStroke == fStroke; |
| 275 | } |
| 276 | |
| 277 | bool fStroke; |
| 278 | |
| 279 | GR_DECLARE_EFFECT_TEST; |
| 280 | |
| 281 | typedef GrEffect INHERITED; |
| 282 | }; |
| 283 | |
| 284 | GR_DEFINE_EFFECT_TEST(EllipseEdgeEffect); |
| 285 | |
| 286 | GrEffectRef* EllipseEdgeEffect::TestCreate(SkMWCRandom* random, |
| 287 | GrContext* context, |
| 288 | const GrDrawTargetCaps&, |
| 289 | GrTexture* textures[]) { |
| 290 | return EllipseEdgeEffect::Create(random->nextBool()); |
| 291 | } |
| 292 | |
| 293 | /////////////////////////////////////////////////////////////////////////////// |
| 294 | |
commit-bot@chromium.org | ef284a8 | 2013-07-11 22:29:29 +0000 | [diff] [blame] | 295 | void GrOvalRenderer::reset() { |
| 296 | GrSafeSetNull(fRRectIndexBuffer); |
| 297 | } |
| 298 | |
commit-bot@chromium.org | 37d883d | 2013-05-02 13:11:22 +0000 | [diff] [blame] | 299 | bool GrOvalRenderer::drawOval(GrDrawTarget* target, const GrContext* context, bool useAA, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 300 | const SkRect& oval, const SkStrokeRec& stroke) |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 301 | { |
commit-bot@chromium.org | 37d883d | 2013-05-02 13:11:22 +0000 | [diff] [blame] | 302 | if (!useAA) { |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 303 | return false; |
| 304 | } |
| 305 | |
| 306 | const SkMatrix& vm = context->getMatrix(); |
| 307 | |
skia.committer@gmail.com | 7e32851 | 2013-03-23 07:01:28 +0000 | [diff] [blame] | 308 | // we can draw circles |
| 309 | if (SkScalarNearlyEqual(oval.width(), oval.height()) |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 310 | && circle_stays_circle(vm)) { |
commit-bot@chromium.org | 37d883d | 2013-05-02 13:11:22 +0000 | [diff] [blame] | 311 | this->drawCircle(target, useAA, oval, stroke); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 312 | |
| 313 | // and axis-aligned ellipses only |
| 314 | } else if (vm.rectStaysRect()) { |
commit-bot@chromium.org | 37d883d | 2013-05-02 13:11:22 +0000 | [diff] [blame] | 315 | return this->drawEllipse(target, useAA, oval, stroke); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 316 | |
| 317 | } else { |
| 318 | return false; |
| 319 | } |
| 320 | |
| 321 | return true; |
| 322 | } |
| 323 | |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 324 | namespace { |
| 325 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 326 | /////////////////////////////////////////////////////////////////////////////// |
| 327 | |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 328 | // position + edge |
| 329 | extern const GrVertexAttrib gCircleVertexAttribs[] = { |
| 330 | {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, |
| 331 | {kVec4f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding} |
| 332 | }; |
| 333 | |
| 334 | }; |
| 335 | |
skia.committer@gmail.com | 7e32851 | 2013-03-23 07:01:28 +0000 | [diff] [blame] | 336 | void GrOvalRenderer::drawCircle(GrDrawTarget* target, |
commit-bot@chromium.org | 37d883d | 2013-05-02 13:11:22 +0000 | [diff] [blame] | 337 | bool useAA, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 338 | const SkRect& circle, |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 339 | const SkStrokeRec& stroke) |
| 340 | { |
| 341 | GrDrawState* drawState = target->drawState(); |
| 342 | |
| 343 | const SkMatrix& vm = drawState->getViewMatrix(); |
| 344 | GrPoint center = GrPoint::Make(circle.centerX(), circle.centerY()); |
| 345 | vm.mapPoints(¢er, 1); |
| 346 | SkScalar radius = vm.mapRadius(SkScalarHalf(circle.width())); |
| 347 | SkScalar strokeWidth = vm.mapRadius(stroke.getWidth()); |
| 348 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 349 | GrDrawState::AutoViewMatrixRestore avmr; |
| 350 | if (!avmr.setIdentity(drawState)) { |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 351 | return; |
| 352 | } |
| 353 | |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 354 | drawState->setVertexAttribs<gCircleVertexAttribs>(SK_ARRAY_COUNT(gCircleVertexAttribs)); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 355 | SkASSERT(sizeof(CircleVertex) == drawState->getVertexSize()); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 356 | |
| 357 | GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); |
| 358 | if (!geo.succeeded()) { |
| 359 | GrPrintf("Failed to get space for vertices!\n"); |
| 360 | return; |
| 361 | } |
| 362 | |
| 363 | CircleVertex* verts = reinterpret_cast<CircleVertex*>(geo.vertices()); |
| 364 | |
| 365 | SkStrokeRec::Style style = stroke.getStyle(); |
| 366 | bool isStroked = (SkStrokeRec::kStroke_Style == style || SkStrokeRec::kHairline_Style == style); |
skia.committer@gmail.com | 7e32851 | 2013-03-23 07:01:28 +0000 | [diff] [blame] | 367 | |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 368 | SkScalar innerRadius = 0.0f; |
| 369 | SkScalar outerRadius = radius; |
| 370 | SkScalar halfWidth = 0; |
| 371 | if (style != SkStrokeRec::kFill_Style) { |
| 372 | if (SkScalarNearlyZero(strokeWidth)) { |
| 373 | halfWidth = SK_ScalarHalf; |
| 374 | } else { |
| 375 | halfWidth = SkScalarHalf(strokeWidth); |
| 376 | } |
| 377 | |
| 378 | outerRadius += halfWidth; |
| 379 | if (isStroked) { |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 380 | innerRadius = radius - halfWidth; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | |
commit-bot@chromium.org | cefde6e | 2013-08-30 16:34:52 +0000 | [diff] [blame] | 384 | GrEffectRef* effect = CircleEdgeEffect::Create(isStroked && innerRadius > 0); |
| 385 | static const int kCircleEdgeAttrIndex = 1; |
| 386 | drawState->addCoverageEffect(effect, kCircleEdgeAttrIndex)->unref(); |
| 387 | |
bsalomon@google.com | 58e30fe | 2013-04-01 19:01:20 +0000 | [diff] [blame] | 388 | // The radii are outset for two reasons. First, it allows the shader to simply perform |
| 389 | // clamp(distance-to-center - radius, 0, 1). Second, the outer radius is used to compute the |
| 390 | // verts of the bounding box that is rendered and the outset ensures the box will cover all |
| 391 | // pixels partially covered by the circle. |
| 392 | outerRadius += SK_ScalarHalf; |
| 393 | innerRadius -= SK_ScalarHalf; |
| 394 | |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 395 | SkRect bounds = SkRect::MakeLTRB( |
bsalomon@google.com | 58e30fe | 2013-04-01 19:01:20 +0000 | [diff] [blame] | 396 | center.fX - outerRadius, |
| 397 | center.fY - outerRadius, |
| 398 | center.fX + outerRadius, |
| 399 | center.fY + outerRadius |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 400 | ); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 401 | |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 402 | verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 403 | verts[0].fOffset = SkPoint::Make(-outerRadius, -outerRadius); |
| 404 | verts[0].fOuterRadius = outerRadius; |
| 405 | verts[0].fInnerRadius = innerRadius; |
| 406 | |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 407 | verts[1].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
skia.committer@gmail.com | 4674676 | 2013-04-12 07:01:51 +0000 | [diff] [blame] | 408 | verts[1].fOffset = SkPoint::Make(outerRadius, -outerRadius); |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 409 | verts[1].fOuterRadius = outerRadius; |
| 410 | verts[1].fInnerRadius = innerRadius; |
| 411 | |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 412 | verts[2].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 413 | verts[2].fOffset = SkPoint::Make(-outerRadius, outerRadius); |
| 414 | verts[2].fOuterRadius = outerRadius; |
| 415 | verts[2].fInnerRadius = innerRadius; |
| 416 | |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 417 | verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 418 | verts[3].fOffset = SkPoint::Make(outerRadius, outerRadius); |
| 419 | verts[3].fOuterRadius = outerRadius; |
| 420 | verts[3].fInnerRadius = innerRadius; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 421 | |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 422 | target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 423 | } |
| 424 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 425 | /////////////////////////////////////////////////////////////////////////////// |
| 426 | |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 427 | namespace { |
| 428 | |
| 429 | // position + edge |
| 430 | extern const GrVertexAttrib gEllipseVertexAttribs[] = { |
| 431 | {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, |
| 432 | {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding}, |
| 433 | {kVec4f_GrVertexAttribType, 2*sizeof(GrPoint), kEffect_GrVertexAttribBinding} |
| 434 | }; |
| 435 | |
| 436 | }; |
| 437 | |
jvanverth@google.com | c4f2eca | 2013-04-16 12:30:35 +0000 | [diff] [blame] | 438 | bool GrOvalRenderer::drawEllipse(GrDrawTarget* target, |
commit-bot@chromium.org | 37d883d | 2013-05-02 13:11:22 +0000 | [diff] [blame] | 439 | bool useAA, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 440 | const SkRect& ellipse, |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 441 | const SkStrokeRec& stroke) |
| 442 | { |
| 443 | GrDrawState* drawState = target->drawState(); |
| 444 | #ifdef SK_DEBUG |
| 445 | { |
| 446 | // we should have checked for this previously |
| 447 | bool isAxisAlignedEllipse = drawState->getViewMatrix().rectStaysRect(); |
commit-bot@chromium.org | 37d883d | 2013-05-02 13:11:22 +0000 | [diff] [blame] | 448 | SkASSERT(useAA && isAxisAlignedEllipse); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 449 | } |
| 450 | #endif |
| 451 | |
commit-bot@chromium.org | 0c88828 | 2013-04-19 19:01:45 +0000 | [diff] [blame] | 452 | // do any matrix crunching before we reset the draw state for device coords |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 453 | const SkMatrix& vm = drawState->getViewMatrix(); |
| 454 | GrPoint center = GrPoint::Make(ellipse.centerX(), ellipse.centerY()); |
| 455 | vm.mapPoints(¢er, 1); |
commit-bot@chromium.org | 0c88828 | 2013-04-19 19:01:45 +0000 | [diff] [blame] | 456 | SkScalar ellipseXRadius = SkScalarHalf(ellipse.width()); |
| 457 | SkScalar ellipseYRadius = SkScalarHalf(ellipse.height()); |
skia.committer@gmail.com | 64b682c | 2013-04-20 07:01:07 +0000 | [diff] [blame] | 458 | SkScalar xRadius = SkScalarAbs(vm[SkMatrix::kMScaleX]*ellipseXRadius + |
commit-bot@chromium.org | 0c88828 | 2013-04-19 19:01:45 +0000 | [diff] [blame] | 459 | vm[SkMatrix::kMSkewY]*ellipseYRadius); |
skia.committer@gmail.com | 64b682c | 2013-04-20 07:01:07 +0000 | [diff] [blame] | 460 | SkScalar yRadius = SkScalarAbs(vm[SkMatrix::kMSkewX]*ellipseXRadius + |
commit-bot@chromium.org | 0c88828 | 2013-04-19 19:01:45 +0000 | [diff] [blame] | 461 | vm[SkMatrix::kMScaleY]*ellipseYRadius); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 462 | |
commit-bot@chromium.org | 0c88828 | 2013-04-19 19:01:45 +0000 | [diff] [blame] | 463 | // do (potentially) anisotropic mapping of stroke |
| 464 | SkVector scaledStroke; |
| 465 | SkScalar strokeWidth = stroke.getWidth(); |
| 466 | scaledStroke.fX = SkScalarAbs(strokeWidth*(vm[SkMatrix::kMScaleX] + vm[SkMatrix::kMSkewY])); |
| 467 | scaledStroke.fY = SkScalarAbs(strokeWidth*(vm[SkMatrix::kMSkewX] + vm[SkMatrix::kMScaleY])); |
| 468 | |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 469 | SkStrokeRec::Style style = stroke.getStyle(); |
| 470 | bool isStroked = (SkStrokeRec::kStroke_Style == style || SkStrokeRec::kHairline_Style == style); |
| 471 | |
| 472 | SkScalar innerXRadius = 0.0f; |
| 473 | SkScalar innerYRadius = 0.0f; |
| 474 | if (SkStrokeRec::kFill_Style != style) { |
| 475 | if (SkScalarNearlyZero(scaledStroke.length())) { |
| 476 | scaledStroke.set(SK_ScalarHalf, SK_ScalarHalf); |
| 477 | } else { |
| 478 | scaledStroke.scale(SK_ScalarHalf); |
| 479 | } |
| 480 | |
| 481 | // we only handle thick strokes for near-circular ellipses |
| 482 | if (scaledStroke.length() > SK_ScalarHalf && |
| 483 | (SK_ScalarHalf*xRadius > yRadius || SK_ScalarHalf*yRadius > xRadius)) { |
| 484 | return false; |
| 485 | } |
| 486 | |
| 487 | // we don't handle it if curvature of the stroke is less than curvature of the ellipse |
| 488 | if (scaledStroke.fX*(yRadius*yRadius) < (scaledStroke.fY*scaledStroke.fY)*xRadius || |
| 489 | scaledStroke.fY*(xRadius*xRadius) < (scaledStroke.fX*scaledStroke.fX)*yRadius) { |
| 490 | return false; |
| 491 | } |
| 492 | |
| 493 | // this is legit only if scale & translation (which should be the case at the moment) |
| 494 | if (isStroked) { |
| 495 | innerXRadius = xRadius - scaledStroke.fX; |
| 496 | innerYRadius = yRadius - scaledStroke.fY; |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | xRadius += scaledStroke.fX; |
| 500 | yRadius += scaledStroke.fY; |
| 501 | } |
| 502 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 503 | GrDrawState::AutoViewMatrixRestore avmr; |
| 504 | if (!avmr.setIdentity(drawState)) { |
jvanverth@google.com | c4f2eca | 2013-04-16 12:30:35 +0000 | [diff] [blame] | 505 | return false; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 506 | } |
| 507 | |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 508 | drawState->setVertexAttribs<gEllipseVertexAttribs>(SK_ARRAY_COUNT(gEllipseVertexAttribs)); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 509 | SkASSERT(sizeof(EllipseVertex) == drawState->getVertexSize()); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 510 | |
| 511 | GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); |
| 512 | if (!geo.succeeded()) { |
| 513 | GrPrintf("Failed to get space for vertices!\n"); |
jvanverth@google.com | c4f2eca | 2013-04-16 12:30:35 +0000 | [diff] [blame] | 514 | return false; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices()); |
| 518 | |
commit-bot@chromium.org | cefde6e | 2013-08-30 16:34:52 +0000 | [diff] [blame] | 519 | GrEffectRef* effect = EllipseEdgeEffect::Create(isStroked && |
| 520 | innerXRadius > 0 && innerYRadius > 0); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 521 | |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 522 | static const int kEllipseCenterAttrIndex = 1; |
| 523 | static const int kEllipseEdgeAttrIndex = 2; |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 524 | drawState->addCoverageEffect(effect, kEllipseCenterAttrIndex, kEllipseEdgeAttrIndex)->unref(); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 525 | |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 526 | // Compute the reciprocals of the radii here to save time in the shader |
| 527 | SkScalar xRadRecip = SkScalarInvert(xRadius); |
| 528 | SkScalar yRadRecip = SkScalarInvert(yRadius); |
| 529 | SkScalar xInnerRadRecip = SkScalarInvert(innerXRadius); |
| 530 | SkScalar yInnerRadRecip = SkScalarInvert(innerYRadius); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 531 | |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 532 | // We've extended the outer x radius out half a pixel to antialias. |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 533 | // This will also expand the rect so all the pixels will be captured. |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 534 | // TODO: Consider if we should use sqrt(2)/2 instead |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 535 | xRadius += SK_ScalarHalf; |
| 536 | yRadius += SK_ScalarHalf; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 537 | |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 538 | SkRect bounds = SkRect::MakeLTRB( |
| 539 | center.fX - xRadius, |
| 540 | center.fY - yRadius, |
| 541 | center.fX + xRadius, |
| 542 | center.fY + yRadius |
| 543 | ); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 544 | |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 545 | verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 546 | verts[0].fOffset = SkPoint::Make(-xRadius, -yRadius); |
| 547 | verts[0].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 548 | verts[0].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 549 | |
| 550 | verts[1].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 551 | verts[1].fOffset = SkPoint::Make(xRadius, -yRadius); |
| 552 | verts[1].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 553 | verts[1].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 554 | |
| 555 | verts[2].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 556 | verts[2].fOffset = SkPoint::Make(-xRadius, yRadius); |
| 557 | verts[2].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 558 | verts[2].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 559 | |
| 560 | verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 561 | verts[3].fOffset = SkPoint::Make(xRadius, yRadius); |
| 562 | verts[3].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 563 | verts[3].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
skia.committer@gmail.com | 4674676 | 2013-04-12 07:01:51 +0000 | [diff] [blame] | 564 | |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 565 | target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds); |
jvanverth@google.com | c4f2eca | 2013-04-16 12:30:35 +0000 | [diff] [blame] | 566 | |
| 567 | return true; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 568 | } |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 569 | |
| 570 | /////////////////////////////////////////////////////////////////////////////// |
| 571 | |
| 572 | static const uint16_t gRRectIndices[] = { |
| 573 | // corners |
| 574 | 0, 1, 5, 0, 5, 4, |
| 575 | 2, 3, 7, 2, 7, 6, |
| 576 | 8, 9, 13, 8, 13, 12, |
| 577 | 10, 11, 15, 10, 15, 14, |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 578 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 579 | // edges |
| 580 | 1, 2, 6, 1, 6, 5, |
| 581 | 4, 5, 9, 4, 9, 8, |
| 582 | 6, 7, 11, 6, 11, 10, |
| 583 | 9, 10, 14, 9, 14, 13, |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 584 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 585 | // center |
| 586 | // we place this at the end so that we can ignore these indices when rendering stroke-only |
| 587 | 5, 6, 10, 5, 10, 9 |
| 588 | }; |
| 589 | |
| 590 | |
| 591 | GrIndexBuffer* GrOvalRenderer::rRectIndexBuffer(GrGpu* gpu) { |
| 592 | if (NULL == fRRectIndexBuffer) { |
| 593 | fRRectIndexBuffer = |
| 594 | gpu->createIndexBuffer(sizeof(gRRectIndices), false); |
| 595 | if (NULL != fRRectIndexBuffer) { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 596 | #ifdef SK_DEBUG |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 597 | bool updated = |
| 598 | #endif |
| 599 | fRRectIndexBuffer->updateData(gRRectIndices, |
| 600 | sizeof(gRRectIndices)); |
| 601 | GR_DEBUGASSERT(updated); |
| 602 | } |
| 603 | } |
| 604 | return fRRectIndexBuffer; |
| 605 | } |
| 606 | |
skia.committer@gmail.com | 2fd42c4 | 2013-05-03 07:01:00 +0000 | [diff] [blame] | 607 | bool GrOvalRenderer::drawSimpleRRect(GrDrawTarget* target, GrContext* context, bool useAA, |
commit-bot@chromium.org | 37d883d | 2013-05-02 13:11:22 +0000 | [diff] [blame] | 608 | const SkRRect& rrect, const SkStrokeRec& stroke) |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 609 | { |
commit-bot@chromium.org | 37d883d | 2013-05-02 13:11:22 +0000 | [diff] [blame] | 610 | // only anti-aliased rrects for now |
| 611 | if (!useAA) { |
| 612 | return false; |
| 613 | } |
| 614 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 615 | const SkMatrix& vm = context->getMatrix(); |
| 616 | #ifdef SK_DEBUG |
| 617 | { |
| 618 | // we should have checked for this previously |
commit-bot@chromium.org | 37d883d | 2013-05-02 13:11:22 +0000 | [diff] [blame] | 619 | SkASSERT(useAA && vm.rectStaysRect() && rrect.isSimple()); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 620 | } |
| 621 | #endif |
| 622 | |
| 623 | // do any matrix crunching before we reset the draw state for device coords |
| 624 | const SkRect& rrectBounds = rrect.getBounds(); |
| 625 | SkRect bounds; |
| 626 | vm.mapRect(&bounds, rrectBounds); |
| 627 | |
| 628 | SkVector radii = rrect.getSimpleRadii(); |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 629 | SkScalar xRadius = SkScalarAbs(vm[SkMatrix::kMScaleX]*radii.fX + |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 630 | vm[SkMatrix::kMSkewY]*radii.fY); |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 631 | SkScalar yRadius = SkScalarAbs(vm[SkMatrix::kMSkewX]*radii.fX + |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 632 | vm[SkMatrix::kMScaleY]*radii.fY); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 633 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 634 | // if hairline stroke is greater than radius, we don't handle that right now |
| 635 | SkStrokeRec::Style style = stroke.getStyle(); |
| 636 | if (SkStrokeRec::kHairline_Style == style && |
| 637 | (SK_ScalarHalf >= xRadius || SK_ScalarHalf >= yRadius)) { |
| 638 | return false; |
| 639 | } |
| 640 | |
| 641 | // do (potentially) anisotropic mapping of stroke |
| 642 | SkVector scaledStroke; |
| 643 | SkScalar strokeWidth = stroke.getWidth(); |
| 644 | scaledStroke.fX = SkScalarAbs(strokeWidth*(vm[SkMatrix::kMScaleX] + vm[SkMatrix::kMSkewY])); |
| 645 | scaledStroke.fY = SkScalarAbs(strokeWidth*(vm[SkMatrix::kMSkewX] + vm[SkMatrix::kMScaleY])); |
| 646 | |
| 647 | // if half of strokewidth is greater than radius, we don't handle that right now |
| 648 | if (SK_ScalarHalf*scaledStroke.fX >= xRadius || SK_ScalarHalf*scaledStroke.fY >= yRadius) { |
| 649 | return false; |
| 650 | } |
| 651 | |
| 652 | // reset to device coordinates |
| 653 | GrDrawState* drawState = target->drawState(); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 654 | GrDrawState::AutoViewMatrixRestore avmr; |
| 655 | if (!avmr.setIdentity(drawState)) { |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 656 | return false; |
| 657 | } |
| 658 | |
| 659 | bool isStroked = (SkStrokeRec::kStroke_Style == style || SkStrokeRec::kHairline_Style == style); |
| 660 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 661 | GrIndexBuffer* indexBuffer = this->rRectIndexBuffer(context->getGpu()); |
| 662 | if (NULL == indexBuffer) { |
| 663 | GrPrintf("Failed to create index buffer!\n"); |
| 664 | return false; |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 665 | } |
| 666 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 667 | // if the corners are circles, use the circle renderer |
| 668 | if ((!isStroked || scaledStroke.fX == scaledStroke.fY) && xRadius == yRadius) { |
| 669 | drawState->setVertexAttribs<gCircleVertexAttribs>(SK_ARRAY_COUNT(gCircleVertexAttribs)); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 670 | SkASSERT(sizeof(CircleVertex) == drawState->getVertexSize()); |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 671 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 672 | GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0); |
| 673 | if (!geo.succeeded()) { |
| 674 | GrPrintf("Failed to get space for vertices!\n"); |
| 675 | return false; |
| 676 | } |
| 677 | CircleVertex* verts = reinterpret_cast<CircleVertex*>(geo.vertices()); |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 678 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 679 | SkScalar innerRadius = 0.0f; |
| 680 | SkScalar outerRadius = xRadius; |
| 681 | SkScalar halfWidth = 0; |
| 682 | if (style != SkStrokeRec::kFill_Style) { |
| 683 | if (SkScalarNearlyZero(scaledStroke.fX)) { |
| 684 | halfWidth = SK_ScalarHalf; |
| 685 | } else { |
| 686 | halfWidth = SkScalarHalf(scaledStroke.fX); |
| 687 | } |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 688 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 689 | if (isStroked) { |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 690 | innerRadius = xRadius - halfWidth; |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 691 | } |
| 692 | outerRadius += halfWidth; |
| 693 | bounds.outset(halfWidth, halfWidth); |
| 694 | } |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 695 | |
commit-bot@chromium.org | cefde6e | 2013-08-30 16:34:52 +0000 | [diff] [blame] | 696 | isStroked = (isStroked && innerRadius > 0); |
| 697 | |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 698 | GrEffectRef* effect = CircleEdgeEffect::Create(isStroked); |
| 699 | static const int kCircleEdgeAttrIndex = 1; |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 700 | drawState->addCoverageEffect(effect, kCircleEdgeAttrIndex)->unref(); |
skia.committer@gmail.com | 8be02fc | 2013-05-17 07:01:11 +0000 | [diff] [blame] | 701 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 702 | // The radii are outset for two reasons. First, it allows the shader to simply perform |
| 703 | // clamp(distance-to-center - radius, 0, 1). Second, the outer radius is used to compute the |
| 704 | // verts of the bounding box that is rendered and the outset ensures the box will cover all |
| 705 | // pixels partially covered by the circle. |
| 706 | outerRadius += SK_ScalarHalf; |
| 707 | innerRadius -= SK_ScalarHalf; |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 708 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 709 | // Expand the rect so all the pixels will be captured. |
| 710 | bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 711 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 712 | SkScalar yCoords[4] = { |
| 713 | bounds.fTop, |
| 714 | bounds.fTop + outerRadius, |
| 715 | bounds.fBottom - outerRadius, |
| 716 | bounds.fBottom |
| 717 | }; |
| 718 | SkScalar yOuterRadii[4] = { |
| 719 | -outerRadius, |
| 720 | 0, |
| 721 | 0, |
| 722 | outerRadius |
| 723 | }; |
| 724 | for (int i = 0; i < 4; ++i) { |
| 725 | verts->fPos = SkPoint::Make(bounds.fLeft, yCoords[i]); |
| 726 | verts->fOffset = SkPoint::Make(-outerRadius, yOuterRadii[i]); |
| 727 | verts->fOuterRadius = outerRadius; |
| 728 | verts->fInnerRadius = innerRadius; |
| 729 | verts++; |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 730 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 731 | verts->fPos = SkPoint::Make(bounds.fLeft + outerRadius, yCoords[i]); |
| 732 | verts->fOffset = SkPoint::Make(0, yOuterRadii[i]); |
| 733 | verts->fOuterRadius = outerRadius; |
| 734 | verts->fInnerRadius = innerRadius; |
| 735 | verts++; |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 736 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 737 | verts->fPos = SkPoint::Make(bounds.fRight - outerRadius, yCoords[i]); |
| 738 | verts->fOffset = SkPoint::Make(0, yOuterRadii[i]); |
| 739 | verts->fOuterRadius = outerRadius; |
| 740 | verts->fInnerRadius = innerRadius; |
| 741 | verts++; |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 742 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 743 | verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]); |
| 744 | verts->fOffset = SkPoint::Make(outerRadius, yOuterRadii[i]); |
| 745 | verts->fOuterRadius = outerRadius; |
| 746 | verts->fInnerRadius = innerRadius; |
| 747 | verts++; |
| 748 | } |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 749 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 750 | // drop out the middle quad if we're stroked |
| 751 | int indexCnt = isStroked ? GR_ARRAY_COUNT(gRRectIndices)-6 : GR_ARRAY_COUNT(gRRectIndices); |
| 752 | target->setIndexSourceToBuffer(indexBuffer); |
| 753 | target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bounds); |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 754 | |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 755 | // otherwise we use the ellipse renderer |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 756 | } else { |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 757 | drawState->setVertexAttribs<gEllipseVertexAttribs>(SK_ARRAY_COUNT(gEllipseVertexAttribs)); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 758 | SkASSERT(sizeof(EllipseVertex) == drawState->getVertexSize()); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 759 | |
| 760 | SkScalar innerXRadius = 0.0f; |
| 761 | SkScalar innerYRadius = 0.0f; |
| 762 | if (SkStrokeRec::kFill_Style != style) { |
| 763 | if (SkScalarNearlyZero(scaledStroke.length())) { |
| 764 | scaledStroke.set(SK_ScalarHalf, SK_ScalarHalf); |
| 765 | } else { |
| 766 | scaledStroke.scale(SK_ScalarHalf); |
| 767 | } |
| 768 | |
| 769 | // we only handle thick strokes for near-circular ellipses |
skia.committer@gmail.com | 8be02fc | 2013-05-17 07:01:11 +0000 | [diff] [blame] | 770 | if (scaledStroke.length() > SK_ScalarHalf && |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 771 | (SK_ScalarHalf*xRadius > yRadius || SK_ScalarHalf*yRadius > xRadius)) { |
| 772 | return false; |
| 773 | } |
| 774 | |
| 775 | // we don't handle it if curvature of the stroke is less than curvature of the ellipse |
| 776 | if (scaledStroke.fX*(yRadius*yRadius) < (scaledStroke.fY*scaledStroke.fY)*xRadius || |
| 777 | scaledStroke.fY*(xRadius*xRadius) < (scaledStroke.fX*scaledStroke.fX)*yRadius) { |
| 778 | return false; |
| 779 | } |
| 780 | |
| 781 | // this is legit only if scale & translation (which should be the case at the moment) |
| 782 | if (isStroked) { |
| 783 | innerXRadius = xRadius - scaledStroke.fX; |
| 784 | innerYRadius = yRadius - scaledStroke.fY; |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | xRadius += scaledStroke.fX; |
| 788 | yRadius += scaledStroke.fY; |
| 789 | bounds.outset(scaledStroke.fX, scaledStroke.fY); |
| 790 | } |
jvanverth@google.com | e364741 | 2013-05-08 15:31:43 +0000 | [diff] [blame] | 791 | |
commit-bot@chromium.org | cefde6e | 2013-08-30 16:34:52 +0000 | [diff] [blame] | 792 | isStroked = (isStroked && innerXRadius > 0 && innerYRadius > 0); |
| 793 | |
jvanverth@google.com | e364741 | 2013-05-08 15:31:43 +0000 | [diff] [blame] | 794 | GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0); |
| 795 | if (!geo.succeeded()) { |
| 796 | GrPrintf("Failed to get space for vertices!\n"); |
| 797 | return false; |
| 798 | } |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 799 | EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices()); |
jvanverth@google.com | e364741 | 2013-05-08 15:31:43 +0000 | [diff] [blame] | 800 | |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 801 | GrEffectRef* effect = EllipseEdgeEffect::Create(isStroked); |
jvanverth@google.com | e364741 | 2013-05-08 15:31:43 +0000 | [diff] [blame] | 802 | static const int kEllipseOffsetAttrIndex = 1; |
| 803 | static const int kEllipseRadiiAttrIndex = 2; |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 804 | drawState->addCoverageEffect(effect, |
| 805 | kEllipseOffsetAttrIndex, kEllipseRadiiAttrIndex)->unref(); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 806 | |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 807 | // Compute the reciprocals of the radii here to save time in the shader |
| 808 | SkScalar xRadRecip = SkScalarInvert(xRadius); |
| 809 | SkScalar yRadRecip = SkScalarInvert(yRadius); |
| 810 | SkScalar xInnerRadRecip = SkScalarInvert(innerXRadius); |
| 811 | SkScalar yInnerRadRecip = SkScalarInvert(innerYRadius); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 812 | |
| 813 | // Extend the radii out half a pixel to antialias. |
| 814 | SkScalar xOuterRadius = xRadius + SK_ScalarHalf; |
| 815 | SkScalar yOuterRadius = yRadius + SK_ScalarHalf; |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 816 | |
| 817 | // Expand the rect so all the pixels will be captured. |
| 818 | bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
| 819 | |
| 820 | SkScalar yCoords[4] = { |
| 821 | bounds.fTop, |
| 822 | bounds.fTop + yOuterRadius, |
| 823 | bounds.fBottom - yOuterRadius, |
| 824 | bounds.fBottom |
| 825 | }; |
| 826 | SkScalar yOuterOffsets[4] = { |
jvanverth@google.com | d1b5b14 | 2013-07-02 14:46:03 +0000 | [diff] [blame] | 827 | yOuterRadius, |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 828 | SK_ScalarNearlyZero, // we're using inversesqrt() in the shader, so can't be exactly 0 |
| 829 | SK_ScalarNearlyZero, |
| 830 | yOuterRadius |
| 831 | }; |
| 832 | |
| 833 | for (int i = 0; i < 4; ++i) { |
| 834 | verts->fPos = SkPoint::Make(bounds.fLeft, yCoords[i]); |
jvanverth@google.com | d1b5b14 | 2013-07-02 14:46:03 +0000 | [diff] [blame] | 835 | verts->fOffset = SkPoint::Make(xOuterRadius, yOuterOffsets[i]); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 836 | verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 837 | verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 838 | verts++; |
| 839 | |
| 840 | verts->fPos = SkPoint::Make(bounds.fLeft + xOuterRadius, yCoords[i]); |
| 841 | verts->fOffset = SkPoint::Make(SK_ScalarNearlyZero, yOuterOffsets[i]); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 842 | verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 843 | verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 844 | verts++; |
| 845 | |
| 846 | verts->fPos = SkPoint::Make(bounds.fRight - xOuterRadius, yCoords[i]); |
| 847 | verts->fOffset = SkPoint::Make(SK_ScalarNearlyZero, yOuterOffsets[i]); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 848 | verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 849 | verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 850 | verts++; |
| 851 | |
| 852 | verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]); |
| 853 | verts->fOffset = SkPoint::Make(xOuterRadius, yOuterOffsets[i]); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 854 | verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 855 | verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 856 | verts++; |
| 857 | } |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 858 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 859 | // drop out the middle quad if we're stroked |
| 860 | int indexCnt = isStroked ? GR_ARRAY_COUNT(gRRectIndices)-6 : GR_ARRAY_COUNT(gRRectIndices); |
| 861 | target->setIndexSourceToBuffer(indexBuffer); |
| 862 | target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bounds); |
| 863 | } |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 864 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 865 | return true; |
| 866 | } |