| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | |
| 8 #ifndef GrClipMaskManager_DEFINED | 7 #ifndef GrClipMaskManager_DEFINED |
| 9 #define GrClipMaskManager_DEFINED | 8 #define GrClipMaskManager_DEFINED |
| 10 | 9 |
| 11 #include "GrClipMaskCache.h" | 10 #include "GrClipMaskCache.h" |
| 12 #include "GrContext.h" | 11 #include "GrContext.h" |
| 13 #include "GrDrawState.h" | 12 #include "GrDrawState.h" |
| 14 #include "GrReducedClip.h" | 13 #include "GrReducedClip.h" |
| 15 #include "GrStencil.h" | 14 #include "GrStencil.h" |
| 16 #include "GrTexture.h" | 15 #include "GrTexture.h" |
| 17 | |
| 18 #include "SkClipStack.h" | 16 #include "SkClipStack.h" |
| 19 #include "SkDeque.h" | 17 #include "SkDeque.h" |
| 20 #include "SkPath.h" | 18 #include "SkPath.h" |
| 21 #include "SkRefCnt.h" | 19 #include "SkRefCnt.h" |
| 22 #include "SkTLList.h" | 20 #include "SkTLList.h" |
| 23 #include "SkTypes.h" | 21 #include "SkTypes.h" |
| 24 | 22 |
| 25 class GrClipTarget; | 23 class GrClipTarget; |
| 26 class GrPathRenderer; | 24 class GrPathRenderer; |
| 27 class GrPathRendererChain; | 25 class GrPathRendererChain; |
| 28 class GrTexture; | 26 class GrTexture; |
| 29 class SkPath; | 27 class SkPath; |
| 30 | |
| 31 /** | 28 /** |
| 32 * The clip mask creator handles the generation of the clip mask. If anti | 29 * The clip mask creator handles the generation of the clip mask. If anti |
| 33 * aliasing is requested it will (in the future) generate a single channel | 30 * aliasing is requested it will (in the future) generate a single channel |
| 34 * (8bit) mask. If no anti aliasing is requested it will generate a 1-bit | 31 * (8bit) mask. If no anti aliasing is requested it will generate a 1-bit |
| 35 * mask in the stencil buffer. In the non anti-aliasing case, if the clip | 32 * mask in the stencil buffer. In the non anti-aliasing case, if the clip |
| 36 * mask can be represented as a rectangle then scissoring is used. In all | 33 * mask can be represented as a rectangle then scissoring is used. In all |
| 37 * cases scissoring is used to bound the range of the clip mask. | 34 * cases scissoring is used to bound the range of the clip mask. |
| 38 */ | 35 */ |
| 39 class GrClipMaskManager : SkNoncopyable { | 36 class GrClipMaskManager : SkNoncopyable { |
| 40 public: | 37 public: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 59 SkIRect fRect; | 56 SkIRect fRect; |
| 60 }; | 57 }; |
| 61 | 58 |
| 62 /** | 59 /** |
| 63 * Creates a clip mask if necessary as a stencil buffer or alpha texture | 60 * Creates a clip mask if necessary as a stencil buffer or alpha texture |
| 64 * and sets the GrGpu's scissor and stencil state. If the return is false | 61 * and sets the GrGpu's scissor and stencil state. If the return is false |
| 65 * then the draw can be skipped. The AutoRestoreEffects is initialized by | 62 * then the draw can be skipped. The AutoRestoreEffects is initialized by |
| 66 * the manager when it must install additional effects to implement the | 63 * the manager when it must install additional effects to implement the |
| 67 * clip. devBounds is optional but can help optimize clipping. | 64 * clip. devBounds is optional but can help optimize clipping. |
| 68 */ | 65 */ |
| 69 bool setupClipping(const GrClipData* clipDataIn, | 66 bool setupClipping(GrDrawState*, |
| 70 const SkRect* devBounds, | |
| 71 GrDrawState::AutoRestoreEffects*, | 67 GrDrawState::AutoRestoreEffects*, |
| 72 GrDrawState::AutoRestoreStencil*, | 68 GrDrawState::AutoRestoreStencil*, |
| 73 ScissorState*); | 69 ScissorState*, |
| 70 const GrClipData* clipDataIn, |
| 71 const SkRect* devBounds); |
| 74 | 72 |
| 75 /** | 73 /** |
| 76 * Purge resources to free up memory. TODO: This class shouldn't hold any lo
ng lived refs | 74 * Purge resources to free up memory. TODO: This class shouldn't hold any lo
ng lived refs |
| 77 * which will allow ResourceCache2 to automatically purge anything this clas
s has created. | 75 * which will allow ResourceCache2 to automatically purge anything this clas
s has created. |
| 78 */ | 76 */ |
| 79 void purgeResources(); | 77 void purgeResources(); |
| 80 | 78 |
| 81 bool isClipInStencil() const { | 79 bool isClipInStencil() const { |
| 82 return kStencil_ClipMaskType == fCurrClipMaskType; | 80 return kStencil_ClipMaskType == fCurrClipMaskType; |
| 83 } | 81 } |
| 82 |
| 84 bool isClipInAlpha() const { | 83 bool isClipInAlpha() const { |
| 85 return kAlpha_ClipMaskType == fCurrClipMaskType; | 84 return kAlpha_ClipMaskType == fCurrClipMaskType; |
| 86 } | 85 } |
| 87 | 86 |
| 88 GrContext* getContext() { | 87 GrContext* getContext() { |
| 89 return fAACache.getContext(); | 88 return fAACache.getContext(); |
| 90 } | 89 } |
| 91 | 90 |
| 92 void setClipTarget(GrClipTarget*); | 91 void setClipTarget(GrClipTarget*); |
| 93 | 92 |
| 94 void adjustPathStencilParams(GrStencilSettings*); | 93 void adjustPathStencilParams(const GrStencilBuffer*, GrStencilSettings*); |
| 95 | 94 |
| 96 private: | 95 private: |
| 97 /** | 96 /** |
| 98 * Informs the helper function adjustStencilParams() about how the stencil | 97 * Informs the helper function adjustStencilParams() about how the stencil |
| 99 * buffer clip is being used. | 98 * buffer clip is being used. |
| 100 */ | 99 */ |
| 101 enum StencilClipMode { | 100 enum StencilClipMode { |
| 102 // Draw to the clip bit of the stencil buffer | 101 // Draw to the clip bit of the stencil buffer |
| 103 kModifyClip_StencilClipMode, | 102 kModifyClip_StencilClipMode, |
| 104 // Clip against the existing representation of the clip in the high bit | 103 // Clip against the existing representation of the clip in the high bit |
| 105 // of the stencil buffer. | 104 // of the stencil buffer. |
| 106 kRespectClip_StencilClipMode, | 105 kRespectClip_StencilClipMode, |
| 107 // Neither writing to nor clipping against the clip bit. | 106 // Neither writing to nor clipping against the clip bit. |
| 108 kIgnoreClip_StencilClipMode, | 107 kIgnoreClip_StencilClipMode, |
| 109 }; | 108 }; |
| 110 | 109 |
| 111 // Attempts to install a series of coverage effects to implement the clip. R
eturn indicates | 110 // Attempts to install a series of coverage effects to implement the clip. R
eturn indicates |
| 112 // whether the element list was successfully converted to effects. | 111 // whether the element list was successfully converted to effects. |
| 113 bool installClipEffects(const GrReducedClip::ElementList&, | 112 bool installClipEffects(GrDrawState*, |
| 114 GrDrawState::AutoRestoreEffects*, | 113 GrDrawState::AutoRestoreEffects*, |
| 114 const GrReducedClip::ElementList&, |
| 115 const SkVector& clipOffset, | 115 const SkVector& clipOffset, |
| 116 const SkRect* devBounds); | 116 const SkRect* devBounds); |
| 117 | 117 |
| 118 // Draws the clip into the stencil buffer | 118 // Draws the clip into the stencil buffer |
| 119 bool createStencilClipMask(int32_t elementsGenID, | 119 bool createStencilClipMask(GrRenderTarget*, |
| 120 int32_t elementsGenID, |
| 120 GrReducedClip::InitialState initialState, | 121 GrReducedClip::InitialState initialState, |
| 121 const GrReducedClip::ElementList& elements, | 122 const GrReducedClip::ElementList& elements, |
| 122 const SkIRect& clipSpaceIBounds, | 123 const SkIRect& clipSpaceIBounds, |
| 123 const SkIPoint& clipSpaceToStencilOffset); | 124 const SkIPoint& clipSpaceToStencilOffset); |
| 125 |
| 124 // Creates an alpha mask of the clip. The mask is a rasterization of element
s through the | 126 // Creates an alpha mask of the clip. The mask is a rasterization of element
s through the |
| 125 // rect specified by clipSpaceIBounds. | 127 // rect specified by clipSpaceIBounds. |
| 126 GrTexture* createAlphaClipMask(int32_t elementsGenID, | 128 GrTexture* createAlphaClipMask(int32_t elementsGenID, |
| 127 GrReducedClip::InitialState initialState, | 129 GrReducedClip::InitialState initialState, |
| 128 const GrReducedClip::ElementList& elements, | 130 const GrReducedClip::ElementList& elements, |
| 129 const SkIRect& clipSpaceIBounds); | 131 const SkIRect& clipSpaceIBounds); |
| 132 |
| 130 // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the
result texture. | 133 // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the
result texture. |
| 131 GrTexture* createSoftwareClipMask(int32_t elementsGenID, | 134 GrTexture* createSoftwareClipMask(int32_t elementsGenID, |
| 132 GrReducedClip::InitialState initialState, | 135 GrReducedClip::InitialState initialState, |
| 133 const GrReducedClip::ElementList& elements
, | 136 const GrReducedClip::ElementList& elements
, |
| 134 const SkIRect& clipSpaceIBounds); | 137 const SkIRect& clipSpaceIBounds); |
| 135 | 138 |
| 136 // Returns the cached mask texture if it matches the elementsGenID and the c
lipSpaceIBounds. | 139 // Returns the cached mask texture if it matches the elementsGenID and the c
lipSpaceIBounds. |
| 137 // Returns NULL if not found. | 140 // Returns NULL if not found. |
| 138 GrTexture* getCachedMaskTexture(int32_t elementsGenID, const SkIRect& clipSp
aceIBounds); | 141 GrTexture* getCachedMaskTexture(int32_t elementsGenID, const SkIRect& clipSp
aceIBounds); |
| 139 | 142 |
| 140 | |
| 141 // Handles allocation (if needed) of a clip alpha-mask texture for both the
sw-upload | 143 // Handles allocation (if needed) of a clip alpha-mask texture for both the
sw-upload |
| 142 // or gpu-rendered cases. | 144 // or gpu-rendered cases. |
| 143 GrTexture* allocMaskTexture(int32_t elementsGenID, | 145 GrTexture* allocMaskTexture(int32_t elementsGenID, |
| 144 const SkIRect& clipSpaceIBounds, | 146 const SkIRect& clipSpaceIBounds, |
| 145 bool willUpload); | 147 bool willUpload); |
| 146 | 148 |
| 147 bool useSWOnlyPath(const GrReducedClip::ElementList& elements); | 149 bool useSWOnlyPath(const GrDrawState*, const GrReducedClip::ElementList& ele
ments); |
| 148 | 150 |
| 149 // Draws a clip element into the target alpha mask. The caller should have a
lready setup the | 151 // Draws a clip element into the target alpha mask. The caller should have a
lready setup the |
| 150 // desired blend operation. Optionally if the caller already selected a path
renderer it can | 152 // desired blend operation. Optionally if the caller already selected a path
renderer it can |
| 151 // be passed. Otherwise the function will select one if the element is a pat
h. | 153 // be passed. Otherwise the function will select one if the element is a pat
h. |
| 152 bool drawElement(GrTexture* target, const SkClipStack::Element*, GrPathRende
rer* = NULL); | 154 bool drawElement(GrDrawState*, |
| 155 GrTexture* target, |
| 156 const SkClipStack::Element*, |
| 157 GrPathRenderer* pr = NULL); |
| 153 | 158 |
| 154 // Determines whether it is possible to draw the element to both the stencil
buffer and the | 159 // Determines whether it is possible to draw the element to both the stencil
buffer and the |
| 155 // alpha mask simultaneously. If so and the element is a path a compatible p
ath renderer is | 160 // alpha mask simultaneously. If so and the element is a path a compatible p
ath renderer is |
| 156 // also returned. | 161 // also returned. |
| 157 bool canStencilAndDrawElement(GrTexture* target, const SkClipStack::Element*
, GrPathRenderer**); | 162 bool canStencilAndDrawElement(GrDrawState*, |
| 163 GrTexture* target, |
| 164 GrPathRenderer**, |
| 165 const SkClipStack::Element*); |
| 158 | 166 |
| 159 void mergeMask(GrTexture* dstMask, | 167 void mergeMask(GrDrawState*, |
| 168 GrTexture* dstMask, |
| 160 GrTexture* srcMask, | 169 GrTexture* srcMask, |
| 161 SkRegion::Op op, | 170 SkRegion::Op op, |
| 162 const SkIRect& dstBound, | 171 const SkIRect& dstBound, |
| 163 const SkIRect& srcBound); | 172 const SkIRect& srcBound); |
| 164 | 173 |
| 165 GrTexture* createTempMask(int width, int height); | 174 GrTexture* createTempMask(int width, int height); |
| 166 | 175 |
| 167 void setupCache(const SkClipStack& clip, | 176 void setupCache(const SkClipStack& clip, |
| 168 const SkIRect& bounds); | 177 const SkIRect& bounds); |
| 169 | |
| 170 /** | 178 /** |
| 171 * Called prior to return control back the GrGpu in setupClipping. It | 179 * Called prior to return control back the GrGpu in setupClipping. It |
| 172 * updates the GrGpu with stencil settings that account stencil-based | 180 * updates the GrGpu with stencil settings that account stencil-based |
| 173 * clipping. | 181 * clipping. |
| 174 */ | 182 */ |
| 175 void setDrawStateStencil(GrDrawState::AutoRestoreStencil* asr); | 183 void setDrawStateStencil(GrDrawState*, GrDrawState::AutoRestoreStencil*); |
| 176 | 184 |
| 177 /** | 185 /** |
| 178 * Adjusts the stencil settings to account for interaction with stencil | 186 * Adjusts the stencil settings to account for interaction with stencil |
| 179 * clipping. | 187 * clipping. |
| 180 */ | 188 */ |
| 181 void adjustStencilParams(GrStencilSettings* settings, | 189 void adjustStencilParams(GrStencilSettings* settings, |
| 182 StencilClipMode mode, | 190 StencilClipMode mode, |
| 183 int stencilBitCnt); | 191 int stencilBitCnt); |
| 184 | 192 |
| 185 /** | 193 /** |
| 186 * We may represent the clip as a mask in the stencil buffer or as an alpha | 194 * We may represent the clip as a mask in the stencil buffer or as an alpha |
| 187 * texture. It may be neither because the scissor rect suffices or we | 195 * texture. It may be neither because the scissor rect suffices or we |
| 188 * haven't yet examined the clip. | 196 * haven't yet examined the clip. |
| 189 */ | 197 */ |
| 190 enum ClipMaskType { | 198 enum ClipMaskType { |
| 191 kNone_ClipMaskType, | 199 kNone_ClipMaskType, |
| 192 kStencil_ClipMaskType, | 200 kStencil_ClipMaskType, |
| 193 kAlpha_ClipMaskType, | 201 kAlpha_ClipMaskType, |
| 194 } fCurrClipMaskType; | 202 } fCurrClipMaskType; |
| 195 | 203 |
| 196 GrClipMaskCache fAACache; // cache for the AA path | 204 GrClipMaskCache fAACache; // cache for the AA path |
| 197 GrClipTarget* fClipTarget; | 205 GrClipTarget* fClipTarget; |
| 198 StencilClipMode fClipMode; | 206 StencilClipMode fClipMode; |
| 199 | 207 |
| 200 typedef SkNoncopyable INHERITED; | 208 typedef SkNoncopyable INHERITED; |
| 201 }; | 209 }; |
| 202 | |
| 203 #endif // GrClipMaskManager_DEFINED | 210 #endif // GrClipMaskManager_DEFINED |
| OLD | NEW |