ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 "GrMSAAPathRenderer.h" |
| 9 | |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 10 | #include "GrAuditTrail.h" |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 11 | #include "GrClip.h" |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 12 | #include "GrDefaultGeoProcFactory.h" |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 13 | #include "GrFixedClip.h" |
Brian Salomon | dad2923 | 2016-12-01 16:40:24 -0500 | [diff] [blame] | 14 | #include "GrMesh.h" |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 15 | #include "GrOpFlushState.h" |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 16 | #include "GrPathStencilSettings.h" |
| 17 | #include "GrPathUtils.h" |
bsalomon | bb24383 | 2016-07-22 07:10:19 -0700 | [diff] [blame] | 18 | #include "GrPipelineBuilder.h" |
Hal Canary | 95e3c05 | 2017-01-11 12:44:43 -0500 | [diff] [blame] | 19 | #include "SkAutoMalloc.h" |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 20 | #include "SkGeometry.h" |
| 21 | #include "SkTraceEvent.h" |
Brian Salomon | dad2923 | 2016-12-01 16:40:24 -0500 | [diff] [blame] | 22 | #include "gl/GrGLVaryingHandler.h" |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 23 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
Brian Salomon | dad2923 | 2016-12-01 16:40:24 -0500 | [diff] [blame] | 24 | #include "glsl/GrGLSLGeometryProcessor.h" |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 25 | #include "glsl/GrGLSLProgramDataManager.h" |
| 26 | #include "glsl/GrGLSLUtil.h" |
Brian Salomon | dad2923 | 2016-12-01 16:40:24 -0500 | [diff] [blame] | 27 | #include "glsl/GrGLSLVertexShaderBuilder.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 28 | #include "ops/GrMeshDrawOp.h" |
| 29 | #include "ops/GrRectOpFactory.h" |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 30 | |
| 31 | static const float kTolerance = 0.5f; |
| 32 | |
| 33 | //////////////////////////////////////////////////////////////////////////////// |
| 34 | // Helpers for drawPath |
| 35 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 36 | static inline bool single_pass_shape(const GrShape& shape) { |
| 37 | if (!shape.inverseFilled()) { |
| 38 | return shape.knownToBeConvex(); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 39 | } |
| 40 | return false; |
| 41 | } |
| 42 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 43 | GrPathRenderer::StencilSupport GrMSAAPathRenderer::onGetStencilSupport(const GrShape& shape) const { |
| 44 | if (single_pass_shape(shape)) { |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 45 | return GrPathRenderer::kNoRestriction_StencilSupport; |
| 46 | } else { |
| 47 | return GrPathRenderer::kStencilOnly_StencilSupport; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | struct MSAALineVertices { |
| 52 | struct Vertex { |
| 53 | SkPoint fPosition; |
| 54 | SkColor fColor; |
| 55 | }; |
| 56 | Vertex* vertices; |
| 57 | Vertex* nextVertex; |
| 58 | #ifdef SK_DEBUG |
| 59 | Vertex* verticesEnd; |
| 60 | #endif |
| 61 | uint16_t* indices; |
| 62 | uint16_t* nextIndex; |
| 63 | }; |
| 64 | |
| 65 | struct MSAAQuadVertices { |
| 66 | struct Vertex { |
| 67 | SkPoint fPosition; |
| 68 | SkPoint fUV; |
| 69 | SkColor fColor; |
| 70 | }; |
| 71 | Vertex* vertices; |
| 72 | Vertex* nextVertex; |
| 73 | #ifdef SK_DEBUG |
| 74 | Vertex* verticesEnd; |
| 75 | #endif |
| 76 | uint16_t* indices; |
| 77 | uint16_t* nextIndex; |
| 78 | }; |
| 79 | |
| 80 | static inline void append_contour_edge_indices(uint16_t fanCenterIdx, |
| 81 | uint16_t edgeV0Idx, |
| 82 | MSAALineVertices& lines) { |
| 83 | *(lines.nextIndex++) = fanCenterIdx; |
| 84 | *(lines.nextIndex++) = edgeV0Idx; |
| 85 | *(lines.nextIndex++) = edgeV0Idx + 1; |
| 86 | } |
| 87 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 88 | static inline void add_quad(MSAALineVertices& lines, MSAAQuadVertices& quads, const SkPoint pts[], |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 89 | SkColor color, bool indexed, uint16_t subpathLineIdxStart) { |
| 90 | SkASSERT(lines.nextVertex < lines.verticesEnd); |
| 91 | *lines.nextVertex = { pts[2], color }; |
| 92 | if (indexed) { |
| 93 | int prevIdx = (uint16_t) (lines.nextVertex - lines.vertices - 1); |
| 94 | if (prevIdx > subpathLineIdxStart) { |
| 95 | append_contour_edge_indices(subpathLineIdxStart, prevIdx, lines); |
| 96 | } |
| 97 | } |
| 98 | lines.nextVertex++; |
| 99 | |
| 100 | SkASSERT(quads.nextVertex + 2 < quads.verticesEnd); |
| 101 | // the texture coordinates are drawn from the Loop-Blinn rendering algorithm |
| 102 | *(quads.nextVertex++) = { pts[0], SkPoint::Make(0.0, 0.0), color }; |
| 103 | *(quads.nextVertex++) = { pts[1], SkPoint::Make(0.5, 0.0), color }; |
| 104 | *(quads.nextVertex++) = { pts[2], SkPoint::Make(1.0, 1.0), color }; |
| 105 | if (indexed) { |
| 106 | uint16_t offset = (uint16_t) (quads.nextVertex - quads.vertices) - 3; |
| 107 | *(quads.nextIndex++) = offset++; |
| 108 | *(quads.nextIndex++) = offset++; |
| 109 | *(quads.nextIndex++) = offset++; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | class MSAAQuadProcessor : public GrGeometryProcessor { |
| 114 | public: |
| 115 | static GrGeometryProcessor* Create(const SkMatrix& viewMatrix) { |
| 116 | return new MSAAQuadProcessor(viewMatrix); |
| 117 | } |
| 118 | |
Brian Salomon | d3b6597 | 2017-03-22 12:05:03 -0400 | [diff] [blame] | 119 | ~MSAAQuadProcessor() override {} |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 120 | |
| 121 | const char* name() const override { return "MSAAQuadProcessor"; } |
| 122 | |
| 123 | const Attribute* inPosition() const { return fInPosition; } |
| 124 | const Attribute* inUV() const { return fInUV; } |
| 125 | const Attribute* inColor() const { return fInColor; } |
| 126 | const SkMatrix& viewMatrix() const { return fViewMatrix; } |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 127 | |
| 128 | class GLSLProcessor : public GrGLSLGeometryProcessor { |
| 129 | public: |
| 130 | GLSLProcessor(const GrGeometryProcessor& qpr) {} |
| 131 | |
| 132 | void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
| 133 | const MSAAQuadProcessor& qp = args.fGP.cast<MSAAQuadProcessor>(); |
| 134 | GrGLSLVertexBuilder* vsBuilder = args.fVertBuilder; |
| 135 | GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
| 136 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
| 137 | |
| 138 | // emit attributes |
| 139 | varyingHandler->emitAttributes(qp); |
| 140 | varyingHandler->addPassThroughAttribute(qp.inColor(), args.fOutputColor); |
| 141 | |
| 142 | GrGLSLVertToFrag uv(kVec2f_GrSLType); |
| 143 | varyingHandler->addVarying("uv", &uv, kHigh_GrSLPrecision); |
| 144 | vsBuilder->codeAppendf("%s = %s;", uv.vsOut(), qp.inUV()->fName); |
| 145 | |
| 146 | // Setup position |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 147 | this->setupPosition(vsBuilder, uniformHandler, gpArgs, qp.inPosition()->fName, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 148 | qp.viewMatrix(), &fViewMatrixUniform); |
| 149 | |
| 150 | // emit transforms |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 151 | this->emitTransforms(vsBuilder, varyingHandler, uniformHandler, gpArgs->fPositionVar, |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 152 | qp.inPosition()->fName, SkMatrix::I(), |
| 153 | args.fFPCoordTransformHandler); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 154 | |
| 155 | GrGLSLPPFragmentBuilder* fsBuilder = args.fFragBuilder; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 156 | fsBuilder->codeAppendf("if (%s.x * %s.x >= %s.y) discard;", uv.fsIn(), uv.fsIn(), |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 157 | uv.fsIn()); |
| 158 | fsBuilder->codeAppendf("%s = vec4(1.0);", args.fOutputCoverage); |
| 159 | } |
| 160 | |
| 161 | static inline void GenKey(const GrGeometryProcessor& gp, |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 162 | const GrShaderCaps&, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 163 | GrProcessorKeyBuilder* b) { |
| 164 | const MSAAQuadProcessor& qp = gp.cast<MSAAQuadProcessor>(); |
| 165 | uint32_t key = 0; |
| 166 | key |= qp.viewMatrix().hasPerspective() ? 0x1 : 0x0; |
| 167 | key |= qp.viewMatrix().isIdentity() ? 0x2: 0x0; |
| 168 | b->add32(key); |
| 169 | } |
| 170 | |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 171 | void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor& gp, |
| 172 | FPCoordTransformIter&& transformIter) override { |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 173 | const MSAAQuadProcessor& qp = gp.cast<MSAAQuadProcessor>(); |
| 174 | if (!qp.viewMatrix().isIdentity()) { |
| 175 | float viewMatrix[3 * 3]; |
| 176 | GrGLSLGetMatrix<3>(viewMatrix, qp.viewMatrix()); |
| 177 | pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
| 178 | } |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 179 | this->setTransformDataHelper(SkMatrix::I(), pdman, &transformIter); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 180 | } |
| 181 | |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 182 | private: |
| 183 | typedef GrGLSLGeometryProcessor INHERITED; |
| 184 | |
| 185 | UniformHandle fViewMatrixUniform; |
| 186 | }; |
| 187 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 188 | virtual void getGLSLProcessorKey(const GrShaderCaps& caps, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 189 | GrProcessorKeyBuilder* b) const override { |
| 190 | GLSLProcessor::GenKey(*this, caps, b); |
| 191 | } |
| 192 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 193 | virtual GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override { |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 194 | return new GLSLProcessor(*this); |
| 195 | } |
| 196 | |
| 197 | private: |
| 198 | MSAAQuadProcessor(const SkMatrix& viewMatrix) |
| 199 | : fViewMatrix(viewMatrix) { |
| 200 | this->initClassID<MSAAQuadProcessor>(); |
bsalomon | 6cb807b | 2016-08-17 11:33:39 -0700 | [diff] [blame] | 201 | fInPosition = &this->addVertexAttrib("inPosition", kVec2f_GrVertexAttribType, |
| 202 | kHigh_GrSLPrecision); |
| 203 | fInUV = &this->addVertexAttrib("inUV", kVec2f_GrVertexAttribType, kHigh_GrSLPrecision); |
| 204 | fInColor = &this->addVertexAttrib("inColor", kVec4ub_GrVertexAttribType); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 205 | this->setSampleShading(1.0f); |
| 206 | } |
| 207 | |
| 208 | const Attribute* fInPosition; |
| 209 | const Attribute* fInUV; |
| 210 | const Attribute* fInColor; |
| 211 | SkMatrix fViewMatrix; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 212 | |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 213 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
| 214 | |
| 215 | typedef GrGeometryProcessor INHERITED; |
| 216 | }; |
| 217 | |
Brian Salomon | d3ccb0a | 2017-04-03 10:38:00 -0400 | [diff] [blame] | 218 | class MSAAPathOp final : public GrLegacyMeshDrawOp { |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 219 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 220 | DEFINE_OP_CLASS_ID |
Brian Salomon | d3ccb0a | 2017-04-03 10:38:00 -0400 | [diff] [blame] | 221 | static std::unique_ptr<GrLegacyMeshDrawOp> Make(GrColor color, const SkPath& path, |
| 222 | const SkMatrix& viewMatrix, |
| 223 | const SkRect& devBounds) { |
bsalomon | 50c56a3 | 2016-06-30 12:05:32 -0700 | [diff] [blame] | 224 | int contourCount; |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 225 | int maxLineVertices; |
| 226 | int maxQuadVertices; |
Brian Salomon | 32ebaba | 2017-03-30 10:22:28 -0400 | [diff] [blame] | 227 | ComputeWorstCasePointCount(path, viewMatrix, &contourCount, &maxLineVertices, |
| 228 | &maxQuadVertices); |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 229 | bool isIndexed = contourCount > 1; |
| 230 | if (isIndexed && |
| 231 | (maxLineVertices > kMaxIndexedVertexCnt || maxQuadVertices > kMaxIndexedVertexCnt)) { |
| 232 | return nullptr; |
| 233 | } |
| 234 | |
Brian Salomon | d3ccb0a | 2017-04-03 10:38:00 -0400 | [diff] [blame] | 235 | return std::unique_ptr<GrLegacyMeshDrawOp>(new MSAAPathOp( |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 236 | color, path, viewMatrix, devBounds, maxLineVertices, maxQuadVertices, isIndexed)); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 239 | const char* name() const override { return "MSAAPathOp"; } |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 240 | |
Brian Salomon | 7c3e718 | 2016-12-01 09:35:30 -0500 | [diff] [blame] | 241 | SkString dumpInfo() const override { |
| 242 | SkString string; |
| 243 | string.appendf("Indexed: %d\n", fIsIndexed); |
| 244 | for (const auto& path : fPaths) { |
| 245 | string.appendf("Color: 0x%08x\n", path.fColor); |
| 246 | } |
| 247 | string.append(DumpPipelineInfo(*this->pipeline())); |
| 248 | string.append(INHERITED::dumpInfo()); |
| 249 | return string; |
| 250 | } |
| 251 | |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 252 | private: |
| 253 | MSAAPathOp(GrColor color, const SkPath& path, const SkMatrix& viewMatrix, |
| 254 | const SkRect& devBounds, int maxLineVertices, int maxQuadVertices, bool isIndexed) |
| 255 | : INHERITED(ClassID()) |
| 256 | , fViewMatrix(viewMatrix) |
| 257 | , fMaxLineVertices(maxLineVertices) |
| 258 | , fMaxQuadVertices(maxQuadVertices) |
| 259 | , fIsIndexed(isIndexed) { |
| 260 | fPaths.emplace_back(PathInfo{color, path}); |
| 261 | this->setBounds(devBounds, HasAABloat::kNo, IsZeroArea::kNo); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Brian Salomon | a811b12 | 2017-03-30 08:21:32 -0400 | [diff] [blame] | 264 | void getProcessorAnalysisInputs(GrProcessorAnalysisColor* color, |
| 265 | GrProcessorAnalysisCoverage* coverage) const override { |
Brian Salomon | c0b642c | 2017-03-27 13:09:36 -0400 | [diff] [blame] | 266 | color->setToConstant(fPaths[0].fColor); |
Brian Salomon | a811b12 | 2017-03-30 08:21:32 -0400 | [diff] [blame] | 267 | *coverage = GrProcessorAnalysisCoverage::kNone; |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 268 | } |
| 269 | |
Brian Salomon | e7d3048 | 2017-03-29 12:09:15 -0400 | [diff] [blame] | 270 | void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override { |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 271 | optimizations.getOverrideColorIfSet(&fPaths[0].fColor); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Brian Salomon | 32ebaba | 2017-03-30 10:22:28 -0400 | [diff] [blame] | 274 | static void ComputeWorstCasePointCount(const SkPath& path, const SkMatrix& m, int* subpaths, |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 275 | int* outLinePointCount, int* outQuadPointCount) { |
Brian Salomon | 32ebaba | 2017-03-30 10:22:28 -0400 | [diff] [blame] | 276 | SkScalar tolerance = GrPathUtils::scaleToleranceToSrc(kTolerance, m, path.getBounds()); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 277 | int linePointCount = 0; |
| 278 | int quadPointCount = 0; |
| 279 | *subpaths = 1; |
| 280 | |
| 281 | bool first = true; |
| 282 | |
bsalomon | 8eb43e5 | 2016-09-21 07:47:34 -0700 | [diff] [blame] | 283 | SkPath::Iter iter(path, true); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 284 | SkPath::Verb verb; |
| 285 | |
| 286 | SkPoint pts[4]; |
| 287 | while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { |
| 288 | switch (verb) { |
| 289 | case SkPath::kLine_Verb: |
| 290 | linePointCount += 1; |
| 291 | break; |
| 292 | case SkPath::kConic_Verb: { |
| 293 | SkScalar weight = iter.conicWeight(); |
| 294 | SkAutoConicToQuads converter; |
Brian Salomon | 32ebaba | 2017-03-30 10:22:28 -0400 | [diff] [blame] | 295 | converter.computeQuads(pts, weight, tolerance); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 296 | int quadPts = converter.countQuads(); |
| 297 | linePointCount += quadPts; |
| 298 | quadPointCount += 3 * quadPts; |
| 299 | } |
| 300 | case SkPath::kQuad_Verb: |
| 301 | linePointCount += 1; |
| 302 | quadPointCount += 3; |
| 303 | break; |
| 304 | case SkPath::kCubic_Verb: { |
| 305 | SkSTArray<15, SkPoint, true> quadPts; |
Brian Salomon | 32ebaba | 2017-03-30 10:22:28 -0400 | [diff] [blame] | 306 | GrPathUtils::convertCubicToQuads(pts, tolerance, &quadPts); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 307 | int count = quadPts.count(); |
| 308 | linePointCount += count / 3; |
| 309 | quadPointCount += count; |
| 310 | break; |
| 311 | } |
| 312 | case SkPath::kMove_Verb: |
| 313 | linePointCount += 1; |
| 314 | if (!first) { |
| 315 | ++(*subpaths); |
| 316 | } |
| 317 | break; |
| 318 | default: |
| 319 | break; |
| 320 | } |
| 321 | first = false; |
| 322 | } |
| 323 | *outLinePointCount = linePointCount; |
| 324 | *outQuadPointCount = quadPointCount; |
| 325 | } |
| 326 | |
| 327 | void onPrepareDraws(Target* target) const override { |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 328 | if (fMaxLineVertices == 0) { |
| 329 | SkASSERT(fMaxQuadVertices == 0); |
| 330 | return; |
| 331 | } |
| 332 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 333 | GrPrimitiveType primitiveType = fIsIndexed ? kTriangles_GrPrimitiveType |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 334 | : kTriangleFan_GrPrimitiveType; |
| 335 | |
| 336 | // allocate vertex / index buffers |
| 337 | const GrBuffer* lineVertexBuffer; |
| 338 | int firstLineVertex; |
| 339 | MSAALineVertices lines; |
| 340 | size_t lineVertexStride = sizeof(MSAALineVertices::Vertex); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 341 | lines.vertices = (MSAALineVertices::Vertex*) target->makeVertexSpace(lineVertexStride, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 342 | fMaxLineVertices, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 343 | &lineVertexBuffer, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 344 | &firstLineVertex); |
| 345 | if (!lines.vertices) { |
| 346 | SkDebugf("Could not allocate vertices\n"); |
| 347 | return; |
| 348 | } |
| 349 | lines.nextVertex = lines.vertices; |
| 350 | SkDEBUGCODE(lines.verticesEnd = lines.vertices + fMaxLineVertices;) |
| 351 | |
| 352 | MSAAQuadVertices quads; |
| 353 | size_t quadVertexStride = sizeof(MSAAQuadVertices::Vertex); |
Hal Canary | 95e3c05 | 2017-01-11 12:44:43 -0500 | [diff] [blame] | 354 | SkAutoMalloc quadVertexPtr(fMaxQuadVertices * quadVertexStride); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 355 | quads.vertices = (MSAAQuadVertices::Vertex*) quadVertexPtr.get(); |
| 356 | quads.nextVertex = quads.vertices; |
| 357 | SkDEBUGCODE(quads.verticesEnd = quads.vertices + fMaxQuadVertices;) |
| 358 | |
| 359 | const GrBuffer* lineIndexBuffer = nullptr; |
| 360 | int firstLineIndex; |
| 361 | if (fIsIndexed) { |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 362 | lines.indices = |
| 363 | target->makeIndexSpace(3 * fMaxLineVertices, &lineIndexBuffer, &firstLineIndex); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 364 | if (!lines.indices) { |
| 365 | SkDebugf("Could not allocate indices\n"); |
| 366 | return; |
| 367 | } |
| 368 | lines.nextIndex = lines.indices; |
| 369 | } else { |
| 370 | lines.indices = nullptr; |
| 371 | lines.nextIndex = nullptr; |
| 372 | } |
| 373 | |
| 374 | SkAutoFree quadIndexPtr; |
| 375 | if (fIsIndexed) { |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 376 | quads.indices = (uint16_t*)sk_malloc_throw(3 * fMaxQuadVertices * sizeof(uint16_t)); |
Hal Canary | 95e3c05 | 2017-01-11 12:44:43 -0500 | [diff] [blame] | 377 | quadIndexPtr.reset(quads.indices); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 378 | quads.nextIndex = quads.indices; |
| 379 | } else { |
| 380 | quads.indices = nullptr; |
| 381 | quads.nextIndex = nullptr; |
| 382 | } |
| 383 | |
| 384 | // fill buffers |
bsalomon | 50c56a3 | 2016-06-30 12:05:32 -0700 | [diff] [blame] | 385 | for (int i = 0; i < fPaths.count(); i++) { |
| 386 | const PathInfo& pathInfo = fPaths[i]; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 387 | |
| 388 | if (!this->createGeom(lines, |
| 389 | quads, |
bsalomon | 50c56a3 | 2016-06-30 12:05:32 -0700 | [diff] [blame] | 390 | pathInfo.fPath, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 391 | fViewMatrix, |
bsalomon | 50c56a3 | 2016-06-30 12:05:32 -0700 | [diff] [blame] | 392 | pathInfo.fColor, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 393 | fIsIndexed)) { |
| 394 | return; |
| 395 | } |
| 396 | } |
| 397 | int lineVertexOffset = (int) (lines.nextVertex - lines.vertices); |
| 398 | int lineIndexOffset = (int) (lines.nextIndex - lines.indices); |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 399 | SkASSERT(lineVertexOffset <= fMaxLineVertices && lineIndexOffset <= 3 * fMaxLineVertices); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 400 | int quadVertexOffset = (int) (quads.nextVertex - quads.vertices); |
| 401 | int quadIndexOffset = (int) (quads.nextIndex - quads.indices); |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 402 | SkASSERT(quadVertexOffset <= fMaxQuadVertices && quadIndexOffset <= 3 * fMaxQuadVertices); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 403 | |
| 404 | if (lineVertexOffset) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 405 | sk_sp<GrGeometryProcessor> lineGP; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 406 | { |
| 407 | using namespace GrDefaultGeoProcFactory; |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 408 | lineGP = GrDefaultGeoProcFactory::Make(Color(Color::kPremulGrColorAttribute_Type), |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 409 | Coverage::kSolid_Type, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 410 | LocalCoords(LocalCoords::kUnused_Type), |
| 411 | fViewMatrix); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 412 | } |
| 413 | SkASSERT(lineVertexStride == lineGP->getVertexStride()); |
| 414 | |
| 415 | GrMesh lineMeshes; |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 416 | lineMeshes.fPrimitiveType = primitiveType; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 417 | if (fIsIndexed) { |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 418 | lineMeshes.fIndexBuffer.reset(lineIndexBuffer); |
| 419 | lineMeshes.fIndexCount = lineIndexOffset; |
| 420 | lineMeshes.fBaseIndex = firstLineIndex; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 421 | } |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 422 | lineMeshes.fVertexBuffer.reset(lineVertexBuffer); |
| 423 | lineMeshes.fVertexCount = lineVertexOffset; |
| 424 | lineMeshes.fBaseVertex = firstLineVertex; |
| 425 | |
Brian Salomon | d3ccb0a | 2017-04-03 10:38:00 -0400 | [diff] [blame] | 426 | target->draw(lineGP.get(), this->pipeline(), lineMeshes); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | if (quadVertexOffset) { |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 430 | sk_sp<const GrGeometryProcessor> quadGP(MSAAQuadProcessor::Create(fViewMatrix)); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 431 | SkASSERT(quadVertexStride == quadGP->getVertexStride()); |
| 432 | |
| 433 | const GrBuffer* quadVertexBuffer; |
| 434 | int firstQuadVertex; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 435 | MSAAQuadVertices::Vertex* quadVertices = (MSAAQuadVertices::Vertex*) |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 436 | target->makeVertexSpace(quadVertexStride, quadVertexOffset, &quadVertexBuffer, |
| 437 | &firstQuadVertex); |
| 438 | memcpy(quadVertices, quads.vertices, quadVertexStride * quadVertexOffset); |
| 439 | GrMesh quadMeshes; |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 440 | quadMeshes.fPrimitiveType = kTriangles_GrPrimitiveType; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 441 | if (fIsIndexed) { |
| 442 | const GrBuffer* quadIndexBuffer; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 443 | uint16_t* quadIndices = (uint16_t*) target->makeIndexSpace(quadIndexOffset, |
| 444 | &quadIndexBuffer, |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 445 | &quadMeshes.fBaseIndex); |
| 446 | quadMeshes.fIndexBuffer.reset(quadIndexBuffer); |
| 447 | quadMeshes.fIndexCount = quadIndexOffset; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 448 | memcpy(quadIndices, quads.indices, sizeof(uint16_t) * quadIndexOffset); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 449 | } |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 450 | quadMeshes.fVertexBuffer.reset(quadVertexBuffer); |
| 451 | quadMeshes.fVertexCount = quadVertexOffset; |
| 452 | quadMeshes.fBaseVertex = firstQuadVertex; |
| 453 | |
Brian Salomon | d3ccb0a | 2017-04-03 10:38:00 -0400 | [diff] [blame] | 454 | target->draw(quadGP.get(), this->pipeline(), quadMeshes); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 458 | bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override { |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 459 | MSAAPathOp* that = t->cast<MSAAPathOp>(); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 460 | if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 461 | that->bounds(), caps)) { |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 462 | return false; |
| 463 | } |
| 464 | |
Jim Van Verth | 9d01fbc | 2017-02-22 14:50:52 -0500 | [diff] [blame] | 465 | if (this->bounds().intersects(that->bounds())) { |
| 466 | return false; |
| 467 | } |
| 468 | |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 469 | if (!fViewMatrix.cheapEqualTo(that->fViewMatrix)) { |
| 470 | return false; |
| 471 | } |
| 472 | |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 473 | // If we grow to include 2+ paths we will be indexed. |
| 474 | if (((fMaxLineVertices + that->fMaxLineVertices) > kMaxIndexedVertexCnt) || |
| 475 | ((fMaxQuadVertices + that->fMaxQuadVertices) > kMaxIndexedVertexCnt)) { |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 476 | return false; |
| 477 | } |
| 478 | |
bsalomon | 50c56a3 | 2016-06-30 12:05:32 -0700 | [diff] [blame] | 479 | fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin()); |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 480 | this->joinBounds(*that); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 481 | fIsIndexed = true; |
| 482 | fMaxLineVertices += that->fMaxLineVertices; |
| 483 | fMaxQuadVertices += that->fMaxQuadVertices; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 484 | return true; |
| 485 | } |
| 486 | |
| 487 | bool createGeom(MSAALineVertices& lines, |
| 488 | MSAAQuadVertices& quads, |
| 489 | const SkPath& path, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 490 | const SkMatrix& m, |
| 491 | SkColor color, |
| 492 | bool isIndexed) const { |
| 493 | { |
Brian Salomon | 32ebaba | 2017-03-30 10:22:28 -0400 | [diff] [blame] | 494 | const SkScalar tolerance = GrPathUtils::scaleToleranceToSrc(kTolerance, m, |
| 495 | path.getBounds()); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 496 | uint16_t subpathIdxStart = (uint16_t) (lines.nextVertex - lines.vertices); |
| 497 | |
| 498 | SkPoint pts[4]; |
| 499 | |
| 500 | bool first = true; |
bsalomon | 8eb43e5 | 2016-09-21 07:47:34 -0700 | [diff] [blame] | 501 | SkPath::Iter iter(path, true); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 502 | |
| 503 | bool done = false; |
| 504 | while (!done) { |
| 505 | SkPath::Verb verb = iter.next(pts); |
| 506 | switch (verb) { |
| 507 | case SkPath::kMove_Verb: |
| 508 | if (!first) { |
| 509 | uint16_t currIdx = (uint16_t) (lines.nextVertex - lines.vertices); |
| 510 | subpathIdxStart = currIdx; |
| 511 | } |
| 512 | SkASSERT(lines.nextVertex < lines.verticesEnd); |
| 513 | *(lines.nextVertex++) = { pts[0], color }; |
| 514 | break; |
| 515 | case SkPath::kLine_Verb: |
| 516 | if (isIndexed) { |
| 517 | uint16_t prevIdx = (uint16_t) (lines.nextVertex - lines.vertices - 1); |
| 518 | if (prevIdx > subpathIdxStart) { |
| 519 | append_contour_edge_indices(subpathIdxStart, prevIdx, lines); |
| 520 | } |
| 521 | } |
| 522 | SkASSERT(lines.nextVertex < lines.verticesEnd); |
| 523 | *(lines.nextVertex++) = { pts[1], color }; |
| 524 | break; |
| 525 | case SkPath::kConic_Verb: { |
| 526 | SkScalar weight = iter.conicWeight(); |
| 527 | SkAutoConicToQuads converter; |
Brian Salomon | 32ebaba | 2017-03-30 10:22:28 -0400 | [diff] [blame] | 528 | const SkPoint* quadPts = converter.computeQuads(pts, weight, tolerance); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 529 | for (int i = 0; i < converter.countQuads(); ++i) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 530 | add_quad(lines, quads, quadPts + i * 2, color, isIndexed, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 531 | subpathIdxStart); |
| 532 | } |
| 533 | break; |
| 534 | } |
| 535 | case SkPath::kQuad_Verb: { |
| 536 | add_quad(lines, quads, pts, color, isIndexed, subpathIdxStart); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 537 | break; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 538 | } |
| 539 | case SkPath::kCubic_Verb: { |
| 540 | SkSTArray<15, SkPoint, true> quadPts; |
Brian Salomon | 32ebaba | 2017-03-30 10:22:28 -0400 | [diff] [blame] | 541 | GrPathUtils::convertCubicToQuads(pts, tolerance, &quadPts); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 542 | int count = quadPts.count(); |
| 543 | for (int i = 0; i < count; i += 3) { |
| 544 | add_quad(lines, quads, &quadPts[i], color, isIndexed, subpathIdxStart); |
| 545 | } |
| 546 | break; |
| 547 | } |
| 548 | case SkPath::kClose_Verb: |
| 549 | break; |
| 550 | case SkPath::kDone_Verb: |
| 551 | done = true; |
| 552 | } |
| 553 | first = false; |
| 554 | } |
| 555 | } |
| 556 | return true; |
| 557 | } |
| 558 | |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 559 | // Lines and quads may render with an index buffer. However, we don't have any support for |
| 560 | // overflowing the max index. |
| 561 | static constexpr int kMaxIndexedVertexCnt = SK_MaxU16 / 3; |
bsalomon | 50c56a3 | 2016-06-30 12:05:32 -0700 | [diff] [blame] | 562 | struct PathInfo { |
| 563 | GrColor fColor; |
| 564 | SkPath fPath; |
| 565 | }; |
| 566 | |
| 567 | SkSTArray<1, PathInfo, true> fPaths; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 568 | |
| 569 | SkMatrix fViewMatrix; |
| 570 | int fMaxLineVertices; |
| 571 | int fMaxQuadVertices; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 572 | bool fIsIndexed; |
| 573 | |
Brian Salomon | d3ccb0a | 2017-04-03 10:38:00 -0400 | [diff] [blame] | 574 | typedef GrLegacyMeshDrawOp INHERITED; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 575 | }; |
| 576 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 577 | bool GrMSAAPathRenderer::internalDrawPath(GrRenderTargetContext* renderTargetContext, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 578 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 579 | GrAAType aaType, |
robertphillips | d2b6d64 | 2016-07-21 08:55:08 -0700 | [diff] [blame] | 580 | const GrUserStencilSettings& userStencilSettings, |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 581 | const GrClip& clip, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 582 | const SkMatrix& viewMatrix, |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 583 | const GrShape& shape, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 584 | bool stencilOnly) { |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 585 | SkASSERT(shape.style().isSimpleFill()); |
| 586 | SkPath path; |
| 587 | shape.asPath(&path); |
| 588 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 589 | const GrUserStencilSettings* passes[2] = {nullptr, nullptr}; |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 590 | bool reverse = false; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 591 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 592 | if (single_pass_shape(shape)) { |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 593 | if (stencilOnly) { |
| 594 | passes[0] = &gDirectToStencil; |
| 595 | } else { |
robertphillips | d2b6d64 | 2016-07-21 08:55:08 -0700 | [diff] [blame] | 596 | passes[0] = &userStencilSettings; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 597 | } |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 598 | } else { |
| 599 | switch (path.getFillType()) { |
| 600 | case SkPath::kInverseEvenOdd_FillType: |
| 601 | reverse = true; |
| 602 | // fallthrough |
| 603 | case SkPath::kEvenOdd_FillType: |
| 604 | passes[0] = &gEOStencilPass; |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 605 | if (!stencilOnly) { |
| 606 | passes[1] = reverse ? &gInvEOColorPass : &gEOColorPass; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 607 | } |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 608 | break; |
| 609 | |
| 610 | case SkPath::kInverseWinding_FillType: |
| 611 | reverse = true; |
| 612 | // fallthrough |
| 613 | case SkPath::kWinding_FillType: |
Brian Salomon | 15b2509 | 2017-05-08 11:10:53 -0400 | [diff] [blame^] | 614 | passes[0] = &gWindStencilPass; |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 615 | if (!stencilOnly) { |
| 616 | passes[1] = reverse ? &gInvWindColorPass : &gWindColorPass; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 617 | } |
| 618 | break; |
| 619 | default: |
| 620 | SkDEBUGFAIL("Unknown path fFill!"); |
| 621 | return false; |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | SkRect devBounds; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 626 | GetPathDevBounds(path, renderTargetContext->width(), renderTargetContext->height(), viewMatrix, |
| 627 | &devBounds); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 628 | |
Brian Salomon | d4652ca | 2017-01-13 12:11:36 -0500 | [diff] [blame] | 629 | SkASSERT(passes[0]); |
| 630 | { // First pass |
Brian Salomon | d3ccb0a | 2017-04-03 10:38:00 -0400 | [diff] [blame] | 631 | std::unique_ptr<GrLegacyMeshDrawOp> op = |
Brian Salomon | d4652ca | 2017-01-13 12:11:36 -0500 | [diff] [blame] | 632 | MSAAPathOp::Make(paint.getColor(), path, viewMatrix, devBounds); |
| 633 | if (!op) { |
| 634 | return false; |
| 635 | } |
| 636 | bool firstPassIsStencil = stencilOnly || passes[1]; |
| 637 | // If we have a cover pass then we ignore the paint in the first pass and apply it in the |
| 638 | // second. |
| 639 | GrPaint::MoveOrNew firstPassPaint(paint, firstPassIsStencil); |
| 640 | if (firstPassIsStencil) { |
| 641 | firstPassPaint.paint().setXPFactory(GrDisableColorXPFactory::Get()); |
| 642 | } |
| 643 | GrPipelineBuilder pipelineBuilder(std::move(firstPassPaint), aaType); |
| 644 | pipelineBuilder.setUserStencil(passes[0]); |
Brian Salomon | e14bd80 | 2017-04-04 15:13:25 -0400 | [diff] [blame] | 645 | renderTargetContext->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op)); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 646 | } |
robertphillips | 8e37530 | 2016-07-11 10:43:58 -0700 | [diff] [blame] | 647 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 648 | if (passes[1]) { |
| 649 | SkRect bounds; |
| 650 | SkMatrix localMatrix = SkMatrix::I(); |
| 651 | if (reverse) { |
| 652 | // draw over the dev bounds (which will be the whole dst surface for inv fill). |
| 653 | bounds = devBounds; |
| 654 | SkMatrix vmi; |
| 655 | // mapRect through persp matrix may not be correct |
| 656 | if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) { |
| 657 | vmi.mapRect(&bounds); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 658 | } else { |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 659 | if (!viewMatrix.invert(&localMatrix)) { |
| 660 | return false; |
| 661 | } |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 662 | } |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 663 | } else { |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 664 | bounds = path.getBounds(); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 665 | } |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 666 | const SkMatrix& viewM = |
| 667 | (reverse && viewMatrix.hasPerspective()) ? SkMatrix::I() : viewMatrix; |
Brian Salomon | d3ccb0a | 2017-04-03 10:38:00 -0400 | [diff] [blame] | 668 | std::unique_ptr<GrLegacyMeshDrawOp> op(GrRectOpFactory::MakeNonAAFill( |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 669 | paint.getColor(), viewM, bounds, nullptr, &localMatrix)); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 670 | |
| 671 | GrPipelineBuilder pipelineBuilder(std::move(paint), aaType); |
| 672 | pipelineBuilder.setUserStencil(passes[1]); |
| 673 | |
Brian Salomon | e14bd80 | 2017-04-04 15:13:25 -0400 | [diff] [blame] | 674 | renderTargetContext->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op)); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 675 | } |
| 676 | return true; |
| 677 | } |
| 678 | |
| 679 | bool GrMSAAPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 680 | // This path renderer only fills and relies on MSAA for antialiasing. Stroked shapes are |
| 681 | // handled by passing on the original shape and letting the caller compute the stroked shape |
| 682 | // which will have a fill style. |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 683 | return args.fShape->style().isSimpleFill() && (GrAAType::kCoverage != args.fAAType); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | bool GrMSAAPathRenderer::onDrawPath(const DrawPathArgs& args) { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 687 | GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(), |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 688 | "GrMSAAPathRenderer::onDrawPath"); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 689 | SkTLazy<GrShape> tmpShape; |
| 690 | const GrShape* shape = args.fShape; |
| 691 | if (shape->style().applies()) { |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 692 | SkScalar styleScale = GrStyle::MatrixToScaleFactor(*args.fViewMatrix); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 693 | tmpShape.init(args.fShape->applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, styleScale)); |
| 694 | shape = tmpShape.get(); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 695 | } |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 696 | return this->internalDrawPath(args.fRenderTargetContext, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 697 | std::move(args.fPaint), |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 698 | args.fAAType, |
robertphillips | d2b6d64 | 2016-07-21 08:55:08 -0700 | [diff] [blame] | 699 | *args.fUserStencilSettings, |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 700 | *args.fClip, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 701 | *args.fViewMatrix, |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 702 | *shape, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 703 | false); |
| 704 | } |
| 705 | |
| 706 | void GrMSAAPathRenderer::onStencilPath(const StencilPathArgs& args) { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 707 | GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(), |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 708 | "GrMSAAPathRenderer::onStencilPath"); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 709 | SkASSERT(args.fShape->style().isSimpleFill()); |
| 710 | SkASSERT(!args.fShape->mayBeInverseFilledAfterStyling()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 711 | |
| 712 | GrPaint paint; |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 713 | paint.setXPFactory(GrDisableColorXPFactory::Get()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 714 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 715 | this->internalDrawPath(args.fRenderTargetContext, std::move(paint), args.fAAType, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 716 | GrUserStencilSettings::kUnused, *args.fClip, *args.fViewMatrix, |
| 717 | *args.fShape, true); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | /////////////////////////////////////////////////////////////////////////////////////////////////// |