OLD | NEW |
1 #ifndef RecordTestUtils_DEFINED | 1 #ifndef RecordTestUtils_DEFINED |
2 #define RecordTestUtils_DEFINED | 2 #define RecordTestUtils_DEFINED |
3 | 3 |
4 #include "SkRecord.h" | 4 #include "SkRecord.h" |
5 #include "SkRecords.h" | 5 #include "SkRecords.h" |
6 | 6 |
7 // If the command we're reading is a U, set ptr to it, otherwise set it to NULL. | 7 // If the command we're reading is a U, set ptr to it, otherwise set it to NULL. |
8 template <typename U> | 8 template <typename U> |
9 struct ReadAs { | 9 struct ReadAs { |
10 ReadAs() : ptr(NULL), type(SkRecords::Type(~0)) {} | 10 ReadAs() : ptr(NULL), type(SkRecords::Type(~0)) {} |
(...skipping 10 matching lines...) Expand all Loading... |
21 // Assert that the ith command in record is of type T, and return it. | 21 // Assert that the ith command in record is of type T, and return it. |
22 template <typename T> | 22 template <typename T> |
23 static const T* assert_type(skiatest::Reporter* r, const SkRecord& record, unsig
ned index) { | 23 static const T* assert_type(skiatest::Reporter* r, const SkRecord& record, unsig
ned index) { |
24 ReadAs<T> reader; | 24 ReadAs<T> reader; |
25 record.visit<void>(index, reader); | 25 record.visit<void>(index, reader); |
26 REPORTER_ASSERT(r, T::kType == reader.type); | 26 REPORTER_ASSERT(r, T::kType == reader.type); |
27 REPORTER_ASSERT(r, SkToBool(reader.ptr)); | 27 REPORTER_ASSERT(r, SkToBool(reader.ptr)); |
28 return reader.ptr; | 28 return reader.ptr; |
29 } | 29 } |
30 | 30 |
31 template <typename DrawT> struct MatchType { | |
32 template <typename T> int operator()(const T&) { return 0; } | |
33 int operator()(const DrawT&) { return 1; } | |
34 }; | |
35 | |
36 template <typename DrawT> int count_instances_of_type(const SkRecord& record) { | |
37 MatchType<DrawT> matcher; | |
38 int counter = 0; | |
39 for (unsigned i = 0; i < record.count(); i++) { | |
40 counter += record.visit<int>(i, matcher); | |
41 } | |
42 return counter; | |
43 } | |
44 | |
45 template <typename DrawT> int find_first_instances_of_type(const SkRecord& recor
d) { | |
46 MatchType<DrawT> matcher; | |
47 for (unsigned i = 0; i < record.count(); i++) { | |
48 if (record.visit<int>(i, matcher)) { | |
49 return i; | |
50 } | |
51 } | |
52 return -1; | |
53 } | |
54 | |
55 #endif//RecordTestUtils_DEFINED | 31 #endif//RecordTestUtils_DEFINED |
OLD | NEW |