blob: 53bf0bcb1df153a9ca8cea53af90bad573622228 [file] [log] [blame]
bsalomon@google.com45a15f52012-12-10 19:10:17 +00001/*
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.com45a15f52012-12-10 19:10:17 +00008#ifndef GrPathRendererChain_DEFINED
9#define GrPathRendererChain_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/GrPathRenderer.h"
robertphillips68737822015-10-29 12:12:21 -070012
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#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.com45a15f52012-12-10 19:10:17 +000017
Chris Daltonc3176002021-07-23 15:33:09 -060018class GrAtlasPathRenderer;
Chris Dalton43a8b0c2021-06-14 17:10:07 -060019class GrTessellationPathRenderer;
bsalomon@google.com45a15f52012-12-10 19:10:17 +000020
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 */
robertphillips13391dd2015-10-30 05:15:11 -070027class GrPathRendererChain : public SkNoncopyable {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000028public:
bsalomon6b2552f2016-09-15 13:50:26 -070029 struct Options {
bsalomon39ef7fb2016-09-21 11:16:05 -070030 bool fAllowPathMaskCaching = false;
Chris Dalton37ae4b02019-12-28 14:51:11 -070031 GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kDefault;
bsalomon6b2552f2016-09-15 13:50:26 -070032 };
Robert Phillips69893702019-02-22 11:16:30 -050033 GrPathRendererChain(GrRecordingContext* context, const Options&);
bsalomon@google.com45a15f52012-12-10 19:10:17 +000034
bsalomon@google.com45a15f52012-12-10 19:10:17 +000035 /** Documents how the caller plans to use a GrPathRenderer to draw a path. It affects the PR
36 returned by getPathRenderer */
Brian Salomon82125e92016-12-10 09:35:48 -050037 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.com45a15f52012-12-10 19:10:17 +000041 };
robertphillips68737822015-10-29 12:12:21 -070042
bsalomon@google.com45a15f52012-12-10 19:10:17 +000043 /** 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.comc7b4be72012-12-11 02:01:20 +000046 StencilSupport in GrPathRenderer.h. */
robertphillips68737822015-10-29 12:12:21 -070047 GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
bsalomon@google.com45a15f52012-12-10 19:10:17 +000048 DrawType drawType,
robertphillips68737822015-10-29 12:12:21 -070049 GrPathRenderer::StencilSupport* stencilSupport);
bsalomon@google.com45a15f52012-12-10 19:10:17 +000050
Chris Daltonc3176002021-07-23 15:33:09 -060051 /** 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 Daltone6ae4762021-02-05 14:56:21 -070057 /** Returns a direct pointer to the tessellation path renderer, or null if it is not in the
58 chain. */
Chris Dalton43a8b0c2021-06-14 17:10:07 -060059 GrTessellationPathRenderer* getTessellationPathRenderer() {
Chris Daltone6ae4762021-02-05 14:56:21 -070060 return fTessellationPathRenderer;
61 }
62
bsalomon@google.com45a15f52012-12-10 19:10:17 +000063private:
bsalomon@google.com45a15f52012-12-10 19:10:17 +000064 enum {
65 kPreAllocCount = 8,
66 };
csmartdalton008b9d82017-02-22 12:00:42 -070067 SkSTArray<kPreAllocCount, sk_sp<GrPathRenderer>> fChain;
Chris Daltonc3176002021-07-23 15:33:09 -060068 GrAtlasPathRenderer* fAtlasPathRenderer = nullptr;
Chris Dalton43a8b0c2021-06-14 17:10:07 -060069 GrTessellationPathRenderer* fTessellationPathRenderer = nullptr;
bsalomon@google.com45a15f52012-12-10 19:10:17 +000070};
71
bsalomon@google.com45a15f52012-12-10 19:10:17 +000072#endif