blob: ade30551ae5011a014e1229767a1d87a916ccb75 [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
robertphillips13391dd2015-10-30 05:15:11 -070013#include "SkTypes.h"
bsalomon@google.com45a15f52012-12-10 19:10:17 +000014#include "SkTArray.h"
15
16class GrContext;
bsalomon@google.com45a15f52012-12-10 19:10:17 +000017
18/**
19 * Keeps track of an ordered list of path renderers. When a path needs to be
20 * drawn this list is scanned to find the most preferred renderer. To add your
21 * path renderer to the list implement the GrPathRenderer::AddPathRenderers
22 * function.
23 */
robertphillips13391dd2015-10-30 05:15:11 -070024class GrPathRendererChain : public SkNoncopyable {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000025public:
bsalomon@google.com45a15f52012-12-10 19:10:17 +000026 GrPathRendererChain(GrContext* context);
27
28 ~GrPathRendererChain();
29
bsalomon@google.com45a15f52012-12-10 19:10:17 +000030 /** Documents how the caller plans to use a GrPathRenderer to draw a path. It affects the PR
31 returned by getPathRenderer */
32 enum DrawType {
33 kColor_DrawType, // draw to the color buffer, no AA
34 kColorAntiAlias_DrawType, // draw to color buffer, with partial coverage AA
35 kStencilOnly_DrawType, // draw just to the stencil buffer
36 kStencilAndColor_DrawType, // draw the stencil and color buffer, no AA
37 kStencilAndColorAntiAlias_DrawType // draw the stencil and color buffer, with partial
38 // coverage AA.
39 };
robertphillips68737822015-10-29 12:12:21 -070040
bsalomon@google.com45a15f52012-12-10 19:10:17 +000041 /** Returns a GrPathRenderer compatible with the request if one is available. If the caller
42 is drawing the path to the stencil buffer then stencilSupport can be used to determine
43 whether the path can be rendered with arbitrary stencil rules or not. See comments on
skia.committer@gmail.comc7b4be72012-12-11 02:01:20 +000044 StencilSupport in GrPathRenderer.h. */
robertphillips68737822015-10-29 12:12:21 -070045 GrPathRenderer* getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
bsalomon@google.com45a15f52012-12-10 19:10:17 +000046 DrawType drawType,
robertphillips68737822015-10-29 12:12:21 -070047 GrPathRenderer::StencilSupport* stencilSupport);
bsalomon@google.com45a15f52012-12-10 19:10:17 +000048
49private:
robertphillips68737822015-10-29 12:12:21 -070050 // takes a ref and unrefs in destructor
51 GrPathRenderer* addPathRenderer(GrPathRenderer* pr);
52
bsalomon@google.com45a15f52012-12-10 19:10:17 +000053 enum {
54 kPreAllocCount = 8,
55 };
bsalomon@google.com45a15f52012-12-10 19:10:17 +000056 SkSTArray<kPreAllocCount, GrPathRenderer*, true> fChain;
bsalomon@google.com45a15f52012-12-10 19:10:17 +000057};
58
bsalomon@google.com45a15f52012-12-10 19:10:17 +000059#endif