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