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

Side by Side Diff: tests/RecordPatternTest.cpp

Issue 798593003: Revert of Defer saves() until they're needed (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/RecordOptsTest.cpp ('k') | tests/RecordReplaceDrawTest.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>,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(&record, 1920, 1200); 77 SkRecorder recorder(&record, 1920, 1200);
78 int index = 0; 78
79 recorder.save();
80 recorder.restore();
81 REPORTER_ASSERT(r, pattern.match(&record, 0));
79 82
80 recorder.save(); 83 recorder.save();
81 recorder.clipRect(SkRect::MakeWH(300, 200)); 84 recorder.clipRect(SkRect::MakeWH(300, 200));
82 recorder.restore(); 85 recorder.restore();
83 REPORTER_ASSERT(r, pattern.match(&record, index)); 86 REPORTER_ASSERT(r, pattern.match(&record, 2));
84 index += 3;
85 87
86 recorder.save(); 88 recorder.save();
87 recorder.clipRect(SkRect::MakeWH(300, 200)); 89 recorder.clipRect(SkRect::MakeWH(300, 200));
88 recorder.clipRect(SkRect::MakeWH(100, 100)); 90 recorder.clipRect(SkRect::MakeWH(100, 100));
89 recorder.restore(); 91 recorder.restore();
90 REPORTER_ASSERT(r, pattern.match(&record, index)); 92 REPORTER_ASSERT(r, pattern.match(&record, 5));
93 }
94
95 DEF_TEST(RecordPattern_IsDraw, r) {
96 Pattern3<Is<Save>, IsDraw, Is<Restore> > pattern;
97
98 SkRecord record;
99 SkRecorder recorder(&record, 1920, 1200);
100
101 recorder.save();
102 recorder.clipRect(SkRect::MakeWH(300, 200));
103 recorder.restore();
104
105 REPORTER_ASSERT(r, !pattern.match(&record, 0));
106
107 SkPaint paint;
108
109 recorder.save();
110 paint.setColor(0xEEAA8822);
111 recorder.drawRect(SkRect::MakeWH(300, 200), paint);
112 recorder.restore();
113
114 recorder.save();
115 paint.setColor(0xFACEFACE);
116 recorder.drawPaint(paint);
117 recorder.restore();
118
119 REPORTER_ASSERT(r, pattern.match(&record, 3));
120 REPORTER_ASSERT(r, pattern.first<Save>() != NULL);
121 REPORTER_ASSERT(r, pattern.second<SkPaint>()->getColor() == 0xEEAA8822);
122 REPORTER_ASSERT(r, pattern.third<Restore>() != NULL);
123
124 REPORTER_ASSERT(r, pattern.match(&record, 6));
125 REPORTER_ASSERT(r, pattern.first<Save>() != NULL);
126 REPORTER_ASSERT(r, pattern.second<SkPaint>()->getColor() == 0xFACEFACE);
127 REPORTER_ASSERT(r, pattern.third<Restore>() != NULL);
91 } 128 }
92 129
93 DEF_TEST(RecordPattern_Complex, r) { 130 DEF_TEST(RecordPattern_Complex, r) {
94 Pattern3<Is<Save>, 131 Pattern3<Is<Save>,
95 Star<Not<Or3<Is<Save>, 132 Star<Not<Or3<Is<Save>,
96 Is<Restore>, 133 Is<Restore>,
97 IsDraw> > >, 134 IsDraw> > >,
98 Is<Restore> > pattern; 135 Is<Restore> > pattern;
99 136
100 SkRecord record; 137 SkRecord record;
101 SkRecorder recorder(&record, 1920, 1200); 138 SkRecorder recorder(&record, 1920, 1200);
102 unsigned start, begin, end;
103 139
104 start = record.count(); 140 recorder.save();
141 recorder.restore();
142 REPORTER_ASSERT(r, pattern.match(&record, 0) == 2);
143
144 recorder.save();
145 recorder.save();
146 recorder.restore();
147 recorder.restore();
148 REPORTER_ASSERT(r, !pattern.match(&record, 2));
149 REPORTER_ASSERT(r, pattern.match(&record, 3) == 5);
150
105 recorder.save(); 151 recorder.save();
106 recorder.clipRect(SkRect::MakeWH(300, 200)); 152 recorder.clipRect(SkRect::MakeWH(300, 200));
107 recorder.restore(); 153 recorder.restore();
108 REPORTER_ASSERT(r, pattern.match(&record, 0) == record.count()); 154 REPORTER_ASSERT(r, pattern.match(&record, 6) == 9);
109 end = start;
110 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
111 REPORTER_ASSERT(r, begin == start);
112 REPORTER_ASSERT(r, end == record.count());
113 155
114 start = record.count();
115 recorder.save(); 156 recorder.save();
116 recorder.clipRect(SkRect::MakeWH(300, 200)); 157 recorder.clipRect(SkRect::MakeWH(300, 200));
117 recorder.drawRect(SkRect::MakeWH(100, 3000), SkPaint()); 158 recorder.drawRect(SkRect::MakeWH(100, 3000), SkPaint());
118 recorder.restore(); 159 recorder.restore();
119 REPORTER_ASSERT(r, !pattern.match(&record, start)); 160 REPORTER_ASSERT(r, !pattern.match(&record, 9));
120 end = start;
121 REPORTER_ASSERT(r, !pattern.search(&record, &begin, &end));
122 161
123 start = record.count();
124 recorder.save(); 162 recorder.save();
125 recorder.pushCull(SkRect::MakeWH(300, 200)); 163 recorder.pushCull(SkRect::MakeWH(300, 200));
126 recorder.clipRect(SkRect::MakeWH(300, 200)); 164 recorder.clipRect(SkRect::MakeWH(300, 200));
127 recorder.clipRect(SkRect::MakeWH(100, 400)); 165 recorder.clipRect(SkRect::MakeWH(100, 400));
128 recorder.popCull(); 166 recorder.popCull();
129 recorder.restore(); 167 recorder.restore();
130 REPORTER_ASSERT(r, pattern.match(&record, start) == record.count()); 168 REPORTER_ASSERT(r, pattern.match(&record, 13) == 19);
131 end = start; 169
170 // Same as above, but using pattern.search to step through matches.
171 unsigned begin, end = 0;
132 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end)); 172 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
133 REPORTER_ASSERT(r, begin == start); 173 REPORTER_ASSERT(r, begin == 0);
134 REPORTER_ASSERT(r, end == record.count()); 174 REPORTER_ASSERT(r, end == 2);
175
176 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
177 REPORTER_ASSERT(r, begin == 3);
178 REPORTER_ASSERT(r, end == 5);
179
180 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
181 REPORTER_ASSERT(r, begin == 6);
182 REPORTER_ASSERT(r, end == 9);
183
184 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
185 REPORTER_ASSERT(r, begin == 13);
186 REPORTER_ASSERT(r, end == 19);
135 187
136 REPORTER_ASSERT(r, !pattern.search(&record, &begin, &end)); 188 REPORTER_ASSERT(r, !pattern.search(&record, &begin, &end));
137 } 189 }
138 190
139 DEF_TEST(RecordPattern_SaveLayerIsNotADraw, r) { 191 DEF_TEST(RecordPattern_SaveLayerIsNotADraw, r) {
140 Pattern1<IsDraw> pattern; 192 Pattern1<IsDraw> pattern;
141 193
142 SkRecord record; 194 SkRecord record;
143 SkRecorder recorder(&record, 1920, 1200); 195 SkRecorder recorder(&record, 1920, 1200);
144 recorder.saveLayer(NULL, NULL); 196 recorder.saveLayer(NULL, NULL);
145 197
146 REPORTER_ASSERT(r, !pattern.match(&record, 0)); 198 REPORTER_ASSERT(r, !pattern.match(&record, 0));
147 } 199 }
OLDNEW
« no previous file with comments | « tests/RecordOptsTest.cpp ('k') | tests/RecordReplaceDrawTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698