bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 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 | |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 8 | #ifndef GrPathRendererChain_DEFINED |
| 9 | #define GrPathRendererChain_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/GrPathRenderer.h" |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 12 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "include/core/SkTypes.h" |
| 14 | #include "include/private/GrTypesPriv.h" |
| 15 | #include "include/private/SkNoncopyable.h" |
| 16 | #include "include/private/SkTArray.h" |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 17 | |
Chris Dalton | c317600 | 2021-07-23 15:33:09 -0600 | [diff] [blame] | 18 | class GrAtlasPathRenderer; |
Chris Dalton | 43a8b0c | 2021-06-14 17:10:07 -0600 | [diff] [blame] | 19 | class GrTessellationPathRenderer; |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 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 | */ |
robertphillips | 13391dd | 2015-10-30 05:15:11 -0700 | [diff] [blame] | 27 | class GrPathRendererChain : public SkNoncopyable { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 28 | public: |
bsalomon | 6b2552f | 2016-09-15 13:50:26 -0700 | [diff] [blame] | 29 | struct Options { |
bsalomon | 39ef7fb | 2016-09-21 11:16:05 -0700 | [diff] [blame] | 30 | bool fAllowPathMaskCaching = false; |
Chris Dalton | 37ae4b0 | 2019-12-28 14:51:11 -0700 | [diff] [blame] | 31 | GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kDefault; |
bsalomon | 6b2552f | 2016-09-15 13:50:26 -0700 | [diff] [blame] | 32 | }; |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 33 | GrPathRendererChain(GrRecordingContext* context, const Options&); |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 34 | |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 35 | /** Documents how the caller plans to use a GrPathRenderer to draw a path. It affects the PR |
| 36 | returned by getPathRenderer */ |
Brian Salomon | 82125e9 | 2016-12-10 09:35:48 -0500 | [diff] [blame] | 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 |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 41 | }; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 42 | |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 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 |
skia.committer@gmail.com | c7b4be7 | 2012-12-11 02:01:20 +0000 | [diff] [blame] | 46 | StencilSupport in GrPathRenderer.h. */ |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 47 | GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 48 | DrawType drawType, |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 49 | GrPathRenderer::StencilSupport* stencilSupport); |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 50 | |
Chris Dalton | c317600 | 2021-07-23 15:33:09 -0600 | [diff] [blame] | 51 | /** Returns a direct pointer to the atlas path renderer, or null if it is not in the |
| 52 | chain. */ |
| 53 | GrAtlasPathRenderer* getAtlasPathRenderer() { |
| 54 | return fAtlasPathRenderer; |
| 55 | } |
| 56 | |
Chris Dalton | e6ae476 | 2021-02-05 14:56:21 -0700 | [diff] [blame] | 57 | /** Returns a direct pointer to the tessellation path renderer, or null if it is not in the |
| 58 | chain. */ |
Chris Dalton | 43a8b0c | 2021-06-14 17:10:07 -0600 | [diff] [blame] | 59 | GrTessellationPathRenderer* getTessellationPathRenderer() { |
Chris Dalton | e6ae476 | 2021-02-05 14:56:21 -0700 | [diff] [blame] | 60 | return fTessellationPathRenderer; |
| 61 | } |
| 62 | |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 63 | private: |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 64 | enum { |
| 65 | kPreAllocCount = 8, |
| 66 | }; |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 67 | SkSTArray<kPreAllocCount, sk_sp<GrPathRenderer>> fChain; |
Chris Dalton | c317600 | 2021-07-23 15:33:09 -0600 | [diff] [blame] | 68 | GrAtlasPathRenderer* fAtlasPathRenderer = nullptr; |
Chris Dalton | 43a8b0c | 2021-06-14 17:10:07 -0600 | [diff] [blame] | 69 | GrTessellationPathRenderer* fTessellationPathRenderer = nullptr; |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 72 | #endif |