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 | |
| 119 | virtual ~MSAAQuadProcessor() {} |
| 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 | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 218 | class MSAAPathOp final : public GrMeshDrawOp { |
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 | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 221 | static std::unique_ptr<GrDrawOp> Make(GrColor color, const SkPath& path, |
| 222 | const SkMatrix& viewMatrix, const SkRect& devBounds) { |
bsalomon | 50c56a3 | 2016-06-30 12:05:32 -0700 | [diff] [blame] | 223 | int contourCount; |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 224 | int maxLineVertices; |
| 225 | int maxQuadVertices; |
| 226 | ComputeWorstCasePointCount(path, &contourCount, &maxLineVertices, &maxQuadVertices); |
| 227 | bool isIndexed = contourCount > 1; |
| 228 | if (isIndexed && |
| 229 | (maxLineVertices > kMaxIndexedVertexCnt || maxQuadVertices > kMaxIndexedVertexCnt)) { |
| 230 | return nullptr; |
| 231 | } |
| 232 | |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 233 | return std::unique_ptr<GrDrawOp>(new MSAAPathOp( |
| 234 | color, path, viewMatrix, devBounds, maxLineVertices, maxQuadVertices, isIndexed)); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 237 | const char* name() const override { return "MSAAPathOp"; } |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 238 | |
Brian Salomon | 7c3e718 | 2016-12-01 09:35:30 -0500 | [diff] [blame] | 239 | SkString dumpInfo() const override { |
| 240 | SkString string; |
| 241 | string.appendf("Indexed: %d\n", fIsIndexed); |
| 242 | for (const auto& path : fPaths) { |
| 243 | string.appendf("Color: 0x%08x\n", path.fColor); |
| 244 | } |
| 245 | string.append(DumpPipelineInfo(*this->pipeline())); |
| 246 | string.append(INHERITED::dumpInfo()); |
| 247 | return string; |
| 248 | } |
| 249 | |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 250 | private: |
| 251 | MSAAPathOp(GrColor color, const SkPath& path, const SkMatrix& viewMatrix, |
| 252 | const SkRect& devBounds, int maxLineVertices, int maxQuadVertices, bool isIndexed) |
| 253 | : INHERITED(ClassID()) |
| 254 | , fViewMatrix(viewMatrix) |
| 255 | , fMaxLineVertices(maxLineVertices) |
| 256 | , fMaxQuadVertices(maxQuadVertices) |
| 257 | , fIsIndexed(isIndexed) { |
| 258 | fPaths.emplace_back(PathInfo{color, path}); |
| 259 | this->setBounds(devBounds, HasAABloat::kNo, IsZeroArea::kNo); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 262 | void getPipelineAnalysisInput(GrPipelineAnalysisDrawOpInput* input) const override { |
| 263 | input->pipelineColorInput()->setKnownFourComponents(fPaths[0].fColor); |
| 264 | input->pipelineCoverageInput()->setKnownSingleComponent(0xff); |
| 265 | } |
| 266 | |
| 267 | void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override { |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 268 | optimizations.getOverrideColorIfSet(&fPaths[0].fColor); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 271 | static void ComputeWorstCasePointCount(const SkPath& path, int* subpaths, |
| 272 | int* outLinePointCount, int* outQuadPointCount) { |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 273 | int linePointCount = 0; |
| 274 | int quadPointCount = 0; |
| 275 | *subpaths = 1; |
| 276 | |
| 277 | bool first = true; |
| 278 | |
bsalomon | 8eb43e5 | 2016-09-21 07:47:34 -0700 | [diff] [blame] | 279 | SkPath::Iter iter(path, true); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 280 | SkPath::Verb verb; |
| 281 | |
| 282 | SkPoint pts[4]; |
| 283 | while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { |
| 284 | switch (verb) { |
| 285 | case SkPath::kLine_Verb: |
| 286 | linePointCount += 1; |
| 287 | break; |
| 288 | case SkPath::kConic_Verb: { |
| 289 | SkScalar weight = iter.conicWeight(); |
| 290 | SkAutoConicToQuads converter; |
| 291 | converter.computeQuads(pts, weight, kTolerance); |
| 292 | int quadPts = converter.countQuads(); |
| 293 | linePointCount += quadPts; |
| 294 | quadPointCount += 3 * quadPts; |
| 295 | } |
| 296 | case SkPath::kQuad_Verb: |
| 297 | linePointCount += 1; |
| 298 | quadPointCount += 3; |
| 299 | break; |
| 300 | case SkPath::kCubic_Verb: { |
| 301 | SkSTArray<15, SkPoint, true> quadPts; |
| 302 | GrPathUtils::convertCubicToQuads(pts, kTolerance, &quadPts); |
| 303 | int count = quadPts.count(); |
| 304 | linePointCount += count / 3; |
| 305 | quadPointCount += count; |
| 306 | break; |
| 307 | } |
| 308 | case SkPath::kMove_Verb: |
| 309 | linePointCount += 1; |
| 310 | if (!first) { |
| 311 | ++(*subpaths); |
| 312 | } |
| 313 | break; |
| 314 | default: |
| 315 | break; |
| 316 | } |
| 317 | first = false; |
| 318 | } |
| 319 | *outLinePointCount = linePointCount; |
| 320 | *outQuadPointCount = quadPointCount; |
| 321 | } |
| 322 | |
| 323 | void onPrepareDraws(Target* target) const override { |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 324 | if (fMaxLineVertices == 0) { |
| 325 | SkASSERT(fMaxQuadVertices == 0); |
| 326 | return; |
| 327 | } |
| 328 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 329 | GrPrimitiveType primitiveType = fIsIndexed ? kTriangles_GrPrimitiveType |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 330 | : kTriangleFan_GrPrimitiveType; |
| 331 | |
| 332 | // allocate vertex / index buffers |
| 333 | const GrBuffer* lineVertexBuffer; |
| 334 | int firstLineVertex; |
| 335 | MSAALineVertices lines; |
| 336 | size_t lineVertexStride = sizeof(MSAALineVertices::Vertex); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 337 | lines.vertices = (MSAALineVertices::Vertex*) target->makeVertexSpace(lineVertexStride, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 338 | fMaxLineVertices, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 339 | &lineVertexBuffer, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 340 | &firstLineVertex); |
| 341 | if (!lines.vertices) { |
| 342 | SkDebugf("Could not allocate vertices\n"); |
| 343 | return; |
| 344 | } |
| 345 | lines.nextVertex = lines.vertices; |
| 346 | SkDEBUGCODE(lines.verticesEnd = lines.vertices + fMaxLineVertices;) |
| 347 | |
| 348 | MSAAQuadVertices quads; |
| 349 | size_t quadVertexStride = sizeof(MSAAQuadVertices::Vertex); |
Hal Canary | 95e3c05 | 2017-01-11 12:44:43 -0500 | [diff] [blame^] | 350 | SkAutoMalloc quadVertexPtr(fMaxQuadVertices * quadVertexStride); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 351 | quads.vertices = (MSAAQuadVertices::Vertex*) quadVertexPtr.get(); |
| 352 | quads.nextVertex = quads.vertices; |
| 353 | SkDEBUGCODE(quads.verticesEnd = quads.vertices + fMaxQuadVertices;) |
| 354 | |
| 355 | const GrBuffer* lineIndexBuffer = nullptr; |
| 356 | int firstLineIndex; |
| 357 | if (fIsIndexed) { |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 358 | lines.indices = |
| 359 | target->makeIndexSpace(3 * fMaxLineVertices, &lineIndexBuffer, &firstLineIndex); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 360 | if (!lines.indices) { |
| 361 | SkDebugf("Could not allocate indices\n"); |
| 362 | return; |
| 363 | } |
| 364 | lines.nextIndex = lines.indices; |
| 365 | } else { |
| 366 | lines.indices = nullptr; |
| 367 | lines.nextIndex = nullptr; |
| 368 | } |
| 369 | |
| 370 | SkAutoFree quadIndexPtr; |
| 371 | if (fIsIndexed) { |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 372 | quads.indices = (uint16_t*)sk_malloc_throw(3 * fMaxQuadVertices * sizeof(uint16_t)); |
Hal Canary | 95e3c05 | 2017-01-11 12:44:43 -0500 | [diff] [blame^] | 373 | quadIndexPtr.reset(quads.indices); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 374 | quads.nextIndex = quads.indices; |
| 375 | } else { |
| 376 | quads.indices = nullptr; |
| 377 | quads.nextIndex = nullptr; |
| 378 | } |
| 379 | |
| 380 | // fill buffers |
bsalomon | 50c56a3 | 2016-06-30 12:05:32 -0700 | [diff] [blame] | 381 | for (int i = 0; i < fPaths.count(); i++) { |
| 382 | const PathInfo& pathInfo = fPaths[i]; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 383 | |
| 384 | if (!this->createGeom(lines, |
| 385 | quads, |
bsalomon | 50c56a3 | 2016-06-30 12:05:32 -0700 | [diff] [blame] | 386 | pathInfo.fPath, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 387 | fViewMatrix, |
bsalomon | 50c56a3 | 2016-06-30 12:05:32 -0700 | [diff] [blame] | 388 | pathInfo.fColor, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 389 | fIsIndexed)) { |
| 390 | return; |
| 391 | } |
| 392 | } |
| 393 | int lineVertexOffset = (int) (lines.nextVertex - lines.vertices); |
| 394 | int lineIndexOffset = (int) (lines.nextIndex - lines.indices); |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 395 | SkASSERT(lineVertexOffset <= fMaxLineVertices && lineIndexOffset <= 3 * fMaxLineVertices); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 396 | int quadVertexOffset = (int) (quads.nextVertex - quads.vertices); |
| 397 | int quadIndexOffset = (int) (quads.nextIndex - quads.indices); |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 398 | SkASSERT(quadVertexOffset <= fMaxQuadVertices && quadIndexOffset <= 3 * fMaxQuadVertices); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 399 | |
| 400 | if (lineVertexOffset) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 401 | sk_sp<GrGeometryProcessor> lineGP; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 402 | { |
| 403 | using namespace GrDefaultGeoProcFactory; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 404 | lineGP = GrDefaultGeoProcFactory::Make(Color(Color::kAttribute_Type), |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 405 | Coverage::kSolid_Type, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 406 | LocalCoords(LocalCoords::kUnused_Type), |
| 407 | fViewMatrix); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 408 | } |
| 409 | SkASSERT(lineVertexStride == lineGP->getVertexStride()); |
| 410 | |
| 411 | GrMesh lineMeshes; |
| 412 | if (fIsIndexed) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 413 | lineMeshes.initIndexed(primitiveType, lineVertexBuffer, lineIndexBuffer, |
| 414 | firstLineVertex, firstLineIndex, lineVertexOffset, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 415 | lineIndexOffset); |
| 416 | } else { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 417 | lineMeshes.init(primitiveType, lineVertexBuffer, firstLineVertex, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 418 | lineVertexOffset); |
| 419 | } |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 420 | target->draw(lineGP.get(), lineMeshes); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | if (quadVertexOffset) { |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 424 | sk_sp<const GrGeometryProcessor> quadGP(MSAAQuadProcessor::Create(fViewMatrix)); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 425 | SkASSERT(quadVertexStride == quadGP->getVertexStride()); |
| 426 | |
| 427 | const GrBuffer* quadVertexBuffer; |
| 428 | int firstQuadVertex; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 429 | MSAAQuadVertices::Vertex* quadVertices = (MSAAQuadVertices::Vertex*) |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 430 | target->makeVertexSpace(quadVertexStride, quadVertexOffset, &quadVertexBuffer, |
| 431 | &firstQuadVertex); |
| 432 | memcpy(quadVertices, quads.vertices, quadVertexStride * quadVertexOffset); |
| 433 | GrMesh quadMeshes; |
| 434 | if (fIsIndexed) { |
| 435 | const GrBuffer* quadIndexBuffer; |
| 436 | int firstQuadIndex; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 437 | uint16_t* quadIndices = (uint16_t*) target->makeIndexSpace(quadIndexOffset, |
| 438 | &quadIndexBuffer, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 439 | &firstQuadIndex); |
| 440 | memcpy(quadIndices, quads.indices, sizeof(uint16_t) * quadIndexOffset); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 441 | quadMeshes.initIndexed(kTriangles_GrPrimitiveType, quadVertexBuffer, |
| 442 | quadIndexBuffer, firstQuadVertex, firstQuadIndex, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 443 | quadVertexOffset, quadIndexOffset); |
| 444 | } else { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 445 | quadMeshes.init(kTriangles_GrPrimitiveType, quadVertexBuffer, firstQuadVertex, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 446 | quadVertexOffset); |
| 447 | } |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 448 | target->draw(quadGP.get(), quadMeshes); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 452 | bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override { |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 453 | MSAAPathOp* that = t->cast<MSAAPathOp>(); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 454 | if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), |
| 455 | that->bounds(), caps)) { |
| 456 | return false; |
| 457 | } |
| 458 | |
| 459 | if (!fViewMatrix.cheapEqualTo(that->fViewMatrix)) { |
| 460 | return false; |
| 461 | } |
| 462 | |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 463 | // If we grow to include 2+ paths we will be indexed. |
| 464 | if (((fMaxLineVertices + that->fMaxLineVertices) > kMaxIndexedVertexCnt) || |
| 465 | ((fMaxQuadVertices + that->fMaxQuadVertices) > kMaxIndexedVertexCnt)) { |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 466 | return false; |
| 467 | } |
| 468 | |
bsalomon | 50c56a3 | 2016-06-30 12:05:32 -0700 | [diff] [blame] | 469 | fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin()); |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 470 | this->joinBounds(*that); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 471 | fIsIndexed = true; |
| 472 | fMaxLineVertices += that->fMaxLineVertices; |
| 473 | fMaxQuadVertices += that->fMaxQuadVertices; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 474 | return true; |
| 475 | } |
| 476 | |
| 477 | bool createGeom(MSAALineVertices& lines, |
| 478 | MSAAQuadVertices& quads, |
| 479 | const SkPath& path, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 480 | const SkMatrix& m, |
| 481 | SkColor color, |
| 482 | bool isIndexed) const { |
| 483 | { |
| 484 | uint16_t subpathIdxStart = (uint16_t) (lines.nextVertex - lines.vertices); |
| 485 | |
| 486 | SkPoint pts[4]; |
| 487 | |
| 488 | bool first = true; |
bsalomon | 8eb43e5 | 2016-09-21 07:47:34 -0700 | [diff] [blame] | 489 | SkPath::Iter iter(path, true); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 490 | |
| 491 | bool done = false; |
| 492 | while (!done) { |
| 493 | SkPath::Verb verb = iter.next(pts); |
| 494 | switch (verb) { |
| 495 | case SkPath::kMove_Verb: |
| 496 | if (!first) { |
| 497 | uint16_t currIdx = (uint16_t) (lines.nextVertex - lines.vertices); |
| 498 | subpathIdxStart = currIdx; |
| 499 | } |
| 500 | SkASSERT(lines.nextVertex < lines.verticesEnd); |
| 501 | *(lines.nextVertex++) = { pts[0], color }; |
| 502 | break; |
| 503 | case SkPath::kLine_Verb: |
| 504 | if (isIndexed) { |
| 505 | uint16_t prevIdx = (uint16_t) (lines.nextVertex - lines.vertices - 1); |
| 506 | if (prevIdx > subpathIdxStart) { |
| 507 | append_contour_edge_indices(subpathIdxStart, prevIdx, lines); |
| 508 | } |
| 509 | } |
| 510 | SkASSERT(lines.nextVertex < lines.verticesEnd); |
| 511 | *(lines.nextVertex++) = { pts[1], color }; |
| 512 | break; |
| 513 | case SkPath::kConic_Verb: { |
| 514 | SkScalar weight = iter.conicWeight(); |
| 515 | SkAutoConicToQuads converter; |
bsalomon | 50c56a3 | 2016-06-30 12:05:32 -0700 | [diff] [blame] | 516 | const SkPoint* quadPts = converter.computeQuads(pts, weight, kTolerance); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 517 | for (int i = 0; i < converter.countQuads(); ++i) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 518 | add_quad(lines, quads, quadPts + i * 2, color, isIndexed, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 519 | subpathIdxStart); |
| 520 | } |
| 521 | break; |
| 522 | } |
| 523 | case SkPath::kQuad_Verb: { |
| 524 | add_quad(lines, quads, pts, color, isIndexed, subpathIdxStart); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 525 | break; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 526 | } |
| 527 | case SkPath::kCubic_Verb: { |
| 528 | SkSTArray<15, SkPoint, true> quadPts; |
| 529 | GrPathUtils::convertCubicToQuads(pts, kTolerance, &quadPts); |
| 530 | int count = quadPts.count(); |
| 531 | for (int i = 0; i < count; i += 3) { |
| 532 | add_quad(lines, quads, &quadPts[i], color, isIndexed, subpathIdxStart); |
| 533 | } |
| 534 | break; |
| 535 | } |
| 536 | case SkPath::kClose_Verb: |
| 537 | break; |
| 538 | case SkPath::kDone_Verb: |
| 539 | done = true; |
| 540 | } |
| 541 | first = false; |
| 542 | } |
| 543 | } |
| 544 | return true; |
| 545 | } |
| 546 | |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 547 | // Lines and quads may render with an index buffer. However, we don't have any support for |
| 548 | // overflowing the max index. |
| 549 | static constexpr int kMaxIndexedVertexCnt = SK_MaxU16 / 3; |
bsalomon | 50c56a3 | 2016-06-30 12:05:32 -0700 | [diff] [blame] | 550 | struct PathInfo { |
| 551 | GrColor fColor; |
| 552 | SkPath fPath; |
| 553 | }; |
| 554 | |
| 555 | SkSTArray<1, PathInfo, true> fPaths; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 556 | |
| 557 | SkMatrix fViewMatrix; |
| 558 | int fMaxLineVertices; |
| 559 | int fMaxQuadVertices; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 560 | bool fIsIndexed; |
| 561 | |
Brian Salomon | dad2923 | 2016-12-01 16:40:24 -0500 | [diff] [blame] | 562 | typedef GrMeshDrawOp INHERITED; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 563 | }; |
| 564 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 565 | bool GrMSAAPathRenderer::internalDrawPath(GrRenderTargetContext* renderTargetContext, |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 566 | const GrPaint& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 567 | GrAAType aaType, |
robertphillips | d2b6d64 | 2016-07-21 08:55:08 -0700 | [diff] [blame] | 568 | const GrUserStencilSettings& userStencilSettings, |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 569 | const GrClip& clip, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 570 | const SkMatrix& viewMatrix, |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 571 | const GrShape& shape, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 572 | bool stencilOnly) { |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 573 | SkASSERT(shape.style().isSimpleFill()); |
| 574 | SkPath path; |
| 575 | shape.asPath(&path); |
| 576 | |
robertphillips | 8e37530 | 2016-07-11 10:43:58 -0700 | [diff] [blame] | 577 | static const int kMaxNumPasses = 2; |
| 578 | |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 579 | int passCount = 0; |
robertphillips | 8e37530 | 2016-07-11 10:43:58 -0700 | [diff] [blame] | 580 | const GrUserStencilSettings* passes[kMaxNumPasses]; |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 581 | bool reverse = false; |
| 582 | bool lastPassIsBounds; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 583 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 584 | if (single_pass_shape(shape)) { |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 585 | passCount = 1; |
| 586 | if (stencilOnly) { |
| 587 | passes[0] = &gDirectToStencil; |
| 588 | } else { |
robertphillips | d2b6d64 | 2016-07-21 08:55:08 -0700 | [diff] [blame] | 589 | passes[0] = &userStencilSettings; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 590 | } |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 591 | lastPassIsBounds = false; |
| 592 | } else { |
| 593 | switch (path.getFillType()) { |
| 594 | case SkPath::kInverseEvenOdd_FillType: |
| 595 | reverse = true; |
| 596 | // fallthrough |
| 597 | case SkPath::kEvenOdd_FillType: |
| 598 | passes[0] = &gEOStencilPass; |
| 599 | if (stencilOnly) { |
| 600 | passCount = 1; |
| 601 | lastPassIsBounds = false; |
| 602 | } else { |
| 603 | passCount = 2; |
| 604 | lastPassIsBounds = true; |
| 605 | if (reverse) { |
| 606 | passes[1] = &gInvEOColorPass; |
| 607 | } else { |
| 608 | passes[1] = &gEOColorPass; |
| 609 | } |
| 610 | } |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 611 | break; |
| 612 | |
| 613 | case SkPath::kInverseWinding_FillType: |
| 614 | reverse = true; |
| 615 | // fallthrough |
| 616 | case SkPath::kWinding_FillType: |
| 617 | passes[0] = &gWindStencilSeparateWithWrap; |
| 618 | passCount = 2; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 619 | if (stencilOnly) { |
| 620 | lastPassIsBounds = false; |
robertphillips | 8e37530 | 2016-07-11 10:43:58 -0700 | [diff] [blame] | 621 | passCount = 1; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 622 | } else { |
| 623 | lastPassIsBounds = true; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 624 | if (reverse) { |
robertphillips | 8e37530 | 2016-07-11 10:43:58 -0700 | [diff] [blame] | 625 | passes[1] = &gInvWindColorPass; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 626 | } else { |
robertphillips | 8e37530 | 2016-07-11 10:43:58 -0700 | [diff] [blame] | 627 | passes[1] = &gWindColorPass; |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 628 | } |
| 629 | } |
| 630 | break; |
| 631 | default: |
| 632 | SkDEBUGFAIL("Unknown path fFill!"); |
| 633 | return false; |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | SkRect devBounds; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 638 | GetPathDevBounds(path, renderTargetContext->width(), renderTargetContext->height(), viewMatrix, |
| 639 | &devBounds); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 640 | |
robertphillips | 8e37530 | 2016-07-11 10:43:58 -0700 | [diff] [blame] | 641 | SkASSERT(passCount <= kMaxNumPasses); |
| 642 | |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 643 | for (int p = 0; p < passCount; ++p) { |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 644 | if (lastPassIsBounds && (p == passCount-1)) { |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 645 | SkRect bounds; |
| 646 | SkMatrix localMatrix = SkMatrix::I(); |
| 647 | if (reverse) { |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 648 | // draw over the dev bounds (which will be the whole dst surface for inv fill). |
| 649 | bounds = devBounds; |
| 650 | SkMatrix vmi; |
| 651 | // mapRect through persp matrix may not be correct |
| 652 | if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) { |
| 653 | vmi.mapRect(&bounds); |
| 654 | } else { |
| 655 | if (!viewMatrix.invert(&localMatrix)) { |
| 656 | return false; |
| 657 | } |
| 658 | } |
| 659 | } else { |
| 660 | bounds = path.getBounds(); |
| 661 | } |
| 662 | const SkMatrix& viewM = (reverse && viewMatrix.hasPerspective()) ? SkMatrix::I() : |
| 663 | viewMatrix; |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 664 | std::unique_ptr<GrDrawOp> op(GrRectOpFactory::MakeNonAAFill( |
| 665 | paint.getColor(), viewM, bounds, nullptr, &localMatrix)); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 666 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 667 | GrPipelineBuilder pipelineBuilder(paint, aaType); |
bsalomon | bb24383 | 2016-07-22 07:10:19 -0700 | [diff] [blame] | 668 | pipelineBuilder.setUserStencil(passes[p]); |
| 669 | |
Brian Salomon | 24f1978 | 2016-12-13 15:10:11 -0500 | [diff] [blame] | 670 | renderTargetContext->addDrawOp(pipelineBuilder, clip, std::move(op)); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 671 | } else { |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 672 | std::unique_ptr<GrDrawOp> op = |
| 673 | MSAAPathOp::Make(paint.getColor(), path, viewMatrix, devBounds); |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 674 | if (!op) { |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 675 | return false; |
| 676 | } |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 677 | GrPipelineBuilder pipelineBuilder(paint, aaType); |
bsalomon | bb24383 | 2016-07-22 07:10:19 -0700 | [diff] [blame] | 678 | pipelineBuilder.setUserStencil(passes[p]); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 679 | if (passCount > 1) { |
bsalomon | bb24383 | 2016-07-22 07:10:19 -0700 | [diff] [blame] | 680 | pipelineBuilder.setDisableColorXPFactory(); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 681 | } |
Brian Salomon | 24f1978 | 2016-12-13 15:10:11 -0500 | [diff] [blame] | 682 | renderTargetContext->addDrawOp(pipelineBuilder, clip, std::move(op)); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 683 | } |
| 684 | } |
| 685 | return true; |
| 686 | } |
| 687 | |
| 688 | bool GrMSAAPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 689 | // This path renderer only fills and relies on MSAA for antialiasing. Stroked shapes are |
| 690 | // handled by passing on the original shape and letting the caller compute the stroked shape |
| 691 | // which will have a fill style. |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 692 | return args.fShape->style().isSimpleFill() && (GrAAType::kCoverage != args.fAAType); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | bool GrMSAAPathRenderer::onDrawPath(const DrawPathArgs& args) { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 696 | GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(), |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 697 | "GrMSAAPathRenderer::onDrawPath"); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 698 | SkTLazy<GrShape> tmpShape; |
| 699 | const GrShape* shape = args.fShape; |
| 700 | if (shape->style().applies()) { |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 701 | SkScalar styleScale = GrStyle::MatrixToScaleFactor(*args.fViewMatrix); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 702 | tmpShape.init(args.fShape->applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, styleScale)); |
| 703 | shape = tmpShape.get(); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 704 | } |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 705 | return this->internalDrawPath(args.fRenderTargetContext, |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 706 | *args.fPaint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 707 | args.fAAType, |
robertphillips | d2b6d64 | 2016-07-21 08:55:08 -0700 | [diff] [blame] | 708 | *args.fUserStencilSettings, |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 709 | *args.fClip, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 710 | *args.fViewMatrix, |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 711 | *shape, |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 712 | false); |
| 713 | } |
| 714 | |
| 715 | void GrMSAAPathRenderer::onStencilPath(const StencilPathArgs& args) { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 716 | GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(), |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 717 | "GrMSAAPathRenderer::onStencilPath"); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 718 | SkASSERT(args.fShape->style().isSimpleFill()); |
| 719 | SkASSERT(!args.fShape->mayBeInverseFilledAfterStyling()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 720 | |
| 721 | GrPaint paint; |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 722 | paint.setXPFactory(GrDisableColorXPFactory::Get()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 723 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 724 | this->internalDrawPath(args.fRenderTargetContext, paint, args.fAAType, |
| 725 | GrUserStencilSettings::kUnused, *args.fClip, *args.fViewMatrix, |
| 726 | *args.fShape, true); |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | /////////////////////////////////////////////////////////////////////////////////////////////////// |