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 | |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 10 | #include "gl/builders/GrGLProgramBuilder.h" |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 11 | #include "gl/GrGLProcessor.h" |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 12 | #include "gl/GrGLSL.h" |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 13 | #include "gl/GrGLGeometryProcessor.h" |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 14 | #include "GrProcessor.h" |
| 15 | #include "GrTBackendProcessorFactory.h" |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 16 | |
| 17 | #include "GrDrawState.h" |
| 18 | #include "GrDrawTarget.h" |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 19 | #include "GrGpu.h" |
| 20 | |
| 21 | #include "SkRRect.h" |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 22 | #include "SkStrokeRec.h" |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 23 | #include "SkTLazy.h" |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 24 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 25 | #include "GrGeometryProcessor.h" |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 26 | #include "effects/GrRRectEffect.h" |
commit-bot@chromium.org | 234d4fb | 2013-09-30 19:55:49 +0000 | [diff] [blame] | 27 | |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 28 | namespace { |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 29 | // TODO(joshualitt) add per vertex colors |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 30 | struct CircleVertex { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 31 | SkPoint fPos; |
| 32 | SkPoint fOffset; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 33 | SkScalar fOuterRadius; |
| 34 | SkScalar fInnerRadius; |
| 35 | }; |
| 36 | |
| 37 | struct EllipseVertex { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 38 | SkPoint fPos; |
| 39 | SkPoint fOffset; |
| 40 | SkPoint fOuterRadii; |
| 41 | SkPoint fInnerRadii; |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 44 | struct DIEllipseVertex { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 45 | SkPoint fPos; |
| 46 | SkPoint fOuterOffset; |
| 47 | SkPoint fInnerOffset; |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 50 | inline bool circle_stays_circle(const SkMatrix& m) { |
| 51 | return m.isSimilarity(); |
| 52 | } |
| 53 | |
| 54 | } |
| 55 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 56 | /////////////////////////////////////////////////////////////////////////////// |
| 57 | |
| 58 | /** |
| 59 | * 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] | 60 | * 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] | 61 | */ |
| 62 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 63 | class CircleEdgeEffect : public GrGeometryProcessor { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 64 | public: |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 65 | static GrGeometryProcessor* Create(bool stroke) { |
bsalomon | 98b33eb | 2014-10-15 11:05:26 -0700 | [diff] [blame] | 66 | GR_CREATE_STATIC_PROCESSOR(gCircleStrokeEdge, CircleEdgeEffect, (true)); |
| 67 | GR_CREATE_STATIC_PROCESSOR(gCircleFillEdge, CircleEdgeEffect, (false)); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 68 | |
| 69 | if (stroke) { |
bsalomon@google.com | d42aca3 | 2013-04-23 15:37:27 +0000 | [diff] [blame] | 70 | gCircleStrokeEdge->ref(); |
| 71 | return gCircleStrokeEdge; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 72 | } else { |
bsalomon@google.com | d42aca3 | 2013-04-23 15:37:27 +0000 | [diff] [blame] | 73 | gCircleFillEdge->ref(); |
| 74 | return gCircleFillEdge; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 78 | const GrShaderVar& inCircleEdge() const { return fInCircleEdge; } |
| 79 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 80 | virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERRIDE { |
| 81 | return GrTBackendGeometryProcessorFactory<CircleEdgeEffect>::getInstance(); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | virtual ~CircleEdgeEffect() {} |
| 85 | |
| 86 | static const char* Name() { return "CircleEdge"; } |
| 87 | |
| 88 | inline bool isStroked() const { return fStroke; } |
| 89 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 90 | class GLProcessor : public GrGLGeometryProcessor { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 91 | public: |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 92 | GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&) |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 93 | : INHERITED (factory) {} |
| 94 | |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 95 | virtual void emitCode(const EmitArgs& args) SK_OVERRIDE { |
| 96 | const CircleEdgeEffect& circleEffect = args.fGP.cast<CircleEdgeEffect>(); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 97 | GrGLVertToFrag v(kVec4f_GrSLType); |
| 98 | args.fPB->addVarying("CircleEdge", &v); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 99 | |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 100 | GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();; |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 101 | vsBuilder->codeAppendf("%s = %s;", v.vsOut(), circleEffect.inCircleEdge().c_str()); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 102 | |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 103 | GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 104 | fsBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn()); |
| 105 | fsBuilder->codeAppendf("float edgeAlpha = clamp(%s.z - d, 0.0, 1.0);", v.fsIn()); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 106 | if (circleEffect.isStroked()) { |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 107 | fsBuilder->codeAppendf("float innerAlpha = clamp(d - %s.w, 0.0, 1.0);", |
| 108 | v.fsIn()); |
| 109 | fsBuilder->codeAppend("edgeAlpha *= innerAlpha;"); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 110 | } |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 111 | |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 112 | fsBuilder->codeAppendf("%s = %s;\n", args.fOutput, |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 113 | (GrGLSLExpr4(args.fInput) * GrGLSLExpr1("edgeAlpha")).c_str()); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 114 | } |
| 115 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 116 | static void GenKey(const GrProcessor& processor, const GrGLCaps&, |
| 117 | GrProcessorKeyBuilder* b) { |
| 118 | const CircleEdgeEffect& circleEffect = processor.cast<CircleEdgeEffect>(); |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 119 | b->add32(circleEffect.isStroked()); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 120 | } |
| 121 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 122 | virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE {} |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 123 | |
| 124 | private: |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 125 | typedef GrGLGeometryProcessor INHERITED; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | |
| 129 | private: |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 130 | CircleEdgeEffect(bool stroke) |
| 131 | : fInCircleEdge(this->addVertexAttrib( |
| 132 | GrShaderVar("inCircleEdge", |
| 133 | kVec4f_GrSLType, |
| 134 | GrShaderVar::kAttribute_TypeModifier))) { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 135 | fStroke = stroke; |
| 136 | } |
| 137 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 138 | virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 139 | const CircleEdgeEffect& cee = other.cast<CircleEdgeEffect>(); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 140 | return cee.fStroke == fStroke; |
| 141 | } |
| 142 | |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 143 | virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { |
egdaniel | ccb2e38 | 2014-10-13 12:53:46 -0700 | [diff] [blame] | 144 | inout->mulByUnknownAlpha(); |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 145 | } |
| 146 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 147 | const GrShaderVar& fInCircleEdge; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 148 | bool fStroke; |
| 149 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 150 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 151 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 152 | typedef GrGeometryProcessor INHERITED; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 153 | }; |
| 154 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 155 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(CircleEdgeEffect); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 156 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 157 | GrGeometryProcessor* CircleEdgeEffect::TestCreate(SkRandom* random, |
| 158 | GrContext* context, |
| 159 | const GrDrawTargetCaps&, |
| 160 | GrTexture* textures[]) { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 161 | return CircleEdgeEffect::Create(random->nextBool()); |
| 162 | } |
| 163 | |
| 164 | /////////////////////////////////////////////////////////////////////////////// |
| 165 | |
| 166 | /** |
| 167 | * 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] | 168 | * ellipse, specified as a 2D offset from center, and the reciprocals of the outer and inner radii, |
| 169 | * in both x and y directions. |
| 170 | * |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 171 | * 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] | 172 | */ |
| 173 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 174 | class EllipseEdgeEffect : public GrGeometryProcessor { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 175 | public: |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 176 | static GrGeometryProcessor* Create(bool stroke) { |
bsalomon | 98b33eb | 2014-10-15 11:05:26 -0700 | [diff] [blame] | 177 | GR_CREATE_STATIC_PROCESSOR(gEllipseStrokeEdge, EllipseEdgeEffect, (true)); |
| 178 | GR_CREATE_STATIC_PROCESSOR(gEllipseFillEdge, EllipseEdgeEffect, (false)); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 179 | |
| 180 | if (stroke) { |
bsalomon@google.com | d42aca3 | 2013-04-23 15:37:27 +0000 | [diff] [blame] | 181 | gEllipseStrokeEdge->ref(); |
| 182 | return gEllipseStrokeEdge; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 183 | } else { |
bsalomon@google.com | d42aca3 | 2013-04-23 15:37:27 +0000 | [diff] [blame] | 184 | gEllipseFillEdge->ref(); |
| 185 | return gEllipseFillEdge; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 189 | virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERRIDE { |
| 190 | return GrTBackendGeometryProcessorFactory<EllipseEdgeEffect>::getInstance(); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | virtual ~EllipseEdgeEffect() {} |
| 194 | |
| 195 | static const char* Name() { return "EllipseEdge"; } |
| 196 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 197 | const GrShaderVar& inEllipseOffset() const { return fInEllipseOffset; } |
| 198 | const GrShaderVar& inEllipseRadii() const { return fInEllipseRadii; } |
| 199 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 200 | inline bool isStroked() const { return fStroke; } |
| 201 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 202 | class GLProcessor : public GrGLGeometryProcessor { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 203 | public: |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 204 | GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&) |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 205 | : INHERITED (factory) {} |
| 206 | |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 207 | virtual void emitCode(const EmitArgs& args) SK_OVERRIDE { |
| 208 | const EllipseEdgeEffect& ellipseEffect = args.fGP.cast<EllipseEdgeEffect>(); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 209 | |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 210 | GrGLVertToFrag ellipseOffsets(kVec2f_GrSLType); |
| 211 | args.fPB->addVarying("EllipseOffsets", &ellipseOffsets); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 212 | |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 213 | GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 214 | vsBuilder->codeAppendf("%s = %s;", ellipseOffsets.vsOut(), |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 215 | ellipseEffect.inEllipseOffset().c_str()); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 216 | |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 217 | GrGLVertToFrag ellipseRadii(kVec4f_GrSLType); |
| 218 | args.fPB->addVarying("EllipseRadii", &ellipseRadii); |
| 219 | vsBuilder->codeAppendf("%s = %s;", ellipseRadii.vsOut(), |
| 220 | ellipseEffect.inEllipseRadii().c_str()); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 221 | |
skia.committer@gmail.com | 8be02fc | 2013-05-17 07:01:11 +0000 | [diff] [blame] | 222 | // for outer curve |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 223 | GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 224 | fsBuilder->codeAppendf("vec2 scaledOffset = %s*%s.xy;", ellipseOffsets.fsIn(), |
| 225 | ellipseRadii.fsIn()); |
| 226 | fsBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset) - 1.0;"); |
| 227 | fsBuilder->codeAppendf("vec2 grad = 2.0*scaledOffset*%s.xy;", ellipseRadii.fsIn()); |
| 228 | fsBuilder->codeAppend("float grad_dot = dot(grad, grad);"); |
| 229 | |
commit-bot@chromium.org | 1b035d8 | 2014-04-09 17:11:09 +0000 | [diff] [blame] | 230 | // avoid calling inversesqrt on zero. |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 231 | fsBuilder->codeAppend("grad_dot = max(grad_dot, 1.0e-4);"); |
| 232 | fsBuilder->codeAppend("float invlen = inversesqrt(grad_dot);"); |
| 233 | fsBuilder->codeAppend("float edgeAlpha = clamp(0.5-test*invlen, 0.0, 1.0);"); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 234 | |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 235 | // for inner curve |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 236 | if (ellipseEffect.isStroked()) { |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 237 | fsBuilder->codeAppendf("scaledOffset = %s*%s.zw;", |
| 238 | ellipseOffsets.fsIn(), ellipseRadii.fsIn()); |
| 239 | fsBuilder->codeAppend("test = dot(scaledOffset, scaledOffset) - 1.0;"); |
| 240 | fsBuilder->codeAppendf("grad = 2.0*scaledOffset*%s.zw;", |
| 241 | ellipseRadii.fsIn()); |
| 242 | fsBuilder->codeAppend("invlen = inversesqrt(dot(grad, grad));"); |
| 243 | fsBuilder->codeAppend("edgeAlpha *= clamp(0.5+test*invlen, 0.0, 1.0);"); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 244 | } |
| 245 | |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 246 | fsBuilder->codeAppendf("%s = %s;", args.fOutput, |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 247 | (GrGLSLExpr4(args.fInput) * GrGLSLExpr1("edgeAlpha")).c_str()); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 248 | } |
| 249 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 250 | static void GenKey(const GrProcessor& processor, const GrGLCaps&, |
| 251 | GrProcessorKeyBuilder* b) { |
| 252 | const EllipseEdgeEffect& ellipseEffect = processor.cast<EllipseEdgeEffect>(); |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 253 | b->add32(ellipseEffect.isStroked()); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 254 | } |
| 255 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 256 | virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | private: |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 260 | typedef GrGLGeometryProcessor INHERITED; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 261 | }; |
| 262 | |
| 263 | private: |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 264 | EllipseEdgeEffect(bool stroke) |
| 265 | : fInEllipseOffset(this->addVertexAttrib( |
| 266 | GrShaderVar("inEllipseOffset", |
| 267 | kVec2f_GrSLType, |
| 268 | GrShaderVar::kAttribute_TypeModifier))) |
| 269 | , fInEllipseRadii(this->addVertexAttrib( |
| 270 | GrShaderVar("inEllipseRadii", |
| 271 | kVec4f_GrSLType, |
| 272 | GrShaderVar::kAttribute_TypeModifier))) { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 273 | fStroke = stroke; |
| 274 | } |
| 275 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 276 | virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 277 | const EllipseEdgeEffect& eee = other.cast<EllipseEdgeEffect>(); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 278 | return eee.fStroke == fStroke; |
| 279 | } |
| 280 | |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 281 | virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { |
egdaniel | ccb2e38 | 2014-10-13 12:53:46 -0700 | [diff] [blame] | 282 | inout->mulByUnknownAlpha(); |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 283 | } |
| 284 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 285 | const GrShaderVar& fInEllipseOffset; |
| 286 | const GrShaderVar& fInEllipseRadii; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 287 | bool fStroke; |
| 288 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 289 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 290 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 291 | typedef GrGeometryProcessor INHERITED; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 292 | }; |
| 293 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 294 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(EllipseEdgeEffect); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 295 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 296 | GrGeometryProcessor* EllipseEdgeEffect::TestCreate(SkRandom* random, |
| 297 | GrContext* context, |
| 298 | const GrDrawTargetCaps&, |
| 299 | GrTexture* textures[]) { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 300 | return EllipseEdgeEffect::Create(random->nextBool()); |
| 301 | } |
| 302 | |
| 303 | /////////////////////////////////////////////////////////////////////////////// |
| 304 | |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 305 | /** |
skia.committer@gmail.com | 6fc1b49 | 2013-09-06 07:01:45 +0000 | [diff] [blame] | 306 | * The output of this effect is a modulation of the input color and coverage for an ellipse, |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 307 | * specified as a 2D offset from center for both the outer and inner paths (if stroked). The |
| 308 | * implict equation used is for a unit circle (x^2 + y^2 - 1 = 0) and the edge corrected by |
| 309 | * using differentials. |
| 310 | * |
| 311 | * The result is device-independent and can be used with any affine matrix. |
| 312 | */ |
| 313 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 314 | class DIEllipseEdgeEffect : public GrGeometryProcessor { |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 315 | public: |
| 316 | enum Mode { kStroke = 0, kHairline, kFill }; |
| 317 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 318 | static GrGeometryProcessor* Create(Mode mode) { |
bsalomon | 98b33eb | 2014-10-15 11:05:26 -0700 | [diff] [blame] | 319 | GR_CREATE_STATIC_PROCESSOR(gEllipseStrokeEdge, DIEllipseEdgeEffect, (kStroke)); |
| 320 | GR_CREATE_STATIC_PROCESSOR(gEllipseHairlineEdge, DIEllipseEdgeEffect, (kHairline)); |
| 321 | GR_CREATE_STATIC_PROCESSOR(gEllipseFillEdge, DIEllipseEdgeEffect, (kFill)); |
skia.committer@gmail.com | 6fc1b49 | 2013-09-06 07:01:45 +0000 | [diff] [blame] | 322 | |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 323 | if (kStroke == mode) { |
| 324 | gEllipseStrokeEdge->ref(); |
| 325 | return gEllipseStrokeEdge; |
| 326 | } else if (kHairline == mode) { |
| 327 | gEllipseHairlineEdge->ref(); |
| 328 | return gEllipseHairlineEdge; |
| 329 | } else { |
| 330 | gEllipseFillEdge->ref(); |
| 331 | return gEllipseFillEdge; |
| 332 | } |
| 333 | } |
| 334 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 335 | virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERRIDE { |
| 336 | return GrTBackendGeometryProcessorFactory<DIEllipseEdgeEffect>::getInstance(); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | virtual ~DIEllipseEdgeEffect() {} |
| 340 | |
| 341 | static const char* Name() { return "DIEllipseEdge"; } |
| 342 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 343 | const GrShaderVar& inEllipseOffsets0() const { return fInEllipseOffsets0; } |
| 344 | const GrShaderVar& inEllipseOffsets1() const { return fInEllipseOffsets1; } |
| 345 | |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 346 | inline Mode getMode() const { return fMode; } |
| 347 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 348 | class GLProcessor : public GrGLGeometryProcessor { |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 349 | public: |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 350 | GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&) |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 351 | : INHERITED (factory) {} |
| 352 | |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 353 | virtual void emitCode(const EmitArgs& args) SK_OVERRIDE { |
| 354 | const DIEllipseEdgeEffect& ellipseEffect = args.fGP.cast<DIEllipseEdgeEffect>(); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 355 | |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 356 | GrGLVertToFrag offsets0(kVec2f_GrSLType); |
| 357 | args.fPB->addVarying("EllipseOffsets0", &offsets0); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 358 | |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 359 | GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 360 | vsBuilder->codeAppendf("%s = %s;", offsets0.vsOut(), |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 361 | ellipseEffect.inEllipseOffsets0().c_str()); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 362 | |
| 363 | GrGLVertToFrag offsets1(kVec2f_GrSLType); |
| 364 | args.fPB->addVarying("EllipseOffsets1", &offsets1); |
| 365 | vsBuilder->codeAppendf("%s = %s;", offsets1.vsOut(), |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 366 | ellipseEffect.inEllipseOffsets1().c_str()); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 367 | |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 368 | GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 369 | SkAssertResult(fsBuilder->enableFeature( |
| 370 | GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 371 | // for outer curve |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 372 | fsBuilder->codeAppendf("vec2 scaledOffset = %s.xy;", offsets0.fsIn()); |
| 373 | fsBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset) - 1.0;"); |
| 374 | fsBuilder->codeAppendf("vec2 duvdx = dFdx(%s);", offsets0.fsIn()); |
| 375 | fsBuilder->codeAppendf("vec2 duvdy = dFdy(%s);", offsets0.fsIn()); |
| 376 | fsBuilder->codeAppendf("vec2 grad = vec2(2.0*%s.x*duvdx.x + 2.0*%s.y*duvdx.y," |
| 377 | " 2.0*%s.x*duvdy.x + 2.0*%s.y*duvdy.y);", |
| 378 | offsets0.fsIn(), offsets0.fsIn(), offsets0.fsIn(), offsets0.fsIn()); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 379 | |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 380 | fsBuilder->codeAppend("float grad_dot = dot(grad, grad);"); |
commit-bot@chromium.org | 1b035d8 | 2014-04-09 17:11:09 +0000 | [diff] [blame] | 381 | // avoid calling inversesqrt on zero. |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 382 | fsBuilder->codeAppend("grad_dot = max(grad_dot, 1.0e-4);"); |
| 383 | fsBuilder->codeAppend("float invlen = inversesqrt(grad_dot);"); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 384 | if (kHairline == ellipseEffect.getMode()) { |
| 385 | // can probably do this with one step |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 386 | fsBuilder->codeAppend("float edgeAlpha = clamp(1.0-test*invlen, 0.0, 1.0);"); |
| 387 | fsBuilder->codeAppend("edgeAlpha *= clamp(1.0+test*invlen, 0.0, 1.0);"); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 388 | } else { |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 389 | fsBuilder->codeAppend("float edgeAlpha = clamp(0.5-test*invlen, 0.0, 1.0);"); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | // for inner curve |
| 393 | if (kStroke == ellipseEffect.getMode()) { |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 394 | fsBuilder->codeAppendf("scaledOffset = %s.xy;", offsets1.fsIn()); |
| 395 | fsBuilder->codeAppend("test = dot(scaledOffset, scaledOffset) - 1.0;"); |
| 396 | fsBuilder->codeAppendf("duvdx = dFdx(%s);", offsets1.fsIn()); |
| 397 | fsBuilder->codeAppendf("duvdy = dFdy(%s);", offsets1.fsIn()); |
| 398 | fsBuilder->codeAppendf("grad = vec2(2.0*%s.x*duvdx.x + 2.0*%s.y*duvdx.y," |
| 399 | " 2.0*%s.x*duvdy.x + 2.0*%s.y*duvdy.y);", |
| 400 | offsets1.fsIn(), offsets1.fsIn(), offsets1.fsIn(), |
| 401 | offsets1.fsIn()); |
| 402 | fsBuilder->codeAppend("invlen = inversesqrt(dot(grad, grad));"); |
| 403 | fsBuilder->codeAppend("edgeAlpha *= clamp(0.5+test*invlen, 0.0, 1.0);"); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 404 | } |
| 405 | |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame^] | 406 | fsBuilder->codeAppendf("%s = %s;", args.fOutput, |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 407 | (GrGLSLExpr4(args.fInput) * GrGLSLExpr1("edgeAlpha")).c_str()); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 408 | } |
| 409 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 410 | static void GenKey(const GrProcessor& processor, const GrGLCaps&, |
| 411 | GrProcessorKeyBuilder* b) { |
| 412 | const DIEllipseEdgeEffect& ellipseEffect = processor.cast<DIEllipseEdgeEffect>(); |
skia.committer@gmail.com | 6fc1b49 | 2013-09-06 07:01:45 +0000 | [diff] [blame] | 413 | |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 414 | b->add32(ellipseEffect.getMode()); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 415 | } |
| 416 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 417 | virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE { |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | private: |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 421 | typedef GrGLGeometryProcessor INHERITED; |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 422 | }; |
| 423 | |
| 424 | private: |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 425 | DIEllipseEdgeEffect(Mode mode) |
| 426 | : fInEllipseOffsets0(this->addVertexAttrib( |
| 427 | GrShaderVar("inEllipseOffsets0", |
| 428 | kVec2f_GrSLType, |
| 429 | GrShaderVar::kAttribute_TypeModifier))) |
| 430 | , fInEllipseOffsets1(this->addVertexAttrib( |
| 431 | GrShaderVar("inEllipseOffsets1", |
| 432 | kVec2f_GrSLType, |
| 433 | GrShaderVar::kAttribute_TypeModifier))) { |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 434 | fMode = mode; |
| 435 | } |
| 436 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 437 | virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 438 | const DIEllipseEdgeEffect& eee = other.cast<DIEllipseEdgeEffect>(); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 439 | return eee.fMode == fMode; |
| 440 | } |
| 441 | |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 442 | virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { |
egdaniel | ccb2e38 | 2014-10-13 12:53:46 -0700 | [diff] [blame] | 443 | inout->mulByUnknownAlpha(); |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 444 | } |
| 445 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 446 | const GrShaderVar& fInEllipseOffsets0; |
| 447 | const GrShaderVar& fInEllipseOffsets1; |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 448 | Mode fMode; |
| 449 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 450 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 451 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 452 | typedef GrGeometryProcessor INHERITED; |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 453 | }; |
| 454 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 455 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DIEllipseEdgeEffect); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 456 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 457 | GrGeometryProcessor* DIEllipseEdgeEffect::TestCreate(SkRandom* random, |
| 458 | GrContext* context, |
| 459 | const GrDrawTargetCaps&, |
| 460 | GrTexture* textures[]) { |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 461 | return DIEllipseEdgeEffect::Create((Mode)(random->nextRangeU(0,2))); |
| 462 | } |
| 463 | |
| 464 | /////////////////////////////////////////////////////////////////////////////// |
| 465 | |
commit-bot@chromium.org | ef284a8 | 2013-07-11 22:29:29 +0000 | [diff] [blame] | 466 | void GrOvalRenderer::reset() { |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 467 | SkSafeSetNull(fRRectIndexBuffer); |
joshualitt | 58a6544 | 2014-10-22 20:53:24 -0700 | [diff] [blame] | 468 | SkSafeSetNull(fStrokeRRectIndexBuffer); |
commit-bot@chromium.org | ef284a8 | 2013-07-11 22:29:29 +0000 | [diff] [blame] | 469 | } |
| 470 | |
commit-bot@chromium.org | 37d883d | 2013-05-02 13:11:22 +0000 | [diff] [blame] | 471 | bool GrOvalRenderer::drawOval(GrDrawTarget* target, const GrContext* context, bool useAA, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 472 | const SkRect& oval, const SkStrokeRec& stroke) |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 473 | { |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 474 | bool useCoverageAA = useAA && |
| 475 | !target->getDrawState().getRenderTarget()->isMultisampled() && |
| 476 | !target->shouldDisableCoverageAAForBlend(); |
| 477 | |
| 478 | if (!useCoverageAA) { |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 479 | return false; |
| 480 | } |
| 481 | |
| 482 | const SkMatrix& vm = context->getMatrix(); |
| 483 | |
skia.committer@gmail.com | 7e32851 | 2013-03-23 07:01:28 +0000 | [diff] [blame] | 484 | // we can draw circles |
| 485 | if (SkScalarNearlyEqual(oval.width(), oval.height()) |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 486 | && circle_stays_circle(vm)) { |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 487 | this->drawCircle(target, context, useCoverageAA, oval, stroke); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 488 | // if we have shader derivative support, render as device-independent |
| 489 | } else if (target->caps()->shaderDerivativeSupport()) { |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 490 | return this->drawDIEllipse(target, context, useCoverageAA, oval, stroke); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 491 | // otherwise axis-aligned ellipses only |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 492 | } else if (vm.rectStaysRect()) { |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 493 | return this->drawEllipse(target, context, useCoverageAA, oval, stroke); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 494 | } else { |
| 495 | return false; |
| 496 | } |
| 497 | |
| 498 | return true; |
| 499 | } |
| 500 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 501 | /////////////////////////////////////////////////////////////////////////////// |
| 502 | |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 503 | // position + edge |
| 504 | extern const GrVertexAttrib gCircleVertexAttribs[] = { |
| 505 | {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 506 | {kVec4f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAttribBinding} |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 507 | }; |
| 508 | |
skia.committer@gmail.com | 7e32851 | 2013-03-23 07:01:28 +0000 | [diff] [blame] | 509 | void GrOvalRenderer::drawCircle(GrDrawTarget* target, |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 510 | const GrContext* context, |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 511 | bool useCoverageAA, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 512 | const SkRect& circle, |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 513 | const SkStrokeRec& stroke) |
| 514 | { |
| 515 | GrDrawState* drawState = target->drawState(); |
| 516 | |
| 517 | const SkMatrix& vm = drawState->getViewMatrix(); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 518 | SkPoint center = SkPoint::Make(circle.centerX(), circle.centerY()); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 519 | vm.mapPoints(¢er, 1); |
| 520 | SkScalar radius = vm.mapRadius(SkScalarHalf(circle.width())); |
| 521 | SkScalar strokeWidth = vm.mapRadius(stroke.getWidth()); |
| 522 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 523 | GrDrawState::AutoViewMatrixRestore avmr; |
| 524 | if (!avmr.setIdentity(drawState)) { |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 525 | return; |
| 526 | } |
| 527 | |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 528 | drawState->setVertexAttribs<gCircleVertexAttribs>(SK_ARRAY_COUNT(gCircleVertexAttribs), |
| 529 | sizeof(CircleVertex)); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 530 | |
| 531 | GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); |
| 532 | if (!geo.succeeded()) { |
| 533 | GrPrintf("Failed to get space for vertices!\n"); |
| 534 | return; |
| 535 | } |
| 536 | |
| 537 | CircleVertex* verts = reinterpret_cast<CircleVertex*>(geo.vertices()); |
| 538 | |
| 539 | SkStrokeRec::Style style = stroke.getStyle(); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 540 | bool isStrokeOnly = SkStrokeRec::kStroke_Style == style || |
| 541 | SkStrokeRec::kHairline_Style == style; |
| 542 | bool hasStroke = isStrokeOnly || SkStrokeRec::kStrokeAndFill_Style == style; |
skia.committer@gmail.com | 7e32851 | 2013-03-23 07:01:28 +0000 | [diff] [blame] | 543 | |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 544 | SkScalar innerRadius = 0.0f; |
| 545 | SkScalar outerRadius = radius; |
| 546 | SkScalar halfWidth = 0; |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 547 | if (hasStroke) { |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 548 | if (SkScalarNearlyZero(strokeWidth)) { |
| 549 | halfWidth = SK_ScalarHalf; |
| 550 | } else { |
| 551 | halfWidth = SkScalarHalf(strokeWidth); |
| 552 | } |
| 553 | |
| 554 | outerRadius += halfWidth; |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 555 | if (isStrokeOnly) { |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 556 | innerRadius = radius - halfWidth; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 557 | } |
| 558 | } |
| 559 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 560 | GrGeometryProcessor* gp = CircleEdgeEffect::Create(isStrokeOnly && innerRadius > 0); |
| 561 | drawState->setGeometryProcessor(gp)->unref(); |
commit-bot@chromium.org | cefde6e | 2013-08-30 16:34:52 +0000 | [diff] [blame] | 562 | |
bsalomon@google.com | 58e30fe | 2013-04-01 19:01:20 +0000 | [diff] [blame] | 563 | // The radii are outset for two reasons. First, it allows the shader to simply perform |
| 564 | // clamp(distance-to-center - radius, 0, 1). Second, the outer radius is used to compute the |
| 565 | // verts of the bounding box that is rendered and the outset ensures the box will cover all |
| 566 | // pixels partially covered by the circle. |
| 567 | outerRadius += SK_ScalarHalf; |
| 568 | innerRadius -= SK_ScalarHalf; |
| 569 | |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 570 | SkRect bounds = SkRect::MakeLTRB( |
bsalomon@google.com | 58e30fe | 2013-04-01 19:01:20 +0000 | [diff] [blame] | 571 | center.fX - outerRadius, |
| 572 | center.fY - outerRadius, |
| 573 | center.fX + outerRadius, |
| 574 | center.fY + outerRadius |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 575 | ); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 576 | |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 577 | verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 578 | verts[0].fOffset = SkPoint::Make(-outerRadius, -outerRadius); |
| 579 | verts[0].fOuterRadius = outerRadius; |
| 580 | verts[0].fInnerRadius = innerRadius; |
| 581 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 582 | verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); |
| 583 | verts[1].fOffset = SkPoint::Make(-outerRadius, outerRadius); |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 584 | verts[1].fOuterRadius = outerRadius; |
| 585 | verts[1].fInnerRadius = innerRadius; |
| 586 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 587 | verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
| 588 | verts[2].fOffset = SkPoint::Make(outerRadius, outerRadius); |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 589 | verts[2].fOuterRadius = outerRadius; |
| 590 | verts[2].fInnerRadius = innerRadius; |
| 591 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 592 | verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
| 593 | verts[3].fOffset = SkPoint::Make(outerRadius, -outerRadius); |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 594 | verts[3].fOuterRadius = outerRadius; |
| 595 | verts[3].fInnerRadius = innerRadius; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 596 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 597 | target->setIndexSourceToBuffer(context->getGpu()->getQuadIndexBuffer()); |
| 598 | target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &bounds); |
| 599 | target->resetIndexSource(); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 600 | } |
| 601 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 602 | /////////////////////////////////////////////////////////////////////////////// |
| 603 | |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 604 | // position + offset + 1/radii |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 605 | extern const GrVertexAttrib gEllipseVertexAttribs[] = { |
| 606 | {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 607 | {kVec2f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAttribBinding}, |
| 608 | {kVec4f_GrVertexAttribType, 2*sizeof(SkPoint), kGeometryProcessor_GrVertexAttribBinding} |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 609 | }; |
| 610 | |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 611 | // position + offsets |
| 612 | extern const GrVertexAttrib gDIEllipseVertexAttribs[] = { |
| 613 | {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 614 | {kVec2f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAttribBinding}, |
| 615 | {kVec2f_GrVertexAttribType, 2*sizeof(SkPoint), kGeometryProcessor_GrVertexAttribBinding}, |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 616 | }; |
| 617 | |
jvanverth@google.com | c4f2eca | 2013-04-16 12:30:35 +0000 | [diff] [blame] | 618 | bool GrOvalRenderer::drawEllipse(GrDrawTarget* target, |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 619 | const GrContext* context, |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 620 | bool useCoverageAA, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 621 | const SkRect& ellipse, |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 622 | const SkStrokeRec& stroke) |
| 623 | { |
| 624 | GrDrawState* drawState = target->drawState(); |
| 625 | #ifdef SK_DEBUG |
| 626 | { |
| 627 | // we should have checked for this previously |
| 628 | bool isAxisAlignedEllipse = drawState->getViewMatrix().rectStaysRect(); |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 629 | SkASSERT(useCoverageAA && isAxisAlignedEllipse); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 630 | } |
| 631 | #endif |
| 632 | |
commit-bot@chromium.org | 0c88828 | 2013-04-19 19:01:45 +0000 | [diff] [blame] | 633 | // 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] | 634 | const SkMatrix& vm = drawState->getViewMatrix(); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 635 | SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY()); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 636 | vm.mapPoints(¢er, 1); |
commit-bot@chromium.org | 0c88828 | 2013-04-19 19:01:45 +0000 | [diff] [blame] | 637 | SkScalar ellipseXRadius = SkScalarHalf(ellipse.width()); |
| 638 | SkScalar ellipseYRadius = SkScalarHalf(ellipse.height()); |
skia.committer@gmail.com | 64b682c | 2013-04-20 07:01:07 +0000 | [diff] [blame] | 639 | SkScalar xRadius = SkScalarAbs(vm[SkMatrix::kMScaleX]*ellipseXRadius + |
commit-bot@chromium.org | 0c88828 | 2013-04-19 19:01:45 +0000 | [diff] [blame] | 640 | vm[SkMatrix::kMSkewY]*ellipseYRadius); |
skia.committer@gmail.com | 64b682c | 2013-04-20 07:01:07 +0000 | [diff] [blame] | 641 | SkScalar yRadius = SkScalarAbs(vm[SkMatrix::kMSkewX]*ellipseXRadius + |
commit-bot@chromium.org | 0c88828 | 2013-04-19 19:01:45 +0000 | [diff] [blame] | 642 | vm[SkMatrix::kMScaleY]*ellipseYRadius); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 643 | |
commit-bot@chromium.org | 0c88828 | 2013-04-19 19:01:45 +0000 | [diff] [blame] | 644 | // do (potentially) anisotropic mapping of stroke |
| 645 | SkVector scaledStroke; |
| 646 | SkScalar strokeWidth = stroke.getWidth(); |
| 647 | scaledStroke.fX = SkScalarAbs(strokeWidth*(vm[SkMatrix::kMScaleX] + vm[SkMatrix::kMSkewY])); |
| 648 | scaledStroke.fY = SkScalarAbs(strokeWidth*(vm[SkMatrix::kMSkewX] + vm[SkMatrix::kMScaleY])); |
| 649 | |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 650 | SkStrokeRec::Style style = stroke.getStyle(); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 651 | bool isStrokeOnly = SkStrokeRec::kStroke_Style == style || |
| 652 | SkStrokeRec::kHairline_Style == style; |
| 653 | bool hasStroke = isStrokeOnly || SkStrokeRec::kStrokeAndFill_Style == style; |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 654 | |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 655 | SkScalar innerXRadius = 0; |
| 656 | SkScalar innerYRadius = 0; |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 657 | if (hasStroke) { |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 658 | if (SkScalarNearlyZero(scaledStroke.length())) { |
| 659 | scaledStroke.set(SK_ScalarHalf, SK_ScalarHalf); |
| 660 | } else { |
| 661 | scaledStroke.scale(SK_ScalarHalf); |
| 662 | } |
| 663 | |
| 664 | // we only handle thick strokes for near-circular ellipses |
| 665 | if (scaledStroke.length() > SK_ScalarHalf && |
| 666 | (SK_ScalarHalf*xRadius > yRadius || SK_ScalarHalf*yRadius > xRadius)) { |
| 667 | return false; |
| 668 | } |
| 669 | |
| 670 | // we don't handle it if curvature of the stroke is less than curvature of the ellipse |
| 671 | if (scaledStroke.fX*(yRadius*yRadius) < (scaledStroke.fY*scaledStroke.fY)*xRadius || |
| 672 | scaledStroke.fY*(xRadius*xRadius) < (scaledStroke.fX*scaledStroke.fX)*yRadius) { |
| 673 | return false; |
| 674 | } |
| 675 | |
| 676 | // this is legit only if scale & translation (which should be the case at the moment) |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 677 | if (isStrokeOnly) { |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 678 | innerXRadius = xRadius - scaledStroke.fX; |
| 679 | innerYRadius = yRadius - scaledStroke.fY; |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | xRadius += scaledStroke.fX; |
| 683 | yRadius += scaledStroke.fY; |
| 684 | } |
| 685 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 686 | GrDrawState::AutoViewMatrixRestore avmr; |
| 687 | if (!avmr.setIdentity(drawState)) { |
jvanverth@google.com | c4f2eca | 2013-04-16 12:30:35 +0000 | [diff] [blame] | 688 | return false; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 689 | } |
| 690 | |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 691 | drawState->setVertexAttribs<gEllipseVertexAttribs>(SK_ARRAY_COUNT(gEllipseVertexAttribs), |
| 692 | sizeof(EllipseVertex)); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 693 | |
| 694 | GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); |
| 695 | if (!geo.succeeded()) { |
| 696 | GrPrintf("Failed to get space for vertices!\n"); |
jvanverth@google.com | c4f2eca | 2013-04-16 12:30:35 +0000 | [diff] [blame] | 697 | return false; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices()); |
| 701 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 702 | GrGeometryProcessor* gp = EllipseEdgeEffect::Create(isStrokeOnly && |
| 703 | innerXRadius > 0 && innerYRadius > 0); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 704 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 705 | drawState->setGeometryProcessor(gp)->unref(); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 706 | |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 707 | // Compute the reciprocals of the radii here to save time in the shader |
| 708 | SkScalar xRadRecip = SkScalarInvert(xRadius); |
| 709 | SkScalar yRadRecip = SkScalarInvert(yRadius); |
| 710 | SkScalar xInnerRadRecip = SkScalarInvert(innerXRadius); |
| 711 | SkScalar yInnerRadRecip = SkScalarInvert(innerYRadius); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 712 | |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 713 | // 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] | 714 | // 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] | 715 | // TODO: Consider if we should use sqrt(2)/2 instead |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 716 | xRadius += SK_ScalarHalf; |
| 717 | yRadius += SK_ScalarHalf; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 718 | |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 719 | SkRect bounds = SkRect::MakeLTRB( |
| 720 | center.fX - xRadius, |
| 721 | center.fY - yRadius, |
| 722 | center.fX + xRadius, |
| 723 | center.fY + yRadius |
| 724 | ); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 725 | |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 726 | verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 727 | verts[0].fOffset = SkPoint::Make(-xRadius, -yRadius); |
| 728 | verts[0].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 729 | verts[0].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 730 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 731 | verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); |
| 732 | verts[1].fOffset = SkPoint::Make(-xRadius, yRadius); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 733 | verts[1].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 734 | verts[1].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 735 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 736 | verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
| 737 | verts[2].fOffset = SkPoint::Make(xRadius, yRadius); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 738 | verts[2].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 739 | verts[2].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 740 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 741 | verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
| 742 | verts[3].fOffset = SkPoint::Make(xRadius, -yRadius); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 743 | verts[3].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 744 | verts[3].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
skia.committer@gmail.com | 4674676 | 2013-04-12 07:01:51 +0000 | [diff] [blame] | 745 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 746 | target->setIndexSourceToBuffer(context->getGpu()->getQuadIndexBuffer()); |
| 747 | target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &bounds); |
| 748 | target->resetIndexSource(); |
jvanverth@google.com | c4f2eca | 2013-04-16 12:30:35 +0000 | [diff] [blame] | 749 | |
| 750 | return true; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 751 | } |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 752 | |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 753 | bool GrOvalRenderer::drawDIEllipse(GrDrawTarget* target, |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 754 | const GrContext* context, |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 755 | bool useCoverageAA, |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 756 | const SkRect& ellipse, |
| 757 | const SkStrokeRec& stroke) |
| 758 | { |
| 759 | GrDrawState* drawState = target->drawState(); |
| 760 | const SkMatrix& vm = drawState->getViewMatrix(); |
| 761 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 762 | SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY()); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 763 | SkScalar xRadius = SkScalarHalf(ellipse.width()); |
skia.committer@gmail.com | 6fc1b49 | 2013-09-06 07:01:45 +0000 | [diff] [blame] | 764 | SkScalar yRadius = SkScalarHalf(ellipse.height()); |
| 765 | |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 766 | SkStrokeRec::Style style = stroke.getStyle(); |
skia.committer@gmail.com | 6fc1b49 | 2013-09-06 07:01:45 +0000 | [diff] [blame] | 767 | DIEllipseEdgeEffect::Mode mode = (SkStrokeRec::kStroke_Style == style) ? |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 768 | DIEllipseEdgeEffect::kStroke : |
skia.committer@gmail.com | 6fc1b49 | 2013-09-06 07:01:45 +0000 | [diff] [blame] | 769 | (SkStrokeRec::kHairline_Style == style) ? |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 770 | DIEllipseEdgeEffect::kHairline : DIEllipseEdgeEffect::kFill; |
| 771 | |
| 772 | SkScalar innerXRadius = 0; |
| 773 | SkScalar innerYRadius = 0; |
| 774 | if (SkStrokeRec::kFill_Style != style && SkStrokeRec::kHairline_Style != style) { |
| 775 | SkScalar strokeWidth = stroke.getWidth(); |
| 776 | |
| 777 | if (SkScalarNearlyZero(strokeWidth)) { |
| 778 | strokeWidth = SK_ScalarHalf; |
| 779 | } else { |
| 780 | strokeWidth *= SK_ScalarHalf; |
| 781 | } |
| 782 | |
| 783 | // we only handle thick strokes for near-circular ellipses |
| 784 | if (strokeWidth > SK_ScalarHalf && |
| 785 | (SK_ScalarHalf*xRadius > yRadius || SK_ScalarHalf*yRadius > xRadius)) { |
| 786 | return false; |
| 787 | } |
| 788 | |
| 789 | // we don't handle it if curvature of the stroke is less than curvature of the ellipse |
| 790 | if (strokeWidth*(yRadius*yRadius) < (strokeWidth*strokeWidth)*xRadius || |
| 791 | strokeWidth*(xRadius*xRadius) < (strokeWidth*strokeWidth)*yRadius) { |
| 792 | return false; |
| 793 | } |
| 794 | |
| 795 | // set inner radius (if needed) |
| 796 | if (SkStrokeRec::kStroke_Style == style) { |
| 797 | innerXRadius = xRadius - strokeWidth; |
| 798 | innerYRadius = yRadius - strokeWidth; |
| 799 | } |
| 800 | |
| 801 | xRadius += strokeWidth; |
| 802 | yRadius += strokeWidth; |
| 803 | } |
| 804 | if (DIEllipseEdgeEffect::kStroke == mode) { |
| 805 | mode = (innerXRadius > 0 && innerYRadius > 0) ? DIEllipseEdgeEffect::kStroke : |
| 806 | DIEllipseEdgeEffect::kFill; |
| 807 | } |
| 808 | SkScalar innerRatioX = SkScalarDiv(xRadius, innerXRadius); |
| 809 | SkScalar innerRatioY = SkScalarDiv(yRadius, innerYRadius); |
| 810 | |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 811 | drawState->setVertexAttribs<gDIEllipseVertexAttribs>(SK_ARRAY_COUNT(gDIEllipseVertexAttribs), |
| 812 | sizeof(DIEllipseVertex)); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 813 | |
| 814 | GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); |
| 815 | if (!geo.succeeded()) { |
| 816 | GrPrintf("Failed to get space for vertices!\n"); |
| 817 | return false; |
| 818 | } |
| 819 | |
| 820 | DIEllipseVertex* verts = reinterpret_cast<DIEllipseVertex*>(geo.vertices()); |
| 821 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 822 | GrGeometryProcessor* gp = DIEllipseEdgeEffect::Create(mode); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 823 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 824 | drawState->setGeometryProcessor(gp)->unref(); |
skia.committer@gmail.com | 6fc1b49 | 2013-09-06 07:01:45 +0000 | [diff] [blame] | 825 | |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 826 | // This expands the outer rect so that after CTM we end up with a half-pixel border |
| 827 | SkScalar a = vm[SkMatrix::kMScaleX]; |
| 828 | SkScalar b = vm[SkMatrix::kMSkewX]; |
| 829 | SkScalar c = vm[SkMatrix::kMSkewY]; |
| 830 | SkScalar d = vm[SkMatrix::kMScaleY]; |
| 831 | SkScalar geoDx = SkScalarDiv(SK_ScalarHalf, SkScalarSqrt(a*a + c*c)); |
| 832 | SkScalar geoDy = SkScalarDiv(SK_ScalarHalf, SkScalarSqrt(b*b + d*d)); |
| 833 | // This adjusts the "radius" to include the half-pixel border |
| 834 | SkScalar offsetDx = SkScalarDiv(geoDx, xRadius); |
| 835 | SkScalar offsetDy = SkScalarDiv(geoDy, yRadius); |
| 836 | |
| 837 | SkRect bounds = SkRect::MakeLTRB( |
| 838 | center.fX - xRadius - geoDx, |
| 839 | center.fY - yRadius - geoDy, |
| 840 | center.fX + xRadius + geoDx, |
| 841 | center.fY + yRadius + geoDy |
| 842 | ); |
| 843 | |
| 844 | verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
| 845 | verts[0].fOuterOffset = SkPoint::Make(-1.0f - offsetDx, -1.0f - offsetDy); |
| 846 | verts[0].fInnerOffset = SkPoint::Make(-innerRatioX - offsetDx, -innerRatioY - offsetDy); |
| 847 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 848 | verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); |
| 849 | verts[1].fOuterOffset = SkPoint::Make(-1.0f - offsetDx, 1.0f + offsetDy); |
| 850 | verts[1].fInnerOffset = SkPoint::Make(-innerRatioX - offsetDx, innerRatioY + offsetDy); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 851 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 852 | verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
| 853 | verts[2].fOuterOffset = SkPoint::Make(1.0f + offsetDx, 1.0f + offsetDy); |
| 854 | verts[2].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, innerRatioY + offsetDy); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 855 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 856 | verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
| 857 | verts[3].fOuterOffset = SkPoint::Make(1.0f + offsetDx, -1.0f - offsetDy); |
| 858 | verts[3].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, -innerRatioY - offsetDy); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 859 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 860 | target->setIndexSourceToBuffer(context->getGpu()->getQuadIndexBuffer()); |
| 861 | target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &bounds); |
| 862 | target->resetIndexSource(); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 863 | |
| 864 | return true; |
| 865 | } |
| 866 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 867 | /////////////////////////////////////////////////////////////////////////////// |
| 868 | |
| 869 | static const uint16_t gRRectIndices[] = { |
| 870 | // corners |
| 871 | 0, 1, 5, 0, 5, 4, |
| 872 | 2, 3, 7, 2, 7, 6, |
| 873 | 8, 9, 13, 8, 13, 12, |
| 874 | 10, 11, 15, 10, 15, 14, |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 875 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 876 | // edges |
| 877 | 1, 2, 6, 1, 6, 5, |
| 878 | 4, 5, 9, 4, 9, 8, |
| 879 | 6, 7, 11, 6, 11, 10, |
| 880 | 9, 10, 14, 9, 14, 13, |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 881 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 882 | // center |
| 883 | // we place this at the end so that we can ignore these indices when rendering stroke-only |
| 884 | 5, 6, 10, 5, 10, 9 |
| 885 | }; |
| 886 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 887 | static const int kIndicesPerStrokeRRect = SK_ARRAY_COUNT(gRRectIndices) - 6; |
| 888 | static const int kIndicesPerRRect = SK_ARRAY_COUNT(gRRectIndices); |
| 889 | static const int kVertsPerRRect = 16; |
| 890 | static const int kNumRRectsInIndexBuffer = 256; |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 891 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 892 | GrIndexBuffer* GrOvalRenderer::rRectIndexBuffer(bool isStrokeOnly, GrGpu* gpu) { |
| 893 | if (isStrokeOnly) { |
| 894 | if (NULL == fStrokeRRectIndexBuffer) { |
| 895 | fStrokeRRectIndexBuffer = gpu->createInstancedIndexBuffer(gRRectIndices, |
| 896 | kIndicesPerStrokeRRect, |
| 897 | kNumRRectsInIndexBuffer, |
| 898 | kVertsPerRRect); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 899 | } |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 900 | return fStrokeRRectIndexBuffer; |
| 901 | } else { |
| 902 | if (NULL == fRRectIndexBuffer) { |
| 903 | fRRectIndexBuffer = gpu->createInstancedIndexBuffer(gRRectIndices, |
| 904 | kIndicesPerRRect, |
| 905 | kNumRRectsInIndexBuffer, |
| 906 | kVertsPerRRect); |
| 907 | } |
| 908 | return fRRectIndexBuffer; |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 909 | } |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 910 | } |
| 911 | |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 912 | bool GrOvalRenderer::drawDRRect(GrDrawTarget* target, GrContext* context, bool useAA, |
bsalomon | 8af0523 | 2014-06-03 06:34:58 -0700 | [diff] [blame] | 913 | const SkRRect& origOuter, const SkRRect& origInner) { |
| 914 | bool applyAA = useAA && |
| 915 | !target->getDrawState().getRenderTarget()->isMultisampled() && |
| 916 | !target->shouldDisableCoverageAAForBlend(); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 917 | GrDrawState::AutoRestoreEffects are; |
| 918 | if (!origInner.isEmpty()) { |
| 919 | SkTCopyOnFirstWrite<SkRRect> inner(origInner); |
| 920 | if (!context->getMatrix().isIdentity()) { |
| 921 | if (!origInner.transform(context->getMatrix(), inner.writable())) { |
| 922 | return false; |
| 923 | } |
| 924 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 925 | GrPrimitiveEdgeType edgeType = applyAA ? |
| 926 | kInverseFillAA_GrProcessorEdgeType : |
| 927 | kInverseFillBW_GrProcessorEdgeType; |
| 928 | GrFragmentProcessor* fp = GrRRectEffect::Create(edgeType, *inner); |
| 929 | if (NULL == fp) { |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 930 | return false; |
| 931 | } |
| 932 | are.set(target->drawState()); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 933 | target->drawState()->addCoverageProcessor(fp)->unref(); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | SkStrokeRec fillRec(SkStrokeRec::kFill_InitStyle); |
bsalomon | 8af0523 | 2014-06-03 06:34:58 -0700 | [diff] [blame] | 937 | if (this->drawRRect(target, context, useAA, origOuter, fillRec)) { |
| 938 | return true; |
| 939 | } |
| 940 | |
| 941 | SkASSERT(!origOuter.isEmpty()); |
| 942 | SkTCopyOnFirstWrite<SkRRect> outer(origOuter); |
| 943 | if (!context->getMatrix().isIdentity()) { |
| 944 | if (!origOuter.transform(context->getMatrix(), outer.writable())) { |
| 945 | return false; |
| 946 | } |
| 947 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 948 | GrPrimitiveEdgeType edgeType = applyAA ? kFillAA_GrProcessorEdgeType : |
| 949 | kFillBW_GrProcessorEdgeType; |
| 950 | GrFragmentProcessor* effect = GrRRectEffect::Create(edgeType, *outer); |
bsalomon | 8af0523 | 2014-06-03 06:34:58 -0700 | [diff] [blame] | 951 | if (NULL == effect) { |
| 952 | return false; |
| 953 | } |
| 954 | if (!are.isSet()) { |
| 955 | are.set(target->drawState()); |
| 956 | } |
| 957 | GrDrawState::AutoViewMatrixRestore avmr; |
| 958 | if (!avmr.setIdentity(target->drawState())) { |
| 959 | return false; |
| 960 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 961 | target->drawState()->addCoverageProcessor(effect)->unref(); |
bsalomon | 8af0523 | 2014-06-03 06:34:58 -0700 | [diff] [blame] | 962 | SkRect bounds = outer->getBounds(); |
| 963 | if (applyAA) { |
| 964 | bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
| 965 | } |
bsalomon | 01c8da1 | 2014-08-04 09:21:30 -0700 | [diff] [blame] | 966 | target->drawRect(bounds, NULL, NULL); |
bsalomon | 8af0523 | 2014-06-03 06:34:58 -0700 | [diff] [blame] | 967 | return true; |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | bool GrOvalRenderer::drawRRect(GrDrawTarget* target, GrContext* context, bool useAA, |
| 971 | const SkRRect& rrect, const SkStrokeRec& stroke) { |
| 972 | if (rrect.isOval()) { |
| 973 | return this->drawOval(target, context, useAA, rrect.getBounds(), stroke); |
| 974 | } |
| 975 | |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 976 | bool useCoverageAA = useAA && |
| 977 | !target->getDrawState().getRenderTarget()->isMultisampled() && |
| 978 | !target->shouldDisableCoverageAAForBlend(); |
| 979 | |
commit-bot@chromium.org | 37d883d | 2013-05-02 13:11:22 +0000 | [diff] [blame] | 980 | // only anti-aliased rrects for now |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 981 | if (!useCoverageAA) { |
commit-bot@chromium.org | 37d883d | 2013-05-02 13:11:22 +0000 | [diff] [blame] | 982 | return false; |
| 983 | } |
| 984 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 985 | const SkMatrix& vm = context->getMatrix(); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 986 | |
| 987 | if (!vm.rectStaysRect() || !rrect.isSimple()) { |
| 988 | return false; |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 989 | } |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 990 | |
| 991 | // do any matrix crunching before we reset the draw state for device coords |
| 992 | const SkRect& rrectBounds = rrect.getBounds(); |
| 993 | SkRect bounds; |
| 994 | vm.mapRect(&bounds, rrectBounds); |
| 995 | |
| 996 | SkVector radii = rrect.getSimpleRadii(); |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 997 | SkScalar xRadius = SkScalarAbs(vm[SkMatrix::kMScaleX]*radii.fX + |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 998 | vm[SkMatrix::kMSkewY]*radii.fY); |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 999 | SkScalar yRadius = SkScalarAbs(vm[SkMatrix::kMSkewX]*radii.fX + |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1000 | vm[SkMatrix::kMScaleY]*radii.fY); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1001 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1002 | SkStrokeRec::Style style = stroke.getStyle(); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1003 | |
| 1004 | // do (potentially) anisotropic mapping of stroke |
| 1005 | SkVector scaledStroke; |
| 1006 | SkScalar strokeWidth = stroke.getWidth(); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1007 | |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1008 | bool isStrokeOnly = SkStrokeRec::kStroke_Style == style || |
| 1009 | SkStrokeRec::kHairline_Style == style; |
| 1010 | bool hasStroke = isStrokeOnly || SkStrokeRec::kStrokeAndFill_Style == style; |
| 1011 | |
| 1012 | if (hasStroke) { |
| 1013 | if (SkStrokeRec::kHairline_Style == style) { |
| 1014 | scaledStroke.set(1, 1); |
| 1015 | } else { |
| 1016 | scaledStroke.fX = SkScalarAbs(strokeWidth*(vm[SkMatrix::kMScaleX] + |
| 1017 | vm[SkMatrix::kMSkewY])); |
| 1018 | scaledStroke.fY = SkScalarAbs(strokeWidth*(vm[SkMatrix::kMSkewX] + |
| 1019 | vm[SkMatrix::kMScaleY])); |
| 1020 | } |
| 1021 | |
| 1022 | // if half of strokewidth is greater than radius, we don't handle that right now |
| 1023 | if (SK_ScalarHalf*scaledStroke.fX > xRadius || SK_ScalarHalf*scaledStroke.fY > yRadius) { |
| 1024 | return false; |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | // The way the effect interpolates the offset-to-ellipse/circle-center attribute only works on |
| 1029 | // the interior of the rrect if the radii are >= 0.5. Otherwise, the inner rect of the nine- |
| 1030 | // patch will have fractional coverage. This only matters when the interior is actually filled. |
| 1031 | // We could consider falling back to rect rendering here, since a tiny radius is |
| 1032 | // indistinguishable from a square corner. |
| 1033 | if (!isStrokeOnly && (SK_ScalarHalf > xRadius || SK_ScalarHalf > yRadius)) { |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1034 | return false; |
| 1035 | } |
| 1036 | |
| 1037 | // reset to device coordinates |
| 1038 | GrDrawState* drawState = target->drawState(); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 1039 | GrDrawState::AutoViewMatrixRestore avmr; |
| 1040 | if (!avmr.setIdentity(drawState)) { |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1041 | return false; |
| 1042 | } |
| 1043 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 1044 | GrIndexBuffer* indexBuffer = this->rRectIndexBuffer(isStrokeOnly, context->getGpu()); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1045 | if (NULL == indexBuffer) { |
| 1046 | GrPrintf("Failed to create index buffer!\n"); |
| 1047 | return false; |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1050 | // if the corners are circles, use the circle renderer |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1051 | if ((!hasStroke || scaledStroke.fX == scaledStroke.fY) && xRadius == yRadius) { |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 1052 | drawState->setVertexAttribs<gCircleVertexAttribs>(SK_ARRAY_COUNT(gCircleVertexAttribs), |
| 1053 | sizeof(CircleVertex)); |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1054 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1055 | GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0); |
| 1056 | if (!geo.succeeded()) { |
| 1057 | GrPrintf("Failed to get space for vertices!\n"); |
| 1058 | return false; |
| 1059 | } |
| 1060 | CircleVertex* verts = reinterpret_cast<CircleVertex*>(geo.vertices()); |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1061 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1062 | SkScalar innerRadius = 0.0f; |
| 1063 | SkScalar outerRadius = xRadius; |
| 1064 | SkScalar halfWidth = 0; |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1065 | if (hasStroke) { |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1066 | if (SkScalarNearlyZero(scaledStroke.fX)) { |
| 1067 | halfWidth = SK_ScalarHalf; |
| 1068 | } else { |
| 1069 | halfWidth = SkScalarHalf(scaledStroke.fX); |
| 1070 | } |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1071 | |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1072 | if (isStrokeOnly) { |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1073 | innerRadius = xRadius - halfWidth; |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1074 | } |
| 1075 | outerRadius += halfWidth; |
| 1076 | bounds.outset(halfWidth, halfWidth); |
| 1077 | } |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1078 | |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1079 | isStrokeOnly = (isStrokeOnly && innerRadius >= 0); |
commit-bot@chromium.org | cefde6e | 2013-08-30 16:34:52 +0000 | [diff] [blame] | 1080 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1081 | GrGeometryProcessor* effect = CircleEdgeEffect::Create(isStrokeOnly); |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 1082 | drawState->setGeometryProcessor(effect)->unref(); |
skia.committer@gmail.com | 8be02fc | 2013-05-17 07:01:11 +0000 | [diff] [blame] | 1083 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1084 | // The radii are outset for two reasons. First, it allows the shader to simply perform |
| 1085 | // clamp(distance-to-center - radius, 0, 1). Second, the outer radius is used to compute the |
| 1086 | // verts of the bounding box that is rendered and the outset ensures the box will cover all |
| 1087 | // pixels partially covered by the circle. |
| 1088 | outerRadius += SK_ScalarHalf; |
| 1089 | innerRadius -= SK_ScalarHalf; |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1090 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1091 | // Expand the rect so all the pixels will be captured. |
| 1092 | bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1093 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1094 | SkScalar yCoords[4] = { |
| 1095 | bounds.fTop, |
| 1096 | bounds.fTop + outerRadius, |
| 1097 | bounds.fBottom - outerRadius, |
| 1098 | bounds.fBottom |
| 1099 | }; |
| 1100 | SkScalar yOuterRadii[4] = { |
| 1101 | -outerRadius, |
| 1102 | 0, |
| 1103 | 0, |
| 1104 | outerRadius |
| 1105 | }; |
| 1106 | for (int i = 0; i < 4; ++i) { |
| 1107 | verts->fPos = SkPoint::Make(bounds.fLeft, yCoords[i]); |
| 1108 | verts->fOffset = SkPoint::Make(-outerRadius, yOuterRadii[i]); |
| 1109 | verts->fOuterRadius = outerRadius; |
| 1110 | verts->fInnerRadius = innerRadius; |
| 1111 | verts++; |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1112 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1113 | verts->fPos = SkPoint::Make(bounds.fLeft + outerRadius, yCoords[i]); |
| 1114 | verts->fOffset = SkPoint::Make(0, yOuterRadii[i]); |
| 1115 | verts->fOuterRadius = outerRadius; |
| 1116 | verts->fInnerRadius = innerRadius; |
| 1117 | verts++; |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1118 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1119 | verts->fPos = SkPoint::Make(bounds.fRight - outerRadius, yCoords[i]); |
| 1120 | verts->fOffset = SkPoint::Make(0, yOuterRadii[i]); |
| 1121 | verts->fOuterRadius = outerRadius; |
| 1122 | verts->fInnerRadius = innerRadius; |
| 1123 | verts++; |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1124 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1125 | verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]); |
| 1126 | verts->fOffset = SkPoint::Make(outerRadius, yOuterRadii[i]); |
| 1127 | verts->fOuterRadius = outerRadius; |
| 1128 | verts->fInnerRadius = innerRadius; |
| 1129 | verts++; |
| 1130 | } |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1131 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1132 | // drop out the middle quad if we're stroked |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1133 | int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 : |
| 1134 | SK_ARRAY_COUNT(gRRectIndices); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1135 | target->setIndexSourceToBuffer(indexBuffer); |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 1136 | target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 16, indexCnt, &bounds); |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1137 | |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1138 | // otherwise we use the ellipse renderer |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1139 | } else { |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 1140 | drawState->setVertexAttribs<gEllipseVertexAttribs>(SK_ARRAY_COUNT(gEllipseVertexAttribs), |
| 1141 | sizeof(EllipseVertex)); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1142 | |
| 1143 | SkScalar innerXRadius = 0.0f; |
| 1144 | SkScalar innerYRadius = 0.0f; |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1145 | if (hasStroke) { |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1146 | if (SkScalarNearlyZero(scaledStroke.length())) { |
| 1147 | scaledStroke.set(SK_ScalarHalf, SK_ScalarHalf); |
| 1148 | } else { |
| 1149 | scaledStroke.scale(SK_ScalarHalf); |
| 1150 | } |
| 1151 | |
| 1152 | // we only handle thick strokes for near-circular ellipses |
skia.committer@gmail.com | 8be02fc | 2013-05-17 07:01:11 +0000 | [diff] [blame] | 1153 | if (scaledStroke.length() > SK_ScalarHalf && |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1154 | (SK_ScalarHalf*xRadius > yRadius || SK_ScalarHalf*yRadius > xRadius)) { |
| 1155 | return false; |
| 1156 | } |
| 1157 | |
| 1158 | // we don't handle it if curvature of the stroke is less than curvature of the ellipse |
| 1159 | if (scaledStroke.fX*(yRadius*yRadius) < (scaledStroke.fY*scaledStroke.fY)*xRadius || |
| 1160 | scaledStroke.fY*(xRadius*xRadius) < (scaledStroke.fX*scaledStroke.fX)*yRadius) { |
| 1161 | return false; |
| 1162 | } |
| 1163 | |
| 1164 | // this is legit only if scale & translation (which should be the case at the moment) |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1165 | if (isStrokeOnly) { |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1166 | innerXRadius = xRadius - scaledStroke.fX; |
| 1167 | innerYRadius = yRadius - scaledStroke.fY; |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | xRadius += scaledStroke.fX; |
| 1171 | yRadius += scaledStroke.fY; |
| 1172 | bounds.outset(scaledStroke.fX, scaledStroke.fY); |
| 1173 | } |
jvanverth@google.com | e364741 | 2013-05-08 15:31:43 +0000 | [diff] [blame] | 1174 | |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1175 | isStrokeOnly = (isStrokeOnly && innerXRadius >= 0 && innerYRadius >= 0); |
commit-bot@chromium.org | cefde6e | 2013-08-30 16:34:52 +0000 | [diff] [blame] | 1176 | |
jvanverth@google.com | e364741 | 2013-05-08 15:31:43 +0000 | [diff] [blame] | 1177 | GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0); |
| 1178 | if (!geo.succeeded()) { |
| 1179 | GrPrintf("Failed to get space for vertices!\n"); |
| 1180 | return false; |
| 1181 | } |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1182 | EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices()); |
jvanverth@google.com | e364741 | 2013-05-08 15:31:43 +0000 | [diff] [blame] | 1183 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1184 | GrGeometryProcessor* effect = EllipseEdgeEffect::Create(isStrokeOnly); |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 1185 | drawState->setGeometryProcessor(effect)->unref(); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1186 | |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1187 | // Compute the reciprocals of the radii here to save time in the shader |
| 1188 | SkScalar xRadRecip = SkScalarInvert(xRadius); |
| 1189 | SkScalar yRadRecip = SkScalarInvert(yRadius); |
| 1190 | SkScalar xInnerRadRecip = SkScalarInvert(innerXRadius); |
| 1191 | SkScalar yInnerRadRecip = SkScalarInvert(innerYRadius); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1192 | |
| 1193 | // Extend the radii out half a pixel to antialias. |
| 1194 | SkScalar xOuterRadius = xRadius + SK_ScalarHalf; |
| 1195 | SkScalar yOuterRadius = yRadius + SK_ScalarHalf; |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1196 | |
| 1197 | // Expand the rect so all the pixels will be captured. |
| 1198 | bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
| 1199 | |
| 1200 | SkScalar yCoords[4] = { |
| 1201 | bounds.fTop, |
| 1202 | bounds.fTop + yOuterRadius, |
| 1203 | bounds.fBottom - yOuterRadius, |
| 1204 | bounds.fBottom |
| 1205 | }; |
| 1206 | SkScalar yOuterOffsets[4] = { |
jvanverth@google.com | d1b5b14 | 2013-07-02 14:46:03 +0000 | [diff] [blame] | 1207 | yOuterRadius, |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1208 | SK_ScalarNearlyZero, // we're using inversesqrt() in the shader, so can't be exactly 0 |
| 1209 | SK_ScalarNearlyZero, |
| 1210 | yOuterRadius |
| 1211 | }; |
| 1212 | |
| 1213 | for (int i = 0; i < 4; ++i) { |
| 1214 | verts->fPos = SkPoint::Make(bounds.fLeft, yCoords[i]); |
jvanverth@google.com | d1b5b14 | 2013-07-02 14:46:03 +0000 | [diff] [blame] | 1215 | verts->fOffset = SkPoint::Make(xOuterRadius, yOuterOffsets[i]); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1216 | verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 1217 | verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1218 | verts++; |
| 1219 | |
| 1220 | verts->fPos = SkPoint::Make(bounds.fLeft + xOuterRadius, yCoords[i]); |
| 1221 | verts->fOffset = SkPoint::Make(SK_ScalarNearlyZero, yOuterOffsets[i]); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1222 | verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 1223 | verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1224 | verts++; |
| 1225 | |
| 1226 | verts->fPos = SkPoint::Make(bounds.fRight - xOuterRadius, yCoords[i]); |
| 1227 | verts->fOffset = SkPoint::Make(SK_ScalarNearlyZero, yOuterOffsets[i]); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1228 | verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 1229 | verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1230 | verts++; |
| 1231 | |
| 1232 | verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]); |
| 1233 | verts->fOffset = SkPoint::Make(xOuterRadius, yOuterOffsets[i]); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1234 | verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 1235 | verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1236 | verts++; |
| 1237 | } |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1238 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1239 | // drop out the middle quad if we're stroked |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1240 | int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 : |
| 1241 | SK_ARRAY_COUNT(gRRectIndices); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1242 | target->setIndexSourceToBuffer(indexBuffer); |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 1243 | target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 16, indexCnt, &bounds); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1244 | } |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1245 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 1246 | target->resetIndexSource(); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1247 | return true; |
| 1248 | } |