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

Side by Side Diff: tests/AAClipTest.cpp

Issue 23576015: Change old PRG to be SkLCGRandom; change new one to SkRandom (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fix some spurious SkMWCRandoms Created 7 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « src/utils/SkPathUtils.cpp ('k') | tests/BitmapGetColorTest.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 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 "Test.h" 8 #include "Test.h"
9 #include "SkAAClip.h" 9 #include "SkAAClip.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 // so we translate the rgn to match that before drawing into the mask. 80 // so we translate the rgn to match that before drawing into the mask.
81 // 81 //
82 SkRegion tmpRgn(rgn); 82 SkRegion tmpRgn(rgn);
83 tmpRgn.translate(-rgn.getBounds().fLeft, -rgn.getBounds().fTop); 83 tmpRgn.translate(-rgn.getBounds().fLeft, -rgn.getBounds().fTop);
84 84
85 SkCanvas canvas(bitmap); 85 SkCanvas canvas(bitmap);
86 canvas.clipRegion(tmpRgn); 86 canvas.clipRegion(tmpRgn);
87 canvas.drawColor(SK_ColorBLACK); 87 canvas.drawColor(SK_ColorBLACK);
88 } 88 }
89 89
90 static SkIRect rand_rect(SkMWCRandom& rand, int n) { 90 static SkIRect rand_rect(SkRandom& rand, int n) {
91 int x = rand.nextS() % n; 91 int x = rand.nextS() % n;
92 int y = rand.nextS() % n; 92 int y = rand.nextS() % n;
93 int w = rand.nextU() % n; 93 int w = rand.nextU() % n;
94 int h = rand.nextU() % n; 94 int h = rand.nextU() % n;
95 return SkIRect::MakeXYWH(x, y, w, h); 95 return SkIRect::MakeXYWH(x, y, w, h);
96 } 96 }
97 97
98 static void make_rand_rgn(SkRegion* rgn, SkMWCRandom& rand) { 98 static void make_rand_rgn(SkRegion* rgn, SkRandom& rand) {
99 int count = rand.nextU() % 20; 99 int count = rand.nextU() % 20;
100 for (int i = 0; i < count; ++i) { 100 for (int i = 0; i < count; ++i) {
101 rgn->op(rand_rect(rand, 100), SkRegion::kXOR_Op); 101 rgn->op(rand_rect(rand, 100), SkRegion::kXOR_Op);
102 } 102 }
103 } 103 }
104 104
105 static bool operator==(const SkRegion& rgn, const SkAAClip& aaclip) { 105 static bool operator==(const SkRegion& rgn, const SkAAClip& aaclip) {
106 SkMask mask0, mask1; 106 SkMask mask0, mask1;
107 107
108 copyToMask(rgn, &mask0); 108 copyToMask(rgn, &mask0);
(...skipping 12 matching lines...) Expand all
121 } 121 }
122 122
123 static void setRgnToPath(SkRegion* rgn, const SkPath& path) { 123 static void setRgnToPath(SkRegion* rgn, const SkPath& path) {
124 SkIRect ir; 124 SkIRect ir;
125 path.getBounds().round(&ir); 125 path.getBounds().round(&ir);
126 rgn->setPath(path, SkRegion(ir)); 126 rgn->setPath(path, SkRegion(ir));
127 } 127 }
128 128
129 // aaclip.setRegion should create idential masks to the region 129 // aaclip.setRegion should create idential masks to the region
130 static void test_rgn(skiatest::Reporter* reporter) { 130 static void test_rgn(skiatest::Reporter* reporter) {
131 SkMWCRandom rand; 131 SkRandom rand;
132 for (int i = 0; i < 1000; i++) { 132 for (int i = 0; i < 1000; i++) {
133 SkRegion rgn; 133 SkRegion rgn;
134 make_rand_rgn(&rgn, rand); 134 make_rand_rgn(&rgn, rand);
135 REPORTER_ASSERT(reporter, equalsAAClip(rgn)); 135 REPORTER_ASSERT(reporter, equalsAAClip(rgn));
136 } 136 }
137 137
138 { 138 {
139 SkRegion rgn; 139 SkRegion rgn;
140 SkPath path; 140 SkPath path;
141 path.addCircle(0, 0, SkIntToScalar(30)); 141 path.addCircle(0, 0, SkIntToScalar(30));
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 REPORTER_ASSERT(reporter, clip0.getBounds().isEmpty()); 225 REPORTER_ASSERT(reporter, clip0.getBounds().isEmpty());
226 REPORTER_ASSERT(reporter, clip1 == clip0); 226 REPORTER_ASSERT(reporter, clip1 == clip0);
227 227
228 SkMask mask; 228 SkMask mask;
229 mask.fImage = NULL; 229 mask.fImage = NULL;
230 clip0.copyToMask(&mask); 230 clip0.copyToMask(&mask);
231 REPORTER_ASSERT(reporter, NULL == mask.fImage); 231 REPORTER_ASSERT(reporter, NULL == mask.fImage);
232 REPORTER_ASSERT(reporter, mask.fBounds.isEmpty()); 232 REPORTER_ASSERT(reporter, mask.fBounds.isEmpty());
233 } 233 }
234 234
235 static void rand_irect(SkIRect* r, int N, SkMWCRandom& rand) { 235 static void rand_irect(SkIRect* r, int N, SkRandom& rand) {
236 r->setXYWH(0, 0, rand.nextU() % N, rand.nextU() % N); 236 r->setXYWH(0, 0, rand.nextU() % N, rand.nextU() % N);
237 int dx = rand.nextU() % (2*N); 237 int dx = rand.nextU() % (2*N);
238 int dy = rand.nextU() % (2*N); 238 int dy = rand.nextU() % (2*N);
239 // use int dx,dy to make the subtract be signed 239 // use int dx,dy to make the subtract be signed
240 r->offset(N - dx, N - dy); 240 r->offset(N - dx, N - dy);
241 } 241 }
242 242
243 static void test_irect(skiatest::Reporter* reporter) { 243 static void test_irect(skiatest::Reporter* reporter) {
244 SkMWCRandom rand; 244 SkRandom rand;
245 245
246 for (int i = 0; i < 10000; i++) { 246 for (int i = 0; i < 10000; i++) {
247 SkAAClip clip0, clip1; 247 SkAAClip clip0, clip1;
248 SkRegion rgn0, rgn1; 248 SkRegion rgn0, rgn1;
249 SkIRect r0, r1; 249 SkIRect r0, r1;
250 250
251 rand_irect(&r0, 10, rand); 251 rand_irect(&r0, 10, rand);
252 rand_irect(&r1, 10, rand); 252 rand_irect(&r1, 10, rand);
253 clip0.setRect(r0); 253 clip0.setRect(r0);
254 clip1.setRect(r1); 254 clip1.setRect(r1);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 test_path_bounds(reporter); 399 test_path_bounds(reporter);
400 test_irect(reporter); 400 test_irect(reporter);
401 test_rgn(reporter); 401 test_rgn(reporter);
402 test_path_with_hole(reporter); 402 test_path_with_hole(reporter);
403 test_regressions(); 403 test_regressions();
404 test_nearly_integral(reporter); 404 test_nearly_integral(reporter);
405 } 405 }
406 406
407 #include "TestClassDef.h" 407 #include "TestClassDef.h"
408 DEFINE_TESTCLASS("AAClip", AAClipTestClass, TestAAClip) 408 DEFINE_TESTCLASS("AAClip", AAClipTestClass, TestAAClip)
OLDNEW
« no previous file with comments | « src/utils/SkPathUtils.cpp ('k') | tests/BitmapGetColorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698