blob: 1f70a0f8ef2012e3253b78c9d153b16a7d156d1f [file] [log] [blame]
Chris Daltonb832ce62020-01-06 19:49:37 -07001/*
2 * Copyright 2019 Google LLC.
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 "src/gpu/tessellate/GrGpuTessellationPathRenderer.h"
9
10#include "src/core/SkPathPriv.h"
11#include "src/gpu/GrClip.h"
12#include "src/gpu/GrMemoryPool.h"
13#include "src/gpu/GrRecordingContextPriv.h"
14#include "src/gpu/GrRenderTargetContext.h"
15#include "src/gpu/geometry/GrShape.h"
16#include "src/gpu/tessellate/GrTessellatePathOp.h"
17
18GrPathRenderer::CanDrawPath GrGpuTessellationPathRenderer::onCanDrawPath(
19 const CanDrawPathArgs& args) const {
20 // This class should not have been added to the chain without tessellation support.
21 SkASSERT(args.fCaps->shaderCaps()->tessellationSupport());
Chris Dalton0f6bb8a2020-01-15 09:40:54 -070022 if (!args.fShape->style().isSimpleFill() || args.fShape->inverseFilled() ||
23 args.fViewMatrix->hasPerspective()) {
Chris Daltonb832ce62020-01-06 19:49:37 -070024 return CanDrawPath::kNo;
25 }
26 if (GrAAType::kCoverage == args.fAAType) {
27 SkASSERT(1 == args.fProxy->numSamples());
28 if (!args.fProxy->canUseMixedSamples(*args.fCaps)) {
29 return CanDrawPath::kNo;
30 }
31 }
32 SkPath path;
33 args.fShape->asPath(&path);
34 if (SkPathPriv::ConicWeightCnt(path)) {
35 return CanDrawPath::kNo;
36 }
37 return CanDrawPath::kYes;
38}
39
40bool GrGpuTessellationPathRenderer::onDrawPath(const DrawPathArgs& args) {
41 SkPath path;
42 args.fShape->asPath(&path);
43
Chris Daltonf9aea7f2020-01-21 11:19:26 -070044 auto op = args.fContext->priv().opMemoryPool()->allocate<GrTessellatePathOp>(
45 *args.fViewMatrix, path, std::move(args.fPaint), args.fAAType);
46 args.fRenderTargetContext->addDrawOp(*args.fClip, std::move(op));
Chris Daltonb832ce62020-01-06 19:49:37 -070047
48 return true;
49}
50
51void GrGpuTessellationPathRenderer::onStencilPath(const StencilPathArgs& args) {
52 SkPath path;
53 args.fShape->asPath(&path);
54
55 GrAAType aaType = (GrAA::kYes == args.fDoStencilMSAA) ? GrAAType::kMSAA : GrAAType::kNone;
56
Chris Daltonf9aea7f2020-01-21 11:19:26 -070057 auto op = args.fContext->priv().opMemoryPool()->allocate<GrTessellatePathOp>(
58 *args.fViewMatrix, path, GrPaint(), aaType, GrTessellatePathOp::Flags::kStencilOnly);
59 args.fRenderTargetContext->addDrawOp(*args.fClip, std::move(op));
Chris Daltonb832ce62020-01-06 19:49:37 -070060}