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 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 10 | #include "GrBatchFlushState.h" |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 11 | #include "GrBatchTest.h" |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 12 | #include "GrGeometryProcessor.h" |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 13 | #include "GrInvariantOutput.h" |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 14 | #include "GrProcessor.h" |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 15 | #include "GrResourceProvider.h" |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 16 | #include "SkRRect.h" |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 17 | #include "SkStrokeRec.h" |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 18 | #include "batches/GrVertexBatch.h" |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 19 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 20 | #include "glsl/GrGLSLGeometryProcessor.h" |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 21 | #include "glsl/GrGLSLProgramDataManager.h" |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 22 | #include "glsl/GrGLSLVarying.h" |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 23 | #include "glsl/GrGLSLVertexShaderBuilder.h" |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 24 | #include "glsl/GrGLSLUniformHandler.h" |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 25 | #include "glsl/GrGLSLUtil.h" |
commit-bot@chromium.org | 234d4fb | 2013-09-30 19:55:49 +0000 | [diff] [blame] | 26 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 27 | // TODO(joshualitt) - Break this file up during GrBatch post implementation cleanup |
| 28 | |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 29 | namespace { |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 30 | |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 31 | struct CircleVertex { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 32 | SkPoint fPos; |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 33 | GrColor fColor; |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 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; |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 41 | GrColor fColor; |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 42 | SkPoint fOffset; |
| 43 | SkPoint fOuterRadii; |
| 44 | SkPoint fInnerRadii; |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 47 | struct DIEllipseVertex { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 48 | SkPoint fPos; |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 49 | GrColor fColor; |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 50 | SkPoint fOuterOffset; |
| 51 | SkPoint fInnerOffset; |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 54 | inline bool circle_stays_circle(const SkMatrix& m) { |
| 55 | return m.isSimilarity(); |
| 56 | } |
| 57 | |
| 58 | } |
| 59 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 60 | /////////////////////////////////////////////////////////////////////////////// |
| 61 | |
| 62 | /** |
bsalomon | ce1c886 | 2014-12-15 07:11:22 -0800 | [diff] [blame] | 63 | * The output of this effect is a modulation of the input color and coverage for a circle. It |
| 64 | * operates in a space normalized by the circle radius (outer radius in the case of a stroke) |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 65 | * with origin at the circle center. Three vertex attributes are used: |
bsalomon | ce1c886 | 2014-12-15 07:11:22 -0800 | [diff] [blame] | 66 | * vec2f : position in device space of the bounding geometry vertices |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 67 | * vec4ub: color |
bsalomon | ce1c886 | 2014-12-15 07:11:22 -0800 | [diff] [blame] | 68 | * vec4f : (p.xy, outerRad, innerRad) |
| 69 | * p is the position in the normalized space. |
| 70 | * outerRad is the outerRadius in device space. |
| 71 | * 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] | 72 | */ |
| 73 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 74 | class CircleGeometryProcessor : public GrGeometryProcessor { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 75 | public: |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 76 | CircleGeometryProcessor(bool stroke, const SkMatrix& localMatrix) : fLocalMatrix(localMatrix){ |
| 77 | this->initClassID<CircleGeometryProcessor>(); |
| 78 | fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType, |
| 79 | kHigh_GrSLPrecision)); |
| 80 | fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttribType)); |
| 81 | fInCircleEdge = &this->addVertexAttrib(Attribute("inCircleEdge", |
| 82 | kVec4f_GrVertexAttribType)); |
| 83 | fStroke = stroke; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 84 | } |
| 85 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 86 | const Attribute* inPosition() const { return fInPosition; } |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 87 | const Attribute* inColor() const { return fInColor; } |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 88 | const Attribute* inCircleEdge() const { return fInCircleEdge; } |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 89 | const SkMatrix& localMatrix() const { return fLocalMatrix; } |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 90 | virtual ~CircleGeometryProcessor() {} |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 91 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 92 | const char* name() const override { return "CircleEdge"; } |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 93 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 94 | class GLSLProcessor : public GrGLSLGeometryProcessor { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 95 | public: |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 96 | GLSLProcessor() {} |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 97 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 98 | void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 99 | const CircleGeometryProcessor& cgp = args.fGP.cast<CircleGeometryProcessor>(); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 100 | GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 101 | GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 102 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 103 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 104 | // emit attributes |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 105 | varyingHandler->emitAttributes(cgp); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 106 | |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 107 | GrGLSLVertToFrag v(kVec4f_GrSLType); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 108 | varyingHandler->addVarying("CircleEdge", &v); |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 109 | vertBuilder->codeAppendf("%s = %s;", v.vsOut(), cgp.inCircleEdge()->fName); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 110 | |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 111 | GrGLSLPPFragmentBuilder* fragBuilder = args.fFragBuilder; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 112 | // setup pass through color |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 113 | varyingHandler->addPassThroughAttribute(cgp.inColor(), args.fOutputColor); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 114 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 115 | // Setup position |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 116 | this->setupPosition(vertBuilder, gpArgs, cgp.inPosition()->fName); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 117 | |
| 118 | // emit transforms |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 119 | this->emitTransforms(vertBuilder, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 120 | varyingHandler, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 121 | uniformHandler, |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 122 | gpArgs->fPositionVar, |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 123 | cgp.inPosition()->fName, |
| 124 | cgp.localMatrix(), |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 125 | args.fTransformsIn, |
| 126 | args.fTransformsOut); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 127 | |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 128 | fragBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn()); |
| 129 | fragBuilder->codeAppendf("float edgeAlpha = clamp(%s.z * (1.0 - d), 0.0, 1.0);", |
| 130 | v.fsIn()); |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 131 | if (cgp.fStroke) { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 132 | fragBuilder->codeAppendf("float innerAlpha = clamp(%s.z * (d - %s.w), 0.0, 1.0);", |
| 133 | v.fsIn(), v.fsIn()); |
| 134 | fragBuilder->codeAppend("edgeAlpha *= innerAlpha;"); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 135 | } |
commit-bot@chromium.org | 0a6cb60 | 2013-04-11 15:05:37 +0000 | [diff] [blame] | 136 | |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 137 | fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 138 | } |
| 139 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 140 | static void GenKey(const GrGeometryProcessor& gp, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 141 | const GrGLSLCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 142 | GrProcessorKeyBuilder* b) { |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 143 | const CircleGeometryProcessor& cgp = gp.cast<CircleGeometryProcessor>(); |
| 144 | uint16_t key = cgp.fStroke ? 0x1 : 0x0; |
| 145 | key |= cgp.localMatrix().hasPerspective() ? 0x2 : 0x0; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 146 | b->add32(key); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 147 | } |
| 148 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 149 | void setData(const GrGLSLProgramDataManager& pdman, |
| 150 | const GrPrimitiveProcessor& gp) override { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 151 | } |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 152 | |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 153 | void setTransformData(const GrPrimitiveProcessor& primProc, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 154 | const GrGLSLProgramDataManager& pdman, |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 155 | int index, |
| 156 | const SkTArray<const GrCoordTransform*, true>& transforms) override { |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 157 | this->setTransformDataHelper<CircleGeometryProcessor>(primProc, pdman, index, |
| 158 | transforms); |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 159 | } |
| 160 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 161 | private: |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 162 | typedef GrGLSLGeometryProcessor INHERITED; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 163 | }; |
| 164 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 165 | void getGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override { |
| 166 | GLSLProcessor::GenKey(*this, caps, b); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 167 | } |
| 168 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 169 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) const override { |
| 170 | return new GLSLProcessor(); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 171 | } |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 172 | |
| 173 | private: |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 174 | SkMatrix fLocalMatrix; |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 175 | const Attribute* fInPosition; |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 176 | const Attribute* fInColor; |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 177 | const Attribute* fInCircleEdge; |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 178 | bool fStroke; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 179 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 180 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 181 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 182 | typedef GrGeometryProcessor INHERITED; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 183 | }; |
| 184 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 185 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(CircleGeometryProcessor); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 186 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 187 | sk_sp<GrGeometryProcessor> CircleGeometryProcessor::TestCreate(GrProcessorTestData* d) { |
| 188 | return sk_sp<GrGeometryProcessor>( |
| 189 | new CircleGeometryProcessor(d->fRandom->nextBool(), GrTest::TestMatrix(d->fRandom))); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /////////////////////////////////////////////////////////////////////////////// |
| 193 | |
| 194 | /** |
| 195 | * 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] | 196 | * ellipse, specified as a 2D offset from center, and the reciprocals of the outer and inner radii, |
| 197 | * in both x and y directions. |
| 198 | * |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 199 | * 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] | 200 | */ |
| 201 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 202 | class EllipseGeometryProcessor : public GrGeometryProcessor { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 203 | public: |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 204 | EllipseGeometryProcessor(bool stroke, const SkMatrix& localMatrix) |
| 205 | : fLocalMatrix(localMatrix) { |
| 206 | this->initClassID<EllipseGeometryProcessor>(); |
| 207 | fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType)); |
| 208 | fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttribType)); |
| 209 | fInEllipseOffset = &this->addVertexAttrib(Attribute("inEllipseOffset", |
| 210 | kVec2f_GrVertexAttribType)); |
| 211 | fInEllipseRadii = &this->addVertexAttrib(Attribute("inEllipseRadii", |
| 212 | kVec4f_GrVertexAttribType)); |
| 213 | fStroke = stroke; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 214 | } |
| 215 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 216 | virtual ~EllipseGeometryProcessor() {} |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 217 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 218 | const char* name() const override { return "EllipseEdge"; } |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 219 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 220 | const Attribute* inPosition() const { return fInPosition; } |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 221 | const Attribute* inColor() const { return fInColor; } |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 222 | const Attribute* inEllipseOffset() const { return fInEllipseOffset; } |
| 223 | const Attribute* inEllipseRadii() const { return fInEllipseRadii; } |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 224 | const SkMatrix& localMatrix() const { return fLocalMatrix; } |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 225 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 226 | class GLSLProcessor : public GrGLSLGeometryProcessor { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 227 | public: |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 228 | GLSLProcessor() {} |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 229 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 230 | void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 231 | const EllipseGeometryProcessor& egp = args.fGP.cast<EllipseGeometryProcessor>(); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 232 | GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 233 | GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 234 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 235 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 236 | // emit attributes |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 237 | varyingHandler->emitAttributes(egp); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 238 | |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 239 | GrGLSLVertToFrag ellipseOffsets(kVec2f_GrSLType); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 240 | varyingHandler->addVarying("EllipseOffsets", &ellipseOffsets); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 241 | vertBuilder->codeAppendf("%s = %s;", ellipseOffsets.vsOut(), |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 242 | egp.inEllipseOffset()->fName); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 243 | |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 244 | GrGLSLVertToFrag ellipseRadii(kVec4f_GrSLType); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 245 | varyingHandler->addVarying("EllipseRadii", &ellipseRadii); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 246 | vertBuilder->codeAppendf("%s = %s;", ellipseRadii.vsOut(), |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 247 | egp.inEllipseRadii()->fName); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 248 | |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 249 | GrGLSLPPFragmentBuilder* fragBuilder = args.fFragBuilder; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 250 | // setup pass through color |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 251 | varyingHandler->addPassThroughAttribute(egp.inColor(), args.fOutputColor); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 252 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 253 | // Setup position |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 254 | this->setupPosition(vertBuilder, gpArgs, egp.inPosition()->fName); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 255 | |
| 256 | // emit transforms |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 257 | this->emitTransforms(vertBuilder, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 258 | varyingHandler, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 259 | uniformHandler, |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 260 | gpArgs->fPositionVar, |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 261 | egp.inPosition()->fName, |
| 262 | egp.localMatrix(), |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 263 | args.fTransformsIn, |
| 264 | args.fTransformsOut); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 265 | |
skia.committer@gmail.com | 8be02fc | 2013-05-17 07:01:11 +0000 | [diff] [blame] | 266 | // for outer curve |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 267 | fragBuilder->codeAppendf("vec2 scaledOffset = %s*%s.xy;", ellipseOffsets.fsIn(), |
| 268 | ellipseRadii.fsIn()); |
| 269 | fragBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset) - 1.0;"); |
| 270 | fragBuilder->codeAppendf("vec2 grad = 2.0*scaledOffset*%s.xy;", ellipseRadii.fsIn()); |
| 271 | fragBuilder->codeAppend("float grad_dot = dot(grad, grad);"); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 272 | |
commit-bot@chromium.org | 1b035d8 | 2014-04-09 17:11:09 +0000 | [diff] [blame] | 273 | // avoid calling inversesqrt on zero. |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 274 | fragBuilder->codeAppend("grad_dot = max(grad_dot, 1.0e-4);"); |
| 275 | fragBuilder->codeAppend("float invlen = inversesqrt(grad_dot);"); |
brianosman | c6052ac | 2016-02-12 10:20:00 -0800 | [diff] [blame] | 276 | fragBuilder->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] | 277 | |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 278 | // for inner curve |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 279 | if (egp.fStroke) { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 280 | fragBuilder->codeAppendf("scaledOffset = %s*%s.zw;", |
| 281 | ellipseOffsets.fsIn(), ellipseRadii.fsIn()); |
| 282 | fragBuilder->codeAppend("test = dot(scaledOffset, scaledOffset) - 1.0;"); |
| 283 | fragBuilder->codeAppendf("grad = 2.0*scaledOffset*%s.zw;", |
| 284 | ellipseRadii.fsIn()); |
| 285 | fragBuilder->codeAppend("invlen = inversesqrt(dot(grad, grad));"); |
| 286 | fragBuilder->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] | 287 | } |
| 288 | |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 289 | fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 290 | } |
| 291 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 292 | static void GenKey(const GrGeometryProcessor& gp, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 293 | const GrGLSLCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 294 | GrProcessorKeyBuilder* b) { |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 295 | const EllipseGeometryProcessor& egp = gp.cast<EllipseGeometryProcessor>(); |
| 296 | uint16_t key = egp.fStroke ? 0x1 : 0x0; |
| 297 | key |= egp.localMatrix().hasPerspective() ? 0x2 : 0x0; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 298 | b->add32(key); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 299 | } |
| 300 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 301 | void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor& gp) override { |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 302 | } |
| 303 | |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 304 | void setTransformData(const GrPrimitiveProcessor& primProc, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 305 | const GrGLSLProgramDataManager& pdman, |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 306 | int index, |
| 307 | const SkTArray<const GrCoordTransform*, true>& transforms) override { |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 308 | this->setTransformDataHelper<EllipseGeometryProcessor>(primProc, pdman, index, |
| 309 | transforms); |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 310 | } |
| 311 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 312 | private: |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 313 | typedef GrGLSLGeometryProcessor INHERITED; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 314 | }; |
| 315 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 316 | void getGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override { |
| 317 | GLSLProcessor::GenKey(*this, caps, b); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 318 | } |
| 319 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 320 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) const override { |
| 321 | return new GLSLProcessor(); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 322 | } |
| 323 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 324 | private: |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 325 | const Attribute* fInPosition; |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 326 | const Attribute* fInColor; |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 327 | const Attribute* fInEllipseOffset; |
| 328 | const Attribute* fInEllipseRadii; |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 329 | SkMatrix fLocalMatrix; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 330 | bool fStroke; |
| 331 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 332 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 333 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 334 | typedef GrGeometryProcessor INHERITED; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 335 | }; |
| 336 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 337 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(EllipseGeometryProcessor); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 338 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 339 | sk_sp<GrGeometryProcessor> EllipseGeometryProcessor::TestCreate(GrProcessorTestData* d) { |
| 340 | return sk_sp<GrGeometryProcessor>( |
| 341 | new EllipseGeometryProcessor(d->fRandom->nextBool(), GrTest::TestMatrix(d->fRandom))); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | /////////////////////////////////////////////////////////////////////////////// |
| 345 | |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 346 | /** |
skia.committer@gmail.com | 6fc1b49 | 2013-09-06 07:01:45 +0000 | [diff] [blame] | 347 | * 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] | 348 | * specified as a 2D offset from center for both the outer and inner paths (if stroked). The |
| 349 | * implict equation used is for a unit circle (x^2 + y^2 - 1 = 0) and the edge corrected by |
| 350 | * using differentials. |
| 351 | * |
| 352 | * The result is device-independent and can be used with any affine matrix. |
| 353 | */ |
| 354 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 355 | enum class DIEllipseStyle { kStroke = 0, kHairline, kFill }; |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 356 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 357 | class DIEllipseGeometryProcessor : public GrGeometryProcessor { |
| 358 | public: |
| 359 | DIEllipseGeometryProcessor(const SkMatrix& viewMatrix, DIEllipseStyle style) |
| 360 | : fViewMatrix(viewMatrix) { |
| 361 | this->initClassID<DIEllipseGeometryProcessor>(); |
| 362 | fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType, |
| 363 | kHigh_GrSLPrecision)); |
| 364 | fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttribType)); |
| 365 | fInEllipseOffsets0 = &this->addVertexAttrib(Attribute("inEllipseOffsets0", |
| 366 | kVec2f_GrVertexAttribType)); |
| 367 | fInEllipseOffsets1 = &this->addVertexAttrib(Attribute("inEllipseOffsets1", |
| 368 | kVec2f_GrVertexAttribType)); |
| 369 | fStyle = style; |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 370 | } |
| 371 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 372 | |
| 373 | virtual ~DIEllipseGeometryProcessor() {} |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 374 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 375 | const char* name() const override { return "DIEllipseEdge"; } |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 376 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 377 | const Attribute* inPosition() const { return fInPosition; } |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 378 | const Attribute* inColor() const { return fInColor; } |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 379 | const Attribute* inEllipseOffsets0() const { return fInEllipseOffsets0; } |
| 380 | const Attribute* inEllipseOffsets1() const { return fInEllipseOffsets1; } |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 381 | const SkMatrix& viewMatrix() const { return fViewMatrix; } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 382 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 383 | class GLSLProcessor : public GrGLSLGeometryProcessor { |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 384 | public: |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 385 | GLSLProcessor() |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 386 | : fViewMatrix(SkMatrix::InvalidMatrix()) {} |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 387 | |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 388 | void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 389 | const DIEllipseGeometryProcessor& diegp = args.fGP.cast<DIEllipseGeometryProcessor>(); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 390 | GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 391 | GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 392 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 393 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 394 | // emit attributes |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 395 | varyingHandler->emitAttributes(diegp); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 396 | |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 397 | GrGLSLVertToFrag offsets0(kVec2f_GrSLType); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 398 | varyingHandler->addVarying("EllipseOffsets0", &offsets0); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 399 | vertBuilder->codeAppendf("%s = %s;", offsets0.vsOut(), |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 400 | diegp.inEllipseOffsets0()->fName); |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 401 | |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 402 | GrGLSLVertToFrag offsets1(kVec2f_GrSLType); |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 403 | varyingHandler->addVarying("EllipseOffsets1", &offsets1); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 404 | vertBuilder->codeAppendf("%s = %s;", offsets1.vsOut(), |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 405 | diegp.inEllipseOffsets1()->fName); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 406 | |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 407 | GrGLSLPPFragmentBuilder* fragBuilder = args.fFragBuilder; |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 408 | varyingHandler->addPassThroughAttribute(diegp.inColor(), args.fOutputColor); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 409 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 410 | // Setup position |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 411 | this->setupPosition(vertBuilder, |
| 412 | uniformHandler, |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 413 | gpArgs, |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 414 | diegp.inPosition()->fName, |
| 415 | diegp.viewMatrix(), |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 416 | &fViewMatrixUniform); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 417 | |
| 418 | // emit transforms |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 419 | this->emitTransforms(vertBuilder, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 420 | varyingHandler, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 421 | uniformHandler, |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 422 | gpArgs->fPositionVar, |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 423 | diegp.inPosition()->fName, |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 424 | args.fTransformsIn, |
| 425 | args.fTransformsOut); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 426 | |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 427 | SkAssertResult(fragBuilder->enableFeature( |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 428 | GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 429 | // for outer curve |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 430 | fragBuilder->codeAppendf("vec2 scaledOffset = %s.xy;", offsets0.fsIn()); |
| 431 | fragBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset) - 1.0;"); |
| 432 | fragBuilder->codeAppendf("vec2 duvdx = dFdx(%s);", offsets0.fsIn()); |
| 433 | fragBuilder->codeAppendf("vec2 duvdy = dFdy(%s);", offsets0.fsIn()); |
| 434 | fragBuilder->codeAppendf("vec2 grad = vec2(2.0*%s.x*duvdx.x + 2.0*%s.y*duvdx.y," |
| 435 | " 2.0*%s.x*duvdy.x + 2.0*%s.y*duvdy.y);", |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 436 | offsets0.fsIn(), offsets0.fsIn(), offsets0.fsIn(), |
| 437 | offsets0.fsIn()); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 438 | |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 439 | fragBuilder->codeAppend("float grad_dot = dot(grad, grad);"); |
commit-bot@chromium.org | 1b035d8 | 2014-04-09 17:11:09 +0000 | [diff] [blame] | 440 | // avoid calling inversesqrt on zero. |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 441 | fragBuilder->codeAppend("grad_dot = max(grad_dot, 1.0e-4);"); |
| 442 | fragBuilder->codeAppend("float invlen = inversesqrt(grad_dot);"); |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 443 | if (DIEllipseStyle::kHairline == diegp.fStyle) { |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 444 | // can probably do this with one step |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 445 | fragBuilder->codeAppend("float edgeAlpha = clamp(1.0-test*invlen, 0.0, 1.0);"); |
| 446 | fragBuilder->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] | 447 | } else { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 448 | fragBuilder->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] | 449 | } |
| 450 | |
| 451 | // for inner curve |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 452 | if (DIEllipseStyle::kStroke == diegp.fStyle) { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 453 | fragBuilder->codeAppendf("scaledOffset = %s.xy;", offsets1.fsIn()); |
| 454 | fragBuilder->codeAppend("test = dot(scaledOffset, scaledOffset) - 1.0;"); |
| 455 | fragBuilder->codeAppendf("duvdx = dFdx(%s);", offsets1.fsIn()); |
| 456 | fragBuilder->codeAppendf("duvdy = dFdy(%s);", offsets1.fsIn()); |
| 457 | fragBuilder->codeAppendf("grad = vec2(2.0*%s.x*duvdx.x + 2.0*%s.y*duvdx.y," |
| 458 | " 2.0*%s.x*duvdy.x + 2.0*%s.y*duvdy.y);", |
| 459 | offsets1.fsIn(), offsets1.fsIn(), offsets1.fsIn(), |
| 460 | offsets1.fsIn()); |
| 461 | fragBuilder->codeAppend("invlen = inversesqrt(dot(grad, grad));"); |
| 462 | fragBuilder->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] | 463 | } |
| 464 | |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 465 | fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 466 | } |
| 467 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 468 | static void GenKey(const GrGeometryProcessor& gp, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 469 | const GrGLSLCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 470 | GrProcessorKeyBuilder* b) { |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 471 | const DIEllipseGeometryProcessor& diegp = gp.cast<DIEllipseGeometryProcessor>(); |
| 472 | uint16_t key = static_cast<uint16_t>(diegp.fStyle); |
| 473 | key |= ComputePosKey(diegp.viewMatrix()) << 10; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 474 | b->add32(key); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 475 | } |
| 476 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 477 | void setData(const GrGLSLProgramDataManager& pdman, |
| 478 | const GrPrimitiveProcessor& gp) override { |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 479 | const DIEllipseGeometryProcessor& diegp = gp.cast<DIEllipseGeometryProcessor>(); |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 480 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 481 | if (!diegp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(diegp.viewMatrix())) { |
| 482 | fViewMatrix = diegp.viewMatrix(); |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 483 | float viewMatrix[3 * 3]; |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 484 | GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 485 | pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
| 486 | } |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | private: |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 490 | SkMatrix fViewMatrix; |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 491 | UniformHandle fViewMatrixUniform; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 492 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 493 | typedef GrGLSLGeometryProcessor INHERITED; |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 494 | }; |
| 495 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 496 | void getGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override { |
| 497 | GLSLProcessor::GenKey(*this, caps, b); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 498 | } |
| 499 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 500 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) const override { |
| 501 | return new GLSLProcessor(); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 502 | } |
| 503 | |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 504 | private: |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 505 | const Attribute* fInPosition; |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 506 | const Attribute* fInColor; |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 507 | const Attribute* fInEllipseOffsets0; |
| 508 | const Attribute* fInEllipseOffsets1; |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 509 | SkMatrix fViewMatrix; |
| 510 | DIEllipseStyle fStyle; |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 511 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 512 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 513 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 514 | typedef GrGeometryProcessor INHERITED; |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 515 | }; |
| 516 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 517 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DIEllipseGeometryProcessor); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 518 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 519 | sk_sp<GrGeometryProcessor> DIEllipseGeometryProcessor::TestCreate(GrProcessorTestData* d) { |
| 520 | return sk_sp<GrGeometryProcessor>( |
| 521 | new DIEllipseGeometryProcessor(GrTest::TestMatrix(d->fRandom), |
| 522 | (DIEllipseStyle)(d->fRandom->nextRangeU(0,2)))); |
commit-bot@chromium.org | 5242ed7 | 2013-09-05 19:26:51 +0000 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | /////////////////////////////////////////////////////////////////////////////// |
| 526 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 527 | class CircleBatch : public GrVertexBatch { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 528 | public: |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 529 | DEFINE_BATCH_CLASS_ID |
| 530 | |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 531 | CircleBatch(GrColor color, const SkMatrix& viewMatrix, const SkRect& circle, |
| 532 | const SkStrokeRec& stroke) |
| 533 | : INHERITED(ClassID()) |
| 534 | , fViewMatrixIfUsingLocalCoords(viewMatrix) { |
| 535 | SkPoint center = SkPoint::Make(circle.centerX(), circle.centerY()); |
| 536 | viewMatrix.mapPoints(¢er, 1); |
| 537 | SkScalar radius = viewMatrix.mapRadius(SkScalarHalf(circle.width())); |
| 538 | SkScalar strokeWidth = viewMatrix.mapRadius(stroke.getWidth()); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 539 | |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 540 | SkStrokeRec::Style style = stroke.getStyle(); |
| 541 | bool isStrokeOnly = SkStrokeRec::kStroke_Style == style || |
| 542 | SkStrokeRec::kHairline_Style == style; |
| 543 | bool hasStroke = isStrokeOnly || SkStrokeRec::kStrokeAndFill_Style == style; |
| 544 | |
| 545 | SkScalar innerRadius = 0.0f; |
| 546 | SkScalar outerRadius = radius; |
| 547 | SkScalar halfWidth = 0; |
| 548 | if (hasStroke) { |
| 549 | if (SkScalarNearlyZero(strokeWidth)) { |
| 550 | halfWidth = SK_ScalarHalf; |
| 551 | } else { |
| 552 | halfWidth = SkScalarHalf(strokeWidth); |
| 553 | } |
| 554 | |
| 555 | outerRadius += halfWidth; |
| 556 | if (isStrokeOnly) { |
| 557 | innerRadius = radius - halfWidth; |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | // The radii are outset for two reasons. First, it allows the shader to simply perform |
| 562 | // simpler computation because the computed alpha is zero, rather than 50%, at the radius. |
| 563 | // Second, the outer radius is used to compute the verts of the bounding box that is |
| 564 | // rendered and the outset ensures the box will cover all partially covered by the circle. |
| 565 | outerRadius += SK_ScalarHalf; |
| 566 | innerRadius -= SK_ScalarHalf; |
| 567 | |
| 568 | fGeoData.emplace_back(Geometry { |
| 569 | color, |
| 570 | innerRadius, |
| 571 | outerRadius, |
| 572 | SkRect::MakeLTRB(center.fX - outerRadius, center.fY - outerRadius, |
| 573 | center.fX + outerRadius, center.fY + outerRadius) |
| 574 | }); |
| 575 | this->setBounds(fGeoData.back().fDevBounds); |
| 576 | fStroked = isStrokeOnly && innerRadius > 0; |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 577 | } |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 578 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 579 | const char* name() const override { return "CircleBatch"; } |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 580 | |
robertphillips | e004bfc | 2015-11-16 09:06:59 -0800 | [diff] [blame] | 581 | SkString dumpInfo() const override { |
| 582 | SkString string; |
| 583 | for (int i = 0; i < fGeoData.count(); ++i) { |
| 584 | string.appendf("Color: 0x%08x Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f]," |
| 585 | "InnerRad: %.2f, OuterRad: %.2f\n", |
| 586 | fGeoData[i].fColor, |
| 587 | fGeoData[i].fDevBounds.fLeft, fGeoData[i].fDevBounds.fTop, |
| 588 | fGeoData[i].fDevBounds.fRight, fGeoData[i].fDevBounds.fBottom, |
| 589 | fGeoData[i].fInnerRadius, |
| 590 | fGeoData[i].fOuterRadius); |
| 591 | } |
| 592 | string.append(INHERITED::dumpInfo()); |
| 593 | return string; |
| 594 | } |
| 595 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 596 | void computePipelineOptimizations(GrInitInvariantOutput* color, |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 597 | GrInitInvariantOutput* coverage, |
| 598 | GrBatchToXPOverrides* overrides) const override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 599 | // When this is called on a batch, there is only one geometry bundle |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 600 | color->setKnownFourComponents(fGeoData[0].fColor); |
| 601 | coverage->setUnknownSingleComponent(); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 602 | } |
| 603 | |
bsalomon | e46f9fe | 2015-08-18 06:05:14 -0700 | [diff] [blame] | 604 | private: |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 605 | void initBatchTracker(const GrXPOverridesForBatch& overrides) override { |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 606 | // Handle any overrides that affect our GP. |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 607 | overrides.getOverrideColorIfSet(&fGeoData[0].fColor); |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 608 | if (!overrides.readsLocalCoords()) { |
| 609 | fViewMatrixIfUsingLocalCoords.reset(); |
| 610 | } |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 611 | } |
| 612 | |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 613 | void onPrepareDraws(Target* target) const override { |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 614 | SkMatrix localMatrix; |
| 615 | if (!fViewMatrixIfUsingLocalCoords.invert(&localMatrix)) { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 616 | return; |
| 617 | } |
| 618 | |
| 619 | // Setup geometry processor |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 620 | SkAutoTUnref<GrGeometryProcessor> gp(new CircleGeometryProcessor(fStroked, localMatrix)); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 621 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 622 | int instanceCount = fGeoData.count(); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 623 | size_t vertexStride = gp->getVertexStride(); |
| 624 | SkASSERT(vertexStride == sizeof(CircleVertex)); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 625 | QuadHelper helper; |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 626 | CircleVertex* verts = reinterpret_cast<CircleVertex*>(helper.init(target, vertexStride, |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 627 | instanceCount)); |
| 628 | if (!verts) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 629 | return; |
| 630 | } |
| 631 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 632 | for (int i = 0; i < instanceCount; i++) { |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 633 | const Geometry& geom = fGeoData[i]; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 634 | |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 635 | GrColor color = geom.fColor; |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 636 | SkScalar innerRadius = geom.fInnerRadius; |
| 637 | SkScalar outerRadius = geom.fOuterRadius; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 638 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 639 | const SkRect& bounds = geom.fDevBounds; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 640 | |
| 641 | // The inner radius in the vertex data must be specified in normalized space. |
| 642 | innerRadius = innerRadius / outerRadius; |
| 643 | verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 644 | verts[0].fColor = color; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 645 | verts[0].fOffset = SkPoint::Make(-1, -1); |
| 646 | verts[0].fOuterRadius = outerRadius; |
| 647 | verts[0].fInnerRadius = innerRadius; |
| 648 | |
| 649 | verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 650 | verts[1].fColor = color; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 651 | verts[1].fOffset = SkPoint::Make(-1, 1); |
| 652 | verts[1].fOuterRadius = outerRadius; |
| 653 | verts[1].fInnerRadius = innerRadius; |
| 654 | |
| 655 | verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 656 | verts[2].fColor = color; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 657 | verts[2].fOffset = SkPoint::Make(1, 1); |
| 658 | verts[2].fOuterRadius = outerRadius; |
| 659 | verts[2].fInnerRadius = innerRadius; |
| 660 | |
| 661 | verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 662 | verts[3].fColor = color; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 663 | verts[3].fOffset = SkPoint::Make(1, -1); |
| 664 | verts[3].fOuterRadius = outerRadius; |
| 665 | verts[3].fInnerRadius = innerRadius; |
| 666 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 667 | verts += kVerticesPerQuad; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 668 | } |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 669 | helper.recordDraw(target, gp); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 670 | } |
| 671 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 672 | bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 673 | CircleBatch* that = t->cast<CircleBatch>(); |
| 674 | if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), |
| 675 | that->bounds(), caps)) { |
joshualitt | 8cab9a7 | 2015-07-16 09:13:50 -0700 | [diff] [blame] | 676 | return false; |
| 677 | } |
| 678 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 679 | if (this->fStroked != that->fStroked) { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 680 | return false; |
| 681 | } |
| 682 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 683 | if (!fViewMatrixIfUsingLocalCoords.cheapEqualTo(that->fViewMatrixIfUsingLocalCoords)) { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 684 | return false; |
| 685 | } |
| 686 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 687 | fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 688 | this->joinBounds(that->bounds()); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 689 | return true; |
| 690 | } |
| 691 | |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 692 | struct Geometry { |
| 693 | GrColor fColor; |
| 694 | SkScalar fInnerRadius; |
| 695 | SkScalar fOuterRadius; |
| 696 | SkRect fDevBounds; |
| 697 | }; |
| 698 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 699 | bool fStroked; |
| 700 | SkMatrix fViewMatrixIfUsingLocalCoords; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 701 | SkSTArray<1, Geometry, true> fGeoData; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 702 | |
| 703 | typedef GrVertexBatch INHERITED; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 704 | }; |
| 705 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 706 | /////////////////////////////////////////////////////////////////////////////// |
| 707 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 708 | class EllipseBatch : public GrVertexBatch { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 709 | public: |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 710 | DEFINE_BATCH_CLASS_ID |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 711 | static GrDrawBatch* Create(GrColor color, const SkMatrix& viewMatrix, const SkRect& ellipse, |
| 712 | const SkStrokeRec& stroke) { |
| 713 | SkASSERT(viewMatrix.rectStaysRect()); |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 714 | |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 715 | // do any matrix crunching before we reset the draw state for device coords |
| 716 | SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY()); |
| 717 | viewMatrix.mapPoints(¢er, 1); |
| 718 | SkScalar ellipseXRadius = SkScalarHalf(ellipse.width()); |
| 719 | SkScalar ellipseYRadius = SkScalarHalf(ellipse.height()); |
| 720 | SkScalar xRadius = SkScalarAbs(viewMatrix[SkMatrix::kMScaleX]*ellipseXRadius + |
| 721 | viewMatrix[SkMatrix::kMSkewY]*ellipseYRadius); |
| 722 | SkScalar yRadius = SkScalarAbs(viewMatrix[SkMatrix::kMSkewX]*ellipseXRadius + |
| 723 | viewMatrix[SkMatrix::kMScaleY]*ellipseYRadius); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 724 | |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 725 | // do (potentially) anisotropic mapping of stroke |
| 726 | SkVector scaledStroke; |
| 727 | SkScalar strokeWidth = stroke.getWidth(); |
| 728 | scaledStroke.fX = SkScalarAbs(strokeWidth*(viewMatrix[SkMatrix::kMScaleX] + |
| 729 | viewMatrix[SkMatrix::kMSkewY])); |
| 730 | scaledStroke.fY = SkScalarAbs(strokeWidth*(viewMatrix[SkMatrix::kMSkewX] + |
| 731 | viewMatrix[SkMatrix::kMScaleY])); |
| 732 | |
| 733 | SkStrokeRec::Style style = stroke.getStyle(); |
| 734 | bool isStrokeOnly = SkStrokeRec::kStroke_Style == style || |
| 735 | SkStrokeRec::kHairline_Style == style; |
| 736 | bool hasStroke = isStrokeOnly || SkStrokeRec::kStrokeAndFill_Style == style; |
| 737 | |
| 738 | SkScalar innerXRadius = 0; |
| 739 | SkScalar innerYRadius = 0; |
| 740 | if (hasStroke) { |
| 741 | if (SkScalarNearlyZero(scaledStroke.length())) { |
| 742 | scaledStroke.set(SK_ScalarHalf, SK_ScalarHalf); |
| 743 | } else { |
| 744 | scaledStroke.scale(SK_ScalarHalf); |
| 745 | } |
| 746 | |
| 747 | // we only handle thick strokes for near-circular ellipses |
| 748 | if (scaledStroke.length() > SK_ScalarHalf && |
| 749 | (SK_ScalarHalf*xRadius > yRadius || SK_ScalarHalf*yRadius > xRadius)) { |
| 750 | return nullptr; |
| 751 | } |
| 752 | |
| 753 | // we don't handle it if curvature of the stroke is less than curvature of the ellipse |
| 754 | if (scaledStroke.fX*(yRadius*yRadius) < (scaledStroke.fY*scaledStroke.fY)*xRadius || |
| 755 | scaledStroke.fY*(xRadius*xRadius) < (scaledStroke.fX*scaledStroke.fX)*yRadius) { |
| 756 | return nullptr; |
| 757 | } |
| 758 | |
| 759 | // this is legit only if scale & translation (which should be the case at the moment) |
| 760 | if (isStrokeOnly) { |
| 761 | innerXRadius = xRadius - scaledStroke.fX; |
| 762 | innerYRadius = yRadius - scaledStroke.fY; |
| 763 | } |
| 764 | |
| 765 | xRadius += scaledStroke.fX; |
| 766 | yRadius += scaledStroke.fY; |
| 767 | } |
| 768 | |
| 769 | EllipseBatch* batch = new EllipseBatch(); |
| 770 | batch->fGeoData.emplace_back(Geometry { |
| 771 | color, |
| 772 | xRadius, |
| 773 | yRadius, |
| 774 | innerXRadius, |
| 775 | innerYRadius, |
| 776 | SkRect::MakeLTRB(center.fX - xRadius, center.fY - yRadius, |
| 777 | center.fX + xRadius, center.fY + yRadius) |
| 778 | }); |
| 779 | |
| 780 | // Outset bounds to include half-pixel width antialiasing. |
| 781 | batch->fGeoData[0].fDevBounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
| 782 | |
| 783 | batch->fStroked = isStrokeOnly && innerXRadius > 0 && innerYRadius > 0; |
| 784 | batch->fViewMatrixIfUsingLocalCoords = viewMatrix; |
| 785 | batch->setBounds(batch->fGeoData.back().fDevBounds); |
| 786 | return batch; |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 787 | } |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 788 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 789 | const char* name() const override { return "EllipseBatch"; } |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 790 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 791 | void computePipelineOptimizations(GrInitInvariantOutput* color, |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 792 | GrInitInvariantOutput* coverage, |
| 793 | GrBatchToXPOverrides* overrides) const override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 794 | // When this is called on a batch, there is only one geometry bundle |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 795 | color->setKnownFourComponents(fGeoData[0].fColor); |
| 796 | coverage->setUnknownSingleComponent(); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 797 | } |
| 798 | |
bsalomon | e46f9fe | 2015-08-18 06:05:14 -0700 | [diff] [blame] | 799 | private: |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 800 | EllipseBatch() : INHERITED(ClassID()) {} |
| 801 | |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 802 | void initBatchTracker(const GrXPOverridesForBatch& overrides) override { |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 803 | // Handle any overrides that affect our GP. |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 804 | if (!overrides.readsCoverage()) { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 805 | fGeoData[0].fColor = GrColor_ILLEGAL; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 806 | } |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 807 | if (!overrides.readsLocalCoords()) { |
| 808 | fViewMatrixIfUsingLocalCoords.reset(); |
| 809 | } |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 810 | } |
| 811 | |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 812 | void onPrepareDraws(Target* target) const override { |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 813 | SkMatrix localMatrix; |
| 814 | if (!fViewMatrixIfUsingLocalCoords.invert(&localMatrix)) { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 815 | return; |
| 816 | } |
| 817 | |
| 818 | // Setup geometry processor |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 819 | SkAutoTUnref<GrGeometryProcessor> gp(new EllipseGeometryProcessor(fStroked, localMatrix)); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 820 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 821 | int instanceCount = fGeoData.count(); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 822 | QuadHelper helper; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 823 | size_t vertexStride = gp->getVertexStride(); |
joshualitt | 19e0058 | 2015-02-11 17:36:30 -0800 | [diff] [blame] | 824 | SkASSERT(vertexStride == sizeof(EllipseVertex)); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 825 | EllipseVertex* verts = reinterpret_cast<EllipseVertex*>( |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 826 | helper.init(target, vertexStride, instanceCount)); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 827 | if (!verts) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 828 | return; |
| 829 | } |
| 830 | |
bsalomon | 8415abe | 2015-05-04 11:41:41 -0700 | [diff] [blame] | 831 | for (int i = 0; i < instanceCount; i++) { |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 832 | const Geometry& geom = fGeoData[i]; |
bsalomon | 8415abe | 2015-05-04 11:41:41 -0700 | [diff] [blame] | 833 | |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 834 | GrColor color = geom.fColor; |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 835 | SkScalar xRadius = geom.fXRadius; |
| 836 | SkScalar yRadius = geom.fYRadius; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 837 | |
| 838 | // Compute the reciprocals of the radii here to save time in the shader |
| 839 | SkScalar xRadRecip = SkScalarInvert(xRadius); |
| 840 | SkScalar yRadRecip = SkScalarInvert(yRadius); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 841 | SkScalar xInnerRadRecip = SkScalarInvert(geom.fInnerXRadius); |
| 842 | SkScalar yInnerRadRecip = SkScalarInvert(geom.fInnerYRadius); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 843 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 844 | const SkRect& bounds = geom.fDevBounds; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 845 | |
vjiaoblack | 977996d | 2016-06-30 12:20:54 -0700 | [diff] [blame] | 846 | // fOffsets are expanded from xyRadii to include the half-pixel antialiasing width. |
| 847 | SkScalar xMaxOffset = xRadius + SK_ScalarHalf; |
| 848 | SkScalar yMaxOffset = yRadius + SK_ScalarHalf; |
| 849 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 850 | // The inner radius in the vertex data must be specified in normalized space. |
| 851 | verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 852 | verts[0].fColor = color; |
vjiaoblack | 977996d | 2016-06-30 12:20:54 -0700 | [diff] [blame] | 853 | verts[0].fOffset = SkPoint::Make(-xMaxOffset, -yMaxOffset); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 854 | verts[0].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 855 | verts[0].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
| 856 | |
| 857 | verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 858 | verts[1].fColor = color; |
vjiaoblack | 977996d | 2016-06-30 12:20:54 -0700 | [diff] [blame] | 859 | verts[1].fOffset = SkPoint::Make(-xMaxOffset, yMaxOffset); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 860 | verts[1].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 861 | verts[1].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
| 862 | |
| 863 | verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 864 | verts[2].fColor = color; |
vjiaoblack | 977996d | 2016-06-30 12:20:54 -0700 | [diff] [blame] | 865 | verts[2].fOffset = SkPoint::Make(xMaxOffset, yMaxOffset); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 866 | verts[2].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 867 | verts[2].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
| 868 | |
| 869 | verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 870 | verts[3].fColor = color; |
vjiaoblack | 977996d | 2016-06-30 12:20:54 -0700 | [diff] [blame] | 871 | verts[3].fOffset = SkPoint::Make(xMaxOffset, -yMaxOffset); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 872 | verts[3].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 873 | verts[3].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
| 874 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 875 | verts += kVerticesPerQuad; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 876 | } |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 877 | helper.recordDraw(target, gp); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 878 | } |
| 879 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 880 | bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 881 | EllipseBatch* that = t->cast<EllipseBatch>(); |
| 882 | |
| 883 | if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), |
| 884 | that->bounds(), caps)) { |
joshualitt | 8cab9a7 | 2015-07-16 09:13:50 -0700 | [diff] [blame] | 885 | return false; |
| 886 | } |
| 887 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 888 | if (fStroked != that->fStroked) { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 889 | return false; |
| 890 | } |
| 891 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 892 | if (!fViewMatrixIfUsingLocalCoords.cheapEqualTo(that->fViewMatrixIfUsingLocalCoords)) { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 893 | return false; |
| 894 | } |
| 895 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 896 | fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 897 | this->joinBounds(that->bounds()); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 898 | return true; |
| 899 | } |
| 900 | |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 901 | struct Geometry { |
| 902 | GrColor fColor; |
| 903 | SkScalar fXRadius; |
| 904 | SkScalar fYRadius; |
| 905 | SkScalar fInnerXRadius; |
| 906 | SkScalar fInnerYRadius; |
| 907 | SkRect fDevBounds; |
| 908 | }; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 909 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 910 | bool fStroked; |
| 911 | SkMatrix fViewMatrixIfUsingLocalCoords; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 912 | SkSTArray<1, Geometry, true> fGeoData; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 913 | |
| 914 | typedef GrVertexBatch INHERITED; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 915 | }; |
| 916 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 917 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
| 918 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 919 | class DIEllipseBatch : public GrVertexBatch { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 920 | public: |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 921 | DEFINE_BATCH_CLASS_ID |
| 922 | |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 923 | static GrDrawBatch* Create(GrColor color, |
| 924 | const SkMatrix& viewMatrix, |
| 925 | const SkRect& ellipse, |
| 926 | const SkStrokeRec& stroke) { |
| 927 | SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY()); |
| 928 | SkScalar xRadius = SkScalarHalf(ellipse.width()); |
| 929 | SkScalar yRadius = SkScalarHalf(ellipse.height()); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 930 | |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 931 | SkStrokeRec::Style style = stroke.getStyle(); |
| 932 | DIEllipseStyle dieStyle = (SkStrokeRec::kStroke_Style == style) ? |
| 933 | DIEllipseStyle::kStroke : |
| 934 | (SkStrokeRec::kHairline_Style == style) ? |
| 935 | DIEllipseStyle::kHairline : DIEllipseStyle::kFill; |
| 936 | |
| 937 | SkScalar innerXRadius = 0; |
| 938 | SkScalar innerYRadius = 0; |
| 939 | if (SkStrokeRec::kFill_Style != style && SkStrokeRec::kHairline_Style != style) { |
| 940 | SkScalar strokeWidth = stroke.getWidth(); |
| 941 | |
| 942 | if (SkScalarNearlyZero(strokeWidth)) { |
| 943 | strokeWidth = SK_ScalarHalf; |
| 944 | } else { |
| 945 | strokeWidth *= SK_ScalarHalf; |
| 946 | } |
| 947 | |
| 948 | // we only handle thick strokes for near-circular ellipses |
| 949 | if (strokeWidth > SK_ScalarHalf && |
| 950 | (SK_ScalarHalf*xRadius > yRadius || SK_ScalarHalf*yRadius > xRadius)) { |
| 951 | return nullptr; |
| 952 | } |
| 953 | |
| 954 | // we don't handle it if curvature of the stroke is less than curvature of the ellipse |
| 955 | if (strokeWidth*(yRadius*yRadius) < (strokeWidth*strokeWidth)*xRadius || |
| 956 | strokeWidth*(xRadius*xRadius) < (strokeWidth*strokeWidth)*yRadius) { |
| 957 | return nullptr; |
| 958 | } |
| 959 | |
| 960 | // set inner radius (if needed) |
| 961 | if (SkStrokeRec::kStroke_Style == style) { |
| 962 | innerXRadius = xRadius - strokeWidth; |
| 963 | innerYRadius = yRadius - strokeWidth; |
| 964 | } |
| 965 | |
| 966 | xRadius += strokeWidth; |
| 967 | yRadius += strokeWidth; |
| 968 | } |
| 969 | if (DIEllipseStyle::kStroke == dieStyle) { |
| 970 | dieStyle = (innerXRadius > 0 && innerYRadius > 0) ? DIEllipseStyle ::kStroke : |
| 971 | DIEllipseStyle ::kFill; |
| 972 | } |
| 973 | |
| 974 | // This expands the outer rect so that after CTM we end up with a half-pixel border |
| 975 | SkScalar a = viewMatrix[SkMatrix::kMScaleX]; |
| 976 | SkScalar b = viewMatrix[SkMatrix::kMSkewX]; |
| 977 | SkScalar c = viewMatrix[SkMatrix::kMSkewY]; |
| 978 | SkScalar d = viewMatrix[SkMatrix::kMScaleY]; |
| 979 | SkScalar geoDx = SK_ScalarHalf / SkScalarSqrt(a*a + c*c); |
| 980 | SkScalar geoDy = SK_ScalarHalf / SkScalarSqrt(b*b + d*d); |
| 981 | |
| 982 | DIEllipseBatch* batch = new DIEllipseBatch(); |
| 983 | batch->fGeoData.emplace_back(Geometry { |
| 984 | viewMatrix, |
| 985 | color, |
| 986 | xRadius, |
| 987 | yRadius, |
| 988 | innerXRadius, |
| 989 | innerYRadius, |
| 990 | geoDx, |
| 991 | geoDy, |
| 992 | dieStyle, |
| 993 | SkRect::MakeLTRB(center.fX - xRadius - geoDx, center.fY - yRadius - geoDy, |
| 994 | center.fX + xRadius + geoDx, center.fY + yRadius + geoDy) |
| 995 | }); |
| 996 | SkRect devBounds = batch->fGeoData.back().fBounds; |
| 997 | viewMatrix.mapRect(&devBounds); |
| 998 | batch->setBounds(devBounds); |
| 999 | return batch; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1000 | } |
| 1001 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1002 | const char* name() const override { return "DIEllipseBatch"; } |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1003 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1004 | void computePipelineOptimizations(GrInitInvariantOutput* color, |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 1005 | GrInitInvariantOutput* coverage, |
| 1006 | GrBatchToXPOverrides* overrides) const override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1007 | // When this is called on a batch, there is only one geometry bundle |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 1008 | color->setKnownFourComponents(fGeoData[0].fColor); |
| 1009 | coverage->setUnknownSingleComponent(); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1010 | } |
| 1011 | |
bsalomon | e46f9fe | 2015-08-18 06:05:14 -0700 | [diff] [blame] | 1012 | private: |
| 1013 | |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 1014 | DIEllipseBatch() : INHERITED(ClassID()) {} |
| 1015 | |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 1016 | void initBatchTracker(const GrXPOverridesForBatch& overrides) override { |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1017 | // Handle any overrides that affect our GP. |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 1018 | overrides.getOverrideColorIfSet(&fGeoData[0].fColor); |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1019 | fUsesLocalCoords = overrides.readsLocalCoords(); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1020 | } |
| 1021 | |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 1022 | void onPrepareDraws(Target* target) const override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1023 | // Setup geometry processor |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1024 | SkAutoTUnref<GrGeometryProcessor> gp(new DIEllipseGeometryProcessor(this->viewMatrix(), |
| 1025 | this->style())); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1026 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1027 | int instanceCount = fGeoData.count(); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1028 | size_t vertexStride = gp->getVertexStride(); |
joshualitt | 19e0058 | 2015-02-11 17:36:30 -0800 | [diff] [blame] | 1029 | SkASSERT(vertexStride == sizeof(DIEllipseVertex)); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1030 | QuadHelper helper; |
| 1031 | DIEllipseVertex* verts = reinterpret_cast<DIEllipseVertex*>( |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 1032 | helper.init(target, vertexStride, instanceCount)); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1033 | if (!verts) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 1034 | return; |
| 1035 | } |
| 1036 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1037 | for (int i = 0; i < instanceCount; i++) { |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 1038 | const Geometry& geom = fGeoData[i]; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1039 | |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 1040 | GrColor color = geom.fColor; |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1041 | SkScalar xRadius = geom.fXRadius; |
| 1042 | SkScalar yRadius = geom.fYRadius; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1043 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1044 | const SkRect& bounds = geom.fBounds; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1045 | |
| 1046 | // This adjusts the "radius" to include the half-pixel border |
reed | 80ea19c | 2015-05-12 10:37:34 -0700 | [diff] [blame] | 1047 | SkScalar offsetDx = geom.fGeoDx / xRadius; |
| 1048 | SkScalar offsetDy = geom.fGeoDy / yRadius; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1049 | |
reed | 80ea19c | 2015-05-12 10:37:34 -0700 | [diff] [blame] | 1050 | SkScalar innerRatioX = xRadius / geom.fInnerXRadius; |
| 1051 | SkScalar innerRatioY = yRadius / geom.fInnerYRadius; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1052 | |
| 1053 | verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 1054 | verts[0].fColor = color; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1055 | verts[0].fOuterOffset = SkPoint::Make(-1.0f - offsetDx, -1.0f - offsetDy); |
| 1056 | verts[0].fInnerOffset = SkPoint::Make(-innerRatioX - offsetDx, -innerRatioY - offsetDy); |
| 1057 | |
| 1058 | verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 1059 | verts[1].fColor = color; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1060 | verts[1].fOuterOffset = SkPoint::Make(-1.0f - offsetDx, 1.0f + offsetDy); |
| 1061 | verts[1].fInnerOffset = SkPoint::Make(-innerRatioX - offsetDx, innerRatioY + offsetDy); |
| 1062 | |
| 1063 | verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 1064 | verts[2].fColor = color; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1065 | verts[2].fOuterOffset = SkPoint::Make(1.0f + offsetDx, 1.0f + offsetDy); |
| 1066 | verts[2].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, innerRatioY + offsetDy); |
| 1067 | |
| 1068 | verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 1069 | verts[3].fColor = color; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1070 | verts[3].fOuterOffset = SkPoint::Make(1.0f + offsetDx, -1.0f - offsetDy); |
| 1071 | verts[3].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, -innerRatioY - offsetDy); |
| 1072 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1073 | verts += kVerticesPerQuad; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1074 | } |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 1075 | helper.recordDraw(target, gp); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1076 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1077 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 1078 | bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 1079 | DIEllipseBatch* that = t->cast<DIEllipseBatch>(); |
| 1080 | if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), |
| 1081 | that->bounds(), caps)) { |
joshualitt | 8cab9a7 | 2015-07-16 09:13:50 -0700 | [diff] [blame] | 1082 | return false; |
| 1083 | } |
| 1084 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1085 | if (this->style() != that->style()) { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1086 | return false; |
| 1087 | } |
| 1088 | |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame] | 1089 | // TODO rewrite to allow positioning on CPU |
| 1090 | if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1091 | return false; |
| 1092 | } |
| 1093 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1094 | fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 1095 | this->joinBounds(that->bounds()); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1096 | return true; |
| 1097 | } |
| 1098 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1099 | const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1100 | DIEllipseStyle style() const { return fGeoData[0].fStyle; } |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1101 | |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 1102 | struct Geometry { |
| 1103 | SkMatrix fViewMatrix; |
| 1104 | GrColor fColor; |
| 1105 | SkScalar fXRadius; |
| 1106 | SkScalar fYRadius; |
| 1107 | SkScalar fInnerXRadius; |
| 1108 | SkScalar fInnerYRadius; |
| 1109 | SkScalar fGeoDx; |
| 1110 | SkScalar fGeoDy; |
| 1111 | DIEllipseStyle fStyle; |
| 1112 | SkRect fBounds; |
| 1113 | }; |
| 1114 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1115 | bool fUsesLocalCoords; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1116 | SkSTArray<1, Geometry, true> fGeoData; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 1117 | |
| 1118 | typedef GrVertexBatch INHERITED; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1119 | }; |
| 1120 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1121 | /////////////////////////////////////////////////////////////////////////////// |
| 1122 | |
| 1123 | static const uint16_t gRRectIndices[] = { |
| 1124 | // corners |
| 1125 | 0, 1, 5, 0, 5, 4, |
| 1126 | 2, 3, 7, 2, 7, 6, |
| 1127 | 8, 9, 13, 8, 13, 12, |
| 1128 | 10, 11, 15, 10, 15, 14, |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1129 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1130 | // edges |
| 1131 | 1, 2, 6, 1, 6, 5, |
| 1132 | 4, 5, 9, 4, 9, 8, |
| 1133 | 6, 7, 11, 6, 11, 10, |
| 1134 | 9, 10, 14, 9, 14, 13, |
skia.committer@gmail.com | 2cf444f | 2013-04-26 07:00:58 +0000 | [diff] [blame] | 1135 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1136 | // center |
| 1137 | // we place this at the end so that we can ignore these indices when rendering stroke-only |
| 1138 | 5, 6, 10, 5, 10, 9 |
| 1139 | }; |
| 1140 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 1141 | static const int kIndicesPerStrokeRRect = SK_ARRAY_COUNT(gRRectIndices) - 6; |
| 1142 | static const int kIndicesPerRRect = SK_ARRAY_COUNT(gRRectIndices); |
| 1143 | static const int kVertsPerRRect = 16; |
| 1144 | static const int kNumRRectsInIndexBuffer = 256; |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1145 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 1146 | GR_DECLARE_STATIC_UNIQUE_KEY(gStrokeRRectOnlyIndexBufferKey); |
| 1147 | GR_DECLARE_STATIC_UNIQUE_KEY(gRRectOnlyIndexBufferKey); |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 1148 | static const GrBuffer* ref_rrect_index_buffer(bool strokeOnly, |
| 1149 | GrResourceProvider* resourceProvider) { |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 1150 | GR_DEFINE_STATIC_UNIQUE_KEY(gStrokeRRectOnlyIndexBufferKey); |
| 1151 | GR_DEFINE_STATIC_UNIQUE_KEY(gRRectOnlyIndexBufferKey); |
| 1152 | if (strokeOnly) { |
bsalomon | eae6200 | 2015-07-31 13:59:30 -0700 | [diff] [blame] | 1153 | return resourceProvider->findOrCreateInstancedIndexBuffer( |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 1154 | gRRectIndices, kIndicesPerStrokeRRect, kNumRRectsInIndexBuffer, kVertsPerRRect, |
| 1155 | gStrokeRRectOnlyIndexBufferKey); |
| 1156 | } else { |
bsalomon | eae6200 | 2015-07-31 13:59:30 -0700 | [diff] [blame] | 1157 | return resourceProvider->findOrCreateInstancedIndexBuffer( |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 1158 | gRRectIndices, kIndicesPerRRect, kNumRRectsInIndexBuffer, kVertsPerRRect, |
| 1159 | gRRectOnlyIndexBufferKey); |
| 1160 | |
| 1161 | } |
| 1162 | } |
| 1163 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1164 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1165 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 1166 | class RRectCircleRendererBatch : public GrVertexBatch { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1167 | public: |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 1168 | DEFINE_BATCH_CLASS_ID |
| 1169 | |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 1170 | // A devStrokeWidth <= 0 indicates a fill only. If devStrokeWidth > 0 then strokeOnly indicates |
| 1171 | // whether the rrect is only stroked or stroked and filled. |
| 1172 | RRectCircleRendererBatch(GrColor color, const SkMatrix& viewMatrix, const SkRect& devRect, |
| 1173 | float devRadius, float devStrokeWidth, bool strokeOnly) |
| 1174 | : INHERITED(ClassID()) |
| 1175 | , fViewMatrixIfUsingLocalCoords(viewMatrix) { |
| 1176 | SkRect bounds = devRect; |
| 1177 | SkASSERT(!(devStrokeWidth <= 0 && strokeOnly)); |
| 1178 | SkScalar innerRadius = 0.0f; |
| 1179 | SkScalar outerRadius = devRadius; |
| 1180 | SkScalar halfWidth = 0; |
| 1181 | fStroked = false; |
| 1182 | if (devStrokeWidth > 0) { |
| 1183 | if (SkScalarNearlyZero(devStrokeWidth)) { |
| 1184 | halfWidth = SK_ScalarHalf; |
| 1185 | } else { |
| 1186 | halfWidth = SkScalarHalf(devStrokeWidth); |
| 1187 | } |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1188 | |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 1189 | if (strokeOnly) { |
| 1190 | innerRadius = devRadius - halfWidth; |
| 1191 | fStroked = innerRadius >= 0; |
| 1192 | } |
| 1193 | outerRadius += halfWidth; |
| 1194 | bounds.outset(halfWidth, halfWidth); |
| 1195 | } |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1196 | |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 1197 | // The radii are outset for two reasons. First, it allows the shader to simply perform |
| 1198 | // simpler computation because the computed alpha is zero, rather than 50%, at the radius. |
| 1199 | // Second, the outer radius is used to compute the verts of the bounding box that is |
| 1200 | // rendered and the outset ensures the box will cover all partially covered by the rrect |
| 1201 | // corners. |
| 1202 | outerRadius += SK_ScalarHalf; |
| 1203 | innerRadius -= SK_ScalarHalf; |
| 1204 | |
| 1205 | // Expand the rect so all the pixels will be captured. |
| 1206 | bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
| 1207 | |
| 1208 | fGeoData.emplace_back(Geometry { color, innerRadius, outerRadius, bounds }); |
| 1209 | this->setBounds(bounds); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1210 | } |
| 1211 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1212 | const char* name() const override { return "RRectCircleBatch"; } |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1213 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1214 | void computePipelineOptimizations(GrInitInvariantOutput* color, |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 1215 | GrInitInvariantOutput* coverage, |
| 1216 | GrBatchToXPOverrides* overrides) const override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1217 | // When this is called on a batch, there is only one geometry bundle |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 1218 | color->setKnownFourComponents(fGeoData[0].fColor); |
| 1219 | coverage->setUnknownSingleComponent(); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1220 | } |
| 1221 | |
bsalomon | e46f9fe | 2015-08-18 06:05:14 -0700 | [diff] [blame] | 1222 | private: |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 1223 | void initBatchTracker(const GrXPOverridesForBatch& overrides) override { |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1224 | // Handle any overrides that affect our GP. |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 1225 | overrides.getOverrideColorIfSet(&fGeoData[0].fColor); |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1226 | if (!overrides.readsLocalCoords()) { |
| 1227 | fViewMatrixIfUsingLocalCoords.reset(); |
| 1228 | } |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1229 | } |
| 1230 | |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 1231 | void onPrepareDraws(Target* target) const override { |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1232 | // Invert the view matrix as a local matrix (if any other processors require coords). |
| 1233 | SkMatrix localMatrix; |
| 1234 | if (!fViewMatrixIfUsingLocalCoords.invert(&localMatrix)) { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1235 | return; |
| 1236 | } |
| 1237 | |
| 1238 | // Setup geometry processor |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1239 | SkAutoTUnref<GrGeometryProcessor> gp(new CircleGeometryProcessor(fStroked, localMatrix)); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1240 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1241 | int instanceCount = fGeoData.count(); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1242 | size_t vertexStride = gp->getVertexStride(); |
| 1243 | SkASSERT(vertexStride == sizeof(CircleVertex)); |
| 1244 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1245 | // drop out the middle quad if we're stroked |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1246 | int indicesPerInstance = fStroked ? kIndicesPerStrokeRRect : kIndicesPerRRect; |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 1247 | SkAutoTUnref<const GrBuffer> indexBuffer( |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1248 | ref_rrect_index_buffer(fStroked, target->resourceProvider())); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1249 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1250 | InstancedHelper helper; |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 1251 | CircleVertex* verts = reinterpret_cast<CircleVertex*>(helper.init(target, |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1252 | kTriangles_GrPrimitiveType, vertexStride, indexBuffer, kVertsPerRRect, |
| 1253 | indicesPerInstance, instanceCount)); |
| 1254 | if (!verts || !indexBuffer) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 1255 | SkDebugf("Could not allocate vertices\n"); |
| 1256 | return; |
| 1257 | } |
| 1258 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1259 | for (int i = 0; i < instanceCount; i++) { |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 1260 | const Geometry& args = fGeoData[i]; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1261 | |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 1262 | GrColor color = args.fColor; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1263 | SkScalar outerRadius = args.fOuterRadius; |
| 1264 | |
egdaniel | bc22714 | 2015-04-21 06:28:08 -0700 | [diff] [blame] | 1265 | const SkRect& bounds = args.fDevBounds; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1266 | |
| 1267 | SkScalar yCoords[4] = { |
| 1268 | bounds.fTop, |
| 1269 | bounds.fTop + outerRadius, |
| 1270 | bounds.fBottom - outerRadius, |
| 1271 | bounds.fBottom |
| 1272 | }; |
| 1273 | |
| 1274 | SkScalar yOuterRadii[4] = {-1, 0, 0, 1 }; |
| 1275 | // The inner radius in the vertex data must be specified in normalized space. |
| 1276 | SkScalar innerRadius = args.fInnerRadius / args.fOuterRadius; |
| 1277 | for (int i = 0; i < 4; ++i) { |
| 1278 | verts->fPos = SkPoint::Make(bounds.fLeft, yCoords[i]); |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 1279 | verts->fColor = color; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1280 | verts->fOffset = SkPoint::Make(-1, yOuterRadii[i]); |
| 1281 | verts->fOuterRadius = outerRadius; |
| 1282 | verts->fInnerRadius = innerRadius; |
| 1283 | verts++; |
| 1284 | |
| 1285 | verts->fPos = SkPoint::Make(bounds.fLeft + outerRadius, yCoords[i]); |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 1286 | verts->fColor = color; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1287 | verts->fOffset = SkPoint::Make(0, yOuterRadii[i]); |
| 1288 | verts->fOuterRadius = outerRadius; |
| 1289 | verts->fInnerRadius = innerRadius; |
| 1290 | verts++; |
| 1291 | |
| 1292 | verts->fPos = SkPoint::Make(bounds.fRight - outerRadius, yCoords[i]); |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 1293 | verts->fColor = color; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1294 | verts->fOffset = SkPoint::Make(0, yOuterRadii[i]); |
| 1295 | verts->fOuterRadius = outerRadius; |
| 1296 | verts->fInnerRadius = innerRadius; |
| 1297 | verts++; |
| 1298 | |
| 1299 | verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]); |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 1300 | verts->fColor = color; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1301 | verts->fOffset = SkPoint::Make(1, yOuterRadii[i]); |
| 1302 | verts->fOuterRadius = outerRadius; |
| 1303 | verts->fInnerRadius = innerRadius; |
| 1304 | verts++; |
| 1305 | } |
| 1306 | } |
| 1307 | |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 1308 | helper.recordDraw(target, gp); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1309 | } |
| 1310 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 1311 | bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 1312 | RRectCircleRendererBatch* that = t->cast<RRectCircleRendererBatch>(); |
| 1313 | if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), |
| 1314 | that->bounds(), caps)) { |
joshualitt | 8cab9a7 | 2015-07-16 09:13:50 -0700 | [diff] [blame] | 1315 | return false; |
| 1316 | } |
| 1317 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1318 | if (fStroked != that->fStroked) { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1319 | return false; |
| 1320 | } |
| 1321 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1322 | if (!fViewMatrixIfUsingLocalCoords.cheapEqualTo(that->fViewMatrixIfUsingLocalCoords)) { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1323 | return false; |
| 1324 | } |
| 1325 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1326 | fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 1327 | this->joinBounds(that->bounds()); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1328 | return true; |
| 1329 | } |
| 1330 | |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 1331 | struct Geometry { |
| 1332 | GrColor fColor; |
| 1333 | SkScalar fInnerRadius; |
| 1334 | SkScalar fOuterRadius; |
| 1335 | SkRect fDevBounds; |
| 1336 | }; |
| 1337 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1338 | bool fStroked; |
| 1339 | SkMatrix fViewMatrixIfUsingLocalCoords; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1340 | SkSTArray<1, Geometry, true> fGeoData; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 1341 | |
| 1342 | typedef GrVertexBatch INHERITED; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1343 | }; |
| 1344 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 1345 | class RRectEllipseRendererBatch : public GrVertexBatch { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1346 | public: |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 1347 | DEFINE_BATCH_CLASS_ID |
| 1348 | |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 1349 | // If devStrokeWidths values are <= 0 indicates then fill only. Otherwise, strokeOnly indicates |
| 1350 | // whether the rrect is only stroked or stroked and filled. |
| 1351 | static GrDrawBatch* Create(GrColor color, const SkMatrix& viewMatrix, const SkRect& devRect, |
| 1352 | float devXRadius, float devYRadius, SkVector devStrokeWidths, |
| 1353 | bool strokeOnly) { |
| 1354 | SkASSERT(devXRadius > 0.5); |
| 1355 | SkASSERT(devYRadius > 0.5); |
| 1356 | SkASSERT((devStrokeWidths.fX > 0) == (devStrokeWidths.fY > 0)); |
| 1357 | SkASSERT(!(strokeOnly && devStrokeWidths.fX <= 0)); |
| 1358 | SkScalar innerXRadius = 0.0f; |
| 1359 | SkScalar innerYRadius = 0.0f; |
| 1360 | SkRect bounds = devRect; |
| 1361 | bool stroked = false; |
| 1362 | if (devStrokeWidths.fX > 0) { |
| 1363 | if (SkScalarNearlyZero(devStrokeWidths.length())) { |
| 1364 | devStrokeWidths.set(SK_ScalarHalf, SK_ScalarHalf); |
| 1365 | } else { |
| 1366 | devStrokeWidths.scale(SK_ScalarHalf); |
| 1367 | } |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1368 | |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 1369 | // we only handle thick strokes for near-circular ellipses |
| 1370 | if (devStrokeWidths.length() > SK_ScalarHalf && |
| 1371 | (SK_ScalarHalf*devXRadius > devYRadius || SK_ScalarHalf*devYRadius > devXRadius)) { |
| 1372 | return nullptr; |
| 1373 | } |
| 1374 | |
| 1375 | // we don't handle it if curvature of the stroke is less than curvature of the ellipse |
| 1376 | if (devStrokeWidths.fX*(devYRadius*devYRadius) < |
| 1377 | (devStrokeWidths.fY*devStrokeWidths.fY)*devXRadius) { |
| 1378 | return nullptr; |
| 1379 | } |
| 1380 | if (devStrokeWidths.fY*(devXRadius*devXRadius) < |
| 1381 | (devStrokeWidths.fX*devStrokeWidths.fX)*devYRadius) { |
| 1382 | return nullptr; |
| 1383 | } |
| 1384 | |
| 1385 | // this is legit only if scale & translation (which should be the case at the moment) |
| 1386 | if (strokeOnly) { |
| 1387 | innerXRadius = devXRadius - devStrokeWidths.fX; |
| 1388 | innerYRadius = devYRadius - devStrokeWidths.fY; |
| 1389 | stroked = (innerXRadius >= 0 && innerYRadius >= 0); |
| 1390 | } |
| 1391 | |
| 1392 | devXRadius += devStrokeWidths.fX; |
| 1393 | devYRadius += devStrokeWidths.fY; |
| 1394 | bounds.outset(devStrokeWidths.fX, devStrokeWidths.fY); |
| 1395 | } |
| 1396 | |
| 1397 | // Expand the rect so all the pixels will be captured. |
| 1398 | bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
| 1399 | |
| 1400 | RRectEllipseRendererBatch* batch = new RRectEllipseRendererBatch(); |
| 1401 | batch->fStroked = stroked; |
| 1402 | batch->fViewMatrixIfUsingLocalCoords = viewMatrix; |
| 1403 | batch->fGeoData.emplace_back( |
| 1404 | Geometry {color, devXRadius, devYRadius, innerXRadius, innerYRadius, bounds}); |
| 1405 | batch->setBounds(bounds); |
| 1406 | return batch; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1407 | } |
| 1408 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1409 | const char* name() const override { return "RRectEllipseRendererBatch"; } |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1410 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1411 | void computePipelineOptimizations(GrInitInvariantOutput* color, |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 1412 | GrInitInvariantOutput* coverage, |
| 1413 | GrBatchToXPOverrides* overrides) const override { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1414 | // When this is called on a batch, there is only one geometry bundle |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 1415 | color->setKnownFourComponents(fGeoData[0].fColor); |
| 1416 | coverage->setUnknownSingleComponent(); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1417 | } |
| 1418 | |
bsalomon | e46f9fe | 2015-08-18 06:05:14 -0700 | [diff] [blame] | 1419 | private: |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 1420 | RRectEllipseRendererBatch() : INHERITED(ClassID()) {} |
| 1421 | |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 1422 | void initBatchTracker(const GrXPOverridesForBatch& overrides) override { |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1423 | // Handle overrides that affect our GP. |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 1424 | overrides.getOverrideColorIfSet(&fGeoData[0].fColor); |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1425 | if (!overrides.readsLocalCoords()) { |
| 1426 | fViewMatrixIfUsingLocalCoords.reset(); |
| 1427 | } |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1428 | } |
| 1429 | |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 1430 | void onPrepareDraws(Target* target) const override { |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1431 | SkMatrix localMatrix; |
| 1432 | if (!fViewMatrixIfUsingLocalCoords.invert(&localMatrix)) { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1433 | return; |
| 1434 | } |
| 1435 | |
| 1436 | // Setup geometry processor |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1437 | SkAutoTUnref<GrGeometryProcessor> gp(new EllipseGeometryProcessor(fStroked, localMatrix)); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1438 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1439 | int instanceCount = fGeoData.count(); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1440 | size_t vertexStride = gp->getVertexStride(); |
| 1441 | SkASSERT(vertexStride == sizeof(EllipseVertex)); |
| 1442 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1443 | // drop out the middle quad if we're stroked |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1444 | int indicesPerInstance = fStroked ? kIndicesPerStrokeRRect : kIndicesPerRRect; |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 1445 | SkAutoTUnref<const GrBuffer> indexBuffer( |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1446 | ref_rrect_index_buffer(fStroked, target->resourceProvider())); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1447 | |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1448 | InstancedHelper helper; |
| 1449 | EllipseVertex* verts = reinterpret_cast<EllipseVertex*>( |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 1450 | helper.init(target, kTriangles_GrPrimitiveType, vertexStride, indexBuffer, |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 1451 | kVertsPerRRect, indicesPerInstance, instanceCount)); |
| 1452 | if (!verts || !indexBuffer) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 1453 | SkDebugf("Could not allocate vertices\n"); |
| 1454 | return; |
| 1455 | } |
| 1456 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1457 | for (int i = 0; i < instanceCount; i++) { |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 1458 | const Geometry& args = fGeoData[i]; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1459 | |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 1460 | GrColor color = args.fColor; |
| 1461 | |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1462 | // Compute the reciprocals of the radii here to save time in the shader |
| 1463 | SkScalar xRadRecip = SkScalarInvert(args.fXRadius); |
| 1464 | SkScalar yRadRecip = SkScalarInvert(args.fYRadius); |
| 1465 | SkScalar xInnerRadRecip = SkScalarInvert(args.fInnerXRadius); |
| 1466 | SkScalar yInnerRadRecip = SkScalarInvert(args.fInnerYRadius); |
| 1467 | |
| 1468 | // Extend the radii out half a pixel to antialias. |
| 1469 | SkScalar xOuterRadius = args.fXRadius + SK_ScalarHalf; |
| 1470 | SkScalar yOuterRadius = args.fYRadius + SK_ScalarHalf; |
| 1471 | |
egdaniel | bc22714 | 2015-04-21 06:28:08 -0700 | [diff] [blame] | 1472 | const SkRect& bounds = args.fDevBounds; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1473 | |
| 1474 | SkScalar yCoords[4] = { |
| 1475 | bounds.fTop, |
| 1476 | bounds.fTop + yOuterRadius, |
| 1477 | bounds.fBottom - yOuterRadius, |
| 1478 | bounds.fBottom |
| 1479 | }; |
| 1480 | SkScalar yOuterOffsets[4] = { |
| 1481 | yOuterRadius, |
| 1482 | SK_ScalarNearlyZero, // we're using inversesqrt() in shader, so can't be exactly 0 |
| 1483 | SK_ScalarNearlyZero, |
| 1484 | yOuterRadius |
| 1485 | }; |
| 1486 | |
| 1487 | for (int i = 0; i < 4; ++i) { |
| 1488 | verts->fPos = SkPoint::Make(bounds.fLeft, yCoords[i]); |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 1489 | verts->fColor = color; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1490 | verts->fOffset = SkPoint::Make(xOuterRadius, yOuterOffsets[i]); |
| 1491 | verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 1492 | verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
| 1493 | verts++; |
| 1494 | |
| 1495 | verts->fPos = SkPoint::Make(bounds.fLeft + xOuterRadius, yCoords[i]); |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 1496 | verts->fColor = color; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1497 | verts->fOffset = SkPoint::Make(SK_ScalarNearlyZero, yOuterOffsets[i]); |
| 1498 | verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 1499 | verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
| 1500 | verts++; |
| 1501 | |
| 1502 | verts->fPos = SkPoint::Make(bounds.fRight - xOuterRadius, yCoords[i]); |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 1503 | verts->fColor = color; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1504 | verts->fOffset = SkPoint::Make(SK_ScalarNearlyZero, yOuterOffsets[i]); |
| 1505 | verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 1506 | verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
| 1507 | verts++; |
| 1508 | |
| 1509 | verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]); |
brianosman | bb2ff94 | 2016-02-11 14:15:18 -0800 | [diff] [blame] | 1510 | verts->fColor = color; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1511 | verts->fOffset = SkPoint::Make(xOuterRadius, yOuterOffsets[i]); |
| 1512 | verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 1513 | verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
| 1514 | verts++; |
| 1515 | } |
| 1516 | } |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 1517 | helper.recordDraw(target, gp); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1518 | } |
| 1519 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 1520 | bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 1521 | RRectEllipseRendererBatch* that = t->cast<RRectEllipseRendererBatch>(); |
| 1522 | |
| 1523 | if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), |
| 1524 | that->bounds(), caps)) { |
joshualitt | 8cab9a7 | 2015-07-16 09:13:50 -0700 | [diff] [blame] | 1525 | return false; |
| 1526 | } |
| 1527 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1528 | if (fStroked != that->fStroked) { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1529 | return false; |
| 1530 | } |
| 1531 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1532 | if (!fViewMatrixIfUsingLocalCoords.cheapEqualTo(that->fViewMatrixIfUsingLocalCoords)) { |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1533 | return false; |
| 1534 | } |
| 1535 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1536 | fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 1537 | this->joinBounds(that->bounds()); |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1538 | return true; |
| 1539 | } |
| 1540 | |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 1541 | struct Geometry { |
| 1542 | GrColor fColor; |
| 1543 | SkScalar fXRadius; |
| 1544 | SkScalar fYRadius; |
| 1545 | SkScalar fInnerXRadius; |
| 1546 | SkScalar fInnerYRadius; |
| 1547 | SkRect fDevBounds; |
| 1548 | }; |
| 1549 | |
bsalomon | cdaa97b | 2016-03-08 08:30:14 -0800 | [diff] [blame] | 1550 | bool fStroked; |
| 1551 | SkMatrix fViewMatrixIfUsingLocalCoords; |
| 1552 | SkSTArray<1, Geometry, true> fGeoData; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 1553 | |
| 1554 | typedef GrVertexBatch INHERITED; |
joshualitt | 76e7fb6 | 2015-02-11 08:52:27 -0800 | [diff] [blame] | 1555 | }; |
| 1556 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 1557 | static GrDrawBatch* create_rrect_batch(GrColor color, |
| 1558 | const SkMatrix& viewMatrix, |
| 1559 | const SkRRect& rrect, |
| 1560 | const SkStrokeRec& stroke) { |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1561 | SkASSERT(viewMatrix.rectStaysRect()); |
| 1562 | SkASSERT(rrect.isSimple()); |
| 1563 | SkASSERT(!rrect.isOval()); |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 1564 | |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1565 | // RRect batchs only handle simple, but not too simple, rrects |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1566 | // do any matrix crunching before we reset the draw state for device coords |
| 1567 | const SkRect& rrectBounds = rrect.getBounds(); |
joshualitt | d96a67b | 2015-05-05 14:09:05 -0700 | [diff] [blame] | 1568 | SkRect bounds; |
| 1569 | viewMatrix.mapRect(&bounds, rrectBounds); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1570 | |
| 1571 | SkVector radii = rrect.getSimpleRadii(); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 1572 | SkScalar xRadius = SkScalarAbs(viewMatrix[SkMatrix::kMScaleX]*radii.fX + |
| 1573 | viewMatrix[SkMatrix::kMSkewY]*radii.fY); |
| 1574 | SkScalar yRadius = SkScalarAbs(viewMatrix[SkMatrix::kMSkewX]*radii.fX + |
| 1575 | viewMatrix[SkMatrix::kMScaleY]*radii.fY); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1576 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1577 | SkStrokeRec::Style style = stroke.getStyle(); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1578 | |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 1579 | // Do (potentially) anisotropic mapping of stroke. Use -1s to indicate fill-only draws. |
| 1580 | SkVector scaledStroke = {-1, -1}; |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1581 | SkScalar strokeWidth = stroke.getWidth(); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1582 | |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1583 | bool isStrokeOnly = SkStrokeRec::kStroke_Style == style || |
| 1584 | SkStrokeRec::kHairline_Style == style; |
| 1585 | bool hasStroke = isStrokeOnly || SkStrokeRec::kStrokeAndFill_Style == style; |
| 1586 | |
| 1587 | if (hasStroke) { |
| 1588 | if (SkStrokeRec::kHairline_Style == style) { |
| 1589 | scaledStroke.set(1, 1); |
| 1590 | } else { |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 1591 | scaledStroke.fX = SkScalarAbs(strokeWidth*(viewMatrix[SkMatrix::kMScaleX] + |
| 1592 | viewMatrix[SkMatrix::kMSkewY])); |
| 1593 | scaledStroke.fY = SkScalarAbs(strokeWidth*(viewMatrix[SkMatrix::kMSkewX] + |
| 1594 | viewMatrix[SkMatrix::kMScaleY])); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1595 | } |
| 1596 | |
| 1597 | // if half of strokewidth is greater than radius, we don't handle that right now |
| 1598 | if (SK_ScalarHalf*scaledStroke.fX > xRadius || SK_ScalarHalf*scaledStroke.fY > yRadius) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1599 | return nullptr; |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1600 | } |
| 1601 | } |
| 1602 | |
| 1603 | // The way the effect interpolates the offset-to-ellipse/circle-center attribute only works on |
| 1604 | // the interior of the rrect if the radii are >= 0.5. Otherwise, the inner rect of the nine- |
| 1605 | // patch will have fractional coverage. This only matters when the interior is actually filled. |
| 1606 | // We could consider falling back to rect rendering here, since a tiny radius is |
| 1607 | // indistinguishable from a square corner. |
| 1608 | if (!isStrokeOnly && (SK_ScalarHalf > xRadius || SK_ScalarHalf > yRadius)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1609 | return nullptr; |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1610 | } |
| 1611 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1612 | // if the corners are circles, use the circle renderer |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1613 | if ((!hasStroke || scaledStroke.fX == scaledStroke.fY) && xRadius == yRadius) { |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 1614 | return new RRectCircleRendererBatch(color, viewMatrix, bounds, xRadius, scaledStroke.fX, |
| 1615 | isStrokeOnly); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1616 | // otherwise we use the ellipse renderer |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1617 | } else { |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 1618 | return RRectEllipseRendererBatch::Create(color, viewMatrix, bounds, xRadius, yRadius, |
| 1619 | scaledStroke, isStrokeOnly); |
commit-bot@chromium.org | 6bb3efc | 2013-05-16 13:14:46 +0000 | [diff] [blame] | 1620 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1621 | } |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1622 | } |
| 1623 | |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 1624 | GrDrawBatch* GrOvalRenderer::CreateRRectBatch(GrColor color, |
robertphillips | 0cc2f85 | 2016-02-24 13:36:56 -0800 | [diff] [blame] | 1625 | const SkMatrix& viewMatrix, |
robertphillips | 0cc2f85 | 2016-02-24 13:36:56 -0800 | [diff] [blame] | 1626 | const SkRRect& rrect, |
| 1627 | const SkStrokeRec& stroke, |
| 1628 | GrShaderCaps* shaderCaps) { |
robertphillips | 0cc2f85 | 2016-02-24 13:36:56 -0800 | [diff] [blame] | 1629 | if (rrect.isOval()) { |
robertphillips | b56f927 | 2016-02-25 11:03:52 -0800 | [diff] [blame] | 1630 | return CreateOvalBatch(color, viewMatrix, rrect.getBounds(), stroke, shaderCaps); |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1631 | } |
| 1632 | |
| 1633 | if (!viewMatrix.rectStaysRect() || !rrect.isSimple()) { |
robertphillips | 0cc2f85 | 2016-02-24 13:36:56 -0800 | [diff] [blame] | 1634 | return nullptr; |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1635 | } |
| 1636 | |
robertphillips | 0cc2f85 | 2016-02-24 13:36:56 -0800 | [diff] [blame] | 1637 | return create_rrect_batch(color, viewMatrix, rrect, stroke); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1638 | } |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1639 | |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 1640 | /////////////////////////////////////////////////////////////////////////////// |
| 1641 | |
| 1642 | GrDrawBatch* GrOvalRenderer::CreateOvalBatch(GrColor color, |
| 1643 | const SkMatrix& viewMatrix, |
| 1644 | const SkRect& oval, |
| 1645 | const SkStrokeRec& stroke, |
| 1646 | GrShaderCaps* shaderCaps) { |
| 1647 | // we can draw circles |
| 1648 | if (SkScalarNearlyEqual(oval.width(), oval.height()) && circle_stays_circle(viewMatrix)) { |
| 1649 | return new CircleBatch(color, viewMatrix, oval, stroke); |
| 1650 | } |
| 1651 | |
| 1652 | // if we have shader derivative support, render as device-independent |
| 1653 | if (shaderCaps->shaderDerivativeSupport()) { |
| 1654 | return DIEllipseBatch::Create(color, viewMatrix, oval, stroke); |
| 1655 | } |
| 1656 | |
| 1657 | // otherwise axis-aligned ellipses only |
| 1658 | if (viewMatrix.rectStaysRect()) { |
| 1659 | return EllipseBatch::Create(color, viewMatrix, oval, stroke); |
| 1660 | } |
| 1661 | |
| 1662 | return nullptr; |
| 1663 | } |
| 1664 | |
| 1665 | /////////////////////////////////////////////////////////////////////////////// |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1666 | |
| 1667 | #ifdef GR_TEST_UTILS |
| 1668 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 1669 | DRAW_BATCH_TEST_DEFINE(CircleBatch) { |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1670 | SkMatrix viewMatrix = GrTest::TestMatrix(random); |
| 1671 | GrColor color = GrRandomColor(random); |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 1672 | SkRect circle = GrTest::TestSquare(random); |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 1673 | return new CircleBatch(color, viewMatrix, circle, GrTest::TestStrokeRec(random)); |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1674 | } |
| 1675 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 1676 | DRAW_BATCH_TEST_DEFINE(EllipseBatch) { |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1677 | SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); |
| 1678 | GrColor color = GrRandomColor(random); |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 1679 | SkRect ellipse = GrTest::TestSquare(random); |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 1680 | return EllipseBatch::Create(color, viewMatrix, ellipse, GrTest::TestStrokeRec(random)); |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1681 | } |
| 1682 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 1683 | DRAW_BATCH_TEST_DEFINE(DIEllipseBatch) { |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1684 | SkMatrix viewMatrix = GrTest::TestMatrix(random); |
| 1685 | GrColor color = GrRandomColor(random); |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 1686 | SkRect ellipse = GrTest::TestSquare(random); |
bsalomon | 4b4a7cc | 2016-07-08 04:42:54 -0700 | [diff] [blame^] | 1687 | return DIEllipseBatch::Create(color, viewMatrix, ellipse, GrTest::TestStrokeRec(random)); |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1688 | } |
| 1689 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 1690 | DRAW_BATCH_TEST_DEFINE(RRectBatch) { |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1691 | SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); |
| 1692 | GrColor color = GrRandomColor(random); |
| 1693 | const SkRRect& rrect = GrTest::TestRRectSimple(random); |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 1694 | return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(random)); |
joshualitt | 3e708c5 | 2015-04-30 13:49:27 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | #endif |