OLD | NEW |
(Empty) | |
| 1 #include "Test.h" |
| 2 |
| 3 #include "SkRecord.h" |
| 4 #include "SkRecords.h" |
| 5 |
| 6 // Adds the area of any DrawRect command it sees into area. |
| 7 class AreaSummer { |
| 8 public: |
| 9 explicit AreaSummer(int* area) : fArea(area) {} |
| 10 |
| 11 template <typename T> void operator()(const T&) { } |
| 12 |
| 13 private: |
| 14 int* fArea; |
| 15 }; |
| 16 template <> void AreaSummer::operator()(const SkRecords::DrawRect& record) { |
| 17 *fArea += (int) (record.rect.width() * record.rect.height()); |
| 18 } |
| 19 |
| 20 // Scales out the bottom-right corner of any DrawRect command it sees by 2x. |
| 21 struct Stretch { |
| 22 template <typename T> void operator()(T*) {} |
| 23 }; |
| 24 template <> void Stretch::operator()(SkRecords::DrawRect* record) { |
| 25 record->rect.fRight *= 2; |
| 26 record->rect.fBottom *= 2; |
| 27 } |
| 28 |
| 29 // Basic tests for the low-level SkRecord code. |
| 30 DEF_TEST(Record, r) { |
| 31 SkRecord record; |
| 32 |
| 33 // Add a simple DrawRect command. |
| 34 SkRect rect = SkRect::MakeWH(10, 10); |
| 35 SkPaint paint; |
| 36 SkNEW_PLACEMENT_ARGS(record.append<SkRecords::DrawRect>(), SkRecords::DrawRe
ct, (rect, paint)); |
| 37 |
| 38 // Its area should be 100. |
| 39 int area = 0; |
| 40 record.visit(AreaSummer(&area)); |
| 41 REPORTER_ASSERT(r, area == 100); |
| 42 |
| 43 // Scale 2x. Now it's area should be 400. |
| 44 record.mutate(Stretch()); |
| 45 area = 0; |
| 46 record.visit(AreaSummer(&area)); |
| 47 REPORTER_ASSERT(r, area == 400); |
| 48 } |
OLD | NEW |