aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/RecordTestUtils.h
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2014-12-11 07:07:37 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-12-11 07:07:38 -0800
commit2ff1fcede1e9525285c5de1f35fb2dcb0fab32bd (patch)
treed031604a9c76281aa645c56a94ada8422b5b291d /tests/RecordTestUtils.h
parent8da8e9d7511c2f60855c2e3334ae0fe27365bc96 (diff)
Defer saves() until they're needed
patch from issue 759443006 at patchset 40001 (http://crrev.com/759443006#ps40001) BUG=skia: Review URL: https://codereview.chromium.org/767333002
Diffstat (limited to 'tests/RecordTestUtils.h')
-rw-r--r--tests/RecordTestUtils.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/RecordTestUtils.h b/tests/RecordTestUtils.h
index 0575b83cdd..4bab8e4a39 100644
--- a/tests/RecordTestUtils.h
+++ b/tests/RecordTestUtils.h
@@ -28,4 +28,28 @@ static const T* assert_type(skiatest::Reporter* r, const SkRecord& record, unsig
return reader.ptr;
}
+template <typename DrawT> struct MatchType {
+ template <typename T> int operator()(const T&) { return 0; }
+ int operator()(const DrawT&) { return 1; }
+};
+
+template <typename DrawT> int count_instances_of_type(const SkRecord& record) {
+ MatchType<DrawT> matcher;
+ int counter = 0;
+ for (unsigned i = 0; i < record.count(); i++) {
+ counter += record.visit<int>(i, matcher);
+ }
+ return counter;
+}
+
+template <typename DrawT> int find_first_instances_of_type(const SkRecord& record) {
+ MatchType<DrawT> matcher;
+ for (unsigned i = 0; i < record.count(); i++) {
+ if (record.visit<int>(i, matcher)) {
+ return i;
+ }
+ }
+ return -1;
+}
+
#endif//RecordTestUtils_DEFINED