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