robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 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 | #ifndef GrClipMaskManager_DEFINED |
| 10 | #define GrClipMaskManager_DEFINED |
| 11 | |
| 12 | #include "GrRect.h" |
bsalomon@google.com | 8d033a1 | 2012-04-27 15:52:53 +0000 | [diff] [blame] | 13 | #include "SkPath.h" |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 14 | |
| 15 | class GrGpu; |
| 16 | class GrClip; |
| 17 | class GrPathRenderer; |
| 18 | class GrPathRendererChain; |
| 19 | class SkPath; |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 20 | class GrTexture; |
| 21 | class GrDrawState; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Scissoring needs special handling during stencil clip mask creation |
| 25 | * since the creation process re-entrantly invokes setupClipAndFlushState. |
| 26 | * During this process the call stack is used to keep |
| 27 | * track of (and apply to the GPU) the current scissor settings. |
| 28 | */ |
| 29 | struct ScissoringSettings { |
| 30 | bool fEnableScissoring; |
| 31 | GrIRect fScissorRect; |
| 32 | |
| 33 | void setupScissoring(GrGpu* gpu); |
| 34 | }; |
| 35 | |
| 36 | |
| 37 | /** |
| 38 | * The clip mask creator handles the generation of the clip mask. If anti |
| 39 | * aliasing is requested it will (in the future) generate a single channel |
| 40 | * (8bit) mask. If no anti aliasing is requested it will generate a 1-bit |
| 41 | * mask in the stencil buffer. In the non anti-aliasing case, if the clip |
| 42 | * mask can be represented as a rectangle then scissoring is used. In all |
| 43 | * cases scissoring is used to bound the range of the clip mask. |
| 44 | */ |
| 45 | class GrClipMaskManager { |
| 46 | public: |
| 47 | GrClipMaskManager() |
| 48 | : fClipMaskInStencil(false) |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 49 | , fClipMaskInAlpha(false) |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 50 | , fPathRendererChain(NULL) { |
| 51 | } |
| 52 | |
| 53 | bool createClipMask(GrGpu* gpu, |
| 54 | const GrClip& clip, |
| 55 | ScissoringSettings* scissorSettings); |
| 56 | |
| 57 | void freeResources(); |
| 58 | |
| 59 | bool isClipInStencil() const { return fClipMaskInStencil; } |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 60 | bool isClipInAlpha() const { return fClipMaskInAlpha; } |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 61 | |
| 62 | void resetMask() { |
| 63 | fClipMaskInStencil = false; |
| 64 | } |
| 65 | |
| 66 | protected: |
| 67 | private: |
| 68 | bool fClipMaskInStencil; // is the clip mask in the stencil buffer? |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 69 | bool fClipMaskInAlpha; // is the clip mask in an alpha texture? |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 70 | |
| 71 | // must be instantiated after GrGpu object has been given its owning |
| 72 | // GrContext ptr. (GrGpu is constructed first then handed off to GrContext). |
| 73 | GrPathRendererChain* fPathRendererChain; |
| 74 | |
| 75 | bool createStencilClipMask(GrGpu* gpu, |
| 76 | const GrClip& clip, |
| 77 | const GrRect& bounds, |
| 78 | ScissoringSettings* scissorSettings); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 79 | bool createAlphaClipMask(GrGpu* gpu, const GrClip& clipIn); |
| 80 | |
| 81 | bool drawPath(GrGpu* gpu, |
bsalomon@google.com | 8d033a1 | 2012-04-27 15:52:53 +0000 | [diff] [blame] | 82 | const SkPath& path, |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 83 | GrPathFill fill, |
| 84 | bool doAA); |
| 85 | |
| 86 | bool drawClipShape(GrGpu* gpu, |
| 87 | GrTexture* target, |
| 88 | const GrClip& clipIn, |
| 89 | int index); |
| 90 | |
| 91 | void drawTexture(GrGpu* gpu, |
| 92 | GrTexture* target, |
| 93 | const GrRect& rect, |
| 94 | GrTexture* texture); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 95 | |
| 96 | // determines the path renderer used to draw a clip path element. |
| 97 | GrPathRenderer* getClipPathRenderer(GrGpu* gpu, |
| 98 | const SkPath& path, |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 99 | GrPathFill fill, |
| 100 | bool antiAlias); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 101 | |
| 102 | }; |
| 103 | |
| 104 | #endif // GrClipMaskManager_DEFINED |