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

Side by Side Diff: tests/RecordDrawTest.cpp

Issue 767333002: Defer saves() until they're needed (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update tests 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/PictureBBHTest.cpp ('k') | tests/RecordOptsTest.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 12 matching lines...) Expand all
23 23
24 class JustOneDraw : public SkDrawPictureCallback { 24 class JustOneDraw : public SkDrawPictureCallback {
25 public: 25 public:
26 JustOneDraw() : fCalls(0) {} 26 JustOneDraw() : fCalls(0) {}
27 27
28 virtual bool abortDrawing() SK_OVERRIDE { return fCalls++ > 0; } 28 virtual bool abortDrawing() SK_OVERRIDE { return fCalls++ > 0; }
29 private: 29 private:
30 int fCalls; 30 int fCalls;
31 }; 31 };
32 32
33 DEF_TEST(RecordDraw_LazySaves, r) {
34 // Record two commands.
35 SkRecord record;
36 SkRecorder recorder(&record, W, H);
37
38 REPORTER_ASSERT(r, 0 == record.count());
39 recorder.save();
40 REPORTER_ASSERT(r, 0 == record.count()); // the save was not recorded (ye t)
41 recorder.drawColor(SK_ColorRED);
42 REPORTER_ASSERT(r, 1 == record.count());
43 recorder.scale(2, 2);
44 REPORTER_ASSERT(r, 3 == record.count()); // now we see the save
45 recorder.restore();
46 REPORTER_ASSERT(r, 4 == record.count());
47
48 assert_type<SkRecords::DrawPaint>(r, record, 0);
49 assert_type<SkRecords::Save> (r, record, 1);
50 assert_type<SkRecords::SetMatrix>(r, record, 2);
51 assert_type<SkRecords::Restore> (r, record, 3);
52
53 recorder.save();
54 recorder.save();
55 recorder.restore();
56 recorder.restore();
57 REPORTER_ASSERT(r, 4 == record.count());
58 }
59
33 DEF_TEST(RecordDraw_Abort, r) { 60 DEF_TEST(RecordDraw_Abort, r) {
34 // Record two commands. 61 // Record two commands.
35 SkRecord record; 62 SkRecord record;
36 SkRecorder recorder(&record, W, H); 63 SkRecorder recorder(&record, W, H);
37 recorder.drawRect(SkRect::MakeWH(200, 300), SkPaint()); 64 recorder.drawRect(SkRect::MakeWH(200, 300), SkPaint());
38 recorder.clipRect(SkRect::MakeWH(100, 200)); 65 recorder.clipRect(SkRect::MakeWH(100, 200));
39 66
40 SkRecord rerecord; 67 SkRecord rerecord;
41 SkRecorder canvas(&rerecord, W, H); 68 SkRecorder canvas(&rerecord, W, H);
42 69
43 JustOneDraw callback; 70 JustOneDraw callback;
44 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL/*bbh*/, &callback); 71 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL/*bbh*/, &callback);
45 72
46 REPORTER_ASSERT(r, 3 == rerecord.count()); 73 REPORTER_ASSERT(r, 1 == count_instances_of_type<SkRecords::DrawRect>(rerecor d));
47 assert_type<SkRecords::Save> (r, rerecord, 0); 74 REPORTER_ASSERT(r, 0 == count_instances_of_type<SkRecords::ClipRect>(rerecor d));
48 assert_type<SkRecords::DrawRect>(r, rerecord, 1);
49 assert_type<SkRecords::Restore> (r, rerecord, 2);
50 } 75 }
51 76
52 DEF_TEST(RecordDraw_Unbalanced, r) { 77 DEF_TEST(RecordDraw_Unbalanced, r) {
53 SkRecord record; 78 SkRecord record;
54 SkRecorder recorder(&record, W, H); 79 SkRecorder recorder(&record, W, H);
55 recorder.save(); // We won't balance this, but SkRecordDraw will for us. 80 recorder.save(); // We won't balance this, but SkRecordDraw will for us.
81 recorder.scale(2, 2);
56 82
57 SkRecord rerecord; 83 SkRecord rerecord;
58 SkRecorder canvas(&rerecord, W, H); 84 SkRecorder canvas(&rerecord, W, H);
59 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL/*bbh*/, NULL/*callback*/); 85 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL/*bbh*/, NULL/*callback*/);
60 86
61 REPORTER_ASSERT(r, 4 == rerecord.count()); 87 int save_count = count_instances_of_type<SkRecords::Save>(rerecord);
62 assert_type<SkRecords::Save> (r, rerecord, 0); 88 int restore_count = count_instances_of_type<SkRecords::Save>(rerecord);
63 assert_type<SkRecords::Save> (r, rerecord, 1); 89 REPORTER_ASSERT(r, save_count == restore_count);
64 assert_type<SkRecords::Restore> (r, rerecord, 2);
65 assert_type<SkRecords::Restore> (r, rerecord, 3);
66 } 90 }
67 91
68 DEF_TEST(RecordDraw_SetMatrixClobber, r) { 92 DEF_TEST(RecordDraw_SetMatrixClobber, r) {
69 // Set up an SkRecord that just scales by 2x,3x. 93 // Set up an SkRecord that just scales by 2x,3x.
70 SkRecord scaleRecord; 94 SkRecord scaleRecord;
71 SkRecorder scaleCanvas(&scaleRecord, W, H); 95 SkRecorder scaleCanvas(&scaleRecord, W, H);
72 SkMatrix scale; 96 SkMatrix scale;
73 scale.setScale(2, 3); 97 scale.setScale(2, 3);
74 scaleCanvas.setMatrix(scale); 98 scaleCanvas.setMatrix(scale);
75 99
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 SkRecord record; 210 SkRecord record;
187 SkRecorder recorder(&record, kWidth, kHeight); 211 SkRecorder recorder(&record, kWidth, kHeight);
188 recorder.drawRect(r1, p); 212 recorder.drawRect(r1, p);
189 recorder.drawRect(r2, p); 213 recorder.drawRect(r2, p);
190 recorder.drawRect(r3, p); 214 recorder.drawRect(r3, p);
191 215
192 SkRecord rerecord; 216 SkRecord rerecord;
193 SkRecorder canvas(&rerecord, kWidth, kHeight); 217 SkRecorder canvas(&rerecord, kWidth, kHeight);
194 SkRecordPartialDraw(record, &canvas, NULL, 0, 1, 2, SkMatrix::I()); // repla y just drawRect of r2 218 SkRecordPartialDraw(record, &canvas, NULL, 0, 1, 2, SkMatrix::I()); // repla y just drawRect of r2
195 219
196 REPORTER_ASSERT(r, 3 == rerecord.count()); 220 REPORTER_ASSERT(r, 1 == count_instances_of_type<SkRecords::DrawRect>(rerecor d));
197 assert_type<SkRecords::Save> (r, rerecord, 0); 221 int index = find_first_instances_of_type<SkRecords::DrawRect>(rerecord);
198 assert_type<SkRecords::DrawRect> (r, rerecord, 1); 222 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re record, index);
199 assert_type<SkRecords::Restore> (r, rerecord, 2);
200
201 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re record, 1);
202 REPORTER_ASSERT(r, drawRect->rect == r2); 223 REPORTER_ASSERT(r, drawRect->rect == r2);
203 } 224 }
204 225
205 // A regression test for crbug.com/415468 and skbug.com/2957. 226 // A regression test for crbug.com/415468 and skbug.com/2957.
206 // 227 //
207 // This also now serves as a regression test for crbug.com/418417. We used to a djust the 228 // This also now serves as a regression test for crbug.com/418417. We used to a djust the
208 // bounds for the saveLayer, clip, and restore to be greater than the bounds of the picture. 229 // bounds for the saveLayer, clip, and restore to be greater than the bounds of the picture.
209 // (We were applying the saveLayer paint to the bounds after restore, which make s no sense.) 230 // (We were applying the saveLayer paint to the bounds after restore, which make s no sense.)
210 DEF_TEST(RecordDraw_SaveLayerAffectsClipBounds, r) { 231 DEF_TEST(RecordDraw_SaveLayerAffectsClipBounds, r) {
211 SkRecord record; 232 SkRecord record;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 324
304 { 325 {
305 SkRecord record; 326 SkRecord record;
306 SkRecorder recorder(&record, 10, 10); 327 SkRecorder recorder(&record, 10, 10);
307 recorder.drawImageRect(image, 0, SkRect::MakeWH(10, 10)); 328 recorder.drawImageRect(image, 0, SkRect::MakeWH(10, 10));
308 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL, 0); 329 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL, 0);
309 } 330 }
310 REPORTER_ASSERT(r, canvas.fDrawImageRectCalled); 331 REPORTER_ASSERT(r, canvas.fDrawImageRectCalled);
311 332
312 } 333 }
OLDNEW
« no previous file with comments | « tests/PictureBBHTest.cpp ('k') | tests/RecordOptsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698