| 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 PathRendererChain_DEFINED |
| 9 |
#define PathRendererChain_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkRefCnt.h" |
| 12 |
#include "include/core/SkTypes.h" |
| 13 |
#include "include/private/base/SkNoncopyable.h" |
| 14 |
#include "include/private/base/SkTArray.h" |
| 15 |
#include "include/private/gpu/ganesh/GrTypesPriv.h" |
| 16 |
#include "src/gpu/ganesh/PathRenderer.h" |
| 17 |
#include "src/gpu/ganesh/ops/AtlasRenderTask.h" // IWYU pragma: keep |
| 18 |
|
| 19 |
#include <cstddef> |
| 20 |
|
| 21 |
class GrRecordingContext; |
| 22 |
|
| 23 |
namespace skgpu::ganesh { |
| 24 |
|
| 25 |
class AtlasPathRenderer; |
| 26 |
|
| 27 |
/** |
| 28 |
* Keeps track of an ordered list of path renderers. When a path needs to be |
| 29 |
* drawn this list is scanned to find the most preferred renderer. To add your |
| 30 |
* path renderer to the list implement the GrPathRenderer::AddPathRenderers |
| 31 |
* function. |
| 32 |
*/ |
| 33 |
class PathRendererChain : public SkNoncopyable { |
| 34 |
public: |
| 35 |
struct Options { |
| 36 |
bool fAllowPathMaskCaching = false; |
| 37 |
GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kDefault; |
| 38 |
}; |
| 39 |
PathRendererChain(GrRecordingContext*, const Options&); |
| 40 |
|
| 41 |
/** Documents how the caller plans to use a GrPathRenderer to draw a path. It affects the PR |
| 42 |
returned by getPathRenderer */ |
| 43 |
enum class DrawType { |
| 44 |
kColor, // draw to the color buffer, no AA |
| 45 |
kStencil, // draw just to the stencil buffer |
| 46 |
kStencilAndColor, // draw the stencil and color buffer, no AA |
| 47 |
}; |
| 48 |
|
| 49 |
/** Returns a GrPathRenderer compatible with the request if one is available. If the caller |
| 50 |
is drawing the path to the stencil buffer then stencilSupport can be used to determine |
| 51 |
whether the path can be rendered with arbitrary stencil rules or not. See comments on |
| 52 |
StencilSupport in GrPathRenderer.h. */ |
| 53 |
PathRenderer* getPathRenderer(const PathRenderer::CanDrawPathArgs&, |
| 54 |
DrawType, |
| 55 |
PathRenderer::StencilSupport*); |
| 56 |
|
| 57 |
/** Returns a direct pointer to the atlas path renderer, or null if it is not in the |
| 58 |
chain. */ |
| 59 |
skgpu::ganesh::AtlasPathRenderer* getAtlasPathRenderer() { return fAtlasPathRenderer; } |
| 60 |
|
| 61 |
/** Returns a direct pointer to the tessellation path renderer, or null if it is not in the |
| 62 |
chain. */ |
| 63 |
PathRenderer* getTessellationPathRenderer() { |
| 64 |
return fTessellationPathRenderer; |
| 65 |
} |
| 66 |
|
| 67 |
private: |
| 68 |
static constexpr size_t kPreAllocCount = 8; |
| 69 |
|
| 70 |
skia_private::STArray<kPreAllocCount, sk_sp<PathRenderer>> fChain; |
| 71 |
AtlasPathRenderer* fAtlasPathRenderer = nullptr; |
| 72 |
PathRenderer* fTessellationPathRenderer = nullptr; |
| 73 |
}; |
| 74 |
|
| 75 |
} // namespace skgpu::ganesh |
| 76 |
|
| 77 |
#endif // PathRendererChain_DEFINED |