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

Side by Side Diff: tests/PictureTest.cpp

Issue 12334131: Change random number generator for tests to SkMWCRandom (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Rebase to latest Created 7 years, 9 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 | « tests/PathTest.cpp ('k') | tests/RTreeTest.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 #include "Test.h" 7 #include "Test.h"
8 #include "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkData.h" 10 #include "SkData.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 int count, DrawBitmapProc proc) { 66 int count, DrawBitmapProc proc) {
67 SkPicture* pic = new SkPicture; 67 SkPicture* pic = new SkPicture;
68 SkCanvas* canvas = pic->beginRecording(1000, 1000); 68 SkCanvas* canvas = pic->beginRecording(1000, 1000);
69 for (int i = 0; i < count; ++i) { 69 for (int i = 0; i < count; ++i) {
70 proc(canvas, bm[i], pos[i]); 70 proc(canvas, bm[i], pos[i]);
71 } 71 }
72 pic->endRecording(); 72 pic->endRecording();
73 return pic; 73 return pic;
74 } 74 }
75 75
76 static void rand_rect(SkRect* rect, SkRandom& rand, SkScalar W, SkScalar H) { 76 static void rand_rect(SkRect* rect, SkMWCRandom& rand, SkScalar W, SkScalar H) {
77 rect->fLeft = rand.nextRangeScalar(-W, 2*W); 77 rect->fLeft = rand.nextRangeScalar(-W, 2*W);
78 rect->fTop = rand.nextRangeScalar(-H, 2*H); 78 rect->fTop = rand.nextRangeScalar(-H, 2*H);
79 rect->fRight = rect->fLeft + rand.nextRangeScalar(0, W); 79 rect->fRight = rect->fLeft + rand.nextRangeScalar(0, W);
80 rect->fBottom = rect->fTop + rand.nextRangeScalar(0, H); 80 rect->fBottom = rect->fTop + rand.nextRangeScalar(0, H);
81 81
82 // we integralize rect to make our tests more predictable, since Gather is 82 // we integralize rect to make our tests more predictable, since Gather is
83 // a little sloppy. 83 // a little sloppy.
84 SkIRect ir; 84 SkIRect ir;
85 rect->round(&ir); 85 rect->round(&ir);
86 rect->set(ir); 86 rect->set(ir);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // corresponding bitmap/pixelref 169 // corresponding bitmap/pixelref
170 for (int i = 0; i < N; ++i) { 170 for (int i = 0; i < N; ++i) {
171 make_bm(&bm[i], IW, IH, SkColorSetARGB(0xFF, i, i, i), true); 171 make_bm(&bm[i], IW, IH, SkColorSetARGB(0xFF, i, i, i), true);
172 refs[i] = bm[i].pixelRef(); 172 refs[i] = bm[i].pixelRef();
173 } 173 }
174 174
175 static const DrawBitmapProc procs[] = { 175 static const DrawBitmapProc procs[] = {
176 drawbitmap_proc, drawbitmaprect_proc, drawshader_proc 176 drawbitmap_proc, drawbitmaprect_proc, drawshader_proc
177 }; 177 };
178 178
179 SkRandom rand; 179 SkMWCRandom rand;
180 for (size_t k = 0; k < SK_ARRAY_COUNT(procs); ++k) { 180 for (size_t k = 0; k < SK_ARRAY_COUNT(procs); ++k) {
181 SkAutoTUnref<SkPicture> pic(record_bitmaps(bm, pos, N, procs[k])); 181 SkAutoTUnref<SkPicture> pic(record_bitmaps(bm, pos, N, procs[k]));
182 182
183 // quick check for a small piece of each quadrant, which should just 183 // quick check for a small piece of each quadrant, which should just
184 // contain 1 bitmap. 184 // contain 1 bitmap.
185 for (size_t i = 0; i < SK_ARRAY_COUNT(pos); ++i) { 185 for (size_t i = 0; i < SK_ARRAY_COUNT(pos); ++i) {
186 SkRect r; 186 SkRect r;
187 r.set(2, 2, W - 2, H - 2); 187 r.set(2, 2, W - 2, H - 2);
188 r.offset(pos[i].fX, pos[i].fY); 188 r.offset(pos[i].fX, pos[i].fY);
189 SkAutoDataUnref data(SkPictureUtils::GatherPixelRefs(pic, r)); 189 SkAutoDataUnref data(SkPictureUtils::GatherPixelRefs(pic, r));
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 // Ensure that serializing an empty picture does not assert. Likewise only runs in debug mode. 252 // Ensure that serializing an empty picture does not assert. Likewise only runs in debug mode.
253 static void test_serializing_empty_picture() { 253 static void test_serializing_empty_picture() {
254 SkPicture picture; 254 SkPicture picture;
255 picture.beginRecording(0, 0); 255 picture.beginRecording(0, 0);
256 picture.endRecording(); 256 picture.endRecording();
257 SkDynamicMemoryWStream stream; 257 SkDynamicMemoryWStream stream;
258 picture.serialize(&stream); 258 picture.serialize(&stream);
259 } 259 }
260 #endif 260 #endif
261 261
262 static void rand_op(SkCanvas* canvas, SkRandom& rand) { 262 static void rand_op(SkCanvas* canvas, SkMWCRandom& rand) {
263 SkPaint paint; 263 SkPaint paint;
264 SkRect rect = SkRect::MakeWH(50, 50); 264 SkRect rect = SkRect::MakeWH(50, 50);
265 265
266 SkScalar unit = rand.nextUScalar1(); 266 SkScalar unit = rand.nextUScalar1();
267 if (unit <= 0.3) { 267 if (unit <= 0.3) {
268 // SkDebugf("save\n"); 268 // SkDebugf("save\n");
269 canvas->save(); 269 canvas->save();
270 } else if (unit <= 0.6) { 270 } else if (unit <= 0.6) {
271 // SkDebugf("restore\n"); 271 // SkDebugf("restore\n");
272 canvas->restore(); 272 canvas->restore();
273 } else if (unit <= 0.9) { 273 } else if (unit <= 0.9) {
274 // SkDebugf("clip\n"); 274 // SkDebugf("clip\n");
275 canvas->clipRect(rect); 275 canvas->clipRect(rect);
276 } else { 276 } else {
277 // SkDebugf("draw\n"); 277 // SkDebugf("draw\n");
278 canvas->drawPaint(paint); 278 canvas->drawPaint(paint);
279 } 279 }
280 } 280 }
281 281
282 static void test_peephole() { 282 static void test_peephole() {
283 SkRandom rand; 283 SkMWCRandom rand;
284 284
285 for (int j = 0; j < 100; j++) { 285 for (int j = 0; j < 100; j++) {
286 SkRandom rand2(rand.getSeed()); // remember the seed 286 SkMWCRandom rand2(rand); // remember the seed
287 287
288 SkPicture picture; 288 SkPicture picture;
289 SkCanvas* canvas = picture.beginRecording(100, 100); 289 SkCanvas* canvas = picture.beginRecording(100, 100);
290 290
291 for (int i = 0; i < 1000; ++i) { 291 for (int i = 0; i < 1000; ++i) {
292 rand_op(canvas, rand); 292 rand_op(canvas, rand);
293 } 293 }
294 picture.endRecording(); 294 picture.endRecording();
295
296 rand = rand2;
295 } 297 }
296 298
297 { 299 {
298 SkPicture picture; 300 SkPicture picture;
299 SkCanvas* canvas = picture.beginRecording(100, 100); 301 SkCanvas* canvas = picture.beginRecording(100, 100);
300 SkRect rect = SkRect::MakeWH(50, 50); 302 SkRect rect = SkRect::MakeWH(50, 50);
301 303
302 for (int i = 0; i < 100; ++i) { 304 for (int i = 0; i < 100; ++i) {
303 canvas->save(); 305 canvas->save();
304 } 306 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 test_bad_bitmap(); 427 test_bad_bitmap();
426 #endif 428 #endif
427 test_peephole(); 429 test_peephole();
428 test_gatherpixelrefs(reporter); 430 test_gatherpixelrefs(reporter);
429 test_bitmap_with_encoded_data(reporter); 431 test_bitmap_with_encoded_data(reporter);
430 test_clone_empty(reporter); 432 test_clone_empty(reporter);
431 } 433 }
432 434
433 #include "TestClassDef.h" 435 #include "TestClassDef.h"
434 DEFINE_TESTCLASS("Pictures", PictureTestClass, TestPicture) 436 DEFINE_TESTCLASS("Pictures", PictureTestClass, TestPicture)
OLDNEW
« no previous file with comments | « tests/PathTest.cpp ('k') | tests/RTreeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698