Chromium Code Reviews| 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 | 7 |
| 8 #ifndef GrClipMaskManager_DEFINED | 8 #ifndef GrClipMaskManager_DEFINED |
| 9 #define GrClipMaskManager_DEFINED | 9 #define GrClipMaskManager_DEFINED |
| 10 | 10 |
| 11 #include "GrClipMaskCache.h" | 11 #include "GrClipMaskCache.h" |
| 12 #include "GrContext.h" | 12 #include "GrContext.h" |
| 13 #include "GrDrawState.h" | 13 #include "GrDrawState.h" |
| 14 #include "GrReducedClip.h" | 14 #include "GrReducedClip.h" |
| 15 #include "GrStencil.h" | 15 #include "GrStencil.h" |
| 16 #include "GrTexture.h" | 16 #include "GrTexture.h" |
| 17 | 17 |
| 18 #include "SkClipStack.h" | 18 #include "SkClipStack.h" |
| 19 #include "SkDeque.h" | 19 #include "SkDeque.h" |
| 20 #include "SkPath.h" | 20 #include "SkPath.h" |
| 21 #include "SkRefCnt.h" | 21 #include "SkRefCnt.h" |
| 22 #include "SkTLList.h" | 22 #include "SkTLList.h" |
| 23 #include "SkTypes.h" | 23 #include "SkTypes.h" |
| 24 | 24 |
| 25 class GrGpu; | 25 class GrClipTarget; |
| 26 class GrPathRenderer; | 26 class GrPathRenderer; |
| 27 class GrPathRendererChain; | 27 class GrPathRendererChain; |
| 28 class GrTexture; | 28 class GrTexture; |
| 29 class SkPath; | 29 class SkPath; |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * The clip mask creator handles the generation of the clip mask. If anti | 32 * 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 | 33 * 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 | 34 * (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 | 35 * 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 | 36 * 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. | 37 * cases scissoring is used to bound the range of the clip mask. |
| 38 */ | 38 */ |
| 39 class GrClipMaskManager : SkNoncopyable { | 39 class GrClipMaskManager : SkNoncopyable { |
| 40 public: | 40 public: |
| 41 GrClipMaskManager() | 41 GrClipMaskManager() |
| 42 : fGpu(NULL) | 42 : fCurrClipMaskType(kNone_ClipMaskType) |
| 43 , fCurrClipMaskType(kNone_ClipMaskType) { | 43 , fClipTarget(NULL) { |
| 44 } | 44 } |
| 45 | 45 |
| 46 // The state of the scissor is controlled by the clip manager, no one else s hould set | 46 // The state of the scissor is controlled by the clip manager, no one else s hould set |
| 47 // Scissor state | 47 // Scissor state |
| 48 struct ScissorState { | 48 struct ScissorState { |
| 49 ScissorState() : fEnabled(false) {} | 49 ScissorState() : fEnabled(false) {} |
| 50 void set(const SkIRect& rect) { fRect = rect; fEnabled = true; } | 50 void set(const SkIRect& rect) { fRect = rect; fEnabled = true; } |
| 51 bool fEnabled; | 51 bool fEnabled; |
| 52 SkIRect fRect; | 52 SkIRect fRect; |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 /** | 55 /** |
| 56 * Creates a clip mask if necessary as a stencil buffer or alpha texture | 56 * Creates a clip mask if necessary as a stencil buffer or alpha texture |
| 57 * and sets the GrGpu's scissor and stencil state. If the return is false | 57 * and sets the GrGpu's scissor and stencil state. If the return is false |
| 58 * then the draw can be skipped. The AutoRestoreEffects is initialized by | 58 * then the draw can be skipped. The AutoRestoreEffects is initialized by |
| 59 * the manager when it must install additional effects to implement the | 59 * the manager when it must install additional effects to implement the |
| 60 * clip. devBounds is optional but can help optimize clipping. | 60 * clip. devBounds is optional but can help optimize clipping. |
| 61 */ | 61 */ |
| 62 bool setupClipping(const GrClipData* clipDataIn, | 62 bool setupClipping(const GrClipData* clipDataIn, |
| 63 const SkRect* devBounds, | 63 const SkRect* devBounds, |
| 64 GrDrawState::AutoRestoreEffects*, | 64 GrDrawState::AutoRestoreEffects*, |
| 65 GrDrawState::AutoRestoreStencil*, | 65 GrDrawState::AutoRestoreStencil*, |
| 66 ScissorState* scissorState); | 66 ScissorState*); |
| 67 | 67 |
| 68 /** | 68 /** |
| 69 * Purge resources to free up memory. TODO: This class shouldn't hold any lo ng lived refs | 69 * Purge resources to free up memory. TODO: This class shouldn't hold any lo ng lived refs |
| 70 * which will allow ResourceCache2 to automatically purge anything this clas s has created. | 70 * which will allow ResourceCache2 to automatically purge anything this clas s has created. |
| 71 */ | 71 */ |
| 72 void purgeResources(); | 72 void purgeResources(); |
| 73 | 73 |
| 74 bool isClipInStencil() const { | 74 bool isClipInStencil() const { |
| 75 return kStencil_ClipMaskType == fCurrClipMaskType; | 75 return kStencil_ClipMaskType == fCurrClipMaskType; |
| 76 } | 76 } |
| 77 bool isClipInAlpha() const { | 77 bool isClipInAlpha() const { |
| 78 return kAlpha_ClipMaskType == fCurrClipMaskType; | 78 return kAlpha_ClipMaskType == fCurrClipMaskType; |
| 79 } | 79 } |
| 80 | 80 |
| 81 void invalidateStencilMask() { | 81 void invalidateStencilMask() { |
| 82 if (kStencil_ClipMaskType == fCurrClipMaskType) { | 82 if (kStencil_ClipMaskType == fCurrClipMaskType) { |
| 83 fCurrClipMaskType = kNone_ClipMaskType; | 83 fCurrClipMaskType = kNone_ClipMaskType; |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 GrContext* getContext() { | 87 GrContext* getContext() { |
| 88 return fAACache.getContext(); | 88 return fAACache.getContext(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void setGpu(GrGpu* gpu); | 91 void setClipTarget(GrClipTarget*); |
| 92 | 92 |
| 93 void adjustPathStencilParams(GrStencilSettings* settings); | 93 void adjustPathStencilParams(GrStencilSettings*); |
| 94 | |
| 94 private: | 95 private: |
| 96 enum PrivateDrawStateStateBits { | |
|
bsalomon
2014/10/28 17:53:28
Maybe this sbould be in ClipTarget? Or does clip t
joshualitt
2014/10/28 19:50:30
I'm not sure what you mean, I thought these are on
bsalomon
2014/10/28 19:54:09
Right. Since this bit provides access to setting t
| |
| 97 kFirstBit = (GrDrawState::kLastPublicStateBit << 1), | |
| 98 | |
| 99 kModifyStencilClip_StateBit = kFirstBit, // allows draws to modify | |
| 100 // stencil bits used for | |
| 101 // clipping. | |
| 102 }; | |
| 103 | |
| 95 /** | 104 /** |
| 96 * Informs the helper function adjustStencilParams() about how the stencil | 105 * Informs the helper function adjustStencilParams() about how the stencil |
| 97 * buffer clip is being used. | 106 * buffer clip is being used. |
| 98 */ | 107 */ |
| 99 enum StencilClipMode { | 108 enum StencilClipMode { |
| 100 // Draw to the clip bit of the stencil buffer | 109 // Draw to the clip bit of the stencil buffer |
| 101 kModifyClip_StencilClipMode, | 110 kModifyClip_StencilClipMode, |
| 102 // Clip against the existing representation of the clip in the high bit | 111 // Clip against the existing representation of the clip in the high bit |
| 103 // of the stencil buffer. | 112 // of the stencil buffer. |
| 104 kRespectClip_StencilClipMode, | 113 kRespectClip_StencilClipMode, |
| 105 // Neither writing to nor clipping against the clip bit. | 114 // Neither writing to nor clipping against the clip bit. |
| 106 kIgnoreClip_StencilClipMode, | 115 kIgnoreClip_StencilClipMode, |
| 107 }; | 116 }; |
| 108 | 117 |
| 109 GrGpu* fGpu; | |
| 110 | |
| 111 /** | |
| 112 * We may represent the clip as a mask in the stencil buffer or as an alpha | |
| 113 * texture. It may be neither because the scissor rect suffices or we | |
| 114 * haven't yet examined the clip. | |
| 115 */ | |
| 116 enum ClipMaskType { | |
| 117 kNone_ClipMaskType, | |
| 118 kStencil_ClipMaskType, | |
| 119 kAlpha_ClipMaskType, | |
| 120 } fCurrClipMaskType; | |
| 121 | |
| 122 GrClipMaskCache fAACache; // cache for the AA path | |
| 123 | |
| 124 // Attempts to install a series of coverage effects to implement the clip. R eturn indicates | 118 // Attempts to install a series of coverage effects to implement the clip. R eturn indicates |
| 125 // whether the element list was successfully converted to effects. | 119 // whether the element list was successfully converted to effects. |
| 126 bool installClipEffects(const GrReducedClip::ElementList&, | 120 bool installClipEffects(const GrReducedClip::ElementList&, |
| 127 GrDrawState::AutoRestoreEffects*, | 121 GrDrawState::AutoRestoreEffects*, |
| 128 const SkVector& clipOffset, | 122 const SkVector& clipOffset, |
| 129 const SkRect* devBounds); | 123 const SkRect* devBounds); |
| 130 | 124 |
| 131 // Draws the clip into the stencil buffer | 125 // Draws the clip into the stencil buffer |
| 132 bool createStencilClipMask(int32_t elementsGenID, | 126 bool createStencilClipMask(int32_t elementsGenID, |
| 133 GrReducedClip::InitialState initialState, | 127 GrReducedClip::InitialState initialState, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 void setDrawStateStencil(GrDrawState::AutoRestoreStencil* asr); | 182 void setDrawStateStencil(GrDrawState::AutoRestoreStencil* asr); |
| 189 | 183 |
| 190 /** | 184 /** |
| 191 * Adjusts the stencil settings to account for interaction with stencil | 185 * Adjusts the stencil settings to account for interaction with stencil |
| 192 * clipping. | 186 * clipping. |
| 193 */ | 187 */ |
| 194 void adjustStencilParams(GrStencilSettings* settings, | 188 void adjustStencilParams(GrStencilSettings* settings, |
| 195 StencilClipMode mode, | 189 StencilClipMode mode, |
| 196 int stencilBitCnt); | 190 int stencilBitCnt); |
| 197 | 191 |
| 192 /** | |
| 193 * We may represent the clip as a mask in the stencil buffer or as an alpha | |
| 194 * texture. It may be neither because the scissor rect suffices or we | |
| 195 * haven't yet examined the clip. | |
| 196 */ | |
| 197 enum ClipMaskType { | |
| 198 kNone_ClipMaskType, | |
| 199 kStencil_ClipMaskType, | |
| 200 kAlpha_ClipMaskType, | |
| 201 } fCurrClipMaskType; | |
| 202 | |
| 203 GrClipMaskCache fAACache; // cache for the AA path | |
| 204 GrClipTarget* fClipTarget; | |
| 205 | |
| 198 typedef SkNoncopyable INHERITED; | 206 typedef SkNoncopyable INHERITED; |
| 199 }; | 207 }; |
| 200 | 208 |
| 201 #endif // GrClipMaskManager_DEFINED | 209 #endif // GrClipMaskManager_DEFINED |
| OLD | NEW |