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