1 | /* |
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 | #ifndef GrTessellationPathRenderer_DEFINED |
9 | #define GrTessellationPathRenderer_DEFINED |
10 | |
11 | #include "src/gpu/GrDynamicAtlas.h" |
12 | #include "src/gpu/GrOnFlushResourceProvider.h" |
13 | #include "src/gpu/GrPathRenderer.h" |
14 | #include <map> |
15 | |
16 | // This is the tie-in point for path rendering via GrTessellatePathOp. This path renderer draws |
17 | // paths using a hybrid Red Book "stencil, then cover" method. Curves get linearized by GPU |
18 | // tessellation shaders. This path renderer doesn't apply analytic AA, so it requires a render |
19 | // target that supports either MSAA or mixed samples if AA is desired. |
20 | class GrTessellationPathRenderer : public GrPathRenderer, public GrOnFlushCallbackObject { |
21 | public: |
22 | GrTessellationPathRenderer(const GrCaps&); |
23 | StencilSupport onGetStencilSupport(const GrShape& shape) const override { |
24 | // TODO: Single-pass (e.g., convex) paths can have full support. |
25 | return kStencilOnly_StencilSupport; |
26 | } |
27 | CanDrawPath onCanDrawPath(const CanDrawPathArgs&) const override; |
28 | bool onDrawPath(const DrawPathArgs&) override; |
29 | void onStencilPath(const StencilPathArgs&) override; |
30 | void preFlush(GrOnFlushResourceProvider*, const uint32_t* opsTaskIDs, |
31 | int numOpsTaskIDs) override; |
32 | |
33 | private: |
34 | SkPath* getAtlasUberPath(SkPathFillType fillType, bool antialias) { |
35 | int idx = (int)antialias << 1; |
36 | idx |= (int)fillType & 1; |
37 | return &fAtlasUberPaths[idx]; |
38 | } |
39 | // Allocates space in fAtlas if the path is small and simple enough, and if there is room. |
40 | bool tryAddPathToAtlas(const GrCaps&, const SkMatrix&, const SkPath&, GrAAType, |
41 | SkIRect* devIBounds, SkIVector* devToAtlasOffset); |
42 | void renderAtlas(GrOnFlushResourceProvider*); |
43 | |
44 | GrDynamicAtlas fAtlas; |
45 | SkPath fAtlasUberPaths[4]; // 2 fillTypes * 2 antialias modes. |
46 | }; |
47 | |
48 | #endif |
49 | |