blob: ca8c35bdeb371c39189fa4a8ede6415e64b5ae1f [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
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000011#include "SkRefCnt.h"
bsalomon@google.com45a15f52012-12-10 19:10:17 +000012#include "SkTArray.h"
13
14class GrContext;
15class GrDrawTarget;
16class GrPathRenderer;
17class SkPath;
sugoi@google.com5f74cf82012-12-17 21:16:45 +000018class SkStrokeRec;
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 */
26class GrPathRendererChain : public SkRefCnt {
27public:
28 // See comments in GrPathRenderer.h
29 enum StencilSupport {
30 kNoSupport_StencilSupport,
31 kStencilOnly_StencilSupport,
32 kNoRestriction_StencilSupport,
33 };
34
35 SK_DECLARE_INST_COUNT(GrPathRendererChain)
36
37 GrPathRendererChain(GrContext* context);
38
39 ~GrPathRendererChain();
40
41 // takes a ref and unrefs in destructor
42 GrPathRenderer* addPathRenderer(GrPathRenderer* pr);
43
44 /** Documents how the caller plans to use a GrPathRenderer to draw a path. It affects the PR
45 returned by getPathRenderer */
46 enum DrawType {
47 kColor_DrawType, // draw to the color buffer, no AA
48 kColorAntiAlias_DrawType, // draw to color buffer, with partial coverage AA
49 kStencilOnly_DrawType, // draw just to the stencil buffer
50 kStencilAndColor_DrawType, // draw the stencil and color buffer, no AA
51 kStencilAndColorAntiAlias_DrawType // draw the stencil and color buffer, with partial
52 // coverage AA.
53 };
54 /** Returns a GrPathRenderer compatible with the request if one is available. If the caller
55 is drawing the path to the stencil buffer then stencilSupport can be used to determine
56 whether the path can be rendered with arbitrary stencil rules or not. See comments on
skia.committer@gmail.comc7b4be72012-12-11 02:01:20 +000057 StencilSupport in GrPathRenderer.h. */
bsalomon@google.com45a15f52012-12-10 19:10:17 +000058 GrPathRenderer* getPathRenderer(const SkPath& path,
sugoi@google.com5f74cf82012-12-17 21:16:45 +000059 const SkStrokeRec& rec,
bsalomon@google.com45a15f52012-12-10 19:10:17 +000060 const GrDrawTarget* target,
61 DrawType drawType,
62 StencilSupport* stencilSupport);
63
64private:
bsalomon@google.com45a15f52012-12-10 19:10:17 +000065 GrPathRendererChain();
66
67 void init();
68
69 enum {
70 kPreAllocCount = 8,
71 };
72 bool fInit;
73 GrContext* fOwner;
74 SkSTArray<kPreAllocCount, GrPathRenderer*, true> fChain;
75
76 typedef SkRefCnt INHERITED;
77};
78
bsalomon@google.com45a15f52012-12-10 19:10:17 +000079#endif