| 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 #ifndef GrClipMaskManager_DEFINED | 7 #ifndef GrClipMaskManager_DEFINED |
| 8 #define GrClipMaskManager_DEFINED | 8 #define GrClipMaskManager_DEFINED |
| 9 | 9 |
| 10 #include "GrClipMaskCache.h" | |
| 11 #include "GrPipelineBuilder.h" | 10 #include "GrPipelineBuilder.h" |
| 12 #include "GrReducedClip.h" | 11 #include "GrReducedClip.h" |
| 13 #include "GrStencil.h" | 12 #include "GrStencil.h" |
| 14 #include "GrTexture.h" | 13 #include "GrTexture.h" |
| 15 #include "SkClipStack.h" | 14 #include "SkClipStack.h" |
| 16 #include "SkDeque.h" | 15 #include "SkDeque.h" |
| 17 #include "SkPath.h" | 16 #include "SkPath.h" |
| 18 #include "SkRefCnt.h" | 17 #include "SkRefCnt.h" |
| 19 #include "SkTLList.h" | 18 #include "SkTLList.h" |
| 20 #include "SkTypes.h" | 19 #include "SkTypes.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 42 * then the draw can be skipped. The AutoRestoreEffects is initialized by | 41 * then the draw can be skipped. The AutoRestoreEffects is initialized by |
| 43 * the manager when it must install additional effects to implement the | 42 * the manager when it must install additional effects to implement the |
| 44 * clip. devBounds is optional but can help optimize clipping. | 43 * clip. devBounds is optional but can help optimize clipping. |
| 45 */ | 44 */ |
| 46 bool setupClipping(const GrPipelineBuilder&, | 45 bool setupClipping(const GrPipelineBuilder&, |
| 47 GrPipelineBuilder::AutoRestoreFragmentProcessorState*, | 46 GrPipelineBuilder::AutoRestoreFragmentProcessorState*, |
| 48 GrPipelineBuilder::AutoRestoreStencil*, | 47 GrPipelineBuilder::AutoRestoreStencil*, |
| 49 GrScissorState*, | 48 GrScissorState*, |
| 50 const SkRect* devBounds); | 49 const SkRect* devBounds); |
| 51 | 50 |
| 52 /** | |
| 53 * Purge resources to free up memory. TODO: This class shouldn't hold any lo
ng lived refs | |
| 54 * which will allow GrResourceCache to automatically purge anything this cla
ss has created. | |
| 55 */ | |
| 56 void purgeResources(); | |
| 57 | |
| 58 bool isClipInStencil() const { | 51 bool isClipInStencil() const { |
| 59 return kStencil_ClipMaskType == fCurrClipMaskType; | 52 return kStencil_ClipMaskType == fCurrClipMaskType; |
| 60 } | 53 } |
| 61 | 54 |
| 62 bool isClipInAlpha() const { | 55 bool isClipInAlpha() const { |
| 63 return kAlpha_ClipMaskType == fCurrClipMaskType; | 56 return kAlpha_ClipMaskType == fCurrClipMaskType; |
| 64 } | 57 } |
| 65 | 58 |
| 66 void adjustPathStencilParams(const GrStencilAttachment*, GrStencilSettings*)
; | 59 void adjustPathStencilParams(const GrStencilAttachment*, GrStencilSettings*)
; |
| 67 | 60 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 const SkVector& clipToMaskOffset, | 99 const SkVector& clipToMaskOffset, |
| 107 const SkIRect& clipSpaceIBounds); | 100 const SkIRect& clipSpaceIBounds); |
| 108 | 101 |
| 109 // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the
result texture. | 102 // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the
result texture. |
| 110 GrTexture* createSoftwareClipMask(int32_t elementsGenID, | 103 GrTexture* createSoftwareClipMask(int32_t elementsGenID, |
| 111 GrReducedClip::InitialState initialState, | 104 GrReducedClip::InitialState initialState, |
| 112 const GrReducedClip::ElementList& elements
, | 105 const GrReducedClip::ElementList& elements
, |
| 113 const SkVector& clipToMaskOffset, | 106 const SkVector& clipToMaskOffset, |
| 114 const SkIRect& clipSpaceIBounds); | 107 const SkIRect& clipSpaceIBounds); |
| 115 | 108 |
| 116 // Returns the cached mask texture if it matches the elementsGenID and the c
lipSpaceIBounds. | 109 bool useSWOnlyPath(const GrPipelineBuilder&, |
| 117 // Returns nullptr if not found. | |
| 118 GrTexture* getCachedMaskTexture(int32_t elementsGenID, const SkIRect& clipSp
aceIBounds); | |
| 119 | |
| 120 // Handles allocation (if needed) of a clip alpha-mask texture for both the
sw-upload | |
| 121 // or gpu-rendered cases. | |
| 122 GrTexture* allocMaskTexture(int32_t elementsGenID, | |
| 123 const SkIRect& clipSpaceIBounds, | |
| 124 bool willUpload); | |
| 125 | |
| 126 bool useSWOnlyPath(const GrPipelineBuilder&, | |
| 127 const SkVector& clipToMaskOffset, | 110 const SkVector& clipToMaskOffset, |
| 128 const GrReducedClip::ElementList& elements); | 111 const GrReducedClip::ElementList& elements); |
| 129 | 112 |
| 130 // Draws a clip element into the target alpha mask. The caller should have a
lready setup the | 113 // Draws a clip element into the target alpha mask. The caller should have a
lready setup the |
| 131 // desired blend operation. Optionally if the caller already selected a path
renderer it can | 114 // desired blend operation. Optionally if the caller already selected a path
renderer it can |
| 132 // be passed. Otherwise the function will select one if the element is a pat
h. | 115 // be passed. Otherwise the function will select one if the element is a pat
h. |
| 133 bool drawElement(GrPipelineBuilder*, | 116 bool drawElement(GrPipelineBuilder*, |
| 134 const SkMatrix& viewMatrix, | 117 const SkMatrix& viewMatrix, |
| 135 GrTexture* target, | 118 GrTexture* target, |
| 136 const SkClipStack::Element*, | 119 const SkClipStack::Element*, |
| 137 GrPathRenderer* pr = nullptr); | 120 GrPathRenderer* pr = nullptr); |
| 138 | 121 |
| 139 // Determines whether it is possible to draw the element to both the stencil
buffer and the | 122 // Determines whether it is possible to draw the element to both the stencil
buffer and the |
| 140 // alpha mask simultaneously. If so and the element is a path a compatible p
ath renderer is | 123 // alpha mask simultaneously. If so and the element is a path a compatible p
ath renderer is |
| 141 // also returned. | 124 // also returned. |
| 142 bool canStencilAndDrawElement(GrPipelineBuilder*, | 125 bool canStencilAndDrawElement(GrPipelineBuilder*, |
| 143 GrTexture* target, | 126 GrTexture* target, |
| 144 GrPathRenderer**, | 127 GrPathRenderer**, |
| 145 const SkClipStack::Element*); | 128 const SkClipStack::Element*); |
| 146 | 129 |
| 147 void mergeMask(GrPipelineBuilder*, | 130 void mergeMask(GrPipelineBuilder*, |
| 148 GrTexture* dstMask, | 131 GrTexture* dstMask, |
| 149 GrTexture* srcMask, | 132 GrTexture* srcMask, |
| 150 SkRegion::Op op, | 133 SkRegion::Op op, |
| 151 const SkIRect& dstBound, | 134 const SkIRect& dstBound, |
| 152 const SkIRect& srcBound); | 135 const SkIRect& srcBound); |
| 153 | 136 |
| 154 GrTexture* createTempMask(int width, int height); | 137 GrTexture* createTempMask(int width, int height); |
| 155 | 138 |
| 156 void setupCache(const SkClipStack& clip, | |
| 157 const SkIRect& bounds); | |
| 158 /** | 139 /** |
| 159 * Called prior to return control back the GrGpu in setupClipping. It update
s the | 140 * Called prior to return control back the GrGpu in setupClipping. It update
s the |
| 160 * GrPipelineBuilder with stencil settings that account for stencil-based cl
ipping. | 141 * GrPipelineBuilder with stencil settings that account for stencil-based cl
ipping. |
| 161 */ | 142 */ |
| 162 void setPipelineBuilderStencil(const GrPipelineBuilder&, | 143 void setPipelineBuilderStencil(const GrPipelineBuilder&, |
| 163 GrPipelineBuilder::AutoRestoreStencil*); | 144 GrPipelineBuilder::AutoRestoreStencil*); |
| 164 | 145 |
| 165 /** | 146 /** |
| 166 * Adjusts the stencil settings to account for interaction with stencil | 147 * Adjusts the stencil settings to account for interaction with stencil |
| 167 * clipping. | 148 * clipping. |
| 168 */ | 149 */ |
| 169 void adjustStencilParams(GrStencilSettings* settings, | 150 void adjustStencilParams(GrStencilSettings* settings, |
| 170 StencilClipMode mode, | 151 StencilClipMode mode, |
| 171 int stencilBitCnt); | 152 int stencilBitCnt); |
| 172 | 153 |
| 154 GrTexture* createCachedMask(int width, int height, const GrUniqueKey& key, b
ool renderTarget); |
| 155 |
| 173 /** | 156 /** |
| 174 * We may represent the clip as a mask in the stencil buffer or as an alpha | 157 * We may represent the clip as a mask in the stencil buffer or as an alpha |
| 175 * texture. It may be neither because the scissor rect suffices or we | 158 * texture. It may be neither because the scissor rect suffices or we |
| 176 * haven't yet examined the clip. | 159 * haven't yet examined the clip. |
| 177 */ | 160 */ |
| 178 enum ClipMaskType { | 161 enum ClipMaskType { |
| 179 kNone_ClipMaskType, | 162 kNone_ClipMaskType, |
| 180 kStencil_ClipMaskType, | 163 kStencil_ClipMaskType, |
| 181 kAlpha_ClipMaskType, | 164 kAlpha_ClipMaskType, |
| 182 } fCurrClipMaskType; | 165 } fCurrClipMaskType; |
| 183 | 166 |
| 184 GrClipMaskCache fAACache; // cache for the AA path | |
| 185 GrDrawTarget* fDrawTarget; // This is our owning draw target. | 167 GrDrawTarget* fDrawTarget; // This is our owning draw target. |
| 186 StencilClipMode fClipMode; | 168 StencilClipMode fClipMode; |
| 187 | 169 |
| 188 typedef SkNoncopyable INHERITED; | 170 typedef SkNoncopyable INHERITED; |
| 189 }; | 171 }; |
| 190 #endif // GrClipMaskManager_DEFINED | 172 #endif // GrClipMaskManager_DEFINED |
| OLD | NEW |