blob: 1214b1a5de78d461ad31ecc410887b3680704c62 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#include "Test.h"
#include "SkRecord.h"
#include "SkRecords.h"
// Adds the area of any DrawRect command it sees into area.
class AreaSummer {
public:
explicit AreaSummer(int* area) : fArea(area) {}
template <typename T> void operator()(const T&) { }
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.
int area = 0;
record.visit(AreaSummer(&area));
REPORTER_ASSERT(r, area == 100);
// Scale 2x. Now it's area should be 400.
record.mutate(Stretch());
area = 0;
record.visit(AreaSummer(&area));
REPORTER_ASSERT(r, area == 400);
}
|