Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: src/gpu/GrClipMaskManager.h

Issue 683933003: Clip mask manager moved to ClipTarget (Closed) Base URL: https://skia.googlesource.com/skia.git@clear_stencil_clip_on_drawinfo
Patch Set: rebase on master Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/gpu/GrClipMaskManager.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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. This should really be on Gpu itself. We should revist th is when GPU 47 // Scissor state. This should really be on Gpu itself. We should revist th is when GPU
48 // and drawtarget are separate 48 // and drawtarget are separate
49 struct ScissorState { 49 struct ScissorState {
50 ScissorState() : fEnabled(false) {} 50 ScissorState() : fEnabled(false) {}
51 void set(const SkIRect& rect) { fRect = rect; fEnabled = true; } 51 void set(const SkIRect& rect) { fRect = rect; fEnabled = true; }
52 bool fEnabled; 52 bool fEnabled;
53 SkIRect fRect; 53 SkIRect fRect;
54 }; 54 };
55 55
56 /** 56 /**
57 * Creates a clip mask if necessary as a stencil buffer or alpha texture 57 * Creates a clip mask if necessary as a stencil buffer or alpha texture
58 * and sets the GrGpu's scissor and stencil state. If the return is false 58 * and sets the GrGpu's scissor and stencil state. If the return is false
59 * then the draw can be skipped. The AutoRestoreEffects is initialized by 59 * then the draw can be skipped. The AutoRestoreEffects is initialized by
60 * the manager when it must install additional effects to implement the 60 * the manager when it must install additional effects to implement the
61 * clip. devBounds is optional but can help optimize clipping. 61 * clip. devBounds is optional but can help optimize clipping.
62 */ 62 */
63 bool setupClipping(const GrClipData* clipDataIn, 63 bool setupClipping(const GrClipData* clipDataIn,
64 const SkRect* devBounds, 64 const SkRect* devBounds,
65 GrDrawState::AutoRestoreEffects*, 65 GrDrawState::AutoRestoreEffects*,
66 GrDrawState::AutoRestoreStencil*, 66 GrDrawState::AutoRestoreStencil*,
67 ScissorState* scissorState); 67 ScissorState*);
68 68
69 /** 69 /**
70 * Purge resources to free up memory. TODO: This class shouldn't hold any lo ng lived refs 70 * Purge resources to free up memory. TODO: This class shouldn't hold any lo ng lived refs
71 * which will allow ResourceCache2 to automatically purge anything this clas s has created. 71 * which will allow ResourceCache2 to automatically purge anything this clas s has created.
72 */ 72 */
73 void purgeResources(); 73 void purgeResources();
74 74
75 bool isClipInStencil() const { 75 bool isClipInStencil() const {
76 return kStencil_ClipMaskType == fCurrClipMaskType; 76 return kStencil_ClipMaskType == fCurrClipMaskType;
77 } 77 }
78 bool isClipInAlpha() const { 78 bool isClipInAlpha() const {
79 return kAlpha_ClipMaskType == fCurrClipMaskType; 79 return kAlpha_ClipMaskType == fCurrClipMaskType;
80 } 80 }
81 81
82 void invalidateStencilMask() { 82 void invalidateStencilMask() {
83 if (kStencil_ClipMaskType == fCurrClipMaskType) { 83 if (kStencil_ClipMaskType == fCurrClipMaskType) {
84 fCurrClipMaskType = kNone_ClipMaskType; 84 fCurrClipMaskType = kNone_ClipMaskType;
85 } 85 }
86 } 86 }
87 87
88 GrContext* getContext() { 88 GrContext* getContext() {
89 return fAACache.getContext(); 89 return fAACache.getContext();
90 } 90 }
91 91
92 void setGpu(GrGpu* gpu); 92 void setClipTarget(GrClipTarget*);
93 93
94 void adjustPathStencilParams(GrStencilSettings* settings); 94 void adjustPathStencilParams(GrStencilSettings*);
95
95 private: 96 private:
97 enum PrivateDrawStateStateBits {
98 kFirstBit = (GrDrawState::kLastPublicStateBit << 1),
99
100 kModifyStencilClip_StateBit = kFirstBit, // allows draws to modify
101 // stencil bits used for
102 // clipping.
103 };
104
96 /** 105 /**
97 * Informs the helper function adjustStencilParams() about how the stencil 106 * Informs the helper function adjustStencilParams() about how the stencil
98 * buffer clip is being used. 107 * buffer clip is being used.
99 */ 108 */
100 enum StencilClipMode { 109 enum StencilClipMode {
101 // Draw to the clip bit of the stencil buffer 110 // Draw to the clip bit of the stencil buffer
102 kModifyClip_StencilClipMode, 111 kModifyClip_StencilClipMode,
103 // Clip against the existing representation of the clip in the high bit 112 // Clip against the existing representation of the clip in the high bit
104 // of the stencil buffer. 113 // of the stencil buffer.
105 kRespectClip_StencilClipMode, 114 kRespectClip_StencilClipMode,
106 // Neither writing to nor clipping against the clip bit. 115 // Neither writing to nor clipping against the clip bit.
107 kIgnoreClip_StencilClipMode, 116 kIgnoreClip_StencilClipMode,
108 }; 117 };
109 118
110 GrGpu* fGpu;
111
112 /**
113 * We may represent the clip as a mask in the stencil buffer or as an alpha
114 * texture. It may be neither because the scissor rect suffices or we
115 * haven't yet examined the clip.
116 */
117 enum ClipMaskType {
118 kNone_ClipMaskType,
119 kStencil_ClipMaskType,
120 kAlpha_ClipMaskType,
121 } fCurrClipMaskType;
122
123 GrClipMaskCache fAACache; // cache for the AA path
124
125 // Attempts to install a series of coverage effects to implement the clip. R eturn indicates 119 // Attempts to install a series of coverage effects to implement the clip. R eturn indicates
126 // whether the element list was successfully converted to effects. 120 // whether the element list was successfully converted to effects.
127 bool installClipEffects(const GrReducedClip::ElementList&, 121 bool installClipEffects(const GrReducedClip::ElementList&,
128 GrDrawState::AutoRestoreEffects*, 122 GrDrawState::AutoRestoreEffects*,
129 const SkVector& clipOffset, 123 const SkVector& clipOffset,
130 const SkRect* devBounds); 124 const SkRect* devBounds);
131 125
132 // Draws the clip into the stencil buffer 126 // Draws the clip into the stencil buffer
133 bool createStencilClipMask(int32_t elementsGenID, 127 bool createStencilClipMask(int32_t elementsGenID,
134 GrReducedClip::InitialState initialState, 128 GrReducedClip::InitialState initialState,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 void setDrawStateStencil(GrDrawState::AutoRestoreStencil* asr); 183 void setDrawStateStencil(GrDrawState::AutoRestoreStencil* asr);
190 184
191 /** 185 /**
192 * Adjusts the stencil settings to account for interaction with stencil 186 * Adjusts the stencil settings to account for interaction with stencil
193 * clipping. 187 * clipping.
194 */ 188 */
195 void adjustStencilParams(GrStencilSettings* settings, 189 void adjustStencilParams(GrStencilSettings* settings,
196 StencilClipMode mode, 190 StencilClipMode mode,
197 int stencilBitCnt); 191 int stencilBitCnt);
198 192
193 /**
194 * We may represent the clip as a mask in the stencil buffer or as an alpha
195 * texture. It may be neither because the scissor rect suffices or we
196 * haven't yet examined the clip.
197 */
198 enum ClipMaskType {
199 kNone_ClipMaskType,
200 kStencil_ClipMaskType,
201 kAlpha_ClipMaskType,
202 } fCurrClipMaskType;
203
204 GrClipMaskCache fAACache; // cache for the AA path
205 GrClipTarget* fClipTarget;
206
199 typedef SkNoncopyable INHERITED; 207 typedef SkNoncopyable INHERITED;
200 }; 208 };
201 209
202 #endif // GrClipMaskManager_DEFINED 210 #endif // GrClipMaskManager_DEFINED
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrClipMaskManager.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698