1 | /* |
2 | * Copyright 2011 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 GrPathRendererChain_DEFINED |
9 | #define GrPathRendererChain_DEFINED |
10 | |
11 | #include "src/gpu/GrPathRenderer.h" |
12 | |
13 | #include "include/core/SkTypes.h" |
14 | #include "include/private/GrTypesPriv.h" |
15 | #include "include/private/SkNoncopyable.h" |
16 | #include "include/private/SkTArray.h" |
17 | |
18 | class GrContext; |
19 | class GrCoverageCountingPathRenderer; |
20 | |
21 | /** |
22 | * Keeps track of an ordered list of path renderers. When a path needs to be |
23 | * drawn this list is scanned to find the most preferred renderer. To add your |
24 | * path renderer to the list implement the GrPathRenderer::AddPathRenderers |
25 | * function. |
26 | */ |
27 | class GrPathRendererChain : public SkNoncopyable { |
28 | public: |
29 | struct Options { |
30 | bool fAllowPathMaskCaching = false; |
31 | GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kDefault; |
32 | }; |
33 | GrPathRendererChain(GrRecordingContext* context, const Options&); |
34 | |
35 | /** Documents how the caller plans to use a GrPathRenderer to draw a path. It affects the PR |
36 | returned by getPathRenderer */ |
37 | enum class DrawType { |
38 | kColor, // draw to the color buffer, no AA |
39 | kStencil, // draw just to the stencil buffer |
40 | kStencilAndColor, // draw the stencil and color buffer, no AA |
41 | }; |
42 | |
43 | /** Returns a GrPathRenderer compatible with the request if one is available. If the caller |
44 | is drawing the path to the stencil buffer then stencilSupport can be used to determine |
45 | whether the path can be rendered with arbitrary stencil rules or not. See comments on |
46 | StencilSupport in GrPathRenderer.h. */ |
47 | GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args, |
48 | DrawType drawType, |
49 | GrPathRenderer::StencilSupport* stencilSupport); |
50 | |
51 | /** Returns a direct pointer to the coverage counting path renderer, or null if it is not in the |
52 | chain. */ |
53 | GrCoverageCountingPathRenderer* getCoverageCountingPathRenderer() { |
54 | return fCoverageCountingPathRenderer; |
55 | } |
56 | |
57 | private: |
58 | enum { |
59 | kPreAllocCount = 8, |
60 | }; |
61 | SkSTArray<kPreAllocCount, sk_sp<GrPathRenderer>> fChain; |
62 | GrCoverageCountingPathRenderer* fCoverageCountingPathRenderer = nullptr; |
63 | }; |
64 | |
65 | #endif |
66 | |