blob: 7c8a29c2c5a6dfa7b81316f6dff1adc348898bc1 [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());
22 if (!args.fShape->style().isSimpleFill() || args.fShape->inverseFilled()) {
23 return CanDrawPath::kNo;
24 }
25 if (GrAAType::kCoverage == args.fAAType) {
26 SkASSERT(1 == args.fProxy->numSamples());
27 if (!args.fProxy->canUseMixedSamples(*args.fCaps)) {
28 return CanDrawPath::kNo;
29 }
30 }
31 SkPath path;
32 args.fShape->asPath(&path);
33 if (SkPathPriv::ConicWeightCnt(path)) {
34 return CanDrawPath::kNo;
35 }
36 return CanDrawPath::kYes;
37}
38
39bool GrGpuTessellationPathRenderer::onDrawPath(const DrawPathArgs& args) {
40 SkPath path;
41 args.fShape->asPath(&path);
42
43 GrOpMemoryPool* pool = args.fContext->priv().opMemoryPool();
44 args.fRenderTargetContext->addDrawOp(*args.fClip, pool->allocate<GrTessellatePathOp>(
45 *args.fViewMatrix, path, std::move(args.fPaint), args.fAAType));
46
47 return true;
48}
49
50void GrGpuTessellationPathRenderer::onStencilPath(const StencilPathArgs& args) {
51 SkPath path;
52 args.fShape->asPath(&path);
53
54 GrAAType aaType = (GrAA::kYes == args.fDoStencilMSAA) ? GrAAType::kMSAA : GrAAType::kNone;
55
56 GrOpMemoryPool* pool = args.fContext->priv().opMemoryPool();
57 args.fRenderTargetContext->addDrawOp(*args.fClip, pool->allocate<GrTessellatePathOp>(
58 *args.fViewMatrix, path, GrPaint(), aaType, GrTessellatePathOp::Flags::kStencilOnly));
59}