blob: 1c1fe2b27c633d5667e603e052ef1486c199544d [file] [log] [blame]
Chris Daltone1639692018-08-20 14:00:30 -06001/*
2 * Copyright 2017 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#ifndef GrCCPathParser_DEFINED
9#define GrCCPathParser_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkRect.h"
12#include "include/core/SkRefCnt.h"
13#include "src/core/SkPathPriv.h"
14#include "src/gpu/GrMesh.h"
15#include "src/gpu/GrTessellator.h"
16#include "src/gpu/ccpr/GrCCCoverageProcessor.h"
17#include "src/gpu/ccpr/GrCCFillGeometry.h"
18#include "src/gpu/ops/GrDrawOp.h"
Chris Daltone1639692018-08-20 14:00:30 -060019
20class GrOnFlushResourceProvider;
21class SkMatrix;
22class SkPath;
23
24/**
25 * This class parses SkPaths into CCPR primitives in GPU buffers, then issues calls to draw their
26 * coverage counts.
27 */
28class GrCCFiller {
29public:
Chris Dalton09a7bb22018-08-31 19:53:15 +080030 GrCCFiller(int numPaths, int numSkPoints, int numSkVerbs, int numConicWeights);
Chris Daltone1639692018-08-20 14:00:30 -060031
32 // Parses a device-space SkPath into the current batch, using the SkPath's original verbs and
33 // 'deviceSpacePts'. Accepts an optional post-device-space translate for placement in an atlas.
34 void parseDeviceSpaceFill(const SkPath&, const SkPoint* deviceSpacePts, GrScissorTest,
35 const SkIRect& clippedDevIBounds, const SkIVector& devToAtlasOffset);
36
37 using BatchID = int;
38
39 // Compiles the outstanding parsed paths into a batch, and returns an ID that can be used to
40 // draw their fills in the future.
41 BatchID closeCurrentBatch();
42
43 // Builds internal GPU buffers and prepares for calls to drawFills(). Caller must close the
44 // current batch before calling this method, and cannot parse new paths afer.
45 bool prepareToDraw(GrOnFlushResourceProvider*);
46
47 // Called after prepareToDraw(). Draws the given batch of path fills.
Chris Dalton2c5e0112019-03-29 13:14:18 -050048 void drawFills(
49 GrOpFlushState*, GrCCCoverageProcessor*, BatchID, const SkIRect& drawBounds) const;
Chris Daltone1639692018-08-20 14:00:30 -060050
51private:
52 static constexpr int kNumScissorModes = 2;
53 using PrimitiveTallies = GrCCFillGeometry::PrimitiveTallies;
54
55 // Every kBeginPath verb has a corresponding PathInfo entry.
56 class PathInfo {
57 public:
58 PathInfo(GrScissorTest scissorTest, const SkIVector& devToAtlasOffset)
59 : fScissorTest(scissorTest), fDevToAtlasOffset(devToAtlasOffset) {}
60
61 GrScissorTest scissorTest() const { return fScissorTest; }
62 const SkIVector& devToAtlasOffset() const { return fDevToAtlasOffset; }
63
64 // An empty tessellation fan is also valid; we use negative count to denote not tessellated.
65 bool hasFanTessellation() const { return fFanTessellationCount >= 0; }
66 int fanTessellationCount() const {
67 SkASSERT(this->hasFanTessellation());
68 return fFanTessellationCount;
69 }
70 const GrTessellator::WindingVertex* fanTessellation() const {
71 SkASSERT(this->hasFanTessellation());
72 return fFanTessellation.get();
73 }
74 void tessellateFan(const GrCCFillGeometry&, int verbsIdx, int ptsIdx,
75 const SkIRect& clippedDevIBounds, PrimitiveTallies* newTriangleCounts);
76
77 private:
78 GrScissorTest fScissorTest;
79 SkIVector fDevToAtlasOffset; // Translation from device space to location in atlas.
80 int fFanTessellationCount = -1;
81 std::unique_ptr<const GrTessellator::WindingVertex[]> fFanTessellation;
82 };
83
84 // Defines a batch of CCPR primitives. Start indices are deduced by looking at the previous
85 // Batch in the list.
86 struct Batch {
87 PrimitiveTallies fEndNonScissorIndices;
88 int fEndScissorSubBatchIdx;
89 PrimitiveTallies fTotalPrimitiveCounts;
90 };
91
92 // Defines a sub-batch that will be drawn with the given scissor rect. Start indices are deduced
93 // by looking at the previous ScissorSubBatch in the list.
94 struct ScissorSubBatch {
95 PrimitiveTallies fEndPrimitiveIndices;
96 SkIRect fScissor;
97 };
98
Chris Dalton2c5e0112019-03-29 13:14:18 -050099 void drawPrimitives(GrOpFlushState*, const GrCCCoverageProcessor&, const GrPipeline&, BatchID,
100 int PrimitiveTallies::*instanceType, const SkIRect& drawBounds) const;
Chris Daltone1639692018-08-20 14:00:30 -0600101
102 GrCCFillGeometry fGeometry;
103 SkSTArray<32, PathInfo, true> fPathInfos;
104 SkSTArray<32, Batch, true> fBatches;
105 SkSTArray<32, ScissorSubBatch, true> fScissorSubBatches;
106 PrimitiveTallies fTotalPrimitiveCounts[kNumScissorModes];
107 int fMaxMeshesPerDraw = 0;
108
Brian Salomondbf70722019-02-07 11:31:24 -0500109 sk_sp<GrGpuBuffer> fInstanceBuffer;
Chris Daltone1639692018-08-20 14:00:30 -0600110 PrimitiveTallies fBaseInstances[kNumScissorModes];
111 mutable SkSTArray<32, GrMesh> fMeshesScratchBuffer;
112 mutable SkSTArray<32, SkIRect> fScissorRectScratchBuffer;
113};
114
Chris Daltone1639692018-08-20 14:00:30 -0600115#endif