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 | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 10 | #include "GrBatch.h" |
| 11 | #include "GrBatchTarget.h" |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 12 | #include "GrBatchTest.h" |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 13 | #include "GrBufferAllocPool.h" |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 14 | #include "GrDrawTarget.h" |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 15 | #include "GrGeometryProcessor.h" |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 16 | #include "GrInvariantOutput.h" |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 17 | #include "GrPipelineBuilder.h" |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 18 | #include "GrProcessor.h" |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 19 | #include "GrResourceProvider.h" |
bsalomon | 72e3ae4 | 2015-04-28 08:08:46 -0700 | [diff] [blame] | 20 | #include "GrVertexBuffer.h" |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 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 | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 24 | #include "effects/GrRRectEffect.h" |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 25 | #include "gl/GrGLProcessor.h" |
| 26 | #include "gl/GrGLSL.h" |
| 27 | #include "gl/GrGLGeometryProcessor.h" |
| 28 | #include "gl/builders/GrGLProgramBuilder.h" |
commit-bot@chromium.org | 234d4fb | 2013-09-30 19:55:49 +0000 | [diff] [blame] | 29 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 30 | // TODO(joshualitt) - Break this file up during GrBatch post implementation cleanup |
| 31 | |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 32 | namespace { |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 33 | // TODO(joshualitt) add per vertex colors |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 34 | struct CircleVertex { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 35 | SkPoint fPos; |
| 36 | SkPoint fOffset; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 37 | SkScalar fOuterRadius; |
| 38 | SkScalar fInnerRadius; |
| 39 | }; |
| 40 | |
| 41 | struct EllipseVertex { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 42 | SkPoint fPos; |
| 43 | SkPoint fOffset; |
| 44 | SkPoint fOuterRadii; |
| 45 | SkPoint fInnerRadii; |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 48 | struct DIEllipseVertex { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 49 | SkPoint fPos; |
| 50 | SkPoint fOuterOffset; |
| 51 | SkPoint fInnerOffset; |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 54 | inline bool circle_stays_circle(const SkMatrix& m) { |
| 55 | return m.isSimilarity(); |
| 56 | } |
| 57 | |
| 58 | } |
| 59 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 60 | /////////////////////////////////////////////////////////////////////////////// |
| 61 | |
| 62 | /** |
bsalomon | ce1c886 | 2014-12-15 07:11:22 -0800 | [diff] [blame] | 63 | * The output of this effect is a modulation of the input color and coverage for a circle. It |
| 64 | * operates in a space normalized by the circle radius (outer radius in the case of a stroke) |
| 65 | * with origin at the circle center. Two vertex attributes are used: |
| 66 | * vec2f : position in device space of the bounding geometry vertices |
| 67 | * vec4f : (p.xy, outerRad, innerRad) |
| 68 | * p is the position in the normalized space. |
| 69 | * outerRad is the outerRadius in device space. |
| 70 | * innerRad is the innerRadius in normalized space (ignored if not stroking). |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 71 | */ |
| 72 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 73 | class CircleEdgeEffect : public GrGeometryProcessor { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 74 | public: |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 75 | static GrGeometryProcessor* Create(GrColor color, bool stroke, const SkMatrix& localMatrix) { |
| 76 | return SkNEW_ARGS(CircleEdgeEffect, (color, stroke, localMatrix)); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 77 | } |
| 78 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 79 | const Attribute* inPosition() const { return fInPosition; } |
| 80 | const Attribute* inCircleEdge() const { return fInCircleEdge; } |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 81 | virtual ~CircleEdgeEffect() {} |
| 82 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 83 | const char* name() const override { return "CircleEdge"; } |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 84 | |
| 85 | inline bool isStroked() const { return fStroke; } |
| 86 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 87 | class GLProcessor : public GrGLGeometryProcessor { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 88 | public: |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 89 | GLProcessor(const GrGeometryProcessor&, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 90 | const GrBatchTracker&) |
| 91 | : fColor(GrColor_ILLEGAL) {} |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 92 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 93 | void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 94 | const CircleEdgeEffect& ce = args.fGP.cast<CircleEdgeEffect>(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 95 | GrGLGPBuilder* pb = args.fPB; |
| 96 | const BatchTracker& local = args.fBT.cast<BatchTracker>(); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 97 | GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 98 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 99 | // emit attributes |
| 100 | vsBuilder->emitAttributes(ce); |
| 101 | |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 102 | GrGLVertToFrag v(kVec4f_GrSLType); |
| 103 | args.fPB->addVarying("CircleEdge", &v); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 104 | vsBuilder->codeAppendf("%s = %s;", v.vsOut(), ce.inCircleEdge()->fName); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 105 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 106 | // Setup pass through color |
| 107 | this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NULL, |
| 108 | &fColorUniform); |
| 109 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 110 | // Setup position |
joshualitt | dd21987 | 2015-02-12 14:48:42 -0800 | [diff] [blame] | 111 | this->setupPosition(pb, gpArgs, ce.inPosition()->fName, ce.viewMatrix()); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 112 | |
| 113 | // emit transforms |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 114 | this->emitTransforms(args.fPB, gpArgs->fPositionVar, ce.inPosition()->fName, |
tfarina | 567ff2f | 2015-04-27 07:01:44 -0700 | [diff] [blame] | 115 | ce.localMatrix(), args.fTransformsIn, args.fTransformsOut); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 116 | |
egdaniel | 29bee0f | 2015-04-29 11:54:42 -0700 | [diff] [blame] | 117 | GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 118 | fsBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn()); |
bsalomon | ce1c886 | 2014-12-15 07:11:22 -0800 | [diff] [blame] | 119 | fsBuilder->codeAppendf("float edgeAlpha = clamp(%s.z * (1.0 - d), 0.0, 1.0);", v.fsIn()); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 120 | if (ce.isStroked()) { |
bsalomon | ce1c886 | 2014-12-15 07:11:22 -0800 | [diff] [blame] | 121 | fsBuilder->codeAppendf("float innerAlpha = clamp(%s.z * (d - %s.w), 0.0, 1.0);", |
| 122 | v.fsIn(), v.fsIn()); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 123 | fsBuilder->codeAppend("edgeAlpha *= innerAlpha;"); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 124 | } |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 125 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 126 | fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 127 | } |
| 128 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 129 | static void GenKey(const GrGeometryProcessor& gp, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 130 | const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 131 | const GrGLSLCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 132 | GrProcessorKeyBuilder* b) { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 133 | const BatchTracker& local = bt.cast<BatchTracker>(); |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 134 | const CircleEdgeEffect& circleEffect = gp.cast<CircleEdgeEffect>(); |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 135 | uint16_t key = circleEffect.isStroked() ? 0x1 : 0x0; |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 136 | key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x2 : 0x0; |
| 137 | key |= ComputePosKey(gp.viewMatrix()) << 2; |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 138 | b->add32(key << 16 | local.fInputColorType); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 139 | } |
| 140 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 141 | virtual void setData(const GrGLProgramDataManager& pdman, |
| 142 | const GrPrimitiveProcessor& gp, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 143 | const GrBatchTracker& bt) override { |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 144 | this->setUniformViewMatrix(pdman, gp.viewMatrix()); |
| 145 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 146 | const BatchTracker& local = bt.cast<BatchTracker>(); |
| 147 | if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { |
| 148 | GrGLfloat c[4]; |
| 149 | GrColorToRGBAFloat(local.fColor, c); |
| 150 | pdman.set4fv(fColorUniform, 1, c); |
| 151 | fColor = local.fColor; |
| 152 | } |
| 153 | } |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 154 | |
| 155 | private: |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 156 | GrColor fColor; |
| 157 | UniformHandle fColorUniform; |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 158 | typedef GrGLGeometryProcessor INHERITED; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 159 | }; |
| 160 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 161 | virtual void getGLProcessorKey(const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 162 | const GrGLSLCaps& caps, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 163 | GrProcessorKeyBuilder* b) const override { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 164 | GLProcessor::GenKey(*this, bt, caps, b); |
| 165 | } |
| 166 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 167 | virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 168 | const GrGLSLCaps&) const override { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 169 | return SkNEW_ARGS(GLProcessor, (*this, bt)); |
| 170 | } |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 171 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 172 | void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const override { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 173 | BatchTracker* local = bt->cast<BatchTracker>(); |
| 174 | local->fInputColorType = GetColorInputType(&local->fColor, this->color(), init, false); |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 175 | local->fUsesLocalCoords = init.fUsesLocalCoords; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 176 | } |
| 177 | |
joshualitt | 50cb76b | 2015-04-28 09:17:05 -0700 | [diff] [blame] | 178 | bool onCanMakeEqual(const GrBatchTracker& m, |
| 179 | const GrGeometryProcessor& that, |
| 180 | const GrBatchTracker& t) const override { |
| 181 | const BatchTracker& mine = m.cast<BatchTracker>(); |
| 182 | const BatchTracker& theirs = t.cast<BatchTracker>(); |
| 183 | return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, |
| 184 | that, theirs.fUsesLocalCoords) && |
| 185 | CanCombineOutput(mine.fInputColorType, mine.fColor, |
| 186 | theirs.fInputColorType, theirs.fColor); |
| 187 | } |
| 188 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 189 | private: |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 190 | CircleEdgeEffect(GrColor color, bool stroke, const SkMatrix& localMatrix) |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 191 | : INHERITED(color, SkMatrix::I(), localMatrix) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 192 | this->initClassID<CircleEdgeEffect>(); |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 193 | fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType)); |
| 194 | fInCircleEdge = &this->addVertexAttrib(Attribute("inCircleEdge", |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 195 | kVec4f_GrVertexAttribType)); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 196 | fStroke = stroke; |
| 197 | } |
| 198 | |
joshualitt | 50cb76b | 2015-04-28 09:17:05 -0700 | [diff] [blame] | 199 | bool onIsEqual(const GrGeometryProcessor& other) const override { |
| 200 | const CircleEdgeEffect& cee = other.cast<CircleEdgeEffect>(); |
| 201 | return cee.fStroke == fStroke; |
| 202 | } |
| 203 | |
| 204 | void onGetInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
| 205 | out->setUnknownSingleComponent(); |
| 206 | } |
| 207 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 208 | struct BatchTracker { |
| 209 | GrGPInput fInputColorType; |
| 210 | GrColor fColor; |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 211 | bool fUsesLocalCoords; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 212 | }; |
| 213 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 214 | const Attribute* fInPosition; |
| 215 | const Attribute* fInCircleEdge; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 216 | bool fStroke; |
| 217 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 218 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 219 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 220 | typedef GrGeometryProcessor INHERITED; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 221 | }; |
| 222 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 223 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(CircleEdgeEffect); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 224 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 225 | GrGeometryProcessor* CircleEdgeEffect::TestCreate(SkRandom* random, |
| 226 | GrContext* context, |
| 227 | const GrDrawTargetCaps&, |
| 228 | GrTexture* textures[]) { |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 229 | return CircleEdgeEffect::Create(GrRandomColor(random), |
| 230 | random->nextBool(), |
joshualitt | 4eaf9ce | 2015-04-28 13:31:18 -0700 | [diff] [blame] | 231 | GrTest::TestMatrix(random)); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | /////////////////////////////////////////////////////////////////////////////// |
| 235 | |
| 236 | /** |
| 237 | * 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] | 238 | * ellipse, specified as a 2D offset from center, and the reciprocals of the outer and inner radii, |
| 239 | * in both x and y directions. |
| 240 | * |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 241 | * 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] | 242 | */ |
| 243 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 244 | class EllipseEdgeEffect : public GrGeometryProcessor { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 245 | public: |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 246 | static GrGeometryProcessor* Create(GrColor color, bool stroke, const SkMatrix& localMatrix) { |
| 247 | return SkNEW_ARGS(EllipseEdgeEffect, (color, stroke, localMatrix)); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 248 | } |
| 249 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 250 | virtual ~EllipseEdgeEffect() {} |
| 251 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 252 | const char* name() const override { return "EllipseEdge"; } |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 253 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 254 | const Attribute* inPosition() const { return fInPosition; } |
| 255 | const Attribute* inEllipseOffset() const { return fInEllipseOffset; } |
| 256 | const Attribute* inEllipseRadii() const { return fInEllipseRadii; } |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 257 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 258 | inline bool isStroked() const { return fStroke; } |
| 259 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 260 | class GLProcessor : public GrGLGeometryProcessor { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 261 | public: |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 262 | GLProcessor(const GrGeometryProcessor&, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 263 | const GrBatchTracker&) |
| 264 | : fColor(GrColor_ILLEGAL) {} |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 265 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 266 | void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 267 | const EllipseEdgeEffect& ee = args.fGP.cast<EllipseEdgeEffect>(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 268 | GrGLGPBuilder* pb = args.fPB; |
| 269 | const BatchTracker& local = args.fBT.cast<BatchTracker>(); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 270 | GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 271 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 272 | // emit attributes |
| 273 | vsBuilder->emitAttributes(ee); |
| 274 | |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 275 | GrGLVertToFrag ellipseOffsets(kVec2f_GrSLType); |
| 276 | args.fPB->addVarying("EllipseOffsets", &ellipseOffsets); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 277 | vsBuilder->codeAppendf("%s = %s;", ellipseOffsets.vsOut(), |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 278 | ee.inEllipseOffset()->fName); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 279 | |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 280 | GrGLVertToFrag ellipseRadii(kVec4f_GrSLType); |
| 281 | args.fPB->addVarying("EllipseRadii", &ellipseRadii); |
| 282 | vsBuilder->codeAppendf("%s = %s;", ellipseRadii.vsOut(), |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 283 | ee.inEllipseRadii()->fName); |
| 284 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 285 | // Setup pass through color |
| 286 | this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NULL, |
| 287 | &fColorUniform); |
| 288 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 289 | // Setup position |
joshualitt | dd21987 | 2015-02-12 14:48:42 -0800 | [diff] [blame] | 290 | this->setupPosition(pb, gpArgs, ee.inPosition()->fName, ee.viewMatrix()); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 291 | |
| 292 | // emit transforms |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 293 | this->emitTransforms(args.fPB, gpArgs->fPositionVar, ee.inPosition()->fName, |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 294 | ee.localMatrix(), args.fTransformsIn, args.fTransformsOut); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 295 | |
skia.committer@gmail.com | 8be02fc | 2013-05-17 07:01:11 +0000 | [diff] [blame] | 296 | // for outer curve |
egdaniel | 29bee0f | 2015-04-29 11:54:42 -0700 | [diff] [blame] | 297 | GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 298 | fsBuilder->codeAppendf("vec2 scaledOffset = %s*%s.xy;", ellipseOffsets.fsIn(), |
| 299 | ellipseRadii.fsIn()); |
| 300 | fsBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset) - 1.0;"); |
| 301 | fsBuilder->codeAppendf("vec2 grad = 2.0*scaledOffset*%s.xy;", ellipseRadii.fsIn()); |
| 302 | fsBuilder->codeAppend("float grad_dot = dot(grad, grad);"); |
| 303 | |
commit-bot@chromium.org | 1b035d8 | 2014-04-09 17:11:09 +0000 | [diff] [blame] | 304 | // avoid calling inversesqrt on zero. |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 305 | fsBuilder->codeAppend("grad_dot = max(grad_dot, 1.0e-4);"); |
| 306 | fsBuilder->codeAppend("float invlen = inversesqrt(grad_dot);"); |
| 307 | 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] | 308 | |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 309 | // for inner curve |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 310 | if (ee.isStroked()) { |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 311 | fsBuilder->codeAppendf("scaledOffset = %s*%s.zw;", |
| 312 | ellipseOffsets.fsIn(), ellipseRadii.fsIn()); |
| 313 | fsBuilder->codeAppend("test = dot(scaledOffset, scaledOffset) - 1.0;"); |
| 314 | fsBuilder->codeAppendf("grad = 2.0*scaledOffset*%s.zw;", |
| 315 | ellipseRadii.fsIn()); |
| 316 | fsBuilder->codeAppend("invlen = inversesqrt(dot(grad, grad));"); |
| 317 | 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] | 318 | } |
| 319 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 320 | fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 321 | } |
| 322 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 323 | static void GenKey(const GrGeometryProcessor& gp, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 324 | const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 325 | const GrGLSLCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 326 | GrProcessorKeyBuilder* b) { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 327 | const BatchTracker& local = bt.cast<BatchTracker>(); |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 328 | const EllipseEdgeEffect& ellipseEffect = gp.cast<EllipseEdgeEffect>(); |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 329 | uint16_t key = ellipseEffect.isStroked() ? 0x1 : 0x0; |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 330 | key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x2 : 0x0; |
| 331 | key |= ComputePosKey(gp.viewMatrix()) << 2; |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 332 | b->add32(key << 16 | local.fInputColorType); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 333 | } |
| 334 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 335 | virtual void setData(const GrGLProgramDataManager& pdman, |
| 336 | const GrPrimitiveProcessor& gp, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 337 | const GrBatchTracker& bt) override { |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 338 | this->setUniformViewMatrix(pdman, gp.viewMatrix()); |
| 339 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 340 | const BatchTracker& local = bt.cast<BatchTracker>(); |
| 341 | if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { |
| 342 | GrGLfloat c[4]; |
| 343 | GrColorToRGBAFloat(local.fColor, c); |
| 344 | pdman.set4fv(fColorUniform, 1, c); |
| 345 | fColor = local.fColor; |
| 346 | } |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | private: |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 350 | GrColor fColor; |
| 351 | UniformHandle fColorUniform; |
| 352 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 353 | typedef GrGLGeometryProcessor INHERITED; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 354 | }; |
| 355 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 356 | virtual void getGLProcessorKey(const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 357 | const GrGLSLCaps& caps, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 358 | GrProcessorKeyBuilder* b) const override { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 359 | GLProcessor::GenKey(*this, bt, caps, b); |
| 360 | } |
| 361 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 362 | virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 363 | const GrGLSLCaps&) const override { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 364 | return SkNEW_ARGS(GLProcessor, (*this, bt)); |
| 365 | } |
| 366 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 367 | void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const override { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 368 | BatchTracker* local = bt->cast<BatchTracker>(); |
| 369 | local->fInputColorType = GetColorInputType(&local->fColor, this->color(), init, false); |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 370 | local->fUsesLocalCoords = init.fUsesLocalCoords; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 371 | } |
| 372 | |
joshualitt | 50cb76b | 2015-04-28 09:17:05 -0700 | [diff] [blame] | 373 | bool onCanMakeEqual(const GrBatchTracker& m, |
| 374 | const GrGeometryProcessor& that, |
| 375 | const GrBatchTracker& t) const override { |
| 376 | const BatchTracker& mine = m.cast<BatchTracker>(); |
| 377 | const BatchTracker& theirs = t.cast<BatchTracker>(); |
| 378 | return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, |
| 379 | that, theirs.fUsesLocalCoords) && |
| 380 | CanCombineOutput(mine.fInputColorType, mine.fColor, |
| 381 | theirs.fInputColorType, theirs.fColor); |
| 382 | } |
| 383 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 384 | private: |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 385 | EllipseEdgeEffect(GrColor color, bool stroke, const SkMatrix& localMatrix) |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 386 | : INHERITED(color, SkMatrix::I(), localMatrix) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 387 | this->initClassID<EllipseEdgeEffect>(); |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 388 | fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType)); |
| 389 | fInEllipseOffset = &this->addVertexAttrib(Attribute("inEllipseOffset", |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 390 | kVec2f_GrVertexAttribType)); |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 391 | fInEllipseRadii = &this->addVertexAttrib(Attribute("inEllipseRadii", |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 392 | kVec4f_GrVertexAttribType)); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 393 | fStroke = stroke; |
| 394 | } |
| 395 | |
joshualitt | 50cb76b | 2015-04-28 09:17:05 -0700 | [diff] [blame] | 396 | bool onIsEqual(const GrGeometryProcessor& other) const override { |
| 397 | const EllipseEdgeEffect& eee = other.cast<EllipseEdgeEffect>(); |
| 398 | return eee.fStroke == fStroke; |
| 399 | } |
| 400 | |
| 401 | void onGetInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
| 402 | out->setUnknownSingleComponent(); |
| 403 | } |
| 404 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 405 | struct BatchTracker { |
| 406 | GrGPInput fInputColorType; |
| 407 | GrColor fColor; |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 408 | bool fUsesLocalCoords; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 409 | }; |
| 410 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 411 | const Attribute* fInPosition; |
| 412 | const Attribute* fInEllipseOffset; |
| 413 | const Attribute* fInEllipseRadii; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 414 | bool fStroke; |
| 415 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 416 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 417 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 418 | typedef GrGeometryProcessor INHERITED; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 419 | }; |
| 420 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 421 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(EllipseEdgeEffect); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 422 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 423 | GrGeometryProcessor* EllipseEdgeEffect::TestCreate(SkRandom* random, |
| 424 | GrContext* context, |
| 425 | const GrDrawTargetCaps&, |
| 426 | GrTexture* textures[]) { |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 427 | return EllipseEdgeEffect::Create(GrRandomColor(random), |
| 428 | random->nextBool(), |
joshualitt | 4eaf9ce | 2015-04-28 13:31:18 -0700 | [diff] [blame] | 429 | GrTest::TestMatrix(random)); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | /////////////////////////////////////////////////////////////////////////////// |
| 433 | |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 434 | /** |
skia.committer@gmail.com | 6fc1b49 | 2013-09-06 07:01:45 +0000 | [diff] [blame] | 435 | * 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] | 436 | * specified as a 2D offset from center for both the outer and inner paths (if stroked). The |
| 437 | * implict equation used is for a unit circle (x^2 + y^2 - 1 = 0) and the edge corrected by |
| 438 | * using differentials. |
| 439 | * |
| 440 | * The result is device-independent and can be used with any affine matrix. |
| 441 | */ |
| 442 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 443 | class DIEllipseEdgeEffect : public GrGeometryProcessor { |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 444 | public: |
| 445 | enum Mode { kStroke = 0, kHairline, kFill }; |
| 446 | |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 447 | static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix, Mode mode) { |
| 448 | return SkNEW_ARGS(DIEllipseEdgeEffect, (color, viewMatrix, mode)); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 449 | } |
| 450 | |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 451 | virtual ~DIEllipseEdgeEffect() {} |
| 452 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 453 | const char* name() const override { return "DIEllipseEdge"; } |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 454 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 455 | const Attribute* inPosition() const { return fInPosition; } |
| 456 | const Attribute* inEllipseOffsets0() const { return fInEllipseOffsets0; } |
| 457 | const Attribute* inEllipseOffsets1() const { return fInEllipseOffsets1; } |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 458 | |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 459 | inline Mode getMode() const { return fMode; } |
| 460 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 461 | class GLProcessor : public GrGLGeometryProcessor { |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 462 | public: |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 463 | GLProcessor(const GrGeometryProcessor&, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 464 | const GrBatchTracker&) |
| 465 | : fColor(GrColor_ILLEGAL) {} |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 466 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 467 | void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 468 | const DIEllipseEdgeEffect& ee = args.fGP.cast<DIEllipseEdgeEffect>(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 469 | GrGLGPBuilder* pb = args.fPB; |
| 470 | const BatchTracker& local = args.fBT.cast<BatchTracker>(); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 471 | GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 472 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 473 | // emit attributes |
| 474 | vsBuilder->emitAttributes(ee); |
| 475 | |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 476 | GrGLVertToFrag offsets0(kVec2f_GrSLType); |
| 477 | args.fPB->addVarying("EllipseOffsets0", &offsets0); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 478 | vsBuilder->codeAppendf("%s = %s;", offsets0.vsOut(), |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 479 | ee.inEllipseOffsets0()->fName); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 480 | |
| 481 | GrGLVertToFrag offsets1(kVec2f_GrSLType); |
| 482 | args.fPB->addVarying("EllipseOffsets1", &offsets1); |
| 483 | vsBuilder->codeAppendf("%s = %s;", offsets1.vsOut(), |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 484 | ee.inEllipseOffsets1()->fName); |
| 485 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 486 | // Setup pass through color |
| 487 | this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NULL, |
| 488 | &fColorUniform); |
| 489 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 490 | // Setup position |
joshualitt | dd21987 | 2015-02-12 14:48:42 -0800 | [diff] [blame] | 491 | this->setupPosition(pb, gpArgs, ee.inPosition()->fName, ee.viewMatrix()); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 492 | |
| 493 | // emit transforms |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 494 | this->emitTransforms(args.fPB, gpArgs->fPositionVar, ee.inPosition()->fName, |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 495 | ee.localMatrix(), args.fTransformsIn, args.fTransformsOut); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 496 | |
egdaniel | 29bee0f | 2015-04-29 11:54:42 -0700 | [diff] [blame] | 497 | GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 498 | SkAssertResult(fsBuilder->enableFeature( |
| 499 | GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 500 | // for outer curve |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 501 | fsBuilder->codeAppendf("vec2 scaledOffset = %s.xy;", offsets0.fsIn()); |
| 502 | fsBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset) - 1.0;"); |
| 503 | fsBuilder->codeAppendf("vec2 duvdx = dFdx(%s);", offsets0.fsIn()); |
| 504 | fsBuilder->codeAppendf("vec2 duvdy = dFdy(%s);", offsets0.fsIn()); |
| 505 | fsBuilder->codeAppendf("vec2 grad = vec2(2.0*%s.x*duvdx.x + 2.0*%s.y*duvdx.y," |
| 506 | " 2.0*%s.x*duvdy.x + 2.0*%s.y*duvdy.y);", |
| 507 | offsets0.fsIn(), offsets0.fsIn(), offsets0.fsIn(), offsets0.fsIn()); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 508 | |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 509 | fsBuilder->codeAppend("float grad_dot = dot(grad, grad);"); |
commit-bot@chromium.org | 1b035d8 | 2014-04-09 17:11:09 +0000 | [diff] [blame] | 510 | // avoid calling inversesqrt on zero. |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 511 | fsBuilder->codeAppend("grad_dot = max(grad_dot, 1.0e-4);"); |
| 512 | fsBuilder->codeAppend("float invlen = inversesqrt(grad_dot);"); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 513 | if (kHairline == ee.getMode()) { |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 514 | // can probably do this with one step |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 515 | fsBuilder->codeAppend("float edgeAlpha = clamp(1.0-test*invlen, 0.0, 1.0);"); |
| 516 | 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] | 517 | } else { |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 518 | 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] | 519 | } |
| 520 | |
| 521 | // for inner curve |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 522 | if (kStroke == ee.getMode()) { |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 523 | fsBuilder->codeAppendf("scaledOffset = %s.xy;", offsets1.fsIn()); |
| 524 | fsBuilder->codeAppend("test = dot(scaledOffset, scaledOffset) - 1.0;"); |
| 525 | fsBuilder->codeAppendf("duvdx = dFdx(%s);", offsets1.fsIn()); |
| 526 | fsBuilder->codeAppendf("duvdy = dFdy(%s);", offsets1.fsIn()); |
| 527 | fsBuilder->codeAppendf("grad = vec2(2.0*%s.x*duvdx.x + 2.0*%s.y*duvdx.y," |
| 528 | " 2.0*%s.x*duvdy.x + 2.0*%s.y*duvdy.y);", |
| 529 | offsets1.fsIn(), offsets1.fsIn(), offsets1.fsIn(), |
| 530 | offsets1.fsIn()); |
| 531 | fsBuilder->codeAppend("invlen = inversesqrt(dot(grad, grad));"); |
| 532 | 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] | 533 | } |
| 534 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 535 | fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 536 | } |
| 537 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 538 | static void GenKey(const GrGeometryProcessor& gp, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 539 | const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 540 | const GrGLSLCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 541 | GrProcessorKeyBuilder* b) { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 542 | const BatchTracker& local = bt.cast<BatchTracker>(); |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 543 | const DIEllipseEdgeEffect& ellipseEffect = gp.cast<DIEllipseEdgeEffect>(); |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 544 | uint16_t key = ellipseEffect.getMode(); |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 545 | key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 << 8 : 0x0; |
| 546 | key |= ComputePosKey(gp.viewMatrix()) << 9; |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 547 | b->add32(key << 16 | local.fInputColorType); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 548 | } |
| 549 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 550 | virtual void setData(const GrGLProgramDataManager& pdman, |
| 551 | const GrPrimitiveProcessor& gp, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 552 | const GrBatchTracker& bt) override { |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 553 | this->setUniformViewMatrix(pdman, gp.viewMatrix()); |
| 554 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 555 | const BatchTracker& local = bt.cast<BatchTracker>(); |
| 556 | if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { |
| 557 | GrGLfloat c[4]; |
| 558 | GrColorToRGBAFloat(local.fColor, c); |
| 559 | pdman.set4fv(fColorUniform, 1, c); |
| 560 | fColor = local.fColor; |
| 561 | } |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | private: |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 565 | GrColor fColor; |
| 566 | UniformHandle fColorUniform; |
| 567 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 568 | typedef GrGLGeometryProcessor INHERITED; |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 569 | }; |
| 570 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 571 | virtual void getGLProcessorKey(const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 572 | const GrGLSLCaps& caps, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 573 | GrProcessorKeyBuilder* b) const override { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 574 | GLProcessor::GenKey(*this, bt, caps, b); |
| 575 | } |
| 576 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 577 | virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 578 | const GrGLSLCaps&) const override { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 579 | return SkNEW_ARGS(GLProcessor, (*this, bt)); |
| 580 | } |
| 581 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 582 | void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const override { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 583 | BatchTracker* local = bt->cast<BatchTracker>(); |
| 584 | local->fInputColorType = GetColorInputType(&local->fColor, this->color(), init, false); |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 585 | local->fUsesLocalCoords = init.fUsesLocalCoords; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 586 | } |
| 587 | |
joshualitt | 50cb76b | 2015-04-28 09:17:05 -0700 | [diff] [blame] | 588 | bool onCanMakeEqual(const GrBatchTracker& m, |
| 589 | const GrGeometryProcessor& that, |
| 590 | const GrBatchTracker& t) const override { |
| 591 | const BatchTracker& mine = m.cast<BatchTracker>(); |
| 592 | const BatchTracker& theirs = t.cast<BatchTracker>(); |
| 593 | return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, |
| 594 | that, theirs.fUsesLocalCoords) && |
| 595 | CanCombineOutput(mine.fInputColorType, mine.fColor, |
| 596 | theirs.fInputColorType, theirs.fColor); |
| 597 | } |
| 598 | |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 599 | private: |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 600 | DIEllipseEdgeEffect(GrColor color, const SkMatrix& viewMatrix, Mode mode) |
| 601 | : INHERITED(color, viewMatrix) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 602 | this->initClassID<DIEllipseEdgeEffect>(); |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 603 | fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType)); |
| 604 | fInEllipseOffsets0 = &this->addVertexAttrib(Attribute("inEllipseOffsets0", |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 605 | kVec2f_GrVertexAttribType)); |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 606 | fInEllipseOffsets1 = &this->addVertexAttrib(Attribute("inEllipseOffsets1", |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 607 | kVec2f_GrVertexAttribType)); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 608 | fMode = mode; |
| 609 | } |
| 610 | |
joshualitt | 50cb76b | 2015-04-28 09:17:05 -0700 | [diff] [blame] | 611 | bool onIsEqual(const GrGeometryProcessor& other) const override { |
| 612 | const DIEllipseEdgeEffect& eee = other.cast<DIEllipseEdgeEffect>(); |
| 613 | return eee.fMode == fMode; |
| 614 | } |
| 615 | |
| 616 | void onGetInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
| 617 | out->setUnknownSingleComponent(); |
| 618 | } |
| 619 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 620 | struct BatchTracker { |
| 621 | GrGPInput fInputColorType; |
| 622 | GrColor fColor; |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 623 | bool fUsesLocalCoords; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 624 | }; |
| 625 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 626 | const Attribute* fInPosition; |
| 627 | const Attribute* fInEllipseOffsets0; |
| 628 | const Attribute* fInEllipseOffsets1; |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 629 | Mode fMode; |
| 630 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 631 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 632 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 633 | typedef GrGeometryProcessor INHERITED; |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 634 | }; |
| 635 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 636 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DIEllipseEdgeEffect); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 637 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 638 | GrGeometryProcessor* DIEllipseEdgeEffect::TestCreate(SkRandom* random, |
| 639 | GrContext* context, |
| 640 | const GrDrawTargetCaps&, |
| 641 | GrTexture* textures[]) { |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 642 | return DIEllipseEdgeEffect::Create(GrRandomColor(random), |
joshualitt | 4eaf9ce | 2015-04-28 13:31:18 -0700 | [diff] [blame] | 643 | GrTest::TestMatrix(random), |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 644 | (Mode)(random->nextRangeU(0,2))); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | /////////////////////////////////////////////////////////////////////////////// |
| 648 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 649 | bool GrOvalRenderer::drawOval(GrDrawTarget* target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 650 | GrPipelineBuilder* pipelineBuilder, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 651 | GrColor color, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 652 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 653 | bool useAA, |
| 654 | const SkRect& oval, |
| 655 | const SkStrokeRec& stroke) |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 656 | { |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 657 | bool useCoverageAA = useAA && !pipelineBuilder->getRenderTarget()->isMultisampled(); |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 658 | |
| 659 | if (!useCoverageAA) { |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 660 | return false; |
| 661 | } |
| 662 | |
skia.committer@gmail.com | 7e32851 | 2013-03-23 07:01:28 +0000 | [diff] [blame] | 663 | // we can draw circles |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 664 | if (SkScalarNearlyEqual(oval.width(), oval.height()) && circle_stays_circle(viewMatrix)) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 665 | this->drawCircle(target, pipelineBuilder, color, viewMatrix, useCoverageAA, oval, stroke); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 666 | // if we have shader derivative support, render as device-independent |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 667 | } else if (target->caps()->shaderCaps()->shaderDerivativeSupport()) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 668 | return this->drawDIEllipse(target, pipelineBuilder, color, viewMatrix, useCoverageAA, oval, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 669 | stroke); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 670 | // otherwise axis-aligned ellipses only |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 671 | } else if (viewMatrix.rectStaysRect()) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 672 | return this->drawEllipse(target, pipelineBuilder, color, viewMatrix, useCoverageAA, oval, |
| 673 | stroke); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 674 | } else { |
| 675 | return false; |
| 676 | } |
| 677 | |
| 678 | return true; |
| 679 | } |
| 680 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 681 | /////////////////////////////////////////////////////////////////////////////// |
| 682 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 683 | class CircleBatch : public GrBatch { |
| 684 | public: |
| 685 | struct Geometry { |
| 686 | GrColor fColor; |
| 687 | SkMatrix fViewMatrix; |
| 688 | SkScalar fInnerRadius; |
| 689 | SkScalar fOuterRadius; |
| 690 | bool fStroke; |
egdaniel | bc22714 | 2015-04-21 06:28:08 -0700 | [diff] [blame] | 691 | SkRect fDevBounds; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 692 | }; |
| 693 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 694 | static GrBatch* Create(const Geometry& geometry) { return SkNEW_ARGS(CircleBatch, (geometry)); } |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 695 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 696 | const char* name() const override { return "CircleBatch"; } |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 697 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 698 | void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 699 | // When this is called on a batch, there is only one geometry bundle |
| 700 | out->setKnownFourComponents(fGeoData[0].fColor); |
| 701 | } |
| 702 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 703 | void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 704 | out->setUnknownSingleComponent(); |
| 705 | } |
| 706 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 707 | void initBatchTracker(const GrPipelineInfo& init) override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 708 | // Handle any color overrides |
| 709 | if (init.fColorIgnored) { |
| 710 | fGeoData[0].fColor = GrColor_ILLEGAL; |
| 711 | } else if (GrColor_ILLEGAL != init.fOverrideColor) { |
| 712 | fGeoData[0].fColor = init.fOverrideColor; |
| 713 | } |
| 714 | |
| 715 | // setup batch properties |
| 716 | fBatch.fColorIgnored = init.fColorIgnored; |
| 717 | fBatch.fColor = fGeoData[0].fColor; |
| 718 | fBatch.fStroke = fGeoData[0].fStroke; |
| 719 | fBatch.fUsesLocalCoords = init.fUsesLocalCoords; |
| 720 | fBatch.fCoverageIgnored = init.fCoverageIgnored; |
| 721 | } |
| 722 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 723 | void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 724 | SkMatrix invert; |
| 725 | if (!this->viewMatrix().invert(&invert)) { |
| 726 | return; |
| 727 | } |
| 728 | |
| 729 | // Setup geometry processor |
| 730 | SkAutoTUnref<GrGeometryProcessor> gp(CircleEdgeEffect::Create(this->color(), |
| 731 | this->stroke(), |
| 732 | invert)); |
| 733 | |
| 734 | batchTarget->initDraw(gp, pipeline); |
| 735 | |
| 736 | // TODO this is hacky, but the only way we have to initialize the GP is to use the |
| 737 | // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch |
| 738 | // everywhere we can remove this nastiness |
| 739 | GrPipelineInfo init; |
| 740 | init.fColorIgnored = fBatch.fColorIgnored; |
| 741 | init.fOverrideColor = GrColor_ILLEGAL; |
| 742 | init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 743 | init.fUsesLocalCoords = this->usesLocalCoords(); |
| 744 | gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 745 | |
| 746 | int instanceCount = fGeoData.count(); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 747 | size_t vertexStride = gp->getVertexStride(); |
| 748 | SkASSERT(vertexStride == sizeof(CircleVertex)); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 749 | QuadHelper helper; |
| 750 | CircleVertex* verts = reinterpret_cast<CircleVertex*>(helper.init(batchTarget, vertexStride, |
| 751 | instanceCount)); |
| 752 | if (!verts) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 753 | return; |
| 754 | } |
| 755 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 756 | for (int i = 0; i < instanceCount; i++) { |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 757 | Geometry& geom = fGeoData[i]; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 758 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 759 | SkScalar innerRadius = geom.fInnerRadius; |
| 760 | SkScalar outerRadius = geom.fOuterRadius; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 761 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 762 | const SkRect& bounds = geom.fDevBounds; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 763 | |
| 764 | // The inner radius in the vertex data must be specified in normalized space. |
| 765 | innerRadius = innerRadius / outerRadius; |
| 766 | verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
| 767 | verts[0].fOffset = SkPoint::Make(-1, -1); |
| 768 | verts[0].fOuterRadius = outerRadius; |
| 769 | verts[0].fInnerRadius = innerRadius; |
| 770 | |
| 771 | verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); |
| 772 | verts[1].fOffset = SkPoint::Make(-1, 1); |
| 773 | verts[1].fOuterRadius = outerRadius; |
| 774 | verts[1].fInnerRadius = innerRadius; |
| 775 | |
| 776 | verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
| 777 | verts[2].fOffset = SkPoint::Make(1, 1); |
| 778 | verts[2].fOuterRadius = outerRadius; |
| 779 | verts[2].fInnerRadius = innerRadius; |
| 780 | |
| 781 | verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
| 782 | verts[3].fOffset = SkPoint::Make(1, -1); |
| 783 | verts[3].fOuterRadius = outerRadius; |
| 784 | verts[3].fInnerRadius = innerRadius; |
| 785 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 786 | verts += kVerticesPerQuad; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 787 | } |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 788 | helper.issueDraws(batchTarget); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 792 | |
| 793 | private: |
| 794 | CircleBatch(const Geometry& geometry) { |
| 795 | this->initClassID<CircleBatch>(); |
| 796 | fGeoData.push_back(geometry); |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 797 | |
| 798 | this->setBounds(geometry.fDevBounds); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 799 | } |
| 800 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 801 | bool onCombineIfPossible(GrBatch* t) override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 802 | CircleBatch* that = t->cast<CircleBatch>(); |
| 803 | |
| 804 | // TODO use vertex color to avoid breaking batches |
| 805 | if (this->color() != that->color()) { |
| 806 | return false; |
| 807 | } |
| 808 | |
| 809 | if (this->stroke() != that->stroke()) { |
| 810 | return false; |
| 811 | } |
| 812 | |
| 813 | SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
| 814 | if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
| 815 | return false; |
| 816 | } |
| 817 | |
| 818 | fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()); |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 819 | this->joinBounds(that->bounds()); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 820 | return true; |
| 821 | } |
| 822 | |
| 823 | GrColor color() const { return fBatch.fColor; } |
| 824 | bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 825 | const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
| 826 | bool stroke() const { return fBatch.fStroke; } |
| 827 | |
| 828 | struct BatchTracker { |
| 829 | GrColor fColor; |
| 830 | bool fStroke; |
| 831 | bool fUsesLocalCoords; |
| 832 | bool fColorIgnored; |
| 833 | bool fCoverageIgnored; |
| 834 | }; |
| 835 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 836 | BatchTracker fBatch; |
| 837 | SkSTArray<1, Geometry, true> fGeoData; |
| 838 | }; |
| 839 | |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 840 | static GrBatch* create_circle_batch(GrColor color, |
| 841 | const SkMatrix& viewMatrix, |
| 842 | bool useCoverageAA, |
| 843 | const SkRect& circle, |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 844 | const SkStrokeRec& stroke) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 845 | SkPoint center = SkPoint::Make(circle.centerX(), circle.centerY()); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 846 | viewMatrix.mapPoints(¢er, 1); |
| 847 | SkScalar radius = viewMatrix.mapRadius(SkScalarHalf(circle.width())); |
| 848 | SkScalar strokeWidth = viewMatrix.mapRadius(stroke.getWidth()); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 849 | |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 850 | SkStrokeRec::Style style = stroke.getStyle(); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 851 | bool isStrokeOnly = SkStrokeRec::kStroke_Style == style || |
| 852 | SkStrokeRec::kHairline_Style == style; |
| 853 | bool hasStroke = isStrokeOnly || SkStrokeRec::kStrokeAndFill_Style == style; |
skia.committer@gmail.com | 7e32851 | 2013-03-23 07:01:28 +0000 | [diff] [blame] | 854 | |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 855 | SkScalar innerRadius = 0.0f; |
| 856 | SkScalar outerRadius = radius; |
| 857 | SkScalar halfWidth = 0; |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 858 | if (hasStroke) { |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 859 | if (SkScalarNearlyZero(strokeWidth)) { |
| 860 | halfWidth = SK_ScalarHalf; |
| 861 | } else { |
| 862 | halfWidth = SkScalarHalf(strokeWidth); |
| 863 | } |
| 864 | |
| 865 | outerRadius += halfWidth; |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 866 | if (isStrokeOnly) { |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 867 | innerRadius = radius - halfWidth; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 868 | } |
| 869 | } |
| 870 | |
bsalomon | ce1c886 | 2014-12-15 07:11:22 -0800 | [diff] [blame] | 871 | // The radii are outset for two reasons. First, it allows the shader to simply perform simpler |
| 872 | // computation because the computed alpha is zero, rather than 50%, at the radius. |
| 873 | // Second, the outer radius is used to compute the verts of the bounding box that is rendered |
| 874 | // and the outset ensures the box will cover all partially covered by the circle. |
bsalomon@google.com | 58e30fe | 2013-04-01 19:01:20 +0000 | [diff] [blame] | 875 | outerRadius += SK_ScalarHalf; |
| 876 | innerRadius -= SK_ScalarHalf; |
| 877 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 878 | CircleBatch::Geometry geometry; |
| 879 | geometry.fViewMatrix = viewMatrix; |
| 880 | geometry.fColor = color; |
| 881 | geometry.fInnerRadius = innerRadius; |
| 882 | geometry.fOuterRadius = outerRadius; |
| 883 | geometry.fStroke = isStrokeOnly && innerRadius > 0; |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 884 | geometry.fDevBounds = SkRect::MakeLTRB(center.fX - outerRadius, center.fY - outerRadius, |
| 885 | center.fX + outerRadius, center.fY + outerRadius); |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 886 | |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 887 | return CircleBatch::Create(geometry); |
| 888 | } |
| 889 | |
| 890 | void GrOvalRenderer::drawCircle(GrDrawTarget* target, |
| 891 | GrPipelineBuilder* pipelineBuilder, |
| 892 | GrColor color, |
| 893 | const SkMatrix& viewMatrix, |
| 894 | bool useCoverageAA, |
| 895 | const SkRect& circle, |
| 896 | const SkStrokeRec& stroke) { |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 897 | SkAutoTUnref<GrBatch> batch(create_circle_batch(color, viewMatrix, useCoverageAA, circle, |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 898 | stroke)); |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 899 | target->drawBatch(pipelineBuilder, batch); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 900 | } |
| 901 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 902 | /////////////////////////////////////////////////////////////////////////////// |
| 903 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 904 | class EllipseBatch : public GrBatch { |
| 905 | public: |
| 906 | struct Geometry { |
| 907 | GrColor fColor; |
| 908 | SkMatrix fViewMatrix; |
| 909 | SkScalar fXRadius; |
| 910 | SkScalar fYRadius; |
| 911 | SkScalar fInnerXRadius; |
| 912 | SkScalar fInnerYRadius; |
| 913 | bool fStroke; |
egdaniel | bc22714 | 2015-04-21 06:28:08 -0700 | [diff] [blame] | 914 | SkRect fDevBounds; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 915 | }; |
| 916 | |
| 917 | static GrBatch* Create(const Geometry& geometry) { |
| 918 | return SkNEW_ARGS(EllipseBatch, (geometry)); |
| 919 | } |
| 920 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 921 | const char* name() const override { return "EllipseBatch"; } |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 922 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 923 | void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 924 | // When this is called on a batch, there is only one geometry bundle |
| 925 | out->setKnownFourComponents(fGeoData[0].fColor); |
| 926 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 927 | void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 928 | out->setUnknownSingleComponent(); |
| 929 | } |
| 930 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 931 | void initBatchTracker(const GrPipelineInfo& init) override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 932 | // Handle any color overrides |
| 933 | if (init.fColorIgnored) { |
| 934 | fGeoData[0].fColor = GrColor_ILLEGAL; |
| 935 | } else if (GrColor_ILLEGAL != init.fOverrideColor) { |
| 936 | fGeoData[0].fColor = init.fOverrideColor; |
| 937 | } |
| 938 | |
| 939 | // setup batch properties |
| 940 | fBatch.fColorIgnored = init.fColorIgnored; |
| 941 | fBatch.fColor = fGeoData[0].fColor; |
| 942 | fBatch.fStroke = fGeoData[0].fStroke; |
| 943 | fBatch.fUsesLocalCoords = init.fUsesLocalCoords; |
| 944 | fBatch.fCoverageIgnored = init.fCoverageIgnored; |
| 945 | } |
| 946 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 947 | void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 948 | SkMatrix invert; |
| 949 | if (!this->viewMatrix().invert(&invert)) { |
| 950 | return; |
| 951 | } |
| 952 | |
| 953 | // Setup geometry processor |
| 954 | SkAutoTUnref<GrGeometryProcessor> gp(EllipseEdgeEffect::Create(this->color(), |
| 955 | this->stroke(), |
| 956 | invert)); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 957 | |
| 958 | batchTarget->initDraw(gp, pipeline); |
| 959 | |
| 960 | // TODO this is hacky, but the only way we have to initialize the GP is to use the |
| 961 | // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch |
| 962 | // everywhere we can remove this nastiness |
| 963 | GrPipelineInfo init; |
| 964 | init.fColorIgnored = fBatch.fColorIgnored; |
| 965 | init.fOverrideColor = GrColor_ILLEGAL; |
| 966 | init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 967 | init.fUsesLocalCoords = this->usesLocalCoords(); |
| 968 | gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 969 | |
| 970 | int instanceCount = fGeoData.count(); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 971 | QuadHelper helper; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 972 | size_t vertexStride = gp->getVertexStride(); |
joshualitt | 19e0058 | 2015-02-11 17:36:30 -0800 | [diff] [blame] | 973 | SkASSERT(vertexStride == sizeof(EllipseVertex)); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 974 | EllipseVertex* verts = reinterpret_cast<EllipseVertex*>( |
| 975 | helper.init(batchTarget, vertexStride, instanceCount)); |
| 976 | if (!verts) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 977 | return; |
| 978 | } |
| 979 | |
bsalomon | 8415abe | 2015-05-04 11:41:41 -0700 | [diff] [blame] | 980 | for (int i = 0; i < instanceCount; i++) { |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 981 | Geometry& geom = fGeoData[i]; |
bsalomon | 8415abe | 2015-05-04 11:41:41 -0700 | [diff] [blame] | 982 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 983 | SkScalar xRadius = geom.fXRadius; |
| 984 | SkScalar yRadius = geom.fYRadius; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 985 | |
| 986 | // Compute the reciprocals of the radii here to save time in the shader |
| 987 | SkScalar xRadRecip = SkScalarInvert(xRadius); |
| 988 | SkScalar yRadRecip = SkScalarInvert(yRadius); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 989 | SkScalar xInnerRadRecip = SkScalarInvert(geom.fInnerXRadius); |
| 990 | SkScalar yInnerRadRecip = SkScalarInvert(geom.fInnerYRadius); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 991 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 992 | const SkRect& bounds = geom.fDevBounds; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 993 | |
| 994 | // The inner radius in the vertex data must be specified in normalized space. |
| 995 | verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
| 996 | verts[0].fOffset = SkPoint::Make(-xRadius, -yRadius); |
| 997 | verts[0].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 998 | verts[0].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
| 999 | |
| 1000 | verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); |
| 1001 | verts[1].fOffset = SkPoint::Make(-xRadius, yRadius); |
| 1002 | verts[1].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 1003 | verts[1].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
| 1004 | |
| 1005 | verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
| 1006 | verts[2].fOffset = SkPoint::Make(xRadius, yRadius); |
| 1007 | verts[2].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 1008 | verts[2].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
| 1009 | |
| 1010 | verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
| 1011 | verts[3].fOffset = SkPoint::Make(xRadius, -yRadius); |
| 1012 | verts[3].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 1013 | verts[3].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
| 1014 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1015 | verts += kVerticesPerQuad; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1016 | } |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1017 | helper.issueDraws(batchTarget); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 1021 | |
| 1022 | private: |
| 1023 | EllipseBatch(const Geometry& geometry) { |
| 1024 | this->initClassID<EllipseBatch>(); |
| 1025 | fGeoData.push_back(geometry); |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 1026 | |
| 1027 | this->setBounds(geometry.fDevBounds); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1028 | } |
| 1029 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1030 | bool onCombineIfPossible(GrBatch* t) override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1031 | EllipseBatch* that = t->cast<EllipseBatch>(); |
| 1032 | |
| 1033 | // TODO use vertex color to avoid breaking batches |
| 1034 | if (this->color() != that->color()) { |
| 1035 | return false; |
| 1036 | } |
| 1037 | |
| 1038 | if (this->stroke() != that->stroke()) { |
| 1039 | return false; |
| 1040 | } |
| 1041 | |
| 1042 | SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
| 1043 | if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
| 1044 | return false; |
| 1045 | } |
| 1046 | |
| 1047 | fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()); |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 1048 | this->joinBounds(that->bounds()); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1049 | return true; |
| 1050 | } |
| 1051 | |
| 1052 | GrColor color() const { return fBatch.fColor; } |
| 1053 | bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 1054 | const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
| 1055 | bool stroke() const { return fBatch.fStroke; } |
| 1056 | |
| 1057 | struct BatchTracker { |
| 1058 | GrColor fColor; |
| 1059 | bool fStroke; |
| 1060 | bool fUsesLocalCoords; |
| 1061 | bool fColorIgnored; |
| 1062 | bool fCoverageIgnored; |
| 1063 | }; |
| 1064 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1065 | BatchTracker fBatch; |
| 1066 | SkSTArray<1, Geometry, true> fGeoData; |
| 1067 | }; |
| 1068 | |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1069 | static GrBatch* create_ellipse_batch(GrColor color, |
| 1070 | const SkMatrix& viewMatrix, |
| 1071 | bool useCoverageAA, |
| 1072 | const SkRect& ellipse, |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 1073 | const SkStrokeRec& stroke) { |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 1074 | #ifdef SK_DEBUG |
| 1075 | { |
| 1076 | // we should have checked for this previously |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 1077 | bool isAxisAlignedEllipse = viewMatrix.rectStaysRect(); |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 1078 | SkASSERT(useCoverageAA && isAxisAlignedEllipse); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 1079 | } |
| 1080 | #endif |
| 1081 | |
commit-bot@chromium.org | 0c88828 | 2013-04-19 19:01:45 +0000 | [diff] [blame] | 1082 | // do any matrix crunching before we reset the draw state for device coords |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 1083 | SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY()); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 1084 | viewMatrix.mapPoints(¢er, 1); |
commit-bot@chromium.org | 0c88828 | 2013-04-19 19:01:45 +0000 | [diff] [blame] | 1085 | SkScalar ellipseXRadius = SkScalarHalf(ellipse.width()); |
| 1086 | SkScalar ellipseYRadius = SkScalarHalf(ellipse.height()); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 1087 | SkScalar xRadius = SkScalarAbs(viewMatrix[SkMatrix::kMScaleX]*ellipseXRadius + |
| 1088 | viewMatrix[SkMatrix::kMSkewY]*ellipseYRadius); |
| 1089 | SkScalar yRadius = SkScalarAbs(viewMatrix[SkMatrix::kMSkewX]*ellipseXRadius + |
| 1090 | viewMatrix[SkMatrix::kMScaleY]*ellipseYRadius); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 1091 | |
commit-bot@chromium.org | 0c88828 | 2013-04-19 19:01:45 +0000 | [diff] [blame] | 1092 | // do (potentially) anisotropic mapping of stroke |
| 1093 | SkVector scaledStroke; |
| 1094 | SkScalar strokeWidth = stroke.getWidth(); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 1095 | scaledStroke.fX = SkScalarAbs(strokeWidth*(viewMatrix[SkMatrix::kMScaleX] + |
| 1096 | viewMatrix[SkMatrix::kMSkewY])); |
| 1097 | scaledStroke.fY = SkScalarAbs(strokeWidth*(viewMatrix[SkMatrix::kMSkewX] + |
| 1098 | viewMatrix[SkMatrix::kMScaleY])); |
commit-bot@chromium.org | 0c88828 | 2013-04-19 19:01:45 +0000 | [diff] [blame] | 1099 | |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1100 | SkStrokeRec::Style style = stroke.getStyle(); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1101 | bool isStrokeOnly = SkStrokeRec::kStroke_Style == style || |
| 1102 | SkStrokeRec::kHairline_Style == style; |
| 1103 | bool hasStroke = isStrokeOnly || SkStrokeRec::kStrokeAndFill_Style == style; |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1104 | |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 1105 | SkScalar innerXRadius = 0; |
| 1106 | SkScalar innerYRadius = 0; |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1107 | if (hasStroke) { |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1108 | if (SkScalarNearlyZero(scaledStroke.length())) { |
| 1109 | scaledStroke.set(SK_ScalarHalf, SK_ScalarHalf); |
| 1110 | } else { |
| 1111 | scaledStroke.scale(SK_ScalarHalf); |
| 1112 | } |
| 1113 | |
| 1114 | // we only handle thick strokes for near-circular ellipses |
| 1115 | if (scaledStroke.length() > SK_ScalarHalf && |
| 1116 | (SK_ScalarHalf*xRadius > yRadius || SK_ScalarHalf*yRadius > xRadius)) { |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1117 | return NULL; |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | // we don't handle it if curvature of the stroke is less than curvature of the ellipse |
| 1121 | if (scaledStroke.fX*(yRadius*yRadius) < (scaledStroke.fY*scaledStroke.fY)*xRadius || |
| 1122 | scaledStroke.fY*(xRadius*xRadius) < (scaledStroke.fX*scaledStroke.fX)*yRadius) { |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1123 | return NULL; |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | // 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] | 1127 | if (isStrokeOnly) { |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1128 | innerXRadius = xRadius - scaledStroke.fX; |
| 1129 | innerYRadius = yRadius - scaledStroke.fY; |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | xRadius += scaledStroke.fX; |
| 1133 | yRadius += scaledStroke.fY; |
| 1134 | } |
| 1135 | |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 1136 | // 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] | 1137 | // 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] | 1138 | // TODO: Consider if we should use sqrt(2)/2 instead |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 1139 | xRadius += SK_ScalarHalf; |
| 1140 | yRadius += SK_ScalarHalf; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 1141 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1142 | EllipseBatch::Geometry geometry; |
| 1143 | geometry.fViewMatrix = viewMatrix; |
| 1144 | geometry.fColor = color; |
| 1145 | geometry.fXRadius = xRadius; |
| 1146 | geometry.fYRadius = yRadius; |
| 1147 | geometry.fInnerXRadius = innerXRadius; |
| 1148 | geometry.fInnerYRadius = innerYRadius; |
| 1149 | geometry.fStroke = isStrokeOnly && innerXRadius > 0 && innerYRadius > 0; |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 1150 | geometry.fDevBounds = SkRect::MakeLTRB(center.fX - xRadius, center.fY - yRadius, |
| 1151 | center.fX + xRadius, center.fY + yRadius); |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 1152 | |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1153 | return EllipseBatch::Create(geometry); |
| 1154 | } |
| 1155 | |
| 1156 | bool GrOvalRenderer::drawEllipse(GrDrawTarget* target, |
| 1157 | GrPipelineBuilder* pipelineBuilder, |
| 1158 | GrColor color, |
| 1159 | const SkMatrix& viewMatrix, |
| 1160 | bool useCoverageAA, |
| 1161 | const SkRect& ellipse, |
| 1162 | const SkStrokeRec& stroke) { |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1163 | SkAutoTUnref<GrBatch> batch(create_ellipse_batch(color, viewMatrix, useCoverageAA, ellipse, |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 1164 | stroke)); |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1165 | if (!batch) { |
| 1166 | return false; |
| 1167 | } |
| 1168 | |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 1169 | target->drawBatch(pipelineBuilder, batch); |
jvanverth@google.com | c4f2eca | 2013-04-16 12:30:35 +0000 | [diff] [blame] | 1170 | return true; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 1171 | } |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1172 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1173 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
| 1174 | |
| 1175 | class DIEllipseBatch : public GrBatch { |
| 1176 | public: |
| 1177 | struct Geometry { |
| 1178 | GrColor fColor; |
| 1179 | SkMatrix fViewMatrix; |
| 1180 | SkScalar fXRadius; |
| 1181 | SkScalar fYRadius; |
| 1182 | SkScalar fInnerXRadius; |
| 1183 | SkScalar fInnerYRadius; |
| 1184 | SkScalar fGeoDx; |
| 1185 | SkScalar fGeoDy; |
| 1186 | DIEllipseEdgeEffect::Mode fMode; |
egdaniel | 9ef1bb1 | 2015-04-20 12:28:57 -0700 | [diff] [blame] | 1187 | SkRect fBounds; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1188 | }; |
| 1189 | |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 1190 | static GrBatch* Create(const Geometry& geometry, const SkRect& bounds) { |
| 1191 | return SkNEW_ARGS(DIEllipseBatch, (geometry, bounds)); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1192 | } |
| 1193 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1194 | const char* name() const override { return "DIEllipseBatch"; } |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1195 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1196 | void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1197 | // When this is called on a batch, there is only one geometry bundle |
| 1198 | out->setKnownFourComponents(fGeoData[0].fColor); |
| 1199 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1200 | void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1201 | out->setUnknownSingleComponent(); |
| 1202 | } |
| 1203 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1204 | void initBatchTracker(const GrPipelineInfo& init) override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1205 | // Handle any color overrides |
| 1206 | if (init.fColorIgnored) { |
| 1207 | fGeoData[0].fColor = GrColor_ILLEGAL; |
| 1208 | } else if (GrColor_ILLEGAL != init.fOverrideColor) { |
| 1209 | fGeoData[0].fColor = init.fOverrideColor; |
| 1210 | } |
| 1211 | |
| 1212 | // setup batch properties |
| 1213 | fBatch.fColorIgnored = init.fColorIgnored; |
| 1214 | fBatch.fColor = fGeoData[0].fColor; |
| 1215 | fBatch.fMode = fGeoData[0].fMode; |
| 1216 | fBatch.fUsesLocalCoords = init.fUsesLocalCoords; |
| 1217 | fBatch.fCoverageIgnored = init.fCoverageIgnored; |
| 1218 | } |
| 1219 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1220 | void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1221 | // Setup geometry processor |
| 1222 | SkAutoTUnref<GrGeometryProcessor> gp(DIEllipseEdgeEffect::Create(this->color(), |
| 1223 | this->viewMatrix(), |
| 1224 | this->mode())); |
| 1225 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1226 | batchTarget->initDraw(gp, pipeline); |
| 1227 | |
| 1228 | // TODO this is hacky, but the only way we have to initialize the GP is to use the |
| 1229 | // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch |
| 1230 | // everywhere we can remove this nastiness |
| 1231 | GrPipelineInfo init; |
| 1232 | init.fColorIgnored = fBatch.fColorIgnored; |
| 1233 | init.fOverrideColor = GrColor_ILLEGAL; |
| 1234 | init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 1235 | init.fUsesLocalCoords = this->usesLocalCoords(); |
| 1236 | gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 1237 | |
| 1238 | int instanceCount = fGeoData.count(); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1239 | size_t vertexStride = gp->getVertexStride(); |
joshualitt | 19e0058 | 2015-02-11 17:36:30 -0800 | [diff] [blame] | 1240 | SkASSERT(vertexStride == sizeof(DIEllipseVertex)); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1241 | QuadHelper helper; |
| 1242 | DIEllipseVertex* verts = reinterpret_cast<DIEllipseVertex*>( |
| 1243 | helper.init(batchTarget, vertexStride, instanceCount)); |
| 1244 | if (!verts) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 1245 | return; |
| 1246 | } |
| 1247 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1248 | for (int i = 0; i < instanceCount; i++) { |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1249 | Geometry& geom = fGeoData[i]; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1250 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1251 | SkScalar xRadius = geom.fXRadius; |
| 1252 | SkScalar yRadius = geom.fYRadius; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1253 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1254 | const SkRect& bounds = geom.fBounds; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1255 | |
| 1256 | // This adjusts the "radius" to include the half-pixel border |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1257 | SkScalar offsetDx = SkScalarDiv(geom.fGeoDx, xRadius); |
| 1258 | SkScalar offsetDy = SkScalarDiv(geom.fGeoDy, yRadius); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1259 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1260 | SkScalar innerRatioX = SkScalarDiv(xRadius, geom.fInnerXRadius); |
| 1261 | SkScalar innerRatioY = SkScalarDiv(yRadius, geom.fInnerYRadius); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1262 | |
| 1263 | verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
| 1264 | verts[0].fOuterOffset = SkPoint::Make(-1.0f - offsetDx, -1.0f - offsetDy); |
| 1265 | verts[0].fInnerOffset = SkPoint::Make(-innerRatioX - offsetDx, -innerRatioY - offsetDy); |
| 1266 | |
| 1267 | verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); |
| 1268 | verts[1].fOuterOffset = SkPoint::Make(-1.0f - offsetDx, 1.0f + offsetDy); |
| 1269 | verts[1].fInnerOffset = SkPoint::Make(-innerRatioX - offsetDx, innerRatioY + offsetDy); |
| 1270 | |
| 1271 | verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
| 1272 | verts[2].fOuterOffset = SkPoint::Make(1.0f + offsetDx, 1.0f + offsetDy); |
| 1273 | verts[2].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, innerRatioY + offsetDy); |
| 1274 | |
| 1275 | verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
| 1276 | verts[3].fOuterOffset = SkPoint::Make(1.0f + offsetDx, -1.0f - offsetDy); |
| 1277 | verts[3].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, -innerRatioY - offsetDy); |
| 1278 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1279 | verts += kVerticesPerQuad; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1280 | } |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1281 | helper.issueDraws(batchTarget); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 1285 | |
| 1286 | private: |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 1287 | DIEllipseBatch(const Geometry& geometry, const SkRect& bounds) { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1288 | this->initClassID<DIEllipseBatch>(); |
| 1289 | fGeoData.push_back(geometry); |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 1290 | |
| 1291 | this->setBounds(bounds); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1292 | } |
| 1293 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1294 | bool onCombineIfPossible(GrBatch* t) override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1295 | DIEllipseBatch* that = t->cast<DIEllipseBatch>(); |
| 1296 | |
| 1297 | // TODO use vertex color to avoid breaking batches |
| 1298 | if (this->color() != that->color()) { |
| 1299 | return false; |
| 1300 | } |
| 1301 | |
| 1302 | if (this->mode() != that->mode()) { |
| 1303 | return false; |
| 1304 | } |
| 1305 | |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 1306 | // TODO rewrite to allow positioning on CPU |
| 1307 | if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1308 | return false; |
| 1309 | } |
| 1310 | |
| 1311 | fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()); |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 1312 | this->joinBounds(that->bounds()); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1313 | return true; |
| 1314 | } |
| 1315 | |
| 1316 | GrColor color() const { return fBatch.fColor; } |
| 1317 | bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 1318 | const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
| 1319 | DIEllipseEdgeEffect::Mode mode() const { return fBatch.fMode; } |
| 1320 | |
| 1321 | struct BatchTracker { |
| 1322 | GrColor fColor; |
| 1323 | DIEllipseEdgeEffect::Mode fMode; |
| 1324 | bool fUsesLocalCoords; |
| 1325 | bool fColorIgnored; |
| 1326 | bool fCoverageIgnored; |
| 1327 | }; |
| 1328 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1329 | BatchTracker fBatch; |
| 1330 | SkSTArray<1, Geometry, true> fGeoData; |
| 1331 | }; |
| 1332 | |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1333 | static GrBatch* create_diellipse_batch(GrColor color, |
| 1334 | const SkMatrix& viewMatrix, |
| 1335 | bool useCoverageAA, |
| 1336 | const SkRect& ellipse, |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 1337 | const SkStrokeRec& stroke) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 1338 | SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY()); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 1339 | SkScalar xRadius = SkScalarHalf(ellipse.width()); |
skia.committer@gmail.com | 6fc1b49 | 2013-09-06 07:01:45 +0000 | [diff] [blame] | 1340 | SkScalar yRadius = SkScalarHalf(ellipse.height()); |
| 1341 | |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 1342 | SkStrokeRec::Style style = stroke.getStyle(); |
skia.committer@gmail.com | 6fc1b49 | 2013-09-06 07:01:45 +0000 | [diff] [blame] | 1343 | DIEllipseEdgeEffect::Mode mode = (SkStrokeRec::kStroke_Style == style) ? |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 1344 | DIEllipseEdgeEffect::kStroke : |
skia.committer@gmail.com | 6fc1b49 | 2013-09-06 07:01:45 +0000 | [diff] [blame] | 1345 | (SkStrokeRec::kHairline_Style == style) ? |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 1346 | DIEllipseEdgeEffect::kHairline : DIEllipseEdgeEffect::kFill; |
| 1347 | |
| 1348 | SkScalar innerXRadius = 0; |
| 1349 | SkScalar innerYRadius = 0; |
| 1350 | if (SkStrokeRec::kFill_Style != style && SkStrokeRec::kHairline_Style != style) { |
| 1351 | SkScalar strokeWidth = stroke.getWidth(); |
| 1352 | |
| 1353 | if (SkScalarNearlyZero(strokeWidth)) { |
| 1354 | strokeWidth = SK_ScalarHalf; |
| 1355 | } else { |
| 1356 | strokeWidth *= SK_ScalarHalf; |
| 1357 | } |
| 1358 | |
| 1359 | // we only handle thick strokes for near-circular ellipses |
| 1360 | if (strokeWidth > SK_ScalarHalf && |
| 1361 | (SK_ScalarHalf*xRadius > yRadius || SK_ScalarHalf*yRadius > xRadius)) { |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1362 | return NULL; |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | // we don't handle it if curvature of the stroke is less than curvature of the ellipse |
| 1366 | if (strokeWidth*(yRadius*yRadius) < (strokeWidth*strokeWidth)*xRadius || |
| 1367 | strokeWidth*(xRadius*xRadius) < (strokeWidth*strokeWidth)*yRadius) { |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1368 | return NULL; |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | // set inner radius (if needed) |
| 1372 | if (SkStrokeRec::kStroke_Style == style) { |
| 1373 | innerXRadius = xRadius - strokeWidth; |
| 1374 | innerYRadius = yRadius - strokeWidth; |
| 1375 | } |
| 1376 | |
| 1377 | xRadius += strokeWidth; |
| 1378 | yRadius += strokeWidth; |
| 1379 | } |
| 1380 | if (DIEllipseEdgeEffect::kStroke == mode) { |
| 1381 | mode = (innerXRadius > 0 && innerYRadius > 0) ? DIEllipseEdgeEffect::kStroke : |
| 1382 | DIEllipseEdgeEffect::kFill; |
| 1383 | } |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 1384 | |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 1385 | // This expands the outer rect so that after CTM we end up with a half-pixel border |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 1386 | SkScalar a = viewMatrix[SkMatrix::kMScaleX]; |
| 1387 | SkScalar b = viewMatrix[SkMatrix::kMSkewX]; |
| 1388 | SkScalar c = viewMatrix[SkMatrix::kMSkewY]; |
| 1389 | SkScalar d = viewMatrix[SkMatrix::kMScaleY]; |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 1390 | SkScalar geoDx = SkScalarDiv(SK_ScalarHalf, SkScalarSqrt(a*a + c*c)); |
| 1391 | SkScalar geoDy = SkScalarDiv(SK_ScalarHalf, SkScalarSqrt(b*b + d*d)); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 1392 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1393 | DIEllipseBatch::Geometry geometry; |
| 1394 | geometry.fViewMatrix = viewMatrix; |
| 1395 | geometry.fColor = color; |
| 1396 | geometry.fXRadius = xRadius; |
| 1397 | geometry.fYRadius = yRadius; |
| 1398 | geometry.fInnerXRadius = innerXRadius; |
| 1399 | geometry.fInnerYRadius = innerYRadius; |
| 1400 | geometry.fGeoDx = geoDx; |
| 1401 | geometry.fGeoDy = geoDy; |
| 1402 | geometry.fMode = mode; |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 1403 | geometry.fBounds = SkRect::MakeLTRB(center.fX - xRadius - geoDx, center.fY - yRadius - geoDy, |
| 1404 | center.fX + xRadius + geoDx, center.fY + yRadius + geoDy); |
egdaniel | 9ef1bb1 | 2015-04-20 12:28:57 -0700 | [diff] [blame] | 1405 | |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 1406 | SkRect devBounds = geometry.fBounds; |
| 1407 | viewMatrix.mapRect(&devBounds); |
| 1408 | return DIEllipseBatch::Create(geometry, devBounds); |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1409 | } |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 1410 | |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1411 | bool GrOvalRenderer::drawDIEllipse(GrDrawTarget* target, |
| 1412 | GrPipelineBuilder* pipelineBuilder, |
| 1413 | GrColor color, |
| 1414 | const SkMatrix& viewMatrix, |
| 1415 | bool useCoverageAA, |
| 1416 | const SkRect& ellipse, |
| 1417 | const SkStrokeRec& stroke) { |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1418 | SkAutoTUnref<GrBatch> batch(create_diellipse_batch(color, viewMatrix, useCoverageAA, ellipse, |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 1419 | stroke)); |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1420 | if (!batch) { |
| 1421 | return false; |
| 1422 | } |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 1423 | target->drawBatch(pipelineBuilder, batch); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 1424 | return true; |
| 1425 | } |
| 1426 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1427 | /////////////////////////////////////////////////////////////////////////////// |
| 1428 | |
| 1429 | static const uint16_t gRRectIndices[] = { |
| 1430 | // corners |
| 1431 | 0, 1, 5, 0, 5, 4, |
| 1432 | 2, 3, 7, 2, 7, 6, |
| 1433 | 8, 9, 13, 8, 13, 12, |
| 1434 | 10, 11, 15, 10, 15, 14, |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1435 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1436 | // edges |
| 1437 | 1, 2, 6, 1, 6, 5, |
| 1438 | 4, 5, 9, 4, 9, 8, |
| 1439 | 6, 7, 11, 6, 11, 10, |
| 1440 | 9, 10, 14, 9, 14, 13, |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1441 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1442 | // center |
| 1443 | // we place this at the end so that we can ignore these indices when rendering stroke-only |
| 1444 | 5, 6, 10, 5, 10, 9 |
| 1445 | }; |
| 1446 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 1447 | static const int kIndicesPerStrokeRRect = SK_ARRAY_COUNT(gRRectIndices) - 6; |
| 1448 | static const int kIndicesPerRRect = SK_ARRAY_COUNT(gRRectIndices); |
| 1449 | static const int kVertsPerRRect = 16; |
| 1450 | static const int kNumRRectsInIndexBuffer = 256; |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1451 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 1452 | GR_DECLARE_STATIC_UNIQUE_KEY(gStrokeRRectOnlyIndexBufferKey); |
| 1453 | GR_DECLARE_STATIC_UNIQUE_KEY(gRRectOnlyIndexBufferKey); |
| 1454 | static const GrIndexBuffer* ref_rrect_index_buffer(bool strokeOnly, |
| 1455 | GrResourceProvider* resourceProvider) { |
| 1456 | GR_DEFINE_STATIC_UNIQUE_KEY(gStrokeRRectOnlyIndexBufferKey); |
| 1457 | GR_DEFINE_STATIC_UNIQUE_KEY(gRRectOnlyIndexBufferKey); |
| 1458 | if (strokeOnly) { |
| 1459 | return resourceProvider->refOrCreateInstancedIndexBuffer( |
| 1460 | gRRectIndices, kIndicesPerStrokeRRect, kNumRRectsInIndexBuffer, kVertsPerRRect, |
| 1461 | gStrokeRRectOnlyIndexBufferKey); |
| 1462 | } else { |
| 1463 | return resourceProvider->refOrCreateInstancedIndexBuffer( |
| 1464 | gRRectIndices, kIndicesPerRRect, kNumRRectsInIndexBuffer, kVertsPerRRect, |
| 1465 | gRRectOnlyIndexBufferKey); |
| 1466 | |
| 1467 | } |
| 1468 | } |
| 1469 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1470 | bool GrOvalRenderer::drawDRRect(GrDrawTarget* target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1471 | GrPipelineBuilder* pipelineBuilder, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 1472 | GrColor color, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 1473 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1474 | bool useAA, |
| 1475 | const SkRRect& origOuter, |
| 1476 | const SkRRect& origInner) { |
bsalomon | 8af0523 | 2014-06-03 06:34:58 -0700 | [diff] [blame] | 1477 | bool applyAA = useAA && |
egdaniel | 0bdeec9 | 2015-02-23 12:12:54 -0800 | [diff] [blame] | 1478 | !pipelineBuilder->getRenderTarget()->isMultisampled(); |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 1479 | GrPipelineBuilder::AutoRestoreFragmentProcessors arfp; |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1480 | if (!origInner.isEmpty()) { |
| 1481 | SkTCopyOnFirstWrite<SkRRect> inner(origInner); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 1482 | if (!viewMatrix.isIdentity()) { |
| 1483 | if (!origInner.transform(viewMatrix, inner.writable())) { |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1484 | return false; |
| 1485 | } |
| 1486 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1487 | GrPrimitiveEdgeType edgeType = applyAA ? |
| 1488 | kInverseFillAA_GrProcessorEdgeType : |
| 1489 | kInverseFillBW_GrProcessorEdgeType; |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 1490 | // TODO this needs to be a geometry processor |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1491 | GrFragmentProcessor* fp = GrRRectEffect::Create(edgeType, *inner); |
| 1492 | if (NULL == fp) { |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1493 | return false; |
| 1494 | } |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 1495 | arfp.set(pipelineBuilder); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1496 | pipelineBuilder->addCoverageProcessor(fp)->unref(); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | SkStrokeRec fillRec(SkStrokeRec::kFill_InitStyle); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1500 | if (this->drawRRect(target, pipelineBuilder, color, viewMatrix, useAA, origOuter, fillRec)) { |
bsalomon | 8af0523 | 2014-06-03 06:34:58 -0700 | [diff] [blame] | 1501 | return true; |
| 1502 | } |
| 1503 | |
| 1504 | SkASSERT(!origOuter.isEmpty()); |
| 1505 | SkTCopyOnFirstWrite<SkRRect> outer(origOuter); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 1506 | if (!viewMatrix.isIdentity()) { |
| 1507 | if (!origOuter.transform(viewMatrix, outer.writable())) { |
bsalomon | 8af0523 | 2014-06-03 06:34:58 -0700 | [diff] [blame] | 1508 | return false; |
| 1509 | } |
| 1510 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1511 | GrPrimitiveEdgeType edgeType = applyAA ? kFillAA_GrProcessorEdgeType : |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1512 | kFillBW_GrProcessorEdgeType; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1513 | GrFragmentProcessor* effect = GrRRectEffect::Create(edgeType, *outer); |
bsalomon | 8af0523 | 2014-06-03 06:34:58 -0700 | [diff] [blame] | 1514 | if (NULL == effect) { |
| 1515 | return false; |
| 1516 | } |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 1517 | if (!arfp.isSet()) { |
| 1518 | arfp.set(pipelineBuilder); |
bsalomon | 8af0523 | 2014-06-03 06:34:58 -0700 | [diff] [blame] | 1519 | } |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 1520 | |
| 1521 | SkMatrix invert; |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 1522 | if (!viewMatrix.invert(&invert)) { |
bsalomon | 8af0523 | 2014-06-03 06:34:58 -0700 | [diff] [blame] | 1523 | return false; |
| 1524 | } |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 1525 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1526 | pipelineBuilder->addCoverageProcessor(effect)->unref(); |
bsalomon | 8af0523 | 2014-06-03 06:34:58 -0700 | [diff] [blame] | 1527 | SkRect bounds = outer->getBounds(); |
| 1528 | if (applyAA) { |
| 1529 | bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
| 1530 | } |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1531 | target->drawRect(pipelineBuilder, color, SkMatrix::I(), bounds, NULL, &invert); |
bsalomon | 8af0523 | 2014-06-03 06:34:58 -0700 | [diff] [blame] | 1532 | return true; |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1535 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1536 | |
| 1537 | class RRectCircleRendererBatch : public GrBatch { |
| 1538 | public: |
| 1539 | struct Geometry { |
| 1540 | GrColor fColor; |
| 1541 | SkMatrix fViewMatrix; |
| 1542 | SkScalar fInnerRadius; |
| 1543 | SkScalar fOuterRadius; |
| 1544 | bool fStroke; |
egdaniel | bc22714 | 2015-04-21 06:28:08 -0700 | [diff] [blame] | 1545 | SkRect fDevBounds; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1546 | }; |
| 1547 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 1548 | static GrBatch* Create(const Geometry& geometry) { |
| 1549 | return SkNEW_ARGS(RRectCircleRendererBatch, (geometry)); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1550 | } |
| 1551 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1552 | const char* name() const override { return "RRectCircleBatch"; } |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1553 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1554 | void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1555 | // When this is called on a batch, there is only one geometry bundle |
| 1556 | out->setKnownFourComponents(fGeoData[0].fColor); |
| 1557 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1558 | void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1559 | out->setUnknownSingleComponent(); |
| 1560 | } |
| 1561 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1562 | void initBatchTracker(const GrPipelineInfo& init) override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1563 | // Handle any color overrides |
| 1564 | if (init.fColorIgnored) { |
| 1565 | fGeoData[0].fColor = GrColor_ILLEGAL; |
| 1566 | } else if (GrColor_ILLEGAL != init.fOverrideColor) { |
| 1567 | fGeoData[0].fColor = init.fOverrideColor; |
| 1568 | } |
| 1569 | |
| 1570 | // setup batch properties |
| 1571 | fBatch.fColorIgnored = init.fColorIgnored; |
| 1572 | fBatch.fColor = fGeoData[0].fColor; |
| 1573 | fBatch.fStroke = fGeoData[0].fStroke; |
| 1574 | fBatch.fUsesLocalCoords = init.fUsesLocalCoords; |
| 1575 | fBatch.fCoverageIgnored = init.fCoverageIgnored; |
| 1576 | } |
| 1577 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1578 | void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1579 | // reset to device coordinates |
| 1580 | SkMatrix invert; |
| 1581 | if (!this->viewMatrix().invert(&invert)) { |
| 1582 | SkDebugf("Failed to invert\n"); |
| 1583 | return; |
| 1584 | } |
| 1585 | |
| 1586 | // Setup geometry processor |
| 1587 | SkAutoTUnref<GrGeometryProcessor> gp(CircleEdgeEffect::Create(this->color(), |
| 1588 | this->stroke(), |
| 1589 | invert)); |
| 1590 | |
| 1591 | batchTarget->initDraw(gp, pipeline); |
| 1592 | |
| 1593 | // TODO this is hacky, but the only way we have to initialize the GP is to use the |
| 1594 | // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch |
| 1595 | // everywhere we can remove this nastiness |
| 1596 | GrPipelineInfo init; |
| 1597 | init.fColorIgnored = fBatch.fColorIgnored; |
| 1598 | init.fOverrideColor = GrColor_ILLEGAL; |
| 1599 | init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 1600 | init.fUsesLocalCoords = this->usesLocalCoords(); |
| 1601 | gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 1602 | |
| 1603 | int instanceCount = fGeoData.count(); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1604 | size_t vertexStride = gp->getVertexStride(); |
| 1605 | SkASSERT(vertexStride == sizeof(CircleVertex)); |
| 1606 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1607 | // drop out the middle quad if we're stroked |
| 1608 | int indicesPerInstance = this->stroke() ? kIndicesPerStrokeRRect : kIndicesPerRRect; |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 1609 | SkAutoTUnref<const GrIndexBuffer> indexBuffer( |
| 1610 | ref_rrect_index_buffer(this->stroke(), batchTarget->resourceProvider())); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1611 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1612 | InstancedHelper helper; |
| 1613 | CircleVertex* verts = reinterpret_cast<CircleVertex*>(helper.init(batchTarget, |
| 1614 | kTriangles_GrPrimitiveType, vertexStride, indexBuffer, kVertsPerRRect, |
| 1615 | indicesPerInstance, instanceCount)); |
| 1616 | if (!verts || !indexBuffer) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 1617 | SkDebugf("Could not allocate vertices\n"); |
| 1618 | return; |
| 1619 | } |
| 1620 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1621 | for (int i = 0; i < instanceCount; i++) { |
| 1622 | Geometry& args = fGeoData[i]; |
| 1623 | |
| 1624 | SkScalar outerRadius = args.fOuterRadius; |
| 1625 | |
egdaniel | bc22714 | 2015-04-21 06:28:08 -0700 | [diff] [blame] | 1626 | const SkRect& bounds = args.fDevBounds; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1627 | |
| 1628 | SkScalar yCoords[4] = { |
| 1629 | bounds.fTop, |
| 1630 | bounds.fTop + outerRadius, |
| 1631 | bounds.fBottom - outerRadius, |
| 1632 | bounds.fBottom |
| 1633 | }; |
| 1634 | |
| 1635 | SkScalar yOuterRadii[4] = {-1, 0, 0, 1 }; |
| 1636 | // The inner radius in the vertex data must be specified in normalized space. |
| 1637 | SkScalar innerRadius = args.fInnerRadius / args.fOuterRadius; |
| 1638 | for (int i = 0; i < 4; ++i) { |
| 1639 | verts->fPos = SkPoint::Make(bounds.fLeft, yCoords[i]); |
| 1640 | verts->fOffset = SkPoint::Make(-1, yOuterRadii[i]); |
| 1641 | verts->fOuterRadius = outerRadius; |
| 1642 | verts->fInnerRadius = innerRadius; |
| 1643 | verts++; |
| 1644 | |
| 1645 | verts->fPos = SkPoint::Make(bounds.fLeft + outerRadius, yCoords[i]); |
| 1646 | verts->fOffset = SkPoint::Make(0, yOuterRadii[i]); |
| 1647 | verts->fOuterRadius = outerRadius; |
| 1648 | verts->fInnerRadius = innerRadius; |
| 1649 | verts++; |
| 1650 | |
| 1651 | verts->fPos = SkPoint::Make(bounds.fRight - outerRadius, yCoords[i]); |
| 1652 | verts->fOffset = SkPoint::Make(0, yOuterRadii[i]); |
| 1653 | verts->fOuterRadius = outerRadius; |
| 1654 | verts->fInnerRadius = innerRadius; |
| 1655 | verts++; |
| 1656 | |
| 1657 | verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]); |
| 1658 | verts->fOffset = SkPoint::Make(1, yOuterRadii[i]); |
| 1659 | verts->fOuterRadius = outerRadius; |
| 1660 | verts->fInnerRadius = innerRadius; |
| 1661 | verts++; |
| 1662 | } |
| 1663 | } |
| 1664 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1665 | helper.issueDraws(batchTarget); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 1669 | |
| 1670 | private: |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 1671 | RRectCircleRendererBatch(const Geometry& geometry) { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1672 | this->initClassID<RRectCircleRendererBatch>(); |
| 1673 | fGeoData.push_back(geometry); |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 1674 | |
| 1675 | this->setBounds(geometry.fDevBounds); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1676 | } |
| 1677 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1678 | bool onCombineIfPossible(GrBatch* t) override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1679 | RRectCircleRendererBatch* that = t->cast<RRectCircleRendererBatch>(); |
| 1680 | |
| 1681 | // TODO use vertex color to avoid breaking batches |
| 1682 | if (this->color() != that->color()) { |
| 1683 | return false; |
| 1684 | } |
| 1685 | |
| 1686 | if (this->stroke() != that->stroke()) { |
| 1687 | return false; |
| 1688 | } |
| 1689 | |
| 1690 | SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
| 1691 | if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
| 1692 | return false; |
| 1693 | } |
| 1694 | |
| 1695 | fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()); |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 1696 | this->joinBounds(that->bounds()); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1697 | return true; |
| 1698 | } |
| 1699 | |
| 1700 | GrColor color() const { return fBatch.fColor; } |
| 1701 | bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 1702 | const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
| 1703 | bool stroke() const { return fBatch.fStroke; } |
| 1704 | |
| 1705 | struct BatchTracker { |
| 1706 | GrColor fColor; |
| 1707 | bool fStroke; |
| 1708 | bool fUsesLocalCoords; |
| 1709 | bool fColorIgnored; |
| 1710 | bool fCoverageIgnored; |
| 1711 | }; |
| 1712 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1713 | BatchTracker fBatch; |
| 1714 | SkSTArray<1, Geometry, true> fGeoData; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1715 | }; |
| 1716 | |
| 1717 | class RRectEllipseRendererBatch : public GrBatch { |
| 1718 | public: |
| 1719 | struct Geometry { |
| 1720 | GrColor fColor; |
| 1721 | SkMatrix fViewMatrix; |
| 1722 | SkScalar fXRadius; |
| 1723 | SkScalar fYRadius; |
| 1724 | SkScalar fInnerXRadius; |
| 1725 | SkScalar fInnerYRadius; |
| 1726 | bool fStroke; |
egdaniel | bc22714 | 2015-04-21 06:28:08 -0700 | [diff] [blame] | 1727 | SkRect fDevBounds; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1728 | }; |
| 1729 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 1730 | static GrBatch* Create(const Geometry& geometry) { |
| 1731 | return SkNEW_ARGS(RRectEllipseRendererBatch, (geometry)); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1732 | } |
| 1733 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1734 | const char* name() const override { return "RRectEllipseRendererBatch"; } |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1735 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1736 | void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1737 | // When this is called on a batch, there is only one geometry bundle |
| 1738 | out->setKnownFourComponents(fGeoData[0].fColor); |
| 1739 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1740 | void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1741 | out->setUnknownSingleComponent(); |
| 1742 | } |
| 1743 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1744 | void initBatchTracker(const GrPipelineInfo& init) override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1745 | // Handle any color overrides |
| 1746 | if (init.fColorIgnored) { |
| 1747 | fGeoData[0].fColor = GrColor_ILLEGAL; |
| 1748 | } else if (GrColor_ILLEGAL != init.fOverrideColor) { |
| 1749 | fGeoData[0].fColor = init.fOverrideColor; |
| 1750 | } |
| 1751 | |
| 1752 | // setup batch properties |
| 1753 | fBatch.fColorIgnored = init.fColorIgnored; |
| 1754 | fBatch.fColor = fGeoData[0].fColor; |
| 1755 | fBatch.fStroke = fGeoData[0].fStroke; |
| 1756 | fBatch.fUsesLocalCoords = init.fUsesLocalCoords; |
| 1757 | fBatch.fCoverageIgnored = init.fCoverageIgnored; |
| 1758 | } |
| 1759 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1760 | void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1761 | // reset to device coordinates |
| 1762 | SkMatrix invert; |
| 1763 | if (!this->viewMatrix().invert(&invert)) { |
| 1764 | SkDebugf("Failed to invert\n"); |
| 1765 | return; |
| 1766 | } |
| 1767 | |
| 1768 | // Setup geometry processor |
| 1769 | SkAutoTUnref<GrGeometryProcessor> gp(EllipseEdgeEffect::Create(this->color(), |
| 1770 | this->stroke(), |
| 1771 | invert)); |
| 1772 | |
| 1773 | batchTarget->initDraw(gp, pipeline); |
| 1774 | |
| 1775 | // TODO this is hacky, but the only way we have to initialize the GP is to use the |
| 1776 | // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch |
| 1777 | // everywhere we can remove this nastiness |
| 1778 | GrPipelineInfo init; |
| 1779 | init.fColorIgnored = fBatch.fColorIgnored; |
| 1780 | init.fOverrideColor = GrColor_ILLEGAL; |
| 1781 | init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 1782 | init.fUsesLocalCoords = this->usesLocalCoords(); |
| 1783 | gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 1784 | |
| 1785 | int instanceCount = fGeoData.count(); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1786 | size_t vertexStride = gp->getVertexStride(); |
| 1787 | SkASSERT(vertexStride == sizeof(EllipseVertex)); |
| 1788 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1789 | // drop out the middle quad if we're stroked |
| 1790 | int indicesPerInstance = this->stroke() ? kIndicesPerStrokeRRect : kIndicesPerRRect; |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 1791 | SkAutoTUnref<const GrIndexBuffer> indexBuffer( |
| 1792 | ref_rrect_index_buffer(this->stroke(), batchTarget->resourceProvider())); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1793 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1794 | InstancedHelper helper; |
| 1795 | EllipseVertex* verts = reinterpret_cast<EllipseVertex*>( |
| 1796 | helper.init(batchTarget, kTriangles_GrPrimitiveType, vertexStride, indexBuffer, |
| 1797 | kVertsPerRRect, indicesPerInstance, instanceCount)); |
| 1798 | if (!verts || !indexBuffer) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 1799 | SkDebugf("Could not allocate vertices\n"); |
| 1800 | return; |
| 1801 | } |
| 1802 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1803 | for (int i = 0; i < instanceCount; i++) { |
| 1804 | Geometry& args = fGeoData[i]; |
| 1805 | |
| 1806 | // Compute the reciprocals of the radii here to save time in the shader |
| 1807 | SkScalar xRadRecip = SkScalarInvert(args.fXRadius); |
| 1808 | SkScalar yRadRecip = SkScalarInvert(args.fYRadius); |
| 1809 | SkScalar xInnerRadRecip = SkScalarInvert(args.fInnerXRadius); |
| 1810 | SkScalar yInnerRadRecip = SkScalarInvert(args.fInnerYRadius); |
| 1811 | |
| 1812 | // Extend the radii out half a pixel to antialias. |
| 1813 | SkScalar xOuterRadius = args.fXRadius + SK_ScalarHalf; |
| 1814 | SkScalar yOuterRadius = args.fYRadius + SK_ScalarHalf; |
| 1815 | |
egdaniel | bc22714 | 2015-04-21 06:28:08 -0700 | [diff] [blame] | 1816 | const SkRect& bounds = args.fDevBounds; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1817 | |
| 1818 | SkScalar yCoords[4] = { |
| 1819 | bounds.fTop, |
| 1820 | bounds.fTop + yOuterRadius, |
| 1821 | bounds.fBottom - yOuterRadius, |
| 1822 | bounds.fBottom |
| 1823 | }; |
| 1824 | SkScalar yOuterOffsets[4] = { |
| 1825 | yOuterRadius, |
| 1826 | SK_ScalarNearlyZero, // we're using inversesqrt() in shader, so can't be exactly 0 |
| 1827 | SK_ScalarNearlyZero, |
| 1828 | yOuterRadius |
| 1829 | }; |
| 1830 | |
| 1831 | for (int i = 0; i < 4; ++i) { |
| 1832 | verts->fPos = SkPoint::Make(bounds.fLeft, yCoords[i]); |
| 1833 | verts->fOffset = SkPoint::Make(xOuterRadius, yOuterOffsets[i]); |
| 1834 | verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 1835 | verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
| 1836 | verts++; |
| 1837 | |
| 1838 | verts->fPos = SkPoint::Make(bounds.fLeft + xOuterRadius, yCoords[i]); |
| 1839 | verts->fOffset = SkPoint::Make(SK_ScalarNearlyZero, yOuterOffsets[i]); |
| 1840 | verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 1841 | verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
| 1842 | verts++; |
| 1843 | |
| 1844 | verts->fPos = SkPoint::Make(bounds.fRight - xOuterRadius, yCoords[i]); |
| 1845 | verts->fOffset = SkPoint::Make(SK_ScalarNearlyZero, yOuterOffsets[i]); |
| 1846 | verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 1847 | verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
| 1848 | verts++; |
| 1849 | |
| 1850 | verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]); |
| 1851 | verts->fOffset = SkPoint::Make(xOuterRadius, yOuterOffsets[i]); |
| 1852 | verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 1853 | verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
| 1854 | verts++; |
| 1855 | } |
| 1856 | } |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1857 | helper.issueDraws(batchTarget); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 1861 | |
| 1862 | private: |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 1863 | RRectEllipseRendererBatch(const Geometry& geometry) { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1864 | this->initClassID<RRectEllipseRendererBatch>(); |
| 1865 | fGeoData.push_back(geometry); |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 1866 | |
| 1867 | this->setBounds(geometry.fDevBounds); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1868 | } |
| 1869 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1870 | bool onCombineIfPossible(GrBatch* t) override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1871 | RRectEllipseRendererBatch* that = t->cast<RRectEllipseRendererBatch>(); |
| 1872 | |
| 1873 | // TODO use vertex color to avoid breaking batches |
| 1874 | if (this->color() != that->color()) { |
| 1875 | return false; |
| 1876 | } |
| 1877 | |
| 1878 | if (this->stroke() != that->stroke()) { |
| 1879 | return false; |
| 1880 | } |
| 1881 | |
| 1882 | SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
| 1883 | if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
| 1884 | return false; |
| 1885 | } |
| 1886 | |
| 1887 | fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()); |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 1888 | this->joinBounds(that->bounds()); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1889 | return true; |
| 1890 | } |
| 1891 | |
| 1892 | GrColor color() const { return fBatch.fColor; } |
| 1893 | bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 1894 | const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
| 1895 | bool stroke() const { return fBatch.fStroke; } |
| 1896 | |
| 1897 | struct BatchTracker { |
| 1898 | GrColor fColor; |
| 1899 | bool fStroke; |
| 1900 | bool fUsesLocalCoords; |
| 1901 | bool fColorIgnored; |
| 1902 | bool fCoverageIgnored; |
| 1903 | }; |
| 1904 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1905 | BatchTracker fBatch; |
| 1906 | SkSTArray<1, Geometry, true> fGeoData; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1907 | }; |
| 1908 | |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1909 | static GrBatch* create_rrect_batch(GrColor color, |
| 1910 | const SkMatrix& viewMatrix, |
| 1911 | const SkRRect& rrect, |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 1912 | const SkStrokeRec& stroke) { |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1913 | SkASSERT(viewMatrix.rectStaysRect()); |
| 1914 | SkASSERT(rrect.isSimple()); |
| 1915 | SkASSERT(!rrect.isOval()); |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 1916 | |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1917 | // RRect batchs only handle simple, but not too simple, rrects |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1918 | // do any matrix crunching before we reset the draw state for device coords |
| 1919 | const SkRect& rrectBounds = rrect.getBounds(); |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 1920 | SkRect bounds; |
| 1921 | viewMatrix.mapRect(&bounds, rrectBounds); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1922 | |
| 1923 | SkVector radii = rrect.getSimpleRadii(); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 1924 | SkScalar xRadius = SkScalarAbs(viewMatrix[SkMatrix::kMScaleX]*radii.fX + |
| 1925 | viewMatrix[SkMatrix::kMSkewY]*radii.fY); |
| 1926 | SkScalar yRadius = SkScalarAbs(viewMatrix[SkMatrix::kMSkewX]*radii.fX + |
| 1927 | viewMatrix[SkMatrix::kMScaleY]*radii.fY); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1928 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1929 | SkStrokeRec::Style style = stroke.getStyle(); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1930 | |
| 1931 | // do (potentially) anisotropic mapping of stroke |
| 1932 | SkVector scaledStroke; |
| 1933 | SkScalar strokeWidth = stroke.getWidth(); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1934 | |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1935 | bool isStrokeOnly = SkStrokeRec::kStroke_Style == style || |
| 1936 | SkStrokeRec::kHairline_Style == style; |
| 1937 | bool hasStroke = isStrokeOnly || SkStrokeRec::kStrokeAndFill_Style == style; |
| 1938 | |
| 1939 | if (hasStroke) { |
| 1940 | if (SkStrokeRec::kHairline_Style == style) { |
| 1941 | scaledStroke.set(1, 1); |
| 1942 | } else { |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 1943 | scaledStroke.fX = SkScalarAbs(strokeWidth*(viewMatrix[SkMatrix::kMScaleX] + |
| 1944 | viewMatrix[SkMatrix::kMSkewY])); |
| 1945 | scaledStroke.fY = SkScalarAbs(strokeWidth*(viewMatrix[SkMatrix::kMSkewX] + |
| 1946 | viewMatrix[SkMatrix::kMScaleY])); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1947 | } |
| 1948 | |
| 1949 | // if half of strokewidth is greater than radius, we don't handle that right now |
| 1950 | if (SK_ScalarHalf*scaledStroke.fX > xRadius || SK_ScalarHalf*scaledStroke.fY > yRadius) { |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1951 | return NULL; |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1952 | } |
| 1953 | } |
| 1954 | |
| 1955 | // The way the effect interpolates the offset-to-ellipse/circle-center attribute only works on |
| 1956 | // the interior of the rrect if the radii are >= 0.5. Otherwise, the inner rect of the nine- |
| 1957 | // patch will have fractional coverage. This only matters when the interior is actually filled. |
| 1958 | // We could consider falling back to rect rendering here, since a tiny radius is |
| 1959 | // indistinguishable from a square corner. |
| 1960 | if (!isStrokeOnly && (SK_ScalarHalf > xRadius || SK_ScalarHalf > yRadius)) { |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1961 | return NULL; |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1962 | } |
| 1963 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1964 | // if the corners are circles, use the circle renderer |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1965 | if ((!hasStroke || scaledStroke.fX == scaledStroke.fY) && xRadius == yRadius) { |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1966 | SkScalar innerRadius = 0.0f; |
| 1967 | SkScalar outerRadius = xRadius; |
| 1968 | SkScalar halfWidth = 0; |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1969 | if (hasStroke) { |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1970 | if (SkScalarNearlyZero(scaledStroke.fX)) { |
| 1971 | halfWidth = SK_ScalarHalf; |
| 1972 | } else { |
| 1973 | halfWidth = SkScalarHalf(scaledStroke.fX); |
| 1974 | } |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1975 | |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1976 | if (isStrokeOnly) { |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1977 | innerRadius = xRadius - halfWidth; |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1978 | } |
| 1979 | outerRadius += halfWidth; |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 1980 | bounds.outset(halfWidth, halfWidth); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1981 | } |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1982 | |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1983 | isStrokeOnly = (isStrokeOnly && innerRadius >= 0); |
commit-bot@chromium.org | cefde6e | 2013-08-30 16:34:52 +0000 | [diff] [blame] | 1984 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1985 | // The radii are outset for two reasons. First, it allows the shader to simply perform |
bsalomon | ce1c886 | 2014-12-15 07:11:22 -0800 | [diff] [blame] | 1986 | // simpler computation because the computed alpha is zero, rather than 50%, at the radius. |
| 1987 | // Second, the outer radius is used to compute the verts of the bounding box that is |
| 1988 | // rendered and the outset ensures the box will cover all partially covered by the rrect |
| 1989 | // corners. |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1990 | outerRadius += SK_ScalarHalf; |
| 1991 | innerRadius -= SK_ScalarHalf; |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1992 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1993 | // Expand the rect so all the pixels will be captured. |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 1994 | bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1995 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1996 | RRectCircleRendererBatch::Geometry geometry; |
| 1997 | geometry.fViewMatrix = viewMatrix; |
| 1998 | geometry.fColor = color; |
| 1999 | geometry.fInnerRadius = innerRadius; |
| 2000 | geometry.fOuterRadius = outerRadius; |
| 2001 | geometry.fStroke = isStrokeOnly; |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 2002 | geometry.fDevBounds = bounds; |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 2003 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 2004 | return RRectCircleRendererBatch::Create(geometry); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 2005 | // otherwise we use the ellipse renderer |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 2006 | } else { |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 2007 | SkScalar innerXRadius = 0.0f; |
| 2008 | SkScalar innerYRadius = 0.0f; |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 2009 | if (hasStroke) { |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 2010 | if (SkScalarNearlyZero(scaledStroke.length())) { |
| 2011 | scaledStroke.set(SK_ScalarHalf, SK_ScalarHalf); |
| 2012 | } else { |
| 2013 | scaledStroke.scale(SK_ScalarHalf); |
| 2014 | } |
| 2015 | |
| 2016 | // we only handle thick strokes for near-circular ellipses |
skia.committer@gmail.com | 8be02fc | 2013-05-17 07:01:11 +0000 | [diff] [blame] | 2017 | if (scaledStroke.length() > SK_ScalarHalf && |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 2018 | (SK_ScalarHalf*xRadius > yRadius || SK_ScalarHalf*yRadius > xRadius)) { |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 2019 | return NULL; |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | // we don't handle it if curvature of the stroke is less than curvature of the ellipse |
| 2023 | if (scaledStroke.fX*(yRadius*yRadius) < (scaledStroke.fY*scaledStroke.fY)*xRadius || |
| 2024 | scaledStroke.fY*(xRadius*xRadius) < (scaledStroke.fX*scaledStroke.fX)*yRadius) { |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 2025 | return NULL; |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | // 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] | 2029 | if (isStrokeOnly) { |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 2030 | innerXRadius = xRadius - scaledStroke.fX; |
| 2031 | innerYRadius = yRadius - scaledStroke.fY; |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 2032 | } |
| 2033 | |
| 2034 | xRadius += scaledStroke.fX; |
| 2035 | yRadius += scaledStroke.fY; |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 2036 | bounds.outset(scaledStroke.fX, scaledStroke.fY); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 2037 | } |
jvanverth@google.com | e364741 | 2013-05-08 15:31:43 +0000 | [diff] [blame] | 2038 | |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 2039 | isStrokeOnly = (isStrokeOnly && innerXRadius >= 0 && innerYRadius >= 0); |
commit-bot@chromium.org | cefde6e | 2013-08-30 16:34:52 +0000 | [diff] [blame] | 2040 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 2041 | // Expand the rect so all the pixels will be captured. |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 2042 | bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 2043 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 2044 | RRectEllipseRendererBatch::Geometry geometry; |
| 2045 | geometry.fViewMatrix = viewMatrix; |
| 2046 | geometry.fColor = color; |
| 2047 | geometry.fXRadius = xRadius; |
| 2048 | geometry.fYRadius = yRadius; |
| 2049 | geometry.fInnerXRadius = innerXRadius; |
| 2050 | geometry.fInnerYRadius = innerYRadius; |
| 2051 | geometry.fStroke = isStrokeOnly; |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 2052 | geometry.fDevBounds = bounds; |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 2053 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 2054 | return RRectEllipseRendererBatch::Create(geometry); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 2055 | } |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 2056 | } |
| 2057 | |
| 2058 | bool GrOvalRenderer::drawRRect(GrDrawTarget* target, |
| 2059 | GrPipelineBuilder* pipelineBuilder, |
| 2060 | GrColor color, |
| 2061 | const SkMatrix& viewMatrix, |
| 2062 | bool useAA, |
| 2063 | const SkRRect& rrect, |
| 2064 | const SkStrokeRec& stroke) { |
| 2065 | if (rrect.isOval()) { |
| 2066 | return this->drawOval(target, pipelineBuilder, color, viewMatrix, useAA, rrect.getBounds(), |
| 2067 | stroke); |
| 2068 | } |
| 2069 | |
| 2070 | bool useCoverageAA = useAA && !pipelineBuilder->getRenderTarget()->isMultisampled(); |
| 2071 | |
| 2072 | // only anti-aliased rrects for now |
| 2073 | if (!useCoverageAA) { |
| 2074 | return false; |
| 2075 | } |
| 2076 | |
| 2077 | if (!viewMatrix.rectStaysRect() || !rrect.isSimple()) { |
| 2078 | return false; |
| 2079 | } |
| 2080 | |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 2081 | SkAutoTUnref<GrBatch> batch(create_rrect_batch(color, viewMatrix, rrect, stroke)); |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 2082 | if (!batch) { |
| 2083 | return false; |
| 2084 | } |
| 2085 | |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 2086 | target->drawBatch(pipelineBuilder, batch); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 2087 | return true; |
| 2088 | } |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 2089 | |
| 2090 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2091 | |
| 2092 | #ifdef GR_TEST_UTILS |
| 2093 | |
| 2094 | static SkStrokeRec random_strokerec(SkRandom* random) { |
| 2095 | SkStrokeRec::InitStyle style = |
| 2096 | SkStrokeRec::InitStyle(random->nextULessThan(SkStrokeRec::kFill_InitStyle + 1)); |
| 2097 | SkStrokeRec rec(style); |
| 2098 | bool strokeAndFill = random->nextBool(); |
| 2099 | SkScalar strokeWidth = random->nextBool() ? 0.f : 1.f; |
| 2100 | rec.setStrokeStyle(strokeWidth, strokeAndFill); |
| 2101 | return rec; |
| 2102 | } |
| 2103 | |
| 2104 | BATCH_TEST_DEFINE(CircleBatch) { |
| 2105 | SkMatrix viewMatrix = GrTest::TestMatrix(random); |
| 2106 | GrColor color = GrRandomColor(random); |
| 2107 | bool useCoverageAA = random->nextBool(); |
| 2108 | SkRect circle = GrTest::TestRect(random); |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 2109 | return create_circle_batch(color, viewMatrix, useCoverageAA, circle, random_strokerec(random)); |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 2110 | } |
| 2111 | |
| 2112 | BATCH_TEST_DEFINE(EllipseBatch) { |
| 2113 | SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); |
| 2114 | GrColor color = GrRandomColor(random); |
| 2115 | bool useCoverageAA = random->nextBool(); |
| 2116 | SkRect ellipse = GrTest::TestRect(random); |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 2117 | return create_ellipse_batch(color, viewMatrix, useCoverageAA, ellipse, |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 2118 | random_strokerec(random)); |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 2119 | } |
| 2120 | |
| 2121 | BATCH_TEST_DEFINE(DIEllipseBatch) { |
| 2122 | SkMatrix viewMatrix = GrTest::TestMatrix(random); |
| 2123 | GrColor color = GrRandomColor(random); |
| 2124 | bool useCoverageAA = random->nextBool(); |
| 2125 | SkRect ellipse = GrTest::TestRect(random); |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 2126 | return create_diellipse_batch(color, viewMatrix, useCoverageAA, ellipse, |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 2127 | random_strokerec(random)); |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 2128 | } |
| 2129 | |
| 2130 | BATCH_TEST_DEFINE(RRectBatch) { |
| 2131 | SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); |
| 2132 | GrColor color = GrRandomColor(random); |
| 2133 | const SkRRect& rrect = GrTest::TestRRectSimple(random); |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame^] | 2134 | return create_rrect_batch(color, viewMatrix, rrect, random_strokerec(random)); |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | #endif |