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