blob: 7cb62414c319d6dd14e8178128a7279dc4271af8 [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.org506db0b2014-04-08 23:31:35 +00008#include "Test.h"
9
10#include "SkRecord.h"
commit-bot@chromium.orgad8ce572014-04-21 15:03:36 +000011#include "SkRecordOpts.h"
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000012#include "SkRecorder.h"
13#include "SkRecords.h"
14
commit-bot@chromium.org88c3e272014-04-22 16:57:20 +000015struct SkipScanner {
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000016 template <typename T> void operator()(const T&) {}
17
commit-bot@chromium.org88c3e272014-04-22 16:57:20 +000018 void apply(const SkRecord& record) {
19 for (unsigned i = 0; i < record.count(); i++) {
20 record.visit(i, *this);
21 }
22 }
23
24 SkTDArray<unsigned> fSkips;
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000025};
26
commit-bot@chromium.org88c3e272014-04-22 16:57:20 +000027template <> void SkipScanner::operator()(const SkRecords::PairedPushCull& r) {
28 *fSkips.append() = r.skip;
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000029}
30
31
32DEF_TEST(RecordCulling, r) {
33 SkRecord record;
commit-bot@chromium.orgd9ce2be2014-04-09 23:30:28 +000034 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, 1920, 1080);
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000035
36 recorder.drawRect(SkRect::MakeWH(1000, 10000), SkPaint());
37
38 recorder.pushCull(SkRect::MakeWH(100, 100));
39 recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint());
40 recorder.drawRect(SkRect::MakeWH(30, 30), SkPaint());
41 recorder.pushCull(SkRect::MakeWH(5, 5));
42 recorder.drawRect(SkRect::MakeWH(1, 1), SkPaint());
43 recorder.popCull();
44 recorder.popCull();
45
46 SkRecordAnnotateCullingPairs(&record);
47
commit-bot@chromium.org88c3e272014-04-22 16:57:20 +000048 SkipScanner scan;
49 scan.apply(record);
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000050
commit-bot@chromium.org88c3e272014-04-22 16:57:20 +000051 REPORTER_ASSERT(r, 2 == scan.fSkips.count());
52 REPORTER_ASSERT(r, 6 == scan.fSkips[0]);
53 REPORTER_ASSERT(r, 2 == scan.fSkips[1]);
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000054}