bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 1 | /* |
| 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.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 8 | #ifndef GrPathRendererChain_DEFINED |
| 9 | #define GrPathRendererChain_DEFINED |
| 10 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 11 | #include "SkRefCnt.h" |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 12 | #include "SkTArray.h" |
| 13 | |
| 14 | class GrContext; |
| 15 | class GrDrawTarget; |
| 16 | class GrPathRenderer; |
| 17 | class SkPath; |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 18 | class SkStrokeRec; |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 19 | |
| 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 | */ |
| 26 | class GrPathRendererChain : public SkRefCnt { |
| 27 | public: |
| 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.com | c7b4be7 | 2012-12-11 02:01:20 +0000 | [diff] [blame] | 57 | StencilSupport in GrPathRenderer.h. */ |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 58 | GrPathRenderer* getPathRenderer(const SkPath& path, |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 59 | const SkStrokeRec& rec, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 60 | const GrDrawTarget* target, |
| 61 | DrawType drawType, |
| 62 | StencilSupport* stencilSupport); |
| 63 | |
| 64 | private: |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 65 | 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.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 79 | #endif |