blob: 3c7b0082b1a71475a48edad368807606da3e1f9b [file] [log] [blame]
commit-bot@chromium.orgb7369622014-04-08 20:17:26 +00001#include "Test.h"
2
3#include "SkRecord.h"
4#include "SkRecorder.h"
5#include "SkRecords.h"
6
7#define COUNT(T) + 1
8static const int kRecordTypes = SK_RECORD_TYPES(COUNT);
9#undef COUNT
10
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000011// Tallies the types of commands it sees into a histogram.
commit-bot@chromium.orgb7369622014-04-08 20:17:26 +000012class Tally {
13public:
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000014 Tally() { sk_bzero(&fHistogram, sizeof(fHistogram)); }
commit-bot@chromium.orgb7369622014-04-08 20:17:26 +000015
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000016 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.orgb7369622014-04-08 20:17:26 +000021
22private:
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000023 int fHistogram[kRecordTypes];
commit-bot@chromium.orgb7369622014-04-08 20:17:26 +000024};
25
26DEF_TEST(Recorder, r) {
27 SkRecord record;
28 SkRecorder recorder(&record, 1920, 1080);
29
30 recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint());
31
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000032 Tally tally;
33 record.visit(tally);
commit-bot@chromium.orgb7369622014-04-08 20:17:26 +000034
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000035 REPORTER_ASSERT(r, 1 == tally.count<SkRecords::DrawRect>());
commit-bot@chromium.orgb7369622014-04-08 20:17:26 +000036}