commit-bot@chromium.org | b736962 | 2014-04-08 20:17:26 +0000 | [diff] [blame] | 1 | #include "Test.h" |
| 2 | |
| 3 | #include "SkRecord.h" |
| 4 | #include "SkRecorder.h" |
| 5 | #include "SkRecords.h" |
| 6 | |
| 7 | #define COUNT(T) + 1 |
| 8 | static const int kRecordTypes = SK_RECORD_TYPES(COUNT); |
| 9 | #undef COUNT |
| 10 | |
commit-bot@chromium.org | 506db0b | 2014-04-08 23:31:35 +0000 | [diff] [blame] | 11 | // Tallies the types of commands it sees into a histogram. |
commit-bot@chromium.org | b736962 | 2014-04-08 20:17:26 +0000 | [diff] [blame] | 12 | class Tally { |
| 13 | public: |
commit-bot@chromium.org | 506db0b | 2014-04-08 23:31:35 +0000 | [diff] [blame] | 14 | Tally() { sk_bzero(&fHistogram, sizeof(fHistogram)); } |
commit-bot@chromium.org | b736962 | 2014-04-08 20:17:26 +0000 | [diff] [blame] | 15 | |
commit-bot@chromium.org | 506db0b | 2014-04-08 23:31:35 +0000 | [diff] [blame] | 16 | template <typename T> |
| 17 | void operator()(const T&) { ++fHistogram[T::kType]; } |
| 18 | |
| 19 | template <typename T> |
| 20 | int count() const { return fHistogram[T::kType]; } |
commit-bot@chromium.org | b736962 | 2014-04-08 20:17:26 +0000 | [diff] [blame] | 21 | |
| 22 | private: |
commit-bot@chromium.org | 506db0b | 2014-04-08 23:31:35 +0000 | [diff] [blame] | 23 | int fHistogram[kRecordTypes]; |
commit-bot@chromium.org | b736962 | 2014-04-08 20:17:26 +0000 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | DEF_TEST(Recorder, 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 | b736962 | 2014-04-08 20:17:26 +0000 | [diff] [blame] | 29 | |
| 30 | recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint()); |
| 31 | |
commit-bot@chromium.org | 506db0b | 2014-04-08 23:31:35 +0000 | [diff] [blame] | 32 | Tally tally; |
| 33 | record.visit(tally); |
commit-bot@chromium.org | b736962 | 2014-04-08 20:17:26 +0000 | [diff] [blame] | 34 | |
commit-bot@chromium.org | 506db0b | 2014-04-08 23:31:35 +0000 | [diff] [blame] | 35 | REPORTER_ASSERT(r, 1 == tally.count<SkRecords::DrawRect>()); |
commit-bot@chromium.org | b736962 | 2014-04-08 20:17:26 +0000 | [diff] [blame] | 36 | } |