commit-bot@chromium.org | c4b21e6 | 2014-04-11 18:33:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
commit-bot@chromium.org | 506db0b | 2014-04-08 23:31:35 +0000 | [diff] [blame] | 8 | #include "Test.h" |
| 9 | |
| 10 | #include "SkRecord.h" |
| 11 | #include "SkRecordCulling.h" |
| 12 | #include "SkRecorder.h" |
| 13 | #include "SkRecords.h" |
| 14 | |
| 15 | struct PushCullScanner { |
| 16 | template <typename T> void operator()(const T&) {} |
| 17 | |
| 18 | SkTDArray<unsigned> fPopOffsets; |
| 19 | }; |
| 20 | |
| 21 | template <> void PushCullScanner::operator()(const SkRecords::PushCull& record) { |
| 22 | *fPopOffsets.append() = record.popOffset; |
| 23 | } |
| 24 | |
| 25 | |
| 26 | DEF_TEST(RecordCulling, r) { |
| 27 | SkRecord record; |
commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 28 | SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, 1920, 1080); |
commit-bot@chromium.org | 506db0b | 2014-04-08 23:31:35 +0000 | [diff] [blame] | 29 | |
| 30 | recorder.drawRect(SkRect::MakeWH(1000, 10000), SkPaint()); |
| 31 | |
| 32 | recorder.pushCull(SkRect::MakeWH(100, 100)); |
| 33 | recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint()); |
| 34 | recorder.drawRect(SkRect::MakeWH(30, 30), SkPaint()); |
| 35 | recorder.pushCull(SkRect::MakeWH(5, 5)); |
| 36 | recorder.drawRect(SkRect::MakeWH(1, 1), SkPaint()); |
| 37 | recorder.popCull(); |
| 38 | recorder.popCull(); |
| 39 | |
| 40 | SkRecordAnnotateCullingPairs(&record); |
| 41 | |
| 42 | PushCullScanner scan; |
| 43 | record.visit(scan); |
| 44 | |
| 45 | REPORTER_ASSERT(r, 2 == scan.fPopOffsets.count()); |
| 46 | REPORTER_ASSERT(r, 6 == scan.fPopOffsets[0]); |
| 47 | REPORTER_ASSERT(r, 2 == scan.fPopOffsets[1]); |
| 48 | } |