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