c4b21e6c03
BUG=skia: R=reed@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/235253002 git-svn-id: http://skia.googlecode.com/svn/trunk@14158 2bbb7eff-a529-9590-31e7-b0007b416f81
60 lines
1.4 KiB
C++
60 lines
1.4 KiB
C++
/*
|
|
* Copyright 2014 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "Test.h"
|
|
|
|
#include "SkRecord.h"
|
|
#include "SkRecords.h"
|
|
|
|
// Sums the area of any DrawRect command it sees.
|
|
class AreaSummer {
|
|
public:
|
|
AreaSummer() : fArea(0) {}
|
|
|
|
template <typename T> void operator()(const T&) { }
|
|
|
|
int area() const { return fArea; }
|
|
|
|
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*) {}
|
|
};
|
|
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) {
|
|
SkRecord record;
|
|
|
|
// Add a simple DrawRect command.
|
|
SkRect rect = SkRect::MakeWH(10, 10);
|
|
SkPaint paint;
|
|
SkNEW_PLACEMENT_ARGS(record.append<SkRecords::DrawRect>(), SkRecords::DrawRect, (rect, paint));
|
|
|
|
// Its area should be 100.
|
|
AreaSummer summer;
|
|
record.visit(summer);
|
|
REPORTER_ASSERT(r, summer.area() == 100);
|
|
|
|
// Scale 2x.
|
|
Stretch stretch;
|
|
record.mutate(stretch);
|
|
|
|
// Now its area should be 100 + 400.
|
|
record.visit(summer);
|
|
REPORTER_ASSERT(r, summer.area() == 500);
|
|
}
|