blob: 0f2fcbdd1ab309e953d7e23f1f93277e428aa962 [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
44 GrOpMemoryPool* pool = args.fContext->priv().opMemoryPool();
45 args.fRenderTargetContext->addDrawOp(*args.fClip, pool->allocate<GrTessellatePathOp>(
46 *args.fViewMatrix, path, std::move(args.fPaint), args.fAAType));
47
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
57 GrOpMemoryPool* pool = args.fContext->priv().opMemoryPool();
58 args.fRenderTargetContext->addDrawOp(*args.fClip, pool->allocate<GrTessellatePathOp>(
59 *args.fViewMatrix, path, GrPaint(), aaType, GrTessellatePathOp::Flags::kStencilOnly));
60}