OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Test.h" | 8 #include "Test.h" |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
11 #include "SkImageInfo.h" | 11 #include "SkImageInfo.h" |
12 #include "SkShader.h" | 12 #include "SkShader.h" |
13 #include "SkRecord.h" | 13 #include "SkRecord.h" |
14 #include "SkRecords.h" | 14 #include "SkRecords.h" |
15 | 15 |
16 // Sums the area of any DrawRect command it sees. | 16 // Sums the area of any DrawRect command it sees. |
17 class AreaSummer { | 17 class AreaSummer { |
18 public: | 18 public: |
19 AreaSummer() : fArea(0) {} | 19 AreaSummer() : fArea(0) {} |
20 | 20 |
21 template <typename T> void operator()(const T&) { } | 21 template <typename T> void operator()(const T&) { } |
22 | 22 |
23 void operator()(const SkRecords::DrawRect& draw) { | 23 void operator()(const SkRecords::DrawRect& draw) { |
24 fArea += (int)(draw.rect.width() * draw.rect.height()); | 24 fArea += (int)(draw.rect.width() * draw.rect.height()); |
25 } | 25 } |
26 | 26 |
27 int area() const { return fArea; } | 27 int area() const { return fArea; } |
28 | 28 |
29 void apply(const SkRecord& record) { | 29 void apply(const SkRecord& record) { |
30 for (unsigned i = 0; i < record.count(); i++) { | 30 for (int i = 0; i < record.count(); i++) { |
31 record.visit<void>(i, *this); | 31 record.visit<void>(i, *this); |
32 } | 32 } |
33 } | 33 } |
34 | 34 |
35 private: | 35 private: |
36 int fArea; | 36 int fArea; |
37 }; | 37 }; |
38 | 38 |
39 // Scales out the bottom-right corner of any DrawRect command it sees by 2x. | 39 // Scales out the bottom-right corner of any DrawRect command it sees by 2x. |
40 struct Stretch { | 40 struct Stretch { |
41 template <typename T> void operator()(T*) {} | 41 template <typename T> void operator()(T*) {} |
42 void operator()(SkRecords::DrawRect* draw) { | 42 void operator()(SkRecords::DrawRect* draw) { |
43 draw->rect.fRight *= 2; | 43 draw->rect.fRight *= 2; |
44 draw->rect.fBottom *= 2; | 44 draw->rect.fBottom *= 2; |
45 } | 45 } |
46 | 46 |
47 void apply(SkRecord* record) { | 47 void apply(SkRecord* record) { |
48 for (unsigned i = 0; i < record->count(); i++) { | 48 for (int i = 0; i < record->count(); i++) { |
49 record->mutate<void>(i, *this); | 49 record->mutate<void>(i, *this); |
50 } | 50 } |
51 } | 51 } |
52 }; | 52 }; |
53 | 53 |
54 #define APPEND(record, type, ...) SkNEW_PLACEMENT_ARGS(record.append<type>(), ty
pe, (__VA_ARGS__)) | 54 #define APPEND(record, type, ...) SkNEW_PLACEMENT_ARGS(record.append<type>(), ty
pe, (__VA_ARGS__)) |
55 | 55 |
56 // Basic tests for the low-level SkRecord code. | 56 // Basic tests for the low-level SkRecord code. |
57 DEF_TEST(Record, r) { | 57 DEF_TEST(Record, r) { |
58 SkRecord record; | 58 SkRecord record; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 REPORTER_ASSERT(r, is_aligned(record.alloc<uint32_t>())); | 90 REPORTER_ASSERT(r, is_aligned(record.alloc<uint32_t>())); |
91 REPORTER_ASSERT(r, is_aligned(record.alloc<void*>())); | 91 REPORTER_ASSERT(r, is_aligned(record.alloc<void*>())); |
92 | 92 |
93 // It's not clear if we care that 8-byte values are aligned on 32-bit machin
es. | 93 // It's not clear if we care that 8-byte values are aligned on 32-bit machin
es. |
94 if (sizeof(void*) == 8) { | 94 if (sizeof(void*) == 8) { |
95 REPORTER_ASSERT(r, is_aligned(record.alloc<double>())); | 95 REPORTER_ASSERT(r, is_aligned(record.alloc<double>())); |
96 REPORTER_ASSERT(r, is_aligned(record.alloc<uint64_t>())); | 96 REPORTER_ASSERT(r, is_aligned(record.alloc<uint64_t>())); |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
OLD | NEW |