blob: de17e53d81e63b3d733f2ed7170c2f6c6de9038c [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"
robertphillips13391dd2015-10-30 05:15:11 -070014#include "SkTypes.h"
bsalomon@google.com45a15f52012-12-10 19:10:17 +000015#include "SkTArray.h"
16
17class GrContext;
Chris Daltonfddb6c02017-11-04 15:22:22 -060018class GrCoverageCountingPathRenderer;
bsalomon@google.com45a15f52012-12-10 19:10:17 +000019
20/**
21 * Keeps track of an ordered list of path renderers. When a path needs to be
22 * drawn this list is scanned to find the most preferred renderer. To add your
23 * path renderer to the list implement the GrPathRenderer::AddPathRenderers
24 * function.
25 */
robertphillips13391dd2015-10-30 05:15:11 -070026class GrPathRendererChain : public SkNoncopyable {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000027public:
bsalomon6b2552f2016-09-15 13:50:26 -070028 struct Options {
bsalomon39ef7fb2016-09-21 11:16:05 -070029 bool fAllowPathMaskCaching = false;
Brian Osman8b0f2652017-08-29 15:18:34 -040030 GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kDefault;
bsalomon6b2552f2016-09-15 13:50:26 -070031 };
32 GrPathRendererChain(GrContext* context, const Options&);
bsalomon@google.com45a15f52012-12-10 19:10:17 +000033
bsalomon@google.com45a15f52012-12-10 19:10:17 +000034 /** Documents how the caller plans to use a GrPathRenderer to draw a path. It affects the PR
35 returned by getPathRenderer */
Brian Salomon82125e92016-12-10 09:35:48 -050036 enum class DrawType {
37 kColor, // draw to the color buffer, no AA
38 kStencil, // draw just to the stencil buffer
39 kStencilAndColor, // draw the stencil and color buffer, no AA
bsalomon@google.com45a15f52012-12-10 19:10:17 +000040 };
robertphillips68737822015-10-29 12:12:21 -070041
bsalomon@google.com45a15f52012-12-10 19:10:17 +000042 /** Returns a GrPathRenderer compatible with the request if one is available. If the caller
43 is drawing the path to the stencil buffer then stencilSupport can be used to determine
44 whether the path can be rendered with arbitrary stencil rules or not. See comments on
skia.committer@gmail.comc7b4be72012-12-11 02:01:20 +000045 StencilSupport in GrPathRenderer.h. */
robertphillips68737822015-10-29 12:12:21 -070046 GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
bsalomon@google.com45a15f52012-12-10 19:10:17 +000047 DrawType drawType,
robertphillips68737822015-10-29 12:12:21 -070048 GrPathRenderer::StencilSupport* stencilSupport);
bsalomon@google.com45a15f52012-12-10 19:10:17 +000049
Chris Daltonfddb6c02017-11-04 15:22:22 -060050 /** Returns a direct pointer to the coverage counting path renderer, or null if it is not in the
51 chain. */
52 GrCoverageCountingPathRenderer* getCoverageCountingPathRenderer() {
53 return fCoverageCountingPathRenderer;
54 }
55
bsalomon@google.com45a15f52012-12-10 19:10:17 +000056private:
bsalomon@google.com45a15f52012-12-10 19:10:17 +000057 enum {
58 kPreAllocCount = 8,
59 };
csmartdalton008b9d82017-02-22 12:00:42 -070060 SkSTArray<kPreAllocCount, sk_sp<GrPathRenderer>> fChain;
Chris Daltonfddb6c02017-11-04 15:22:22 -060061 GrCoverageCountingPathRenderer* fCoverageCountingPathRenderer = nullptr;
bsalomon@google.com45a15f52012-12-10 19:10:17 +000062};
63
bsalomon@google.com45a15f52012-12-10 19:10:17 +000064#endif