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

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: 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 int index = 0;
78 79
80 #if 0
79 recorder.save(); 81 recorder.save();
80 recorder.restore(); 82 recorder.restore();
81 REPORTER_ASSERT(r, pattern.match(&record, 0)); 83 REPORTER_ASSERT(r, pattern.match(&record, index));
84 index += 2;
85 #endif
82 86
83 recorder.save(); 87 recorder.save();
84 recorder.clipRect(SkRect::MakeWH(300, 200)); 88 recorder.clipRect(SkRect::MakeWH(300, 200));
85 recorder.restore(); 89 recorder.restore();
86 REPORTER_ASSERT(r, pattern.match(&record, 2)); 90 REPORTER_ASSERT(r, pattern.match(&record, index));
91 index += 3;
87 92
88 recorder.save(); 93 recorder.save();
89 recorder.clipRect(SkRect::MakeWH(300, 200)); 94 recorder.clipRect(SkRect::MakeWH(300, 200));
90 recorder.clipRect(SkRect::MakeWH(100, 100)); 95 recorder.clipRect(SkRect::MakeWH(100, 100));
91 recorder.restore(); 96 recorder.restore();
92 REPORTER_ASSERT(r, pattern.match(&record, 5)); 97 REPORTER_ASSERT(r, pattern.match(&record, index));
93 } 98 }
94 99
95 DEF_TEST(RecordPattern_IsDraw, r) { 100 DEF_TEST(RecordPattern_IsDraw, r) {
96 Pattern3<Is<Save>, IsDraw, Is<Restore> > pattern; 101 Pattern3<Is<Save>, IsDraw, Is<Restore> > pattern;
97 102
98 SkRecord record; 103 SkRecord record;
99 SkRecorder recorder(&record, 1920, 1200); 104 SkRecorder recorder(&record, 1920, 1200);
100 105
101 recorder.save(); 106 recorder.save();
102 recorder.clipRect(SkRect::MakeWH(300, 200)); 107 recorder.clipRect(SkRect::MakeWH(300, 200));
103 recorder.restore(); 108 recorder.restore();
104 109
105 REPORTER_ASSERT(r, !pattern.match(&record, 0)); 110 REPORTER_ASSERT(r, !pattern.match(&record, 0));
106 111
112 #if 0
107 SkPaint paint; 113 SkPaint paint;
108 114
109 recorder.save(); 115 recorder.save();
110 paint.setColor(0xEEAA8822); 116 paint.setColor(0xEEAA8822);
111 recorder.drawRect(SkRect::MakeWH(300, 200), paint); 117 recorder.drawRect(SkRect::MakeWH(300, 200), paint);
112 recorder.restore(); 118 recorder.restore();
113 119
114 recorder.save(); 120 recorder.save();
115 paint.setColor(0xFACEFACE); 121 paint.setColor(0xFACEFACE);
116 recorder.drawPaint(paint); 122 recorder.drawPaint(paint);
117 recorder.restore(); 123 recorder.restore();
118 124
119 REPORTER_ASSERT(r, pattern.match(&record, 3)); 125 REPORTER_ASSERT(r, pattern.match(&record, 3));
120 REPORTER_ASSERT(r, pattern.first<Save>() != NULL); 126 REPORTER_ASSERT(r, pattern.first<Save>() != NULL);
121 REPORTER_ASSERT(r, pattern.second<SkPaint>()->getColor() == 0xEEAA8822); 127 REPORTER_ASSERT(r, pattern.second<SkPaint>()->getColor() == 0xEEAA8822);
122 REPORTER_ASSERT(r, pattern.third<Restore>() != NULL); 128 REPORTER_ASSERT(r, pattern.third<Restore>() != NULL);
123 129
124 REPORTER_ASSERT(r, pattern.match(&record, 6)); 130 REPORTER_ASSERT(r, pattern.match(&record, 6));
125 REPORTER_ASSERT(r, pattern.first<Save>() != NULL); 131 REPORTER_ASSERT(r, pattern.first<Save>() != NULL);
126 REPORTER_ASSERT(r, pattern.second<SkPaint>()->getColor() == 0xFACEFACE); 132 REPORTER_ASSERT(r, pattern.second<SkPaint>()->getColor() == 0xFACEFACE);
127 REPORTER_ASSERT(r, pattern.third<Restore>() != NULL); 133 REPORTER_ASSERT(r, pattern.third<Restore>() != NULL);
134 #endif
128 } 135 }
129 136
137 #if 0
130 DEF_TEST(RecordPattern_Complex, r) { 138 DEF_TEST(RecordPattern_Complex, r) {
131 Pattern3<Is<Save>, 139 Pattern3<Is<Save>,
132 Star<Not<Or3<Is<Save>, 140 Star<Not<Or3<Is<Save>,
133 Is<Restore>, 141 Is<Restore>,
134 IsDraw> > >, 142 IsDraw> > >,
135 Is<Restore> > pattern; 143 Is<Restore> > pattern;
136 144
137 SkRecord record; 145 SkRecord record;
138 SkRecorder recorder(&record, 1920, 1200); 146 SkRecorder recorder(&record, 1920, 1200);
139 147
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end)); 188 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
181 REPORTER_ASSERT(r, begin == 6); 189 REPORTER_ASSERT(r, begin == 6);
182 REPORTER_ASSERT(r, end == 9); 190 REPORTER_ASSERT(r, end == 9);
183 191
184 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end)); 192 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
185 REPORTER_ASSERT(r, begin == 13); 193 REPORTER_ASSERT(r, begin == 13);
186 REPORTER_ASSERT(r, end == 19); 194 REPORTER_ASSERT(r, end == 19);
187 195
188 REPORTER_ASSERT(r, !pattern.search(&record, &begin, &end)); 196 REPORTER_ASSERT(r, !pattern.search(&record, &begin, &end));
189 } 197 }
198 #endif
190 199
191 DEF_TEST(RecordPattern_SaveLayerIsNotADraw, r) { 200 DEF_TEST(RecordPattern_SaveLayerIsNotADraw, r) {
192 Pattern1<IsDraw> pattern; 201 Pattern1<IsDraw> pattern;
193 202
194 SkRecord record; 203 SkRecord record;
195 SkRecorder recorder(&record, 1920, 1200); 204 SkRecorder recorder(&record, 1920, 1200);
196 recorder.saveLayer(NULL, NULL); 205 recorder.saveLayer(NULL, NULL);
197 206
198 REPORTER_ASSERT(r, !pattern.match(&record, 0)); 207 REPORTER_ASSERT(r, !pattern.match(&record, 0));
199 } 208 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698