aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-07 21:16:09 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-07 21:16:09 +0000
commitc71da1f6ed3a5e1a3eb2dd860b8129e1b423f9f4 (patch)
tree64e4be52905cc37f86fbb007187810f1444ed398 /tests
parentba31f1d341bac57ca76a75d67f64434b4b371dc6 (diff)
Convert all SkRecordPattern matchers into SkRecord mutators.
- Allow any return type from SkRecord mutators and visitors; - update existing calls to mutate and visit; - convert match to operator() in SkRecordPattern; - tidy up a few inelegant bits of old code in tests. The net result is that the generated code is much clearer. All the mutate() calls inline as you'd hope, and you can now actually follow along with the disassembly. BUG=skia:2378 R=fmalita@chromium.org, bungeman@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/273643007 git-svn-id: http://skia.googlecode.com/svn/trunk@14631 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r--tests/RecordOptsTest.cpp17
-rw-r--r--tests/RecordTest.cpp19
-rw-r--r--tests/RecorderTest.cpp2
3 files changed, 19 insertions, 19 deletions
diff --git a/tests/RecordOptsTest.cpp b/tests/RecordOptsTest.cpp
index 33142c8a3d..c427c25119 100644
--- a/tests/RecordOptsTest.cpp
+++ b/tests/RecordOptsTest.cpp
@@ -19,26 +19,25 @@ static const int W = 1920, H = 1080;
// If the command we're reading is a U, set ptr to it, otherwise set it to NULL.
template <typename U>
struct ReadAs {
- explicit ReadAs(const U** ptr) : ptr(ptr), type(SkRecords::Type(~0)) {}
+ ReadAs() : ptr(NULL), type(SkRecords::Type(~0)) {}
- const U** ptr;
+ const U* ptr;
SkRecords::Type type;
- void operator()(const U& r) { *ptr = &r; type = U::kType; }
+ void operator()(const U& r) { ptr = &r; type = U::kType; }
template <typename T>
- void operator()(const T&) { *ptr = NULL; type = U::kType; }
+ void operator()(const T&) { type = U::kType; }
};
// Assert that the ith command in record is of type T, and return it.
template <typename T>
static const T* assert_type(skiatest::Reporter* r, const SkRecord& record, unsigned index) {
- const T* ptr = NULL;
- ReadAs<T> reader(&ptr);
- record.visit(index, reader);
+ ReadAs<T> reader;
+ record.visit<void>(index, reader);
REPORTER_ASSERT(r, T::kType == reader.type);
- REPORTER_ASSERT(r, ptr != NULL);
- return ptr;
+ REPORTER_ASSERT(r, NULL != reader.ptr);
+ return reader.ptr;
}
DEF_TEST(RecordOpts_Culling, r) {
diff --git a/tests/RecordTest.cpp b/tests/RecordTest.cpp
index e58ef10dda..9238d97aa7 100644
--- a/tests/RecordTest.cpp
+++ b/tests/RecordTest.cpp
@@ -17,35 +17,36 @@ public:
template <typename T> void operator()(const T&) { }
+ void operator()(const SkRecords::DrawRect& draw) {
+ fArea += (int)(draw.rect.width() * draw.rect.height());
+ }
+
int area() const { return fArea; }
void apply(const SkRecord& record) {
for (unsigned i = 0; i < record.count(); i++) {
- record.visit(i, *this);
+ record.visit<void>(i, *this);
}
}
private:
int fArea;
};
-template <> void AreaSummer::operator()(const SkRecords::DrawRect& record) {
- fArea += (int) (record.rect.width() * record.rect.height());
-}
// Scales out the bottom-right corner of any DrawRect command it sees by 2x.
struct Stretch {
template <typename T> void operator()(T*) {}
+ void operator()(SkRecords::DrawRect* draw) {
+ draw->rect.fRight *= 2;
+ draw->rect.fBottom *= 2;
+ }
void apply(SkRecord* record) {
for (unsigned i = 0; i < record->count(); i++) {
- record->mutate(i, *this);
+ record->mutate<void>(i, *this);
}
}
};
-template <> void Stretch::operator()(SkRecords::DrawRect* record) {
- record->rect.fRight *= 2;
- record->rect.fBottom *= 2;
-}
// Basic tests for the low-level SkRecord code.
DEF_TEST(Record, r) {
diff --git a/tests/RecorderTest.cpp b/tests/RecorderTest.cpp
index 407cf9add0..8fa198cd6d 100644
--- a/tests/RecorderTest.cpp
+++ b/tests/RecorderTest.cpp
@@ -30,7 +30,7 @@ public:
void apply(const SkRecord& record) {
for (unsigned i = 0; i < record.count(); i++) {
- record.visit(i, *this);
+ record.visit<void>(i, *this);
}
}