2015-08-19 16:51:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2014-05-19 15:15:24 +00:00
|
|
|
#ifndef RecordTestUtils_DEFINED
|
|
|
|
#define RecordTestUtils_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkRecord.h"
|
|
|
|
#include "src/core/SkRecords.h"
|
|
|
|
#include "tests/Test.h"
|
2014-05-19 15:15:24 +00:00
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
// If the command we're reading is a U, set ptr to it, otherwise set it to nullptr.
|
2014-05-19 15:15:24 +00:00
|
|
|
template <typename U>
|
|
|
|
struct ReadAs {
|
2015-08-27 14:41:13 +00:00
|
|
|
ReadAs() : ptr(nullptr), type(SkRecords::Type(~0)) {}
|
2014-05-19 15:15:24 +00:00
|
|
|
|
|
|
|
const U* ptr;
|
|
|
|
SkRecords::Type type;
|
|
|
|
|
|
|
|
void operator()(const U& r) { ptr = &r; type = U::kType; }
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void operator()(const T&) { type = U::kType; }
|
|
|
|
};
|
|
|
|
|
|
|
|
// Assert that the ith command in record is of type T, and return it.
|
|
|
|
template <typename T>
|
2015-08-19 16:51:00 +00:00
|
|
|
static const T* assert_type(skiatest::Reporter* r, const SkRecord& record, int index) {
|
2014-05-19 15:15:24 +00:00
|
|
|
ReadAs<T> reader;
|
2016-03-22 18:46:53 +00:00
|
|
|
record.visit(index, reader);
|
2014-05-19 15:15:24 +00:00
|
|
|
REPORTER_ASSERT(r, T::kType == reader.type);
|
2014-09-05 20:34:00 +00:00
|
|
|
REPORTER_ASSERT(r, SkToBool(reader.ptr));
|
2014-05-19 15:15:24 +00:00
|
|
|
return reader.ptr;
|
|
|
|
}
|
|
|
|
|
2014-12-11 15:07:37 +00:00
|
|
|
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;
|
2015-08-19 16:51:00 +00:00
|
|
|
for (int i = 0; i < record.count(); i++) {
|
2016-03-22 18:46:53 +00:00
|
|
|
counter += record.visit(i, matcher);
|
2014-12-11 15:07:37 +00:00
|
|
|
}
|
|
|
|
return counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename DrawT> int find_first_instances_of_type(const SkRecord& record) {
|
|
|
|
MatchType<DrawT> matcher;
|
2015-08-19 16:51:00 +00:00
|
|
|
for (int i = 0; i < record.count(); i++) {
|
2016-03-22 18:46:53 +00:00
|
|
|
if (record.visit(i, matcher)) {
|
2014-12-11 15:07:37 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-05-19 15:15:24 +00:00
|
|
|
#endif//RecordTestUtils_DEFINED
|