OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 | 8 |
9 #include "GrStencil.h" | 9 #include "GrStencil.h" |
10 | 10 |
11 #include "GrProcessor.h" | 11 #include "GrProcessor.h" |
12 | 12 |
13 //////////////////////////////////////////////////////////////////////////////// | 13 //////////////////////////////////////////////////////////////////////////////// |
14 // Stencil Rules for Merging user stencil space into clip | 14 // Stencil Rules for Merging user stencil space into clip |
15 | 15 |
16 // We can't include the clip bit in the ref or mask values because the division | 16 // We can't include the clip bit in the ref or mask values because the division |
17 // between user and clip bits in the stencil depends on the number of stencil | 17 // between user and clip bits in the stencil depends on the number of stencil |
18 // bits in the runtime. Comments below indicate what the code should do to | 18 // bits in the runtime. Comments below indicate what the code should do to |
19 // incorporate the clip bit into these settings. | 19 // incorporate the clip bit into these settings. |
20 | 20 |
21 /////// | 21 /////// |
22 // Replace | 22 // Replace |
23 | 23 |
24 // set the ref to be the clip bit, but mask it out for the test | 24 // set the ref to be the clip bit, but mask it out for the test |
25 GR_STATIC_CONST_SAME_STENCIL(gUserToClipReplace, | 25 static constexpr GrStencilSettings gUserToClipReplace( |
26 kReplace_StencilOp, | 26 kReplace_StencilOp, |
27 kZero_StencilOp, | 27 kZero_StencilOp, |
28 kLess_StencilFunc, | 28 kLess_StencilFunc, |
29 0xffff, // unset clip bit | 29 0xffff, // unset clip bit |
30 0x0000, // set clip bit | 30 0x0000, // set clip bit |
31 0xffff); | 31 0xffff); |
32 | 32 |
33 GR_STATIC_CONST_SAME_STENCIL(gInvUserToClipReplace, | 33 static constexpr GrStencilSettings gInvUserToClipReplace( |
34 kReplace_StencilOp, | 34 kReplace_StencilOp, |
35 kZero_StencilOp, | 35 kZero_StencilOp, |
36 kEqual_StencilFunc, | 36 kEqual_StencilFunc, |
37 0xffff, // unset clip bit | 37 0xffff, // unset clip bit |
38 0x0000, // set clip bit | 38 0x0000, // set clip bit |
39 0xffff); | 39 0xffff); |
40 | 40 |
41 /////// | 41 /////// |
42 // Intersect | 42 // Intersect |
43 GR_STATIC_CONST_SAME_STENCIL(gUserToClipIsect, | 43 static constexpr GrStencilSettings gUserToClipIsect( |
44 kReplace_StencilOp, | 44 kReplace_StencilOp, |
45 kZero_StencilOp, | 45 kZero_StencilOp, |
46 kLess_StencilFunc, | 46 kLess_StencilFunc, |
47 0xffff, | 47 0xffff, |
48 0x0000, // set clip bit | 48 0x0000, // set clip bit |
49 0xffff); | 49 0xffff); |
50 | 50 |
51 GR_STATIC_CONST_SAME_STENCIL(gInvUserToClipIsect, | 51 static constexpr GrStencilSettings gInvUserToClipIsect( |
52 kReplace_StencilOp, | 52 kReplace_StencilOp, |
53 kZero_StencilOp, | 53 kZero_StencilOp, |
54 kEqual_StencilFunc, | 54 kEqual_StencilFunc, |
55 0xffff, | 55 0xffff, |
56 0x0000, // set clip bit | 56 0x0000, // set clip bit |
57 0xffff); | 57 0xffff); |
58 | 58 |
59 /////// | 59 /////// |
60 // Difference | 60 // Difference |
61 GR_STATIC_CONST_SAME_STENCIL(gUserToClipDiff, | 61 static constexpr GrStencilSettings gUserToClipDiff( |
62 kReplace_StencilOp, | 62 kReplace_StencilOp, |
63 kZero_StencilOp, | 63 kZero_StencilOp, |
64 kEqual_StencilFunc, | 64 kEqual_StencilFunc, |
65 0xffff, | 65 0xffff, |
66 0x0000, // set clip bit | 66 0x0000, // set clip bit |
67 0xffff); | 67 0xffff); |
68 | 68 |
69 GR_STATIC_CONST_SAME_STENCIL(gInvUserToClipDiff, | 69 static constexpr GrStencilSettings gInvUserToClipDiff( |
70 kReplace_StencilOp, | 70 kReplace_StencilOp, |
71 kZero_StencilOp, | 71 kZero_StencilOp, |
72 kLess_StencilFunc, | 72 kLess_StencilFunc, |
73 0xffff, | 73 0xffff, |
74 0x0000, // set clip bit | 74 0x0000, // set clip bit |
75 0xffff); | 75 0xffff); |
76 | 76 |
77 /////// | 77 /////// |
78 // Union | 78 // Union |
79 | 79 |
80 // first pass makes all the passing cases >= just clip bit set. | 80 // first pass makes all the passing cases >= just clip bit set. |
81 GR_STATIC_CONST_SAME_STENCIL(gUserToClipUnionPass0, | 81 static constexpr GrStencilSettings gUserToClipUnionPass0( |
82 kReplace_StencilOp, | 82 kReplace_StencilOp, |
83 kKeep_StencilOp, | 83 kKeep_StencilOp, |
84 kLEqual_StencilFunc, | 84 kLEqual_StencilFunc, |
85 0xffff, | 85 0xffff, |
86 0x0001, // set clip bit | 86 0x0001, // set clip bit |
87 0xffff); | 87 0xffff); |
88 | 88 |
89 // second pass allows anything greater than just clip bit set to pass | 89 // second pass allows anything greater than just clip bit set to pass |
90 GR_STATIC_CONST_SAME_STENCIL(gUserToClipUnionPass1, | 90 static constexpr GrStencilSettings gUserToClipUnionPass1( |
91 kReplace_StencilOp, | 91 kReplace_StencilOp, |
92 kZero_StencilOp, | 92 kZero_StencilOp, |
93 kLEqual_StencilFunc, | 93 kLEqual_StencilFunc, |
94 0xffff, | 94 0xffff, |
95 0x0000, // set clip bit | 95 0x0000, // set clip bit |
96 0xffff); | 96 0xffff); |
97 | 97 |
98 // first pass finds zeros in the user bits and if found sets | 98 // first pass finds zeros in the user bits and if found sets |
99 // the clip bit to 1 | 99 // the clip bit to 1 |
100 GR_STATIC_CONST_SAME_STENCIL(gInvUserToClipUnionPass0, | 100 static constexpr GrStencilSettings gInvUserToClipUnionPass0( |
101 kReplace_StencilOp, | 101 kReplace_StencilOp, |
102 kKeep_StencilOp, | 102 kKeep_StencilOp, |
103 kEqual_StencilFunc, | 103 kEqual_StencilFunc, |
104 0xffff, | 104 0xffff, |
105 0x0000, // set clip bit | 105 0x0000, // set clip bit |
106 0x0000 // set clip bit | 106 0x0000 // set clip bit |
107 ); | 107 ); |
108 | 108 |
109 // second pass zeros the user bits | 109 // second pass zeros the user bits |
110 GR_STATIC_CONST_SAME_STENCIL(gInvUserToClipUnionPass1, | 110 static constexpr GrStencilSettings gInvUserToClipUnionPass1( |
111 kZero_StencilOp, | 111 kZero_StencilOp, |
112 kZero_StencilOp, | 112 kZero_StencilOp, |
113 kLess_StencilFunc, | 113 kLess_StencilFunc, |
114 0xffff, | 114 0xffff, |
115 0x0000, | 115 0x0000, |
116 0xffff // unset clip bit | 116 0xffff // unset clip bit |
117 ); | 117 ); |
118 | 118 |
119 /////// | 119 /////// |
120 // Xor | 120 // Xor |
121 GR_STATIC_CONST_SAME_STENCIL(gUserToClipXorPass0, | 121 static constexpr GrStencilSettings gUserToClipXorPass0( |
122 kInvert_StencilOp, | 122 kInvert_StencilOp, |
123 kKeep_StencilOp, | 123 kKeep_StencilOp, |
124 kEqual_StencilFunc, | 124 kEqual_StencilFunc, |
125 0xffff, // unset clip bit | 125 0xffff, // unset clip bit |
126 0x0000, | 126 0x0000, |
127 0xffff); | 127 0xffff); |
128 | 128 |
129 GR_STATIC_CONST_SAME_STENCIL(gUserToClipXorPass1, | 129 static constexpr GrStencilSettings gUserToClipXorPass1( |
130 kReplace_StencilOp, | 130 kReplace_StencilOp, |
131 kZero_StencilOp, | 131 kZero_StencilOp, |
132 kGreater_StencilFunc, | 132 kGreater_StencilFunc, |
133 0xffff, | 133 0xffff, |
134 0x0000, // set clip bit | 134 0x0000, // set clip bit |
135 0xffff); | 135 0xffff); |
136 | 136 |
137 GR_STATIC_CONST_SAME_STENCIL(gInvUserToClipXorPass0, | 137 static constexpr GrStencilSettings gInvUserToClipXorPass0( |
138 kInvert_StencilOp, | 138 kInvert_StencilOp, |
139 kKeep_StencilOp, | 139 kKeep_StencilOp, |
140 kEqual_StencilFunc, | 140 kEqual_StencilFunc, |
141 0xffff, // unset clip bit | 141 0xffff, // unset clip bit |
142 0x0000, | 142 0x0000, |
143 0xffff); | 143 0xffff); |
144 | 144 |
145 GR_STATIC_CONST_SAME_STENCIL(gInvUserToClipXorPass1, | 145 static constexpr GrStencilSettings gInvUserToClipXorPass1( |
146 kReplace_StencilOp, | 146 kReplace_StencilOp, |
147 kZero_StencilOp, | 147 kZero_StencilOp, |
148 kLess_StencilFunc, | 148 kLess_StencilFunc, |
149 0xffff, | 149 0xffff, |
150 0x0000, // set clip bit | 150 0x0000, // set clip bit |
151 0xffff); | 151 0xffff); |
152 | 152 |
153 /////// | 153 /////// |
154 // Reverse Diff | 154 // Reverse Diff |
155 GR_STATIC_CONST_SAME_STENCIL(gUserToClipRDiffPass0, | 155 static constexpr GrStencilSettings gUserToClipRDiffPass0( |
156 kInvert_StencilOp, | 156 kInvert_StencilOp, |
157 kZero_StencilOp, | 157 kZero_StencilOp, |
158 kLess_StencilFunc, | 158 kLess_StencilFunc, |
159 0xffff, // unset clip bit | 159 0xffff, // unset clip bit |
160 0x0000, // set clip bit | 160 0x0000, // set clip bit |
161 0xffff); | 161 0xffff); |
162 | 162 |
163 GR_STATIC_CONST_SAME_STENCIL(gUserToClipRDiffPass1, | 163 static constexpr GrStencilSettings gUserToClipRDiffPass1( |
164 kReplace_StencilOp, | 164 kReplace_StencilOp, |
165 kZero_StencilOp, | 165 kZero_StencilOp, |
166 kEqual_StencilFunc, | 166 kEqual_StencilFunc, |
167 0x0000, // set clip bit | 167 0x0000, // set clip bit |
168 0x0000, // set clip bit | 168 0x0000, // set clip bit |
169 0xffff); | 169 0xffff); |
170 | 170 |
171 // We are looking for stencil values that are all zero. The first pass sets the | 171 // We are looking for stencil values that are all zero. The first pass sets the |
172 // clip bit if the stencil is all zeros. The second pass clears the user bits. | 172 // clip bit if the stencil is all zeros. The second pass clears the user bits. |
173 GR_STATIC_CONST_SAME_STENCIL(gInvUserToClipRDiffPass0, | 173 static constexpr GrStencilSettings gInvUserToClipRDiffPass0( |
174 kInvert_StencilOp, | 174 kInvert_StencilOp, |
175 kZero_StencilOp, | 175 kZero_StencilOp, |
176 kEqual_StencilFunc, | 176 kEqual_StencilFunc, |
177 0xffff, | 177 0xffff, |
178 0x0000, | 178 0x0000, |
179 0x0000 // set clip bit | 179 0x0000 // set clip bit |
180 ); | 180 ); |
181 | 181 |
182 GR_STATIC_CONST_SAME_STENCIL(gInvUserToClipRDiffPass1, | 182 static constexpr GrStencilSettings gInvUserToClipRDiffPass1( |
183 kZero_StencilOp, | 183 kZero_StencilOp, |
184 kZero_StencilOp, | 184 kZero_StencilOp, |
185 kAlways_StencilFunc, | 185 kAlways_StencilFunc, |
186 0xffff, | 186 0xffff, |
187 0x0000, | 187 0x0000, |
188 0xffff // unset clip bit | 188 0xffff // unset clip bit |
189 ); | 189 ); |
190 | 190 |
191 /////// | 191 /////// |
192 // Direct to Stencil | 192 // Direct to Stencil |
193 | 193 |
194 // We can render a clip element directly without first writing to the client | 194 // We can render a clip element directly without first writing to the client |
195 // portion of the clip when the fill is not inverse and the set operation will | 195 // portion of the clip when the fill is not inverse and the set operation will |
196 // only modify the in/out status of samples covered by the clip element. | 196 // only modify the in/out status of samples covered by the clip element. |
197 | 197 |
198 // this one only works if used right after stencil clip was cleared. | 198 // this one only works if used right after stencil clip was cleared. |
199 // Our clip mask creation code doesn't allow midstream replace ops. | 199 // Our clip mask creation code doesn't allow midstream replace ops. |
200 GR_STATIC_CONST_SAME_STENCIL(gReplaceClip, | 200 static constexpr GrStencilSettings gReplaceClip( |
201 kReplace_StencilOp, | 201 kReplace_StencilOp, |
202 kReplace_StencilOp, | 202 kReplace_StencilOp, |
203 kAlways_StencilFunc, | 203 kAlways_StencilFunc, |
204 0xffff, | 204 0xffff, |
205 0x0000, // set clip bit | 205 0x0000, // set clip bit |
206 0x0000 // set clipBit | 206 0x0000 // set clipBit |
207 ); | 207 ); |
208 | 208 |
209 GR_STATIC_CONST_SAME_STENCIL(gUnionClip, | 209 static constexpr GrStencilSettings gUnionClip( |
210 kReplace_StencilOp, | 210 kReplace_StencilOp, |
211 kReplace_StencilOp, | 211 kReplace_StencilOp, |
212 kAlways_StencilFunc, | 212 kAlways_StencilFunc, |
213 0xffff, | 213 0xffff, |
214 0x0000, // set clip bit | 214 0x0000, // set clip bit |
215 0x0000 // set clip bit | 215 0x0000 // set clip bit |
216 ); | 216 ); |
217 | 217 |
218 GR_STATIC_CONST_SAME_STENCIL(gXorClip, | 218 static constexpr GrStencilSettings gXorClip( |
219 kInvert_StencilOp, | 219 kInvert_StencilOp, |
220 kInvert_StencilOp, | 220 kInvert_StencilOp, |
221 kAlways_StencilFunc, | 221 kAlways_StencilFunc, |
222 0xffff, | 222 0xffff, |
223 0x0000, | 223 0x0000, |
224 0x0000 // set clip bit | 224 0x0000 // set clip bit |
225 ); | 225 ); |
226 | 226 |
227 GR_STATIC_CONST_SAME_STENCIL(gDiffClip, | 227 static constexpr GrStencilSettings gDiffClip( |
228 kZero_StencilOp, | 228 kZero_StencilOp, |
229 kZero_StencilOp, | 229 kZero_StencilOp, |
230 kAlways_StencilFunc, | 230 kAlways_StencilFunc, |
231 0xffff, | 231 0xffff, |
232 0x0000, | 232 0x0000, |
233 0x0000 // set clip bit | 233 0x0000 // set clip bit |
234 ); | 234 ); |
235 | 235 |
236 bool GrStencilSettings::GetClipPasses( | 236 bool GrStencilSettings::GetClipPasses( |
237 SkRegion::Op op, | 237 SkRegion::Op op, |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 } | 394 } |
395 return false; | 395 return false; |
396 } | 396 } |
397 | 397 |
398 void GrStencilSettings::genKey(GrProcessorKeyBuilder* b) const { | 398 void GrStencilSettings::genKey(GrProcessorKeyBuilder* b) const { |
399 static const int kCount = sizeof(GrStencilSettings) / sizeof(uint32_t); | 399 static const int kCount = sizeof(GrStencilSettings) / sizeof(uint32_t); |
400 GR_STATIC_ASSERT(0 == sizeof(GrStencilSettings) % sizeof(uint32_t)); | 400 GR_STATIC_ASSERT(0 == sizeof(GrStencilSettings) % sizeof(uint32_t)); |
401 uint32_t* key = b->add32n(kCount); | 401 uint32_t* key = b->add32n(kCount); |
402 memcpy(key, this, sizeof(GrStencilSettings)); | 402 memcpy(key, this, sizeof(GrStencilSettings)); |
403 } | 403 } |
OLD | NEW |