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 | |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 12 | #include "GrContext.h" |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 13 | #include "GrNoncopyable.h" |
| 14 | #include "GrRect.h" |
| 15 | #include "GrStencil.h" |
| 16 | #include "GrTexture.h" |
| 17 | |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 18 | #include "SkClipStack.h" |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 19 | #include "SkDeque.h" |
| 20 | #include "SkPath.h" |
| 21 | #include "SkRefCnt.h" |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 22 | |
robertphillips@google.com | 1fcc1b8 | 2012-08-29 12:52:05 +0000 | [diff] [blame] | 23 | #include "GrClipMaskCache.h" |
| 24 | |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 25 | class GrGpu; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 26 | class GrPathRenderer; |
| 27 | class GrPathRendererChain; |
| 28 | class SkPath; |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 29 | class GrTexture; |
| 30 | class GrDrawState; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 31 | |
| 32 | /** |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 33 | * The clip mask creator handles the generation of the clip mask. If anti |
| 34 | * aliasing is requested it will (in the future) generate a single channel |
| 35 | * (8bit) mask. If no anti aliasing is requested it will generate a 1-bit |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 36 | * mask in the stencil buffer. In the non anti-aliasing case, if the clip |
| 37 | * mask can be represented as a rectangle then scissoring is used. In all |
| 38 | * cases scissoring is used to bound the range of the clip mask. |
| 39 | */ |
robertphillips@google.com | fd6daf5 | 2012-05-02 19:32:32 +0000 | [diff] [blame] | 40 | class GrClipMaskManager : public GrNoncopyable { |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 41 | public: |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 42 | GR_DECLARE_RESOURCE_CACHE_DOMAIN(GetAlphaMaskDomain) |
| 43 | |
robertphillips@google.com | 5d8d186 | 2012-08-15 14:36:41 +0000 | [diff] [blame] | 44 | GrClipMaskManager() |
| 45 | : fGpu(NULL) |
bsalomon@google.com | c8f7f47 | 2012-06-18 13:44:51 +0000 | [diff] [blame] | 46 | , fCurrClipMaskType(kNone_ClipMaskType) { |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 47 | } |
| 48 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 49 | /** |
| 50 | * Creates a clip mask if necessary as a stencil buffer or alpha texture |
| 51 | * and sets the GrGpu's scissor and stencil state. If the return is false |
| 52 | * then the draw can be skipped. |
| 53 | */ |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 54 | bool setupClipping(const GrClipData* clipDataIn); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 55 | |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 56 | void releaseResources(); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 57 | |
bsalomon@google.com | c8f7f47 | 2012-06-18 13:44:51 +0000 | [diff] [blame] | 58 | bool isClipInStencil() const { |
| 59 | return kStencil_ClipMaskType == fCurrClipMaskType; |
| 60 | } |
| 61 | bool isClipInAlpha() const { |
| 62 | return kAlpha_ClipMaskType == fCurrClipMaskType; |
| 63 | } |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 64 | |
bsalomon@google.com | c8f7f47 | 2012-06-18 13:44:51 +0000 | [diff] [blame] | 65 | void invalidateStencilMask() { |
| 66 | if (kStencil_ClipMaskType == fCurrClipMaskType) { |
| 67 | fCurrClipMaskType = kNone_ClipMaskType; |
| 68 | } |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 69 | } |
| 70 | |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 71 | void setContext(GrContext* context) { |
| 72 | fAACache.setContext(context); |
| 73 | } |
| 74 | |
robertphillips@google.com | 2c75681 | 2012-05-22 20:28:23 +0000 | [diff] [blame] | 75 | GrContext* getContext() { |
| 76 | return fAACache.getContext(); |
| 77 | } |
| 78 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 79 | void setGpu(GrGpu* gpu) { |
robertphillips@google.com | 5d8d186 | 2012-08-15 14:36:41 +0000 | [diff] [blame] | 80 | fGpu = gpu; |
| 81 | } |
| 82 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 83 | private: |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 84 | /** |
| 85 | * Informs the helper function adjustStencilParams() about how the stencil |
| 86 | * buffer clip is being used. |
| 87 | */ |
| 88 | enum StencilClipMode { |
| 89 | // Draw to the clip bit of the stencil buffer |
| 90 | kModifyClip_StencilClipMode, |
| 91 | // Clip against the existing representation of the clip in the high bit |
| 92 | // of the stencil buffer. |
| 93 | kRespectClip_StencilClipMode, |
| 94 | // Neither writing to nor clipping against the clip bit. |
| 95 | kIgnoreClip_StencilClipMode, |
| 96 | }; |
| 97 | |
bsalomon@google.com | 13b85aa | 2012-06-15 21:09:40 +0000 | [diff] [blame] | 98 | GrGpu* fGpu; |
bsalomon@google.com | c8f7f47 | 2012-06-18 13:44:51 +0000 | [diff] [blame] | 99 | |
| 100 | /** |
| 101 | * We may represent the clip as a mask in the stencil buffer or as an alpha |
| 102 | * texture. It may be neither because the scissor rect suffices or we |
| 103 | * haven't yet examined the clip. |
| 104 | */ |
| 105 | enum ClipMaskType { |
| 106 | kNone_ClipMaskType, |
| 107 | kStencil_ClipMaskType, |
| 108 | kAlpha_ClipMaskType, |
| 109 | } fCurrClipMaskType; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 110 | |
robertphillips@google.com | fd6daf5 | 2012-05-02 19:32:32 +0000 | [diff] [blame] | 111 | GrClipMaskCache fAACache; // cache for the AA path |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 112 | |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 113 | bool createStencilClipMask(const GrClipData& clipDataIn, |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 114 | const GrIRect& devClipBounds); |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 115 | bool createAlphaClipMask(const GrClipData& clipDataIn, |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 116 | GrTexture** result, |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 117 | GrIRect *devResultBounds); |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 118 | bool createSoftwareClipMask(const GrClipData& clipDataIn, |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 119 | GrTexture** result, |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 120 | GrIRect *devResultBounds); |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 121 | bool clipMaskPreamble(const GrClipData& clipDataIn, |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 122 | GrTexture** result, |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 123 | GrIRect *devResultBounds); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 124 | |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 125 | bool useSWOnlyPath(const SkClipStack& clipIn); |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 126 | |
bsalomon@google.com | 13b85aa | 2012-06-15 21:09:40 +0000 | [diff] [blame] | 127 | bool drawClipShape(GrTexture* target, |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 128 | const SkClipStack::Iter::Clip* clip, |
bsalomon@google.com | 6794a25 | 2012-11-08 15:30:53 +0000 | [diff] [blame] | 129 | const SkIRect& clipRect); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 130 | |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 131 | void mergeMask(GrTexture* dstMask, |
| 132 | GrTexture* srcMask, |
| 133 | SkRegion::Op op, |
| 134 | const GrIRect& dstBound, |
| 135 | const GrIRect& srcBound); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 136 | |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 137 | void getTemp(const GrIRect& bounds, GrAutoScratchTexture* temp); |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 138 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 139 | void setupCache(const SkClipStack& clip, |
robertphillips@google.com | 6623fcd | 2012-05-15 16:47:23 +0000 | [diff] [blame] | 140 | const GrIRect& bounds); |
robertphillips@google.com | 6d62df4 | 2012-05-07 18:07:36 +0000 | [diff] [blame] | 141 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 142 | /** |
| 143 | * Called prior to return control back the GrGpu in setupClipping. It |
| 144 | * updates the GrGpu with stencil settings that account stencil-based |
| 145 | * clipping. |
| 146 | */ |
| 147 | void setGpuStencil(); |
| 148 | |
| 149 | /** |
| 150 | * Adjusts the stencil settings to account for interaction with stencil |
| 151 | * clipping. |
| 152 | */ |
| 153 | void adjustStencilParams(GrStencilSettings* settings, |
| 154 | StencilClipMode mode, |
| 155 | int stencilBitCnt); |
| 156 | |
robertphillips@google.com | fd6daf5 | 2012-05-02 19:32:32 +0000 | [diff] [blame] | 157 | typedef GrNoncopyable INHERITED; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | #endif // GrClipMaskManager_DEFINED |