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 #include "SkAAClip.h" | 8 #include "SkAAClip.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkMask.h" | 10 #include "SkMask.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 } | 55 } |
56 return true; | 56 return true; |
57 } | 57 } |
58 | 58 |
59 static void copyToMask(const SkRegion& rgn, SkMask* mask) { | 59 static void copyToMask(const SkRegion& rgn, SkMask* mask) { |
60 mask->fFormat = SkMask::kA8_Format; | 60 mask->fFormat = SkMask::kA8_Format; |
61 | 61 |
62 if (rgn.isEmpty()) { | 62 if (rgn.isEmpty()) { |
63 mask->fBounds.setEmpty(); | 63 mask->fBounds.setEmpty(); |
64 mask->fRowBytes = 0; | 64 mask->fRowBytes = 0; |
65 mask->fImage = NULL; | 65 mask->fImage = nullptr; |
66 return; | 66 return; |
67 } | 67 } |
68 | 68 |
69 mask->fBounds = rgn.getBounds(); | 69 mask->fBounds = rgn.getBounds(); |
70 mask->fRowBytes = mask->fBounds.width(); | 70 mask->fRowBytes = mask->fBounds.width(); |
71 mask->fImage = SkMask::AllocImage(mask->computeImageSize()); | 71 mask->fImage = SkMask::AllocImage(mask->computeImageSize()); |
72 sk_bzero(mask->fImage, mask->computeImageSize()); | 72 sk_bzero(mask->fImage, mask->computeImageSize()); |
73 | 73 |
74 SkImageInfo info = SkImageInfo::Make(mask->fBounds.width(), | 74 SkImageInfo info = SkImageInfo::Make(mask->fBounds.width(), |
75 mask->fBounds.height(), | 75 mask->fBounds.height(), |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 } | 178 } |
179 | 179 |
180 static void test_path_bounds(skiatest::Reporter* reporter) { | 180 static void test_path_bounds(skiatest::Reporter* reporter) { |
181 SkPath path; | 181 SkPath path; |
182 SkAAClip clip; | 182 SkAAClip clip; |
183 const int height = 40; | 183 const int height = 40; |
184 const SkScalar sheight = SkIntToScalar(height); | 184 const SkScalar sheight = SkIntToScalar(height); |
185 | 185 |
186 path.addOval(SkRect::MakeWH(sheight, sheight)); | 186 path.addOval(SkRect::MakeWH(sheight, sheight)); |
187 REPORTER_ASSERT(reporter, sheight == path.getBounds().height()); | 187 REPORTER_ASSERT(reporter, sheight == path.getBounds().height()); |
188 clip.setPath(path, NULL, true); | 188 clip.setPath(path, nullptr, true); |
189 REPORTER_ASSERT(reporter, height == clip.getBounds().height()); | 189 REPORTER_ASSERT(reporter, height == clip.getBounds().height()); |
190 | 190 |
191 // this is the trimmed height of this cubic (with aa). The critical thing | 191 // this is the trimmed height of this cubic (with aa). The critical thing |
192 // for this test is that it is less than height, which represents just | 192 // for this test is that it is less than height, which represents just |
193 // the bounds of the path's control-points. | 193 // the bounds of the path's control-points. |
194 // | 194 // |
195 // This used to fail until we tracked the MinY in the BuilderBlitter. | 195 // This used to fail until we tracked the MinY in the BuilderBlitter. |
196 // | 196 // |
197 const int teardrop_height = 12; | 197 const int teardrop_height = 12; |
198 path.reset(); | 198 path.reset(); |
199 imoveTo(path, 0, 20); | 199 imoveTo(path, 0, 20); |
200 icubicTo(path, 40, 40, 40, 0, 0, 20); | 200 icubicTo(path, 40, 40, 40, 0, 0, 20); |
201 REPORTER_ASSERT(reporter, sheight == path.getBounds().height()); | 201 REPORTER_ASSERT(reporter, sheight == path.getBounds().height()); |
202 clip.setPath(path, NULL, true); | 202 clip.setPath(path, nullptr, true); |
203 REPORTER_ASSERT(reporter, teardrop_height == clip.getBounds().height()); | 203 REPORTER_ASSERT(reporter, teardrop_height == clip.getBounds().height()); |
204 } | 204 } |
205 | 205 |
206 static void test_empty(skiatest::Reporter* reporter) { | 206 static void test_empty(skiatest::Reporter* reporter) { |
207 SkAAClip clip0, clip1; | 207 SkAAClip clip0, clip1; |
208 | 208 |
209 REPORTER_ASSERT(reporter, clip0.isEmpty()); | 209 REPORTER_ASSERT(reporter, clip0.isEmpty()); |
210 REPORTER_ASSERT(reporter, clip0.getBounds().isEmpty()); | 210 REPORTER_ASSERT(reporter, clip0.getBounds().isEmpty()); |
211 REPORTER_ASSERT(reporter, clip1 == clip0); | 211 REPORTER_ASSERT(reporter, clip1 == clip0); |
212 | 212 |
213 clip0.translate(10, 10); // should have no effect on empty | 213 clip0.translate(10, 10); // should have no effect on empty |
214 REPORTER_ASSERT(reporter, clip0.isEmpty()); | 214 REPORTER_ASSERT(reporter, clip0.isEmpty()); |
215 REPORTER_ASSERT(reporter, clip0.getBounds().isEmpty()); | 215 REPORTER_ASSERT(reporter, clip0.getBounds().isEmpty()); |
216 REPORTER_ASSERT(reporter, clip1 == clip0); | 216 REPORTER_ASSERT(reporter, clip1 == clip0); |
217 | 217 |
218 SkIRect r = { 10, 10, 40, 50 }; | 218 SkIRect r = { 10, 10, 40, 50 }; |
219 clip0.setRect(r); | 219 clip0.setRect(r); |
220 REPORTER_ASSERT(reporter, !clip0.isEmpty()); | 220 REPORTER_ASSERT(reporter, !clip0.isEmpty()); |
221 REPORTER_ASSERT(reporter, !clip0.getBounds().isEmpty()); | 221 REPORTER_ASSERT(reporter, !clip0.getBounds().isEmpty()); |
222 REPORTER_ASSERT(reporter, clip0 != clip1); | 222 REPORTER_ASSERT(reporter, clip0 != clip1); |
223 REPORTER_ASSERT(reporter, clip0.getBounds() == r); | 223 REPORTER_ASSERT(reporter, clip0.getBounds() == r); |
224 | 224 |
225 clip0.setEmpty(); | 225 clip0.setEmpty(); |
226 REPORTER_ASSERT(reporter, clip0.isEmpty()); | 226 REPORTER_ASSERT(reporter, clip0.isEmpty()); |
227 REPORTER_ASSERT(reporter, clip0.getBounds().isEmpty()); | 227 REPORTER_ASSERT(reporter, clip0.getBounds().isEmpty()); |
228 REPORTER_ASSERT(reporter, clip1 == clip0); | 228 REPORTER_ASSERT(reporter, clip1 == clip0); |
229 | 229 |
230 SkMask mask; | 230 SkMask mask; |
231 mask.fImage = NULL; | 231 mask.fImage = nullptr; |
232 clip0.copyToMask(&mask); | 232 clip0.copyToMask(&mask); |
233 REPORTER_ASSERT(reporter, NULL == mask.fImage); | 233 REPORTER_ASSERT(reporter, nullptr == mask.fImage); |
234 REPORTER_ASSERT(reporter, mask.fBounds.isEmpty()); | 234 REPORTER_ASSERT(reporter, mask.fBounds.isEmpty()); |
235 } | 235 } |
236 | 236 |
237 static void rand_irect(SkIRect* r, int N, SkRandom& rand) { | 237 static void rand_irect(SkIRect* r, int N, SkRandom& rand) { |
238 r->setXYWH(0, 0, rand.nextU() % N, rand.nextU() % N); | 238 r->setXYWH(0, 0, rand.nextU() % N, rand.nextU() % N); |
239 int dx = rand.nextU() % (2*N); | 239 int dx = rand.nextU() % (2*N); |
240 int dy = rand.nextU() % (2*N); | 240 int dy = rand.nextU() % (2*N); |
241 // use int dx,dy to make the subtract be signed | 241 // use int dx,dy to make the subtract be signed |
242 r->offset(N - dx, N - dy); | 242 r->offset(N - dx, N - dy); |
243 } | 243 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 expected.fImage = (uint8_t*)gExpectedImage; | 301 expected.fImage = (uint8_t*)gExpectedImage; |
302 | 302 |
303 SkPath path; | 303 SkPath path; |
304 path.addRect(SkRect::MakeXYWH(0, 0, | 304 path.addRect(SkRect::MakeXYWH(0, 0, |
305 SkIntToScalar(4), SkIntToScalar(2))); | 305 SkIntToScalar(4), SkIntToScalar(2))); |
306 path.addRect(SkRect::MakeXYWH(0, SkIntToScalar(4), | 306 path.addRect(SkRect::MakeXYWH(0, SkIntToScalar(4), |
307 SkIntToScalar(4), SkIntToScalar(2))); | 307 SkIntToScalar(4), SkIntToScalar(2))); |
308 | 308 |
309 for (int i = 0; i < 2; ++i) { | 309 for (int i = 0; i < 2; ++i) { |
310 SkAAClip clip; | 310 SkAAClip clip; |
311 clip.setPath(path, NULL, 1 == i); | 311 clip.setPath(path, nullptr, 1 == i); |
312 | 312 |
313 SkMask mask; | 313 SkMask mask; |
314 clip.copyToMask(&mask); | 314 clip.copyToMask(&mask); |
315 SkAutoMaskFreeImage freeM(mask.fImage); | 315 SkAutoMaskFreeImage freeM(mask.fImage); |
316 | 316 |
317 REPORTER_ASSERT(reporter, expected == mask); | 317 REPORTER_ASSERT(reporter, expected == mask); |
318 } | 318 } |
319 } | 319 } |
320 | 320 |
321 static void test_really_a_rect(skiatest::Reporter* reporter) { | 321 static void test_really_a_rect(skiatest::Reporter* reporter) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 test_empty(reporter); | 439 test_empty(reporter); |
440 test_path_bounds(reporter); | 440 test_path_bounds(reporter); |
441 test_irect(reporter); | 441 test_irect(reporter); |
442 test_rgn(reporter); | 442 test_rgn(reporter); |
443 test_path_with_hole(reporter); | 443 test_path_with_hole(reporter); |
444 test_regressions(); | 444 test_regressions(); |
445 test_nearly_integral(reporter); | 445 test_nearly_integral(reporter); |
446 test_really_a_rect(reporter); | 446 test_really_a_rect(reporter); |
447 test_crbug_422693(reporter); | 447 test_crbug_422693(reporter); |
448 } | 448 } |
OLD | NEW |