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

Side by Side Diff: tests/RecordPatternTest.cpp

Issue 290653004: Remove SkRecorder's kWriteOnly mode. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 6 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
« no previous file with comments | « tests/RecordOptsTest.cpp ('k') | tests/RecorderTest.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 #include "Test.h" 1 #include "Test.h"
2 2
3 #include "SkRecord.h" 3 #include "SkRecord.h"
4 #include "SkRecordPattern.h" 4 #include "SkRecordPattern.h"
5 #include "SkRecorder.h" 5 #include "SkRecorder.h"
6 #include "SkRecords.h" 6 #include "SkRecords.h"
7 7
8 using namespace SkRecords; 8 using namespace SkRecords;
9 typedef Pattern3<Is<Save>, 9 typedef Pattern3<Is<Save>,
10 Is<ClipRect>, 10 Is<ClipRect>,
11 Is<Restore> > 11 Is<Restore> >
12 SaveClipRectRestore; 12 SaveClipRectRestore;
13 13
14 DEF_TEST(RecordPattern_Simple, r) { 14 DEF_TEST(RecordPattern_Simple, r) {
15 SaveClipRectRestore pattern; 15 SaveClipRectRestore pattern;
16 16
17 SkRecord record; 17 SkRecord record;
18 REPORTER_ASSERT(r, !pattern.match(&record, 0)); 18 REPORTER_ASSERT(r, !pattern.match(&record, 0));
19 19
20 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, 1920, 1200); 20 SkRecorder recorder(&record, 1920, 1200);
21 21
22 // Build up a save-clip-restore block. The pattern will match only it's com plete. 22 // Build up a save-clip-restore block. The pattern will match only it's com plete.
23 recorder.save(); 23 recorder.save();
24 REPORTER_ASSERT(r, !pattern.match(&record, 0)); 24 REPORTER_ASSERT(r, !pattern.match(&record, 0));
25 25
26 recorder.clipRect(SkRect::MakeWH(300, 200)); 26 recorder.clipRect(SkRect::MakeWH(300, 200));
27 REPORTER_ASSERT(r, !pattern.match(&record, 0)); 27 REPORTER_ASSERT(r, !pattern.match(&record, 0));
28 28
29 recorder.restore(); 29 recorder.restore();
30 REPORTER_ASSERT(r, pattern.match(&record, 0)); 30 REPORTER_ASSERT(r, pattern.match(&record, 0));
31 REPORTER_ASSERT(r, pattern.first<Save>() != NULL); 31 REPORTER_ASSERT(r, pattern.first<Save>() != NULL);
32 REPORTER_ASSERT(r, pattern.second<ClipRect>() != NULL); 32 REPORTER_ASSERT(r, pattern.second<ClipRect>() != NULL);
33 REPORTER_ASSERT(r, pattern.third<Restore>() != NULL); 33 REPORTER_ASSERT(r, pattern.third<Restore>() != NULL);
34 } 34 }
35 35
36 DEF_TEST(RecordPattern_StartingIndex, r) { 36 DEF_TEST(RecordPattern_StartingIndex, r) {
37 SaveClipRectRestore pattern; 37 SaveClipRectRestore pattern;
38 38
39 SkRecord record; 39 SkRecord record;
40 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, 1920, 1200); 40 SkRecorder recorder(&record, 1920, 1200);
41 41
42 // There will be two save-clipRect-restore blocks [0,3) and [3,6). 42 // There will be two save-clipRect-restore blocks [0,3) and [3,6).
43 for (int i = 0; i < 2; i++) { 43 for (int i = 0; i < 2; i++) {
44 recorder.save(); 44 recorder.save();
45 recorder.clipRect(SkRect::MakeWH(300, 200)); 45 recorder.clipRect(SkRect::MakeWH(300, 200));
46 recorder.restore(); 46 recorder.restore();
47 } 47 }
48 48
49 // We should match only at 0 and 3. Going over the length should fail grace fully. 49 // We should match only at 0 and 3. Going over the length should fail grace fully.
50 for (unsigned i = 0; i < 8; i++) { 50 for (unsigned i = 0; i < 8; i++) {
51 if (i == 0 || i == 3) { 51 if (i == 0 || i == 3) {
52 REPORTER_ASSERT(r, pattern.match(&record, i) == i + 3); 52 REPORTER_ASSERT(r, pattern.match(&record, i) == i + 3);
53 } else { 53 } else {
54 REPORTER_ASSERT(r, !pattern.match(&record, i)); 54 REPORTER_ASSERT(r, !pattern.match(&record, i));
55 } 55 }
56 } 56 }
57 } 57 }
58 58
59 DEF_TEST(RecordPattern_DontMatchSubsequences, r) { 59 DEF_TEST(RecordPattern_DontMatchSubsequences, r) {
60 SaveClipRectRestore pattern; 60 SaveClipRectRestore pattern;
61 61
62 SkRecord record; 62 SkRecord record;
63 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, 1920, 1200); 63 SkRecorder recorder(&record, 1920, 1200);
64 64
65 recorder.save(); 65 recorder.save();
66 recorder.clipRect(SkRect::MakeWH(300, 200)); 66 recorder.clipRect(SkRect::MakeWH(300, 200));
67 recorder.drawRect(SkRect::MakeWH(600, 300), SkPaint()); 67 recorder.drawRect(SkRect::MakeWH(600, 300), SkPaint());
68 recorder.restore(); 68 recorder.restore();
69 69
70 REPORTER_ASSERT(r, !pattern.match(&record, 0)); 70 REPORTER_ASSERT(r, !pattern.match(&record, 0));
71 } 71 }
72 72
73 DEF_TEST(RecordPattern_Star, r) { 73 DEF_TEST(RecordPattern_Star, r) {
74 Pattern3<Is<Save>, Star<Is<ClipRect> >, Is<Restore> > pattern; 74 Pattern3<Is<Save>, Star<Is<ClipRect> >, Is<Restore> > pattern;
75 75
76 SkRecord record; 76 SkRecord record;
77 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, 1920, 1200); 77 SkRecorder recorder(&record, 1920, 1200);
78 78
79 recorder.save(); 79 recorder.save();
80 recorder.restore(); 80 recorder.restore();
81 REPORTER_ASSERT(r, pattern.match(&record, 0)); 81 REPORTER_ASSERT(r, pattern.match(&record, 0));
82 82
83 recorder.save(); 83 recorder.save();
84 recorder.clipRect(SkRect::MakeWH(300, 200)); 84 recorder.clipRect(SkRect::MakeWH(300, 200));
85 recorder.restore(); 85 recorder.restore();
86 REPORTER_ASSERT(r, pattern.match(&record, 2)); 86 REPORTER_ASSERT(r, pattern.match(&record, 2));
87 87
88 recorder.save(); 88 recorder.save();
89 recorder.clipRect(SkRect::MakeWH(300, 200)); 89 recorder.clipRect(SkRect::MakeWH(300, 200));
90 recorder.clipRect(SkRect::MakeWH(100, 100)); 90 recorder.clipRect(SkRect::MakeWH(100, 100));
91 recorder.restore(); 91 recorder.restore();
92 REPORTER_ASSERT(r, pattern.match(&record, 5)); 92 REPORTER_ASSERT(r, pattern.match(&record, 5));
93 } 93 }
94 94
95 DEF_TEST(RecordPattern_IsDraw, r) { 95 DEF_TEST(RecordPattern_IsDraw, r) {
96 Pattern3<Is<Save>, IsDraw, Is<Restore> > pattern; 96 Pattern3<Is<Save>, IsDraw, Is<Restore> > pattern;
97 97
98 SkRecord record; 98 SkRecord record;
99 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, 1920, 1200); 99 SkRecorder recorder(&record, 1920, 1200);
100 100
101 recorder.save(); 101 recorder.save();
102 recorder.clipRect(SkRect::MakeWH(300, 200)); 102 recorder.clipRect(SkRect::MakeWH(300, 200));
103 recorder.restore(); 103 recorder.restore();
104 104
105 REPORTER_ASSERT(r, !pattern.match(&record, 0)); 105 REPORTER_ASSERT(r, !pattern.match(&record, 0));
106 106
107 SkPaint paint; 107 SkPaint paint;
108 108
109 recorder.save(); 109 recorder.save();
(...skipping 18 matching lines...) Expand all
128 } 128 }
129 129
130 DEF_TEST(RecordPattern_Complex, r) { 130 DEF_TEST(RecordPattern_Complex, r) {
131 Pattern3<Is<Save>, 131 Pattern3<Is<Save>,
132 Star<Not<Or3<Is<Save>, 132 Star<Not<Or3<Is<Save>,
133 Is<Restore>, 133 Is<Restore>,
134 IsDraw> > >, 134 IsDraw> > >,
135 Is<Restore> > pattern; 135 Is<Restore> > pattern;
136 136
137 SkRecord record; 137 SkRecord record;
138 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, 1920, 1200); 138 SkRecorder recorder(&record, 1920, 1200);
139 139
140 recorder.save(); 140 recorder.save();
141 recorder.restore(); 141 recorder.restore();
142 REPORTER_ASSERT(r, pattern.match(&record, 0) == 2); 142 REPORTER_ASSERT(r, pattern.match(&record, 0) == 2);
143 143
144 recorder.save(); 144 recorder.save();
145 recorder.save(); 145 recorder.save();
146 recorder.restore(); 146 recorder.restore();
147 recorder.restore(); 147 recorder.restore();
148 REPORTER_ASSERT(r, !pattern.match(&record, 2)); 148 REPORTER_ASSERT(r, !pattern.match(&record, 2));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 REPORTER_ASSERT(r, begin == 13); 185 REPORTER_ASSERT(r, begin == 13);
186 REPORTER_ASSERT(r, end == 19); 186 REPORTER_ASSERT(r, end == 19);
187 187
188 REPORTER_ASSERT(r, !pattern.search(&record, &begin, &end)); 188 REPORTER_ASSERT(r, !pattern.search(&record, &begin, &end));
189 } 189 }
190 190
191 DEF_TEST(RecordPattern_SaveLayerIsNotADraw, r) { 191 DEF_TEST(RecordPattern_SaveLayerIsNotADraw, r) {
192 Pattern1<IsDraw> pattern; 192 Pattern1<IsDraw> pattern;
193 193
194 SkRecord record; 194 SkRecord record;
195 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, 1920, 1200); 195 SkRecorder recorder(&record, 1920, 1200);
196 recorder.saveLayer(NULL, NULL); 196 recorder.saveLayer(NULL, NULL);
197 197
198 REPORTER_ASSERT(r, !pattern.match(&record, 0)); 198 REPORTER_ASSERT(r, !pattern.match(&record, 0));
199 } 199 }
OLDNEW
« no previous file with comments | « tests/RecordOptsTest.cpp ('k') | tests/RecorderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698