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

Side by Side Diff: tests/RecordPatternTest.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/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 78 int index = 0;
79 recorder.save();
80 recorder.restore();
81 REPORTER_ASSERT(r, pattern.match(&record, 0));
82 79
83 recorder.save(); 80 recorder.save();
84 recorder.clipRect(SkRect::MakeWH(300, 200)); 81 recorder.clipRect(SkRect::MakeWH(300, 200));
85 recorder.restore(); 82 recorder.restore();
86 REPORTER_ASSERT(r, pattern.match(&record, 2)); 83 REPORTER_ASSERT(r, pattern.match(&record, index));
84 index += 3;
87 85
88 recorder.save(); 86 recorder.save();
89 recorder.clipRect(SkRect::MakeWH(300, 200)); 87 recorder.clipRect(SkRect::MakeWH(300, 200));
90 recorder.clipRect(SkRect::MakeWH(100, 100)); 88 recorder.clipRect(SkRect::MakeWH(100, 100));
91 recorder.restore(); 89 recorder.restore();
92 REPORTER_ASSERT(r, pattern.match(&record, 5)); 90 REPORTER_ASSERT(r, pattern.match(&record, index));
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);
128 } 91 }
129 92
130 DEF_TEST(RecordPattern_Complex, r) { 93 DEF_TEST(RecordPattern_Complex, r) {
131 Pattern3<Is<Save>, 94 Pattern3<Is<Save>,
132 Star<Not<Or3<Is<Save>, 95 Star<Not<Or3<Is<Save>,
133 Is<Restore>, 96 Is<Restore>,
134 IsDraw> > >, 97 IsDraw> > >,
135 Is<Restore> > pattern; 98 Is<Restore> > pattern;
136 99
137 SkRecord record; 100 SkRecord record;
138 SkRecorder recorder(&record, 1920, 1200); 101 SkRecorder recorder(&record, 1920, 1200);
102 unsigned start, begin, end;
139 103
140 recorder.save(); 104 start = record.count();
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
151 recorder.save(); 105 recorder.save();
152 recorder.clipRect(SkRect::MakeWH(300, 200)); 106 recorder.clipRect(SkRect::MakeWH(300, 200));
153 recorder.restore(); 107 recorder.restore();
154 REPORTER_ASSERT(r, pattern.match(&record, 6) == 9); 108 REPORTER_ASSERT(r, pattern.match(&record, 0) == record.count());
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());
155 113
114 start = record.count();
156 recorder.save(); 115 recorder.save();
157 recorder.clipRect(SkRect::MakeWH(300, 200)); 116 recorder.clipRect(SkRect::MakeWH(300, 200));
158 recorder.drawRect(SkRect::MakeWH(100, 3000), SkPaint()); 117 recorder.drawRect(SkRect::MakeWH(100, 3000), SkPaint());
159 recorder.restore(); 118 recorder.restore();
160 REPORTER_ASSERT(r, !pattern.match(&record, 9)); 119 REPORTER_ASSERT(r, !pattern.match(&record, start));
120 end = start;
121 REPORTER_ASSERT(r, !pattern.search(&record, &begin, &end));
161 122
123 start = record.count();
162 recorder.save(); 124 recorder.save();
163 recorder.pushCull(SkRect::MakeWH(300, 200)); 125 recorder.pushCull(SkRect::MakeWH(300, 200));
164 recorder.clipRect(SkRect::MakeWH(300, 200)); 126 recorder.clipRect(SkRect::MakeWH(300, 200));
165 recorder.clipRect(SkRect::MakeWH(100, 400)); 127 recorder.clipRect(SkRect::MakeWH(100, 400));
166 recorder.popCull(); 128 recorder.popCull();
167 recorder.restore(); 129 recorder.restore();
168 REPORTER_ASSERT(r, pattern.match(&record, 13) == 19); 130 REPORTER_ASSERT(r, pattern.match(&record, start) == record.count());
169 131 end = start;
170 // Same as above, but using pattern.search to step through matches.
171 unsigned begin, end = 0;
172 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end)); 132 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
173 REPORTER_ASSERT(r, begin == 0); 133 REPORTER_ASSERT(r, begin == start);
174 REPORTER_ASSERT(r, end == 2); 134 REPORTER_ASSERT(r, end == record.count());
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);
187 135
188 REPORTER_ASSERT(r, !pattern.search(&record, &begin, &end)); 136 REPORTER_ASSERT(r, !pattern.search(&record, &begin, &end));
189 } 137 }
190 138
191 DEF_TEST(RecordPattern_SaveLayerIsNotADraw, r) { 139 DEF_TEST(RecordPattern_SaveLayerIsNotADraw, r) {
192 Pattern1<IsDraw> pattern; 140 Pattern1<IsDraw> pattern;
193 141
194 SkRecord record; 142 SkRecord record;
195 SkRecorder recorder(&record, 1920, 1200); 143 SkRecorder recorder(&record, 1920, 1200);
196 recorder.saveLayer(NULL, NULL); 144 recorder.saveLayer(NULL, NULL);
197 145
198 REPORTER_ASSERT(r, !pattern.match(&record, 0)); 146 REPORTER_ASSERT(r, !pattern.match(&record, 0));
199 } 147 }
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