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

Side by Side Diff: tests/RecordDrawTest.cpp

Issue 732653004: option to return drawable from recording (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « tests/PictureTest.cpp ('k') | tools/DumpRecord.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 2014 Google Inc. 2 * Copyright 2014 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 "RecordTestUtils.h" 9 #include "RecordTestUtils.h"
10 10
(...skipping 23 matching lines...) Expand all
34 // Record two commands. 34 // Record two commands.
35 SkRecord record; 35 SkRecord record;
36 SkRecorder recorder(&record, W, H); 36 SkRecorder recorder(&record, W, H);
37 recorder.drawRect(SkRect::MakeWH(200, 300), SkPaint()); 37 recorder.drawRect(SkRect::MakeWH(200, 300), SkPaint());
38 recorder.clipRect(SkRect::MakeWH(100, 200)); 38 recorder.clipRect(SkRect::MakeWH(100, 200));
39 39
40 SkRecord rerecord; 40 SkRecord rerecord;
41 SkRecorder canvas(&rerecord, W, H); 41 SkRecorder canvas(&rerecord, W, H);
42 42
43 JustOneDraw callback; 43 JustOneDraw callback;
44 SkRecordDraw(record, &canvas, NULL, 0, NULL/*bbh*/, &callback); 44 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL/*bbh*/, &callback);
45 45
46 REPORTER_ASSERT(r, 3 == rerecord.count()); 46 REPORTER_ASSERT(r, 3 == rerecord.count());
47 assert_type<SkRecords::Save> (r, rerecord, 0); 47 assert_type<SkRecords::Save> (r, rerecord, 0);
48 assert_type<SkRecords::DrawRect>(r, rerecord, 1); 48 assert_type<SkRecords::DrawRect>(r, rerecord, 1);
49 assert_type<SkRecords::Restore> (r, rerecord, 2); 49 assert_type<SkRecords::Restore> (r, rerecord, 2);
50 } 50 }
51 51
52 DEF_TEST(RecordDraw_Unbalanced, r) { 52 DEF_TEST(RecordDraw_Unbalanced, r) {
53 SkRecord record; 53 SkRecord record;
54 SkRecorder recorder(&record, W, H); 54 SkRecorder recorder(&record, W, H);
55 recorder.save(); // We won't balance this, but SkRecordDraw will for us. 55 recorder.save(); // We won't balance this, but SkRecordDraw will for us.
56 56
57 SkRecord rerecord; 57 SkRecord rerecord;
58 SkRecorder canvas(&rerecord, W, H); 58 SkRecorder canvas(&rerecord, W, H);
59 SkRecordDraw(record, &canvas, NULL, 0, NULL/*bbh*/, NULL/*callback*/); 59 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL/*bbh*/, NULL/*callback*/);
60 60
61 REPORTER_ASSERT(r, 4 == rerecord.count()); 61 REPORTER_ASSERT(r, 4 == rerecord.count());
62 assert_type<SkRecords::Save> (r, rerecord, 0); 62 assert_type<SkRecords::Save> (r, rerecord, 0);
63 assert_type<SkRecords::Save> (r, rerecord, 1); 63 assert_type<SkRecords::Save> (r, rerecord, 1);
64 assert_type<SkRecords::Restore> (r, rerecord, 2); 64 assert_type<SkRecords::Restore> (r, rerecord, 2);
65 assert_type<SkRecords::Restore> (r, rerecord, 3); 65 assert_type<SkRecords::Restore> (r, rerecord, 3);
66 } 66 }
67 67
68 DEF_TEST(RecordDraw_SetMatrixClobber, r) { 68 DEF_TEST(RecordDraw_SetMatrixClobber, r) {
69 // Set up an SkRecord that just scales by 2x,3x. 69 // Set up an SkRecord that just scales by 2x,3x.
70 SkRecord scaleRecord; 70 SkRecord scaleRecord;
71 SkRecorder scaleCanvas(&scaleRecord, W, H); 71 SkRecorder scaleCanvas(&scaleRecord, W, H);
72 SkMatrix scale; 72 SkMatrix scale;
73 scale.setScale(2, 3); 73 scale.setScale(2, 3);
74 scaleCanvas.setMatrix(scale); 74 scaleCanvas.setMatrix(scale);
75 75
76 // Set up an SkRecord with an initial +20, +20 translate. 76 // Set up an SkRecord with an initial +20, +20 translate.
77 SkRecord translateRecord; 77 SkRecord translateRecord;
78 SkRecorder translateCanvas(&translateRecord, W, H); 78 SkRecorder translateCanvas(&translateRecord, W, H);
79 SkMatrix translate; 79 SkMatrix translate;
80 translate.setTranslate(20, 20); 80 translate.setTranslate(20, 20);
81 translateCanvas.setMatrix(translate); 81 translateCanvas.setMatrix(translate);
82 82
83 SkRecordDraw(scaleRecord, &translateCanvas, NULL, 0, NULL/*bbh*/, NULL/*call back*/); 83 SkRecordDraw(scaleRecord, &translateCanvas, NULL, NULL, 0, NULL/*bbh*/, NULL /*callback*/);
84 REPORTER_ASSERT(r, 4 == translateRecord.count()); 84 REPORTER_ASSERT(r, 4 == translateRecord.count());
85 assert_type<SkRecords::SetMatrix>(r, translateRecord, 0); 85 assert_type<SkRecords::SetMatrix>(r, translateRecord, 0);
86 assert_type<SkRecords::Save> (r, translateRecord, 1); 86 assert_type<SkRecords::Save> (r, translateRecord, 1);
87 assert_type<SkRecords::SetMatrix>(r, translateRecord, 2); 87 assert_type<SkRecords::SetMatrix>(r, translateRecord, 2);
88 assert_type<SkRecords::Restore> (r, translateRecord, 3); 88 assert_type<SkRecords::Restore> (r, translateRecord, 3);
89 89
90 // When we look at translateRecord now, it should have its first +20,+20 tra nslate, 90 // When we look at translateRecord now, it should have its first +20,+20 tra nslate,
91 // then a 2x,3x scale that's been concatted with that +20,+20 translate. 91 // then a 2x,3x scale that's been concatted with that +20,+20 translate.
92 const SkRecords::SetMatrix* setMatrix; 92 const SkRecords::SetMatrix* setMatrix;
93 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 0); 93 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 0);
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(10, 10)); 313 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(10, 10));
314 surface->getCanvas()->clear(SK_ColorGREEN); 314 surface->getCanvas()->clear(SK_ColorGREEN);
315 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); 315 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
316 316
317 SkCanvasMock canvas(10, 10); 317 SkCanvasMock canvas(10, 10);
318 318
319 { 319 {
320 SkRecord record; 320 SkRecord record;
321 SkRecorder recorder(&record, 10, 10); 321 SkRecorder recorder(&record, 10, 10);
322 recorder.drawImage(image, 0, 0); 322 recorder.drawImage(image, 0, 0);
323 SkRecordDraw(record, &canvas, NULL, 0, NULL, 0); 323 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL, 0);
324 } 324 }
325 REPORTER_ASSERT(r, canvas.fDrawImageCalled); 325 REPORTER_ASSERT(r, canvas.fDrawImageCalled);
326 canvas.resetTestValues(); 326 canvas.resetTestValues();
327 327
328 { 328 {
329 SkRecord record; 329 SkRecord record;
330 SkRecorder recorder(&record, 10, 10); 330 SkRecorder recorder(&record, 10, 10);
331 recorder.drawImageRect(image, 0, SkRect::MakeWH(10, 10)); 331 recorder.drawImageRect(image, 0, SkRect::MakeWH(10, 10));
332 SkRecordDraw(record, &canvas, NULL, 0, NULL, 0); 332 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL, 0);
333 } 333 }
334 REPORTER_ASSERT(r, canvas.fDrawImageRectCalled); 334 REPORTER_ASSERT(r, canvas.fDrawImageRectCalled);
335 335
336 } 336 }
OLDNEW
« no previous file with comments | « tests/PictureTest.cpp ('k') | tools/DumpRecord.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698