OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 #ifndef RecordTestUtils_DEFINED | 8 #ifndef RecordTestUtils_DEFINED |
9 #define RecordTestUtils_DEFINED | 9 #define RecordTestUtils_DEFINED |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 void operator()(const U& r) { ptr = &r; type = U::kType; } | 23 void operator()(const U& r) { ptr = &r; type = U::kType; } |
24 | 24 |
25 template <typename T> | 25 template <typename T> |
26 void operator()(const T&) { type = U::kType; } | 26 void operator()(const T&) { type = U::kType; } |
27 }; | 27 }; |
28 | 28 |
29 // Assert that the ith command in record is of type T, and return it. | 29 // Assert that the ith command in record is of type T, and return it. |
30 template <typename T> | 30 template <typename T> |
31 static const T* assert_type(skiatest::Reporter* r, const SkRecord& record, int i
ndex) { | 31 static const T* assert_type(skiatest::Reporter* r, const SkRecord& record, int i
ndex) { |
32 ReadAs<T> reader; | 32 ReadAs<T> reader; |
33 record.visit<void>(index, reader); | 33 record.visit(index, reader); |
34 REPORTER_ASSERT(r, T::kType == reader.type); | 34 REPORTER_ASSERT(r, T::kType == reader.type); |
35 REPORTER_ASSERT(r, SkToBool(reader.ptr)); | 35 REPORTER_ASSERT(r, SkToBool(reader.ptr)); |
36 return reader.ptr; | 36 return reader.ptr; |
37 } | 37 } |
38 | 38 |
39 template <typename DrawT> struct MatchType { | 39 template <typename DrawT> struct MatchType { |
40 template <typename T> int operator()(const T&) { return 0; } | 40 template <typename T> int operator()(const T&) { return 0; } |
41 int operator()(const DrawT&) { return 1; } | 41 int operator()(const DrawT&) { return 1; } |
42 }; | 42 }; |
43 | 43 |
44 template <typename DrawT> int count_instances_of_type(const SkRecord& record) { | 44 template <typename DrawT> int count_instances_of_type(const SkRecord& record) { |
45 MatchType<DrawT> matcher; | 45 MatchType<DrawT> matcher; |
46 int counter = 0; | 46 int counter = 0; |
47 for (int i = 0; i < record.count(); i++) { | 47 for (int i = 0; i < record.count(); i++) { |
48 counter += record.visit<int>(i, matcher); | 48 counter += record.visit(i, matcher); |
49 } | 49 } |
50 return counter; | 50 return counter; |
51 } | 51 } |
52 | 52 |
53 template <typename DrawT> int find_first_instances_of_type(const SkRecord& recor
d) { | 53 template <typename DrawT> int find_first_instances_of_type(const SkRecord& recor
d) { |
54 MatchType<DrawT> matcher; | 54 MatchType<DrawT> matcher; |
55 for (int i = 0; i < record.count(); i++) { | 55 for (int i = 0; i < record.count(); i++) { |
56 if (record.visit<int>(i, matcher)) { | 56 if (record.visit(i, matcher)) { |
57 return i; | 57 return i; |
58 } | 58 } |
59 } | 59 } |
60 return -1; | 60 return -1; |
61 } | 61 } |
62 | 62 |
63 #endif//RecordTestUtils_DEFINED | 63 #endif//RecordTestUtils_DEFINED |
OLD | NEW |