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

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: now with faster counter 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
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 } 91 }
94 92
robertphillips 2014/12/11 13:24:36 I think this test is dead - remove it ?
reed1 2014/12/11 14:54:08 Done.
95 DEF_TEST(RecordPattern_IsDraw, r) { 93 DEF_TEST(RecordPattern_IsDraw, r) {
96 Pattern3<Is<Save>, IsDraw, Is<Restore> > pattern; 94 Pattern3<Is<Save>, IsDraw, Is<Restore> > pattern;
97 95
98 SkRecord record; 96 SkRecord record;
99 SkRecorder recorder(&record, 1920, 1200); 97 SkRecorder recorder(&record, 1920, 1200);
100 98
101 recorder.save(); 99 recorder.save();
102 recorder.clipRect(SkRect::MakeWH(300, 200)); 100 recorder.clipRect(SkRect::MakeWH(300, 200));
103 recorder.restore(); 101 recorder.restore();
104 102
105 REPORTER_ASSERT(r, !pattern.match(&record, 0)); 103 REPORTER_ASSERT(r, !pattern.match(&record, 0));
106 104
105 #if 0
107 SkPaint paint; 106 SkPaint paint;
108 107
109 recorder.save(); 108 recorder.save();
110 paint.setColor(0xEEAA8822); 109 paint.setColor(0xEEAA8822);
111 recorder.drawRect(SkRect::MakeWH(300, 200), paint); 110 recorder.drawRect(SkRect::MakeWH(300, 200), paint);
112 recorder.restore(); 111 recorder.restore();
113 112
114 recorder.save(); 113 recorder.save();
115 paint.setColor(0xFACEFACE); 114 paint.setColor(0xFACEFACE);
116 recorder.drawPaint(paint); 115 recorder.drawPaint(paint);
117 recorder.restore(); 116 recorder.restore();
118 117
119 REPORTER_ASSERT(r, pattern.match(&record, 3)); 118 REPORTER_ASSERT(r, pattern.match(&record, 3));
120 REPORTER_ASSERT(r, pattern.first<Save>() != NULL); 119 REPORTER_ASSERT(r, pattern.first<Save>() != NULL);
121 REPORTER_ASSERT(r, pattern.second<SkPaint>()->getColor() == 0xEEAA8822); 120 REPORTER_ASSERT(r, pattern.second<SkPaint>()->getColor() == 0xEEAA8822);
122 REPORTER_ASSERT(r, pattern.third<Restore>() != NULL); 121 REPORTER_ASSERT(r, pattern.third<Restore>() != NULL);
123 122
124 REPORTER_ASSERT(r, pattern.match(&record, 6)); 123 REPORTER_ASSERT(r, pattern.match(&record, 6));
125 REPORTER_ASSERT(r, pattern.first<Save>() != NULL); 124 REPORTER_ASSERT(r, pattern.first<Save>() != NULL);
126 REPORTER_ASSERT(r, pattern.second<SkPaint>()->getColor() == 0xFACEFACE); 125 REPORTER_ASSERT(r, pattern.second<SkPaint>()->getColor() == 0xFACEFACE);
127 REPORTER_ASSERT(r, pattern.third<Restore>() != NULL); 126 REPORTER_ASSERT(r, pattern.third<Restore>() != NULL);
127 #endif
128 } 128 }
129 129
robertphillips 2014/12/11 13:24:36 This test should be pretty easy to bring back to l
reed1 2014/12/11 14:54:08 Done.
130 #if 0
130 DEF_TEST(RecordPattern_Complex, r) { 131 DEF_TEST(RecordPattern_Complex, r) {
131 Pattern3<Is<Save>, 132 Pattern3<Is<Save>,
132 Star<Not<Or3<Is<Save>, 133 Star<Not<Or3<Is<Save>,
133 Is<Restore>, 134 Is<Restore>,
134 IsDraw> > >, 135 IsDraw> > >,
135 Is<Restore> > pattern; 136 Is<Restore> > pattern;
136 137
137 SkRecord record; 138 SkRecord record;
138 SkRecorder recorder(&record, 1920, 1200); 139 SkRecorder recorder(&record, 1920, 1200);
139 140
robertphillips 2014/12/11 13:24:36 Just remove this first test
140 recorder.save(); 141 recorder.save();
141 recorder.restore(); 142 recorder.restore();
142 REPORTER_ASSERT(r, pattern.match(&record, 0) == 2); 143 REPORTER_ASSERT(r, pattern.match(&record, 0) == 2);
143 144
144 recorder.save(); 145 recorder.save();
robertphillips 2014/12/11 13:24:37 clipRect
145 recorder.save(); 146 recorder.save();
robertphillips 2014/12/11 13:24:36 clipRect
146 recorder.restore(); 147 recorder.restore();
147 recorder.restore(); 148 recorder.restore();
148 REPORTER_ASSERT(r, !pattern.match(&record, 2)); 149 REPORTER_ASSERT(r, !pattern.match(&record, 2));
149 REPORTER_ASSERT(r, pattern.match(&record, 3) == 5); 150 REPORTER_ASSERT(r, pattern.match(&record, 3) == 5);
150 151
151 recorder.save(); 152 recorder.save();
152 recorder.clipRect(SkRect::MakeWH(300, 200)); 153 recorder.clipRect(SkRect::MakeWH(300, 200));
153 recorder.restore(); 154 recorder.restore();
154 REPORTER_ASSERT(r, pattern.match(&record, 6) == 9); 155 REPORTER_ASSERT(r, pattern.match(&record, 6) == 9);
155 156
(...skipping 24 matching lines...) Expand all
180 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end)); 181 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
181 REPORTER_ASSERT(r, begin == 6); 182 REPORTER_ASSERT(r, begin == 6);
182 REPORTER_ASSERT(r, end == 9); 183 REPORTER_ASSERT(r, end == 9);
183 184
184 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end)); 185 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
185 REPORTER_ASSERT(r, begin == 13); 186 REPORTER_ASSERT(r, begin == 13);
186 REPORTER_ASSERT(r, end == 19); 187 REPORTER_ASSERT(r, end == 19);
187 188
188 REPORTER_ASSERT(r, !pattern.search(&record, &begin, &end)); 189 REPORTER_ASSERT(r, !pattern.search(&record, &begin, &end));
189 } 190 }
191 #endif
190 192
191 DEF_TEST(RecordPattern_SaveLayerIsNotADraw, r) { 193 DEF_TEST(RecordPattern_SaveLayerIsNotADraw, r) {
192 Pattern1<IsDraw> pattern; 194 Pattern1<IsDraw> pattern;
193 195
194 SkRecord record; 196 SkRecord record;
195 SkRecorder recorder(&record, 1920, 1200); 197 SkRecorder recorder(&record, 1920, 1200);
196 recorder.saveLayer(NULL, NULL); 198 recorder.saveLayer(NULL, NULL);
197 199
198 REPORTER_ASSERT(r, !pattern.match(&record, 0)); 200 REPORTER_ASSERT(r, !pattern.match(&record, 0));
199 } 201 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698