OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #if SK_SUPPORT_GPU | |
9 | |
10 #include "GrTRecorder.h" | |
11 #include "SkMatrix.h" | 8 #include "SkMatrix.h" |
12 #include "SkRandom.h" | 9 #include "SkRandom.h" |
13 #include "SkString.h" | 10 #include "SkString.h" |
14 #include "Test.h" | 11 #include "Test.h" |
15 | 12 |
| 13 #if SK_SUPPORT_GPU |
| 14 |
| 15 #include "GrTRecorder.h" |
| 16 |
16 //////////////////////////////////////////////////////////////////////////////// | 17 //////////////////////////////////////////////////////////////////////////////// |
17 | 18 |
18 static int activeRecorderItems = 0; | 19 static int activeRecorderItems = 0; |
19 | 20 |
20 class IntWrapper { | 21 class IntWrapper { |
21 public: | 22 public: |
22 IntWrapper() {} | 23 IntWrapper() {} |
23 IntWrapper(int value) : fValue(value) {} | 24 IntWrapper(int value) : fValue(value) {} |
24 operator int() { return fValue; } | 25 operator int() { return fValue; } |
25 private: | 26 private: |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 ExtraData::Recorder::Iter iter(recorder); | 95 ExtraData::Recorder::Iter iter(recorder); |
95 for (int i = 0; i < 100; ++i) { | 96 for (int i = 0; i < 100; ++i) { |
96 REPORTER_ASSERT(reporter, iter.next()); | 97 REPORTER_ASSERT(reporter, iter.next()); |
97 REPORTER_ASSERT(reporter, i == iter->fData); | 98 REPORTER_ASSERT(reporter, i == iter->fData); |
98 for (int j = 0; j < i; j++) { | 99 for (int j = 0; j < i; j++) { |
99 REPORTER_ASSERT(reporter, i == iter->extraData()[j]); | 100 REPORTER_ASSERT(reporter, i == iter->extraData()[j]); |
100 } | 101 } |
101 } | 102 } |
102 REPORTER_ASSERT(reporter, !iter.next()); | 103 REPORTER_ASSERT(reporter, !iter.next()); |
103 | 104 |
| 105 ExtraData::Recorder::ReverseIter reverseIter(recorder); |
| 106 for (int i = 99; i >= 0; --i) { |
| 107 REPORTER_ASSERT(reporter, i == reverseIter->fData); |
| 108 for (int j = 0; j < i; j++) { |
| 109 REPORTER_ASSERT(reporter, i == reverseIter->extraData()[j]); |
| 110 } |
| 111 REPORTER_ASSERT(reporter, reverseIter.previous() == !!i); |
| 112 } |
| 113 |
104 recorder.reset(); | 114 recorder.reset(); |
105 REPORTER_ASSERT(reporter, 0 == activeRecorderItems); | 115 REPORTER_ASSERT(reporter, 0 == activeRecorderItems); |
106 } | 116 } |
107 | 117 |
108 enum ClassType { | 118 enum ClassType { |
109 kBase_ClassType, | 119 kBase_ClassType, |
110 kSubclass_ClassType, | 120 kSubclass_ClassType, |
111 kSubSubclass_ClassType, | 121 kSubSubclass_ClassType, |
112 kSubclassExtraData_ClassType, | 122 kSubclassExtraData_ClassType, |
113 kSubclassEmpty_ClassType, | 123 kSubclassEmpty_ClassType, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 private: | 200 private: |
191 static int ValueAt(uint64_t i) { return static_cast<int>(123456789 + 9876543
21 * i); } | 201 static int ValueAt(uint64_t i) { return static_cast<int>(123456789 + 9876543
21 * i); } |
192 int fLength; | 202 int fLength; |
193 }; | 203 }; |
194 | 204 |
195 class SubclassEmpty : public Base { | 205 class SubclassEmpty : public Base { |
196 public: | 206 public: |
197 virtual ClassType getType() { return kSubclassEmpty_ClassType; } | 207 virtual ClassType getType() { return kSubclassEmpty_ClassType; } |
198 }; | 208 }; |
199 | 209 |
| 210 class Order { |
| 211 public: |
| 212 Order() { this->reset(); } |
| 213 void reset() { fCurrent = 0; } |
| 214 ClassType next() { |
| 215 fCurrent = 1664525 * fCurrent + 1013904223; |
| 216 return static_cast<ClassType>(fCurrent % kNumClassTypes); |
| 217 } |
| 218 private: |
| 219 uint32_t fCurrent; |
| 220 }; |
| 221 static void test_subclasses_iters(skiatest::Reporter*, Order&, Base::Recorder::I
ter&, |
| 222 Base::Recorder::ReverseIter&, int = 0); |
200 static void test_subclasses(skiatest::Reporter* reporter) { | 223 static void test_subclasses(skiatest::Reporter* reporter) { |
201 class Order { | |
202 public: | |
203 Order() { this->reset(); } | |
204 void reset() { fCurrent = 0; } | |
205 ClassType next() { | |
206 fCurrent = 1664525 * fCurrent + 1013904223; | |
207 return static_cast<ClassType>(fCurrent % kNumClassTypes); | |
208 } | |
209 private: | |
210 uint32_t fCurrent; | |
211 }; | |
212 | |
213 Base::Recorder recorder(1024); | 224 Base::Recorder recorder(1024); |
214 | 225 |
215 Order order; | 226 Order order; |
216 for (int i = 0; i < 1000; i++) { | 227 for (int i = 0; i < 1000; i++) { |
217 switch (order.next()) { | 228 switch (order.next()) { |
218 case kBase_ClassType: | 229 case kBase_ClassType: |
219 GrNEW_APPEND_TO_RECORDER(recorder, Base, ()); | 230 GrNEW_APPEND_TO_RECORDER(recorder, Base, ()); |
220 break; | 231 break; |
221 | 232 |
222 case kSubclass_ClassType: | 233 case kSubclass_ClassType: |
(...skipping 14 matching lines...) Expand all Loading... |
237 | 248 |
238 default: | 249 default: |
239 ERRORF(reporter, "Invalid class type"); | 250 ERRORF(reporter, "Invalid class type"); |
240 break; | 251 break; |
241 } | 252 } |
242 } | 253 } |
243 REPORTER_ASSERT(reporter, 1000 == activeRecorderItems); | 254 REPORTER_ASSERT(reporter, 1000 == activeRecorderItems); |
244 | 255 |
245 order.reset(); | 256 order.reset(); |
246 Base::Recorder::Iter iter(recorder); | 257 Base::Recorder::Iter iter(recorder); |
247 for (int i = 0; i < 1000; ++i) { | 258 Base::Recorder::ReverseIter reverseIter(recorder); |
248 REPORTER_ASSERT(reporter, iter.next()); | 259 |
249 REPORTER_ASSERT(reporter, order.next() == iter->getType()); | 260 test_subclasses_iters(reporter, order, iter, reverseIter); |
250 iter->validate(reporter); | 261 |
251 } | |
252 REPORTER_ASSERT(reporter, !iter.next()); | 262 REPORTER_ASSERT(reporter, !iter.next()); |
253 | 263 |
254 // Don't reset the recorder. It should automatically destruct all its items. | 264 // Don't reset the recorder. It should automatically destruct all its items. |
255 } | 265 } |
| 266 static void test_subclasses_iters(skiatest::Reporter* reporter, Order& order, |
| 267 Base::Recorder::Iter& iter, |
| 268 Base::Recorder::ReverseIter& reverseIter, int
i) { |
| 269 if (i >= 1000) { |
| 270 return; |
| 271 } |
| 272 |
| 273 ClassType classType = order.next(); |
| 274 |
| 275 REPORTER_ASSERT(reporter, iter.next()); |
| 276 REPORTER_ASSERT(reporter, classType == iter->getType()); |
| 277 iter->validate(reporter); |
| 278 |
| 279 test_subclasses_iters(reporter, order, iter, reverseIter, i + 1); |
| 280 |
| 281 REPORTER_ASSERT(reporter, classType == reverseIter->getType()); |
| 282 reverseIter->validate(reporter); |
| 283 REPORTER_ASSERT(reporter, reverseIter.previous() == !!i); |
| 284 } |
256 | 285 |
257 DEF_GPUTEST(GrTRecorder, reporter, factory) { | 286 DEF_GPUTEST(GrTRecorder, reporter, factory) { |
258 test_empty_back_and_pop(reporter); | 287 test_empty_back_and_pop(reporter); |
259 | 288 |
260 test_extra_data(reporter); | 289 test_extra_data(reporter); |
261 REPORTER_ASSERT(reporter, 0 == activeRecorderItems); // test_extra_data shou
ld call reset(). | 290 REPORTER_ASSERT(reporter, 0 == activeRecorderItems); // test_extra_data shou
ld call reset(). |
262 | 291 |
263 test_subclasses(reporter); | 292 test_subclasses(reporter); |
264 REPORTER_ASSERT(reporter, 0 == activeRecorderItems); // Ensure ~GrTRecorder
invokes dtors. | 293 REPORTER_ASSERT(reporter, 0 == activeRecorderItems); // Ensure ~GrTRecorder
invokes dtors. |
265 } | 294 } |
266 | 295 |
267 #endif | 296 #endif |
OLD | NEW |