blob: 34b3f2c0de26b85bd724010f90627d6463e799ee [file] [log] [blame]
commit-bot@chromium.orgc4b21e62014-04-11 18:33:31 +00001/*
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.orgb7369622014-04-08 20:17:26 +00008#include "Test.h"
9
10#include "SkRecord.h"
11#include "SkRecorder.h"
12#include "SkRecords.h"
13
14#define COUNT(T) + 1
15static const int kRecordTypes = SK_RECORD_TYPES(COUNT);
16#undef COUNT
17
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000018// Tallies the types of commands it sees into a histogram.
commit-bot@chromium.orgb7369622014-04-08 20:17:26 +000019class Tally {
20public:
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000021 Tally() { sk_bzero(&fHistogram, sizeof(fHistogram)); }
commit-bot@chromium.orgb7369622014-04-08 20:17:26 +000022
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000023 template <typename T>
24 void operator()(const T&) { ++fHistogram[T::kType]; }
25
26 template <typename T>
27 int count() const { return fHistogram[T::kType]; }
commit-bot@chromium.orgb7369622014-04-08 20:17:26 +000028
29private:
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000030 int fHistogram[kRecordTypes];
commit-bot@chromium.orgb7369622014-04-08 20:17:26 +000031};
32
33DEF_TEST(Recorder, r) {
34 SkRecord record;
commit-bot@chromium.orgd9ce2be2014-04-09 23:30:28 +000035 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, 1920, 1080);
commit-bot@chromium.orgb7369622014-04-08 20:17:26 +000036
37 recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint());
38
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000039 Tally tally;
40 record.visit(tally);
commit-bot@chromium.orgb7369622014-04-08 20:17:26 +000041
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000042 REPORTER_ASSERT(r, 1 == tally.count<SkRecords::DrawRect>());
commit-bot@chromium.orgb7369622014-04-08 20:17:26 +000043}