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 8 #ifndef GrPathRendererChain_DEFINED 9 #define GrPathRendererChain_DEFINED 10 11 #include "SkRefCnt.h" 12 #include "SkTArray.h" 13 14 class GrContext; 15 class GrDrawTarget; 16 class GrPathRenderer; 17 class SkPath; 18 class SkStrokeRec; 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 57 StencilSupport in GrPathRenderer.h. */ 58 GrPathRenderer* getPathRenderer(const SkPath& path, 59 const SkStrokeRec& rec, 60 const GrDrawTarget* target, 61 DrawType drawType, 62 StencilSupport* stencilSupport); 63 64 private: 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 79 #endif 80