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

Side by Side Diff: tests/PictureTest.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 | « tests/PathUtilsTest.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 "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 int count, DrawBitmapProc proc) { 68 int count, DrawBitmapProc proc) {
69 SkPicture* pic = new SkPicture; 69 SkPicture* pic = new SkPicture;
70 SkCanvas* canvas = pic->beginRecording(1000, 1000); 70 SkCanvas* canvas = pic->beginRecording(1000, 1000);
71 for (int i = 0; i < count; ++i) { 71 for (int i = 0; i < count; ++i) {
72 proc(canvas, bm[i], pos[i]); 72 proc(canvas, bm[i], pos[i]);
73 } 73 }
74 pic->endRecording(); 74 pic->endRecording();
75 return pic; 75 return pic;
76 } 76 }
77 77
78 static void rand_rect(SkRect* rect, SkMWCRandom& rand, SkScalar W, SkScalar H) { 78 static void rand_rect(SkRect* rect, SkRandom& rand, SkScalar W, SkScalar H) {
79 rect->fLeft = rand.nextRangeScalar(-W, 2*W); 79 rect->fLeft = rand.nextRangeScalar(-W, 2*W);
80 rect->fTop = rand.nextRangeScalar(-H, 2*H); 80 rect->fTop = rand.nextRangeScalar(-H, 2*H);
81 rect->fRight = rect->fLeft + rand.nextRangeScalar(0, W); 81 rect->fRight = rect->fLeft + rand.nextRangeScalar(0, W);
82 rect->fBottom = rect->fTop + rand.nextRangeScalar(0, H); 82 rect->fBottom = rect->fTop + rand.nextRangeScalar(0, H);
83 83
84 // we integralize rect to make our tests more predictable, since Gather is 84 // we integralize rect to make our tests more predictable, since Gather is
85 // a little sloppy. 85 // a little sloppy.
86 SkIRect ir; 86 SkIRect ir;
87 rect->round(&ir); 87 rect->round(&ir);
88 rect->set(ir); 88 rect->set(ir);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // corresponding bitmap/pixelref 171 // corresponding bitmap/pixelref
172 for (int i = 0; i < N; ++i) { 172 for (int i = 0; i < N; ++i) {
173 make_bm(&bm[i], IW, IH, SkColorSetARGB(0xFF, i, i, i), true); 173 make_bm(&bm[i], IW, IH, SkColorSetARGB(0xFF, i, i, i), true);
174 refs[i] = bm[i].pixelRef(); 174 refs[i] = bm[i].pixelRef();
175 } 175 }
176 176
177 static const DrawBitmapProc procs[] = { 177 static const DrawBitmapProc procs[] = {
178 drawbitmap_proc, drawbitmaprect_proc, drawshader_proc 178 drawbitmap_proc, drawbitmaprect_proc, drawshader_proc
179 }; 179 };
180 180
181 SkMWCRandom rand; 181 SkRandom rand;
182 for (size_t k = 0; k < SK_ARRAY_COUNT(procs); ++k) { 182 for (size_t k = 0; k < SK_ARRAY_COUNT(procs); ++k) {
183 SkAutoTUnref<SkPicture> pic(record_bitmaps(bm, pos, N, procs[k])); 183 SkAutoTUnref<SkPicture> pic(record_bitmaps(bm, pos, N, procs[k]));
184 184
185 // quick check for a small piece of each quadrant, which should just 185 // quick check for a small piece of each quadrant, which should just
186 // contain 1 bitmap. 186 // contain 1 bitmap.
187 for (size_t i = 0; i < SK_ARRAY_COUNT(pos); ++i) { 187 for (size_t i = 0; i < SK_ARRAY_COUNT(pos); ++i) {
188 SkRect r; 188 SkRect r;
189 r.set(2, 2, W - 2, H - 2); 189 r.set(2, 2, W - 2, H - 2);
190 r.offset(pos[i].fX, pos[i].fY); 190 r.offset(pos[i].fX, pos[i].fY);
191 SkAutoDataUnref data(SkPictureUtils::GatherPixelRefs(pic, r)); 191 SkAutoDataUnref data(SkPictureUtils::GatherPixelRefs(pic, r));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 // Ensure that serializing an empty picture does not assert. Likewise only runs in debug mode. 256 // Ensure that serializing an empty picture does not assert. Likewise only runs in debug mode.
257 static void test_serializing_empty_picture() { 257 static void test_serializing_empty_picture() {
258 SkPicture picture; 258 SkPicture picture;
259 picture.beginRecording(0, 0); 259 picture.beginRecording(0, 0);
260 picture.endRecording(); 260 picture.endRecording();
261 SkDynamicMemoryWStream stream; 261 SkDynamicMemoryWStream stream;
262 picture.serialize(&stream); 262 picture.serialize(&stream);
263 } 263 }
264 #endif 264 #endif
265 265
266 static void rand_op(SkCanvas* canvas, SkMWCRandom& rand) { 266 static void rand_op(SkCanvas* canvas, SkRandom& rand) {
267 SkPaint paint; 267 SkPaint paint;
268 SkRect rect = SkRect::MakeWH(50, 50); 268 SkRect rect = SkRect::MakeWH(50, 50);
269 269
270 SkScalar unit = rand.nextUScalar1(); 270 SkScalar unit = rand.nextUScalar1();
271 if (unit <= 0.3) { 271 if (unit <= 0.3) {
272 // SkDebugf("save\n"); 272 // SkDebugf("save\n");
273 canvas->save(); 273 canvas->save();
274 } else if (unit <= 0.6) { 274 } else if (unit <= 0.6) {
275 // SkDebugf("restore\n"); 275 // SkDebugf("restore\n");
276 canvas->restore(); 276 canvas->restore();
277 } else if (unit <= 0.9) { 277 } else if (unit <= 0.9) {
278 // SkDebugf("clip\n"); 278 // SkDebugf("clip\n");
279 canvas->clipRect(rect); 279 canvas->clipRect(rect);
280 } else { 280 } else {
281 // SkDebugf("draw\n"); 281 // SkDebugf("draw\n");
282 canvas->drawPaint(paint); 282 canvas->drawPaint(paint);
283 } 283 }
284 } 284 }
285 285
286 static void test_peephole() { 286 static void test_peephole() {
287 SkMWCRandom rand; 287 SkRandom rand;
288 288
289 for (int j = 0; j < 100; j++) { 289 for (int j = 0; j < 100; j++) {
290 SkMWCRandom rand2(rand); // remember the seed 290 SkRandom rand2(rand); // remember the seed
291 291
292 SkPicture picture; 292 SkPicture picture;
293 SkCanvas* canvas = picture.beginRecording(100, 100); 293 SkCanvas* canvas = picture.beginRecording(100, 100);
294 294
295 for (int i = 0; i < 1000; ++i) { 295 for (int i = 0; i < 1000; ++i) {
296 rand_op(canvas, rand); 296 rand_op(canvas, rand);
297 } 297 }
298 picture.endRecording(); 298 picture.endRecording();
299 299
300 rand = rand2; 300 rand = rand2;
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 test_peephole(); 617 test_peephole();
618 test_gatherpixelrefs(reporter); 618 test_gatherpixelrefs(reporter);
619 test_bitmap_with_encoded_data(reporter); 619 test_bitmap_with_encoded_data(reporter);
620 test_clone_empty(reporter); 620 test_clone_empty(reporter);
621 test_clip_bound_opt(reporter); 621 test_clip_bound_opt(reporter);
622 test_clip_expansion(reporter); 622 test_clip_expansion(reporter);
623 } 623 }
624 624
625 #include "TestClassDef.h" 625 #include "TestClassDef.h"
626 DEFINE_TESTCLASS("Pictures", PictureTestClass, TestPicture) 626 DEFINE_TESTCLASS("Pictures", PictureTestClass, TestPicture)
OLDNEW
« no previous file with comments | « tests/PathUtilsTest.cpp ('k') | tests/RTreeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698