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" | 10 #include "GrClipMaskCache.h" |
11 #include "GrContext.h" | 11 #include "GrContext.h" |
12 #include "GrDrawState.h" | 12 #include "GrPipelineBuilder.h" |
13 #include "GrReducedClip.h" | 13 #include "GrReducedClip.h" |
14 #include "GrStencil.h" | 14 #include "GrStencil.h" |
15 #include "GrTexture.h" | 15 #include "GrTexture.h" |
16 #include "SkClipStack.h" | 16 #include "SkClipStack.h" |
17 #include "SkDeque.h" | 17 #include "SkDeque.h" |
18 #include "SkPath.h" | 18 #include "SkPath.h" |
19 #include "SkRefCnt.h" | 19 #include "SkRefCnt.h" |
20 #include "SkTLList.h" | 20 #include "SkTLList.h" |
21 #include "SkTypes.h" | 21 #include "SkTypes.h" |
22 | 22 |
(...skipping 18 matching lines...) Expand all Loading... |
41 , fClipMode(kIgnoreClip_StencilClipMode) { | 41 , fClipMode(kIgnoreClip_StencilClipMode) { |
42 } | 42 } |
43 | 43 |
44 /** | 44 /** |
45 * Creates a clip mask if necessary as a stencil buffer or alpha texture | 45 * Creates a clip mask if necessary as a stencil buffer or alpha texture |
46 * and sets the GrGpu's scissor and stencil state. If the return is false | 46 * and sets the GrGpu's scissor and stencil state. If the return is false |
47 * then the draw can be skipped. The AutoRestoreEffects is initialized by | 47 * then the draw can be skipped. The AutoRestoreEffects is initialized by |
48 * the manager when it must install additional effects to implement the | 48 * the manager when it must install additional effects to implement the |
49 * clip. devBounds is optional but can help optimize clipping. | 49 * clip. devBounds is optional but can help optimize clipping. |
50 */ | 50 */ |
51 bool setupClipping(GrDrawState*, | 51 bool setupClipping(GrPipelineBuilder*, |
52 GrDrawState::AutoRestoreEffects*, | 52 GrPipelineBuilder::AutoRestoreEffects*, |
53 GrDrawState::AutoRestoreStencil*, | 53 GrPipelineBuilder::AutoRestoreStencil*, |
54 GrScissorState*, | 54 GrScissorState*, |
55 const GrClipData* clipDataIn, | 55 const GrClipData* clipDataIn, |
56 const SkRect* devBounds); | 56 const SkRect* devBounds); |
57 | 57 |
58 /** | 58 /** |
59 * Purge resources to free up memory. TODO: This class shouldn't hold any lo
ng lived refs | 59 * Purge resources to free up memory. TODO: This class shouldn't hold any lo
ng lived refs |
60 * which will allow ResourceCache2 to automatically purge anything this clas
s has created. | 60 * which will allow ResourceCache2 to automatically purge anything this clas
s has created. |
61 */ | 61 */ |
62 void purgeResources(); | 62 void purgeResources(); |
63 | 63 |
(...skipping 23 matching lines...) Expand all Loading... |
87 kModifyClip_StencilClipMode, | 87 kModifyClip_StencilClipMode, |
88 // Clip against the existing representation of the clip in the high bit | 88 // Clip against the existing representation of the clip in the high bit |
89 // of the stencil buffer. | 89 // of the stencil buffer. |
90 kRespectClip_StencilClipMode, | 90 kRespectClip_StencilClipMode, |
91 // Neither writing to nor clipping against the clip bit. | 91 // Neither writing to nor clipping against the clip bit. |
92 kIgnoreClip_StencilClipMode, | 92 kIgnoreClip_StencilClipMode, |
93 }; | 93 }; |
94 | 94 |
95 // Attempts to install a series of coverage effects to implement the clip. R
eturn indicates | 95 // Attempts to install a series of coverage effects to implement the clip. R
eturn indicates |
96 // whether the element list was successfully converted to effects. | 96 // whether the element list was successfully converted to effects. |
97 bool installClipEffects(GrDrawState*, | 97 bool installClipEffects(GrPipelineBuilder*, |
98 GrDrawState::AutoRestoreEffects*, | 98 GrPipelineBuilder::AutoRestoreEffects*, |
99 const GrReducedClip::ElementList&, | 99 const GrReducedClip::ElementList&, |
100 const SkVector& clipOffset, | 100 const SkVector& clipOffset, |
101 const SkRect* devBounds); | 101 const SkRect* devBounds); |
102 | 102 |
103 // Draws the clip into the stencil buffer | 103 // Draws the clip into the stencil buffer |
104 bool createStencilClipMask(GrRenderTarget*, | 104 bool createStencilClipMask(GrRenderTarget*, |
105 int32_t elementsGenID, | 105 int32_t elementsGenID, |
106 GrReducedClip::InitialState initialState, | 106 GrReducedClip::InitialState initialState, |
107 const GrReducedClip::ElementList& elements, | 107 const GrReducedClip::ElementList& elements, |
108 const SkIRect& clipSpaceIBounds, | 108 const SkIRect& clipSpaceIBounds, |
(...skipping 17 matching lines...) Expand all Loading... |
126 // Returns the cached mask texture if it matches the elementsGenID and the c
lipSpaceIBounds. | 126 // Returns the cached mask texture if it matches the elementsGenID and the c
lipSpaceIBounds. |
127 // Returns NULL if not found. | 127 // Returns NULL if not found. |
128 GrTexture* getCachedMaskTexture(int32_t elementsGenID, const SkIRect& clipSp
aceIBounds); | 128 GrTexture* getCachedMaskTexture(int32_t elementsGenID, const SkIRect& clipSp
aceIBounds); |
129 | 129 |
130 // Handles allocation (if needed) of a clip alpha-mask texture for both the
sw-upload | 130 // Handles allocation (if needed) of a clip alpha-mask texture for both the
sw-upload |
131 // or gpu-rendered cases. | 131 // or gpu-rendered cases. |
132 GrTexture* allocMaskTexture(int32_t elementsGenID, | 132 GrTexture* allocMaskTexture(int32_t elementsGenID, |
133 const SkIRect& clipSpaceIBounds, | 133 const SkIRect& clipSpaceIBounds, |
134 bool willUpload); | 134 bool willUpload); |
135 | 135 |
136 bool useSWOnlyPath(const GrDrawState*, | 136 bool useSWOnlyPath(const GrPipelineBuilder*, |
137 const SkVector& clipToMaskOffset, | 137 const SkVector& clipToMaskOffset, |
138 const GrReducedClip::ElementList& elements); | 138 const GrReducedClip::ElementList& elements); |
139 | 139 |
140 // Draws a clip element into the target alpha mask. The caller should have a
lready setup the | 140 // Draws a clip element into the target alpha mask. The caller should have a
lready setup the |
141 // desired blend operation. Optionally if the caller already selected a path
renderer it can | 141 // desired blend operation. Optionally if the caller already selected a path
renderer it can |
142 // be passed. Otherwise the function will select one if the element is a pat
h. | 142 // be passed. Otherwise the function will select one if the element is a pat
h. |
143 bool drawElement(GrDrawState*, | 143 bool drawElement(GrPipelineBuilder*, |
144 const SkMatrix& viewMatrix, | 144 const SkMatrix& viewMatrix, |
145 GrTexture* target, | 145 GrTexture* target, |
146 const SkClipStack::Element*, | 146 const SkClipStack::Element*, |
147 GrPathRenderer* pr = NULL); | 147 GrPathRenderer* pr = NULL); |
148 | 148 |
149 // Determines whether it is possible to draw the element to both the stencil
buffer and the | 149 // Determines whether it is possible to draw the element to both the stencil
buffer and the |
150 // alpha mask simultaneously. If so and the element is a path a compatible p
ath renderer is | 150 // alpha mask simultaneously. If so and the element is a path a compatible p
ath renderer is |
151 // also returned. | 151 // also returned. |
152 bool canStencilAndDrawElement(GrDrawState*, | 152 bool canStencilAndDrawElement(GrPipelineBuilder*, |
153 GrTexture* target, | 153 GrTexture* target, |
154 GrPathRenderer**, | 154 GrPathRenderer**, |
155 const SkClipStack::Element*); | 155 const SkClipStack::Element*); |
156 | 156 |
157 void mergeMask(GrDrawState*, | 157 void mergeMask(GrPipelineBuilder*, |
158 GrTexture* dstMask, | 158 GrTexture* dstMask, |
159 GrTexture* srcMask, | 159 GrTexture* srcMask, |
160 SkRegion::Op op, | 160 SkRegion::Op op, |
161 const SkIRect& dstBound, | 161 const SkIRect& dstBound, |
162 const SkIRect& srcBound); | 162 const SkIRect& srcBound); |
163 | 163 |
164 GrTexture* createTempMask(int width, int height); | 164 GrTexture* createTempMask(int width, int height); |
165 | 165 |
166 void setupCache(const SkClipStack& clip, | 166 void setupCache(const SkClipStack& clip, |
167 const SkIRect& bounds); | 167 const SkIRect& bounds); |
168 /** | 168 /** |
169 * Called prior to return control back the GrGpu in setupClipping. It | 169 * Called prior to return control back the GrGpu in setupClipping. It |
170 * updates the GrGpu with stencil settings that account stencil-based | 170 * updates the GrGpu with stencil settings that account stencil-based |
171 * clipping. | 171 * clipping. |
172 */ | 172 */ |
173 void setDrawStateStencil(GrDrawState*, GrDrawState::AutoRestoreStencil*); | 173 void setPipelineBuilderStencil(GrPipelineBuilder*, GrPipelineBuilder::AutoRe
storeStencil*); |
174 | 174 |
175 /** | 175 /** |
176 * Adjusts the stencil settings to account for interaction with stencil | 176 * Adjusts the stencil settings to account for interaction with stencil |
177 * clipping. | 177 * clipping. |
178 */ | 178 */ |
179 void adjustStencilParams(GrStencilSettings* settings, | 179 void adjustStencilParams(GrStencilSettings* settings, |
180 StencilClipMode mode, | 180 StencilClipMode mode, |
181 int stencilBitCnt); | 181 int stencilBitCnt); |
182 | 182 |
183 /** | 183 /** |
184 * We may represent the clip as a mask in the stencil buffer or as an alpha | 184 * We may represent the clip as a mask in the stencil buffer or as an alpha |
185 * texture. It may be neither because the scissor rect suffices or we | 185 * texture. It may be neither because the scissor rect suffices or we |
186 * haven't yet examined the clip. | 186 * haven't yet examined the clip. |
187 */ | 187 */ |
188 enum ClipMaskType { | 188 enum ClipMaskType { |
189 kNone_ClipMaskType, | 189 kNone_ClipMaskType, |
190 kStencil_ClipMaskType, | 190 kStencil_ClipMaskType, |
191 kAlpha_ClipMaskType, | 191 kAlpha_ClipMaskType, |
192 } fCurrClipMaskType; | 192 } fCurrClipMaskType; |
193 | 193 |
194 GrClipMaskCache fAACache; // cache for the AA path | 194 GrClipMaskCache fAACache; // cache for the AA path |
195 GrClipTarget* fClipTarget; | 195 GrClipTarget* fClipTarget; |
196 StencilClipMode fClipMode; | 196 StencilClipMode fClipMode; |
197 | 197 |
198 typedef SkNoncopyable INHERITED; | 198 typedef SkNoncopyable INHERITED; |
199 }; | 199 }; |
200 #endif // GrClipMaskManager_DEFINED | 200 #endif // GrClipMaskManager_DEFINED |
OLD | NEW |