blob: bf1ca258b78b3d40841aa960367dc341526b9183 [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"
11#include "SkRecordCulling.h"
12#include "SkRecorder.h"
13#include "SkRecords.h"
14
15struct PushCullScanner {
16 template <typename T> void operator()(const T&) {}
17
18 SkTDArray<unsigned> fPopOffsets;
19};
20
21template <> void PushCullScanner::operator()(const SkRecords::PushCull& record) {
22 *fPopOffsets.append() = record.popOffset;
23}
24
25
26DEF_TEST(RecordCulling, r) {
27 SkRecord record;
commit-bot@chromium.orgd9ce2be2014-04-09 23:30:28 +000028 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, 1920, 1080);
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000029
30 recorder.drawRect(SkRect::MakeWH(1000, 10000), SkPaint());
31
32 recorder.pushCull(SkRect::MakeWH(100, 100));
33 recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint());
34 recorder.drawRect(SkRect::MakeWH(30, 30), SkPaint());
35 recorder.pushCull(SkRect::MakeWH(5, 5));
36 recorder.drawRect(SkRect::MakeWH(1, 1), SkPaint());
37 recorder.popCull();
38 recorder.popCull();
39
40 SkRecordAnnotateCullingPairs(&record);
41
42 PushCullScanner scan;
43 record.visit(scan);
44
45 REPORTER_ASSERT(r, 2 == scan.fPopOffsets.count());
46 REPORTER_ASSERT(r, 6 == scan.fPopOffsets[0]);
47 REPORTER_ASSERT(r, 2 == scan.fPopOffsets[1]);
48}