bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | |
| 10 | #ifndef GrPathRendererChain_DEFINED |
| 11 | #define GrPathRendererChain_DEFINED |
| 12 | |
| 13 | #include "GrRefCnt.h" |
| 14 | #include "SkTArray.h" |
| 15 | |
| 16 | class GrContext; |
| 17 | class GrDrawTarget; |
| 18 | class GrPathRenderer; |
| 19 | class SkPath; |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 20 | class SkStrokeRec; |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * Keeps track of an ordered list of path renderers. When a path needs to be |
| 24 | * drawn this list is scanned to find the most preferred renderer. To add your |
| 25 | * path renderer to the list implement the GrPathRenderer::AddPathRenderers |
| 26 | * function. |
| 27 | */ |
| 28 | class GrPathRendererChain : public SkRefCnt { |
| 29 | public: |
| 30 | // See comments in GrPathRenderer.h |
| 31 | enum StencilSupport { |
| 32 | kNoSupport_StencilSupport, |
| 33 | kStencilOnly_StencilSupport, |
| 34 | kNoRestriction_StencilSupport, |
| 35 | }; |
| 36 | |
| 37 | SK_DECLARE_INST_COUNT(GrPathRendererChain) |
| 38 | |
| 39 | GrPathRendererChain(GrContext* context); |
| 40 | |
| 41 | ~GrPathRendererChain(); |
| 42 | |
| 43 | // takes a ref and unrefs in destructor |
| 44 | GrPathRenderer* addPathRenderer(GrPathRenderer* pr); |
| 45 | |
| 46 | /** Documents how the caller plans to use a GrPathRenderer to draw a path. It affects the PR |
| 47 | returned by getPathRenderer */ |
| 48 | enum DrawType { |
| 49 | kColor_DrawType, // draw to the color buffer, no AA |
| 50 | kColorAntiAlias_DrawType, // draw to color buffer, with partial coverage AA |
| 51 | kStencilOnly_DrawType, // draw just to the stencil buffer |
| 52 | kStencilAndColor_DrawType, // draw the stencil and color buffer, no AA |
| 53 | kStencilAndColorAntiAlias_DrawType // draw the stencil and color buffer, with partial |
| 54 | // coverage AA. |
| 55 | }; |
| 56 | /** Returns a GrPathRenderer compatible with the request if one is available. If the caller |
| 57 | is drawing the path to the stencil buffer then stencilSupport can be used to determine |
| 58 | 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] | 59 | StencilSupport in GrPathRenderer.h. */ |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 60 | GrPathRenderer* getPathRenderer(const SkPath& path, |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 61 | const SkStrokeRec& rec, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 62 | const GrDrawTarget* target, |
| 63 | DrawType drawType, |
| 64 | StencilSupport* stencilSupport); |
| 65 | |
| 66 | private: |
| 67 | |
| 68 | GrPathRendererChain(); |
| 69 | |
| 70 | void init(); |
| 71 | |
| 72 | enum { |
| 73 | kPreAllocCount = 8, |
| 74 | }; |
| 75 | bool fInit; |
| 76 | GrContext* fOwner; |
| 77 | SkSTArray<kPreAllocCount, GrPathRenderer*, true> fChain; |
| 78 | |
| 79 | typedef SkRefCnt INHERITED; |
| 80 | }; |
| 81 | |
| 82 | |
| 83 | #endif |