blob: 3542ec4548756f9067c600d1d3a8305423420bb7 [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
robertphillips68737822015-10-29 12:12:21 -070011#include "GrPathRenderer.h"
12
Brian Osman195c05b2017-08-30 15:14:04 -040013#include "GrTypesPriv.h"
Ben Wagnerd5148e32018-07-16 17:44:06 -040014#include "SkNoncopyable.h"
robertphillips13391dd2015-10-30 05:15:11 -070015#include "SkTypes.h"
bsalomon@google.com45a15f52012-12-10 19:10:17 +000016#include "SkTArray.h"
17
18class GrContext;
Chris Daltonfddb6c02017-11-04 15:22:22 -060019class GrCoverageCountingPathRenderer;
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 Dalton9acfc6c2018-07-26 12:34:49 -060031 GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kAll;
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 Daltonfddb6c02017-11-04 15:22:22 -060051 /** Returns a direct pointer to the coverage counting path renderer, or null if it is not in the
52 chain. */
53 GrCoverageCountingPathRenderer* getCoverageCountingPathRenderer() {
54 return fCoverageCountingPathRenderer;
55 }
56
bsalomon@google.com45a15f52012-12-10 19:10:17 +000057private:
bsalomon@google.com45a15f52012-12-10 19:10:17 +000058 enum {
59 kPreAllocCount = 8,
60 };
csmartdalton008b9d82017-02-22 12:00:42 -070061 SkSTArray<kPreAllocCount, sk_sp<GrPathRenderer>> fChain;
Chris Daltonfddb6c02017-11-04 15:22:22 -060062 GrCoverageCountingPathRenderer* fCoverageCountingPathRenderer = nullptr;
bsalomon@google.com45a15f52012-12-10 19:10:17 +000063};
64
bsalomon@google.com45a15f52012-12-10 19:10:17 +000065#endif