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

Side by Side Diff: tests/RecordOptsTest.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/RecordDrawTest.cpp ('k') | tests/RecordPatternTest.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
11 #include "SkRecord.h" 11 #include "SkRecord.h"
12 #include "SkRecordOpts.h" 12 #include "SkRecordOpts.h"
13 #include "SkRecorder.h" 13 #include "SkRecorder.h"
14 #include "SkRecords.h" 14 #include "SkRecords.h"
15 #include "SkXfermode.h" 15 #include "SkXfermode.h"
16 16
17 static const int W = 1920, H = 1080; 17 static const int W = 1920, H = 1080;
18 18
19 DEF_TEST(RecordOpts_NoopDrawSaveRestore, r) { 19 DEF_TEST(RecordOpts_NoopDraw, r) {
20 SkRecord record; 20 SkRecord record;
21 SkRecorder recorder(&record, W, H); 21 SkRecorder recorder(&record, W, H);
22 22
23 // The save and restore are pointless if there's only draw commands in the m iddle. 23 recorder.drawRect(SkRect::MakeWH(200, 200), SkPaint());
24 recorder.save(); 24 recorder.drawRect(SkRect::MakeWH(300, 300), SkPaint());
25 recorder.drawRect(SkRect::MakeWH(200, 200), SkPaint()); 25 recorder.drawRect(SkRect::MakeWH(100, 100), SkPaint());
26 recorder.drawRect(SkRect::MakeWH(300, 300), SkPaint());
27 recorder.drawRect(SkRect::MakeWH(100, 100), SkPaint());
28 recorder.restore();
29 26
30 record.replace<SkRecords::NoOp>(2); // NoOps should be allowed. 27 record.replace<SkRecords::NoOp>(1); // NoOps should be allowed.
31 28
32 SkRecordNoopSaveRestores(&record); 29 SkRecordNoopSaveRestores(&record);
33 30
34 assert_type<SkRecords::NoOp>(r, record, 0); 31 REPORTER_ASSERT(r, 2 == count_instances_of_type<SkRecords::DrawRect>(record) );
35 assert_type<SkRecords::DrawRect>(r, record, 1);
36 assert_type<SkRecords::NoOp>(r, record, 2);
37 assert_type<SkRecords::DrawRect>(r, record, 3);
38 assert_type<SkRecords::NoOp>(r, record, 4);
39 } 32 }
40 33
41 DEF_TEST(RecordOpts_SingleNoopSaveRestore, r) { 34 DEF_TEST(RecordOpts_SingleNoopSaveRestore, r) {
42 SkRecord record; 35 SkRecord record;
43 SkRecorder recorder(&record, W, H); 36 SkRecorder recorder(&record, W, H);
44 37
45 recorder.save(); 38 recorder.save();
46 recorder.clipRect(SkRect::MakeWH(200, 200)); 39 recorder.clipRect(SkRect::MakeWH(200, 200));
47 recorder.restore(); 40 recorder.restore();
48 41
(...skipping 14 matching lines...) Expand all
63 recorder.restore(); 56 recorder.restore();
64 57
65 // As long as we don't draw in there, everything is a noop. 58 // As long as we don't draw in there, everything is a noop.
66 recorder.save(); 59 recorder.save();
67 recorder.clipRect(SkRect::MakeWH(200, 200)); 60 recorder.clipRect(SkRect::MakeWH(200, 200));
68 recorder.clipRect(SkRect::MakeWH(100, 100)); 61 recorder.clipRect(SkRect::MakeWH(100, 100));
69 recorder.restore(); 62 recorder.restore();
70 recorder.restore(); 63 recorder.restore();
71 64
72 SkRecordNoopSaveRestores(&record); 65 SkRecordNoopSaveRestores(&record);
73 for (unsigned index = 0; index < 8; index++) { 66 for (unsigned index = 0; index < record.count(); index++) {
74 assert_type<SkRecords::NoOp>(r, record, index); 67 assert_type<SkRecords::NoOp>(r, record, index);
75 } 68 }
76 } 69 }
77 70
78 DEF_TEST(RecordOpts_SaveSaveLayerRestoreRestore, r) { 71 DEF_TEST(RecordOpts_SaveSaveLayerRestoreRestore, r) {
79 SkRecord record; 72 SkRecord record;
80 SkRecorder recorder(&record, W, H); 73 SkRecorder recorder(&record, W, H);
81 74
82 // A previous bug NoOp'd away the first 3 commands. 75 // A previous bug NoOp'd away the first 3 commands.
83 recorder.save(); 76 recorder.save();
84 recorder.saveLayer(NULL, NULL); 77 recorder.saveLayer(NULL, NULL);
85 recorder.restore(); 78 recorder.restore();
86 recorder.restore(); 79 recorder.restore();
87 80
88 SkRecordNoopSaveRestores(&record); 81 SkRecordNoopSaveRestores(&record);
89 assert_type<SkRecords::Save> (r, record, 0); 82 switch (record.count()) {
90 assert_type<SkRecords::SaveLayer>(r, record, 1); 83 case 4:
91 assert_type<SkRecords::Restore> (r, record, 2); 84 assert_type<SkRecords::Save> (r, record, 0);
92 assert_type<SkRecords::Restore> (r, record, 3); 85 assert_type<SkRecords::SaveLayer>(r, record, 1);
86 assert_type<SkRecords::Restore> (r, record, 2);
87 assert_type<SkRecords::Restore> (r, record, 3);
88 break;
89 case 2:
90 assert_type<SkRecords::SaveLayer>(r, record, 0);
91 assert_type<SkRecords::Restore> (r, record, 1);
92 break;
93 case 0:
94 break;
95 default:
96 REPORTER_ASSERT(r, false);
97 }
93 } 98 }
94 99
95 static void assert_savelayer_restore(skiatest::Reporter* r, 100 static void assert_savelayer_restore(skiatest::Reporter* r,
96 SkRecord* record, 101 SkRecord* record,
97 unsigned i, 102 unsigned i,
98 bool shouldBeNoOped) { 103 bool shouldBeNoOped) {
99 SkRecordNoopSaveLayerDrawRestores(record); 104 SkRecordNoopSaveLayerDrawRestores(record);
100 if (shouldBeNoOped) { 105 if (shouldBeNoOped) {
101 assert_type<SkRecords::NoOp>(r, *record, i); 106 assert_type<SkRecords::NoOp>(r, *record, i);
102 assert_type<SkRecords::NoOp>(r, *record, i+2); 107 assert_type<SkRecords::NoOp>(r, *record, i+2);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // SaveLayer/Restore removed: we can fold in the alpha! 162 // SaveLayer/Restore removed: we can fold in the alpha!
158 recorder.saveLayer(NULL, &goodLayerPaint); 163 recorder.saveLayer(NULL, &goodLayerPaint);
159 recorder.drawRect(draw, goodDrawPaint); 164 recorder.drawRect(draw, goodDrawPaint);
160 recorder.restore(); 165 recorder.restore();
161 assert_savelayer_restore(r, &record, 15, true); 166 assert_savelayer_restore(r, &record, 15, true);
162 167
163 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re cord, 16); 168 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re cord, 16);
164 REPORTER_ASSERT(r, drawRect != NULL); 169 REPORTER_ASSERT(r, drawRect != NULL);
165 REPORTER_ASSERT(r, drawRect->paint.getColor() == 0x03020202); 170 REPORTER_ASSERT(r, drawRect->paint.getColor() == 0x03020202);
166 } 171 }
OLDNEW
« no previous file with comments | « tests/RecordDrawTest.cpp ('k') | tests/RecordPatternTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698