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