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