blob: c4dab84273bcecb926a2fdbed04c12afdc727d50 [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.orgd9ce2be2014-04-09 23:30:28 +00008#include "Test.h"
9
10#include "SkDebugCanvas.h"
11#include "SkRecord.h"
commit-bot@chromium.orgad8ce572014-04-21 15:03:36 +000012#include "SkRecordOpts.h"
commit-bot@chromium.orgd9ce2be2014-04-09 23:30:28 +000013#include "SkRecordDraw.h"
14#include "SkRecorder.h"
15#include "SkRecords.h"
16
17static const int W = 1920, H = 1080;
18
19DEF_TEST(RecordDraw_Culling, r) {
20 // Record these 7 drawing commands verbatim.
21 SkRecord record;
22 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H);
23
24 recorder.pushCull(SkRect::MakeWH(100, 100));
25 recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint());
26 recorder.drawRect(SkRect::MakeWH(30, 30), SkPaint());
27 recorder.pushCull(SkRect::MakeWH(5, 5));
28 recorder.drawRect(SkRect::MakeWH(1, 1), SkPaint());
29 recorder.popCull();
30 recorder.popCull();
31
32 // Take a pass over to match up pushCulls and popCulls.
33 SkRecordAnnotateCullingPairs(&record);
34
35 // Rerecord into another SkRecord using full SkCanvas semantics,
36 // tracking clips and allowing SkRecordDraw's quickReject() calls to work.
37 SkRecord rerecord;
38 SkRecorder rerecorder(SkRecorder::kReadWrite_Mode, &rerecord, W, H);
39 // This clip intersects the outer cull, but allows us to quick reject the inner one.
40 rerecorder.clipRect(SkRect::MakeLTRB(20, 20, 200, 200));
41
42 SkRecordDraw(record, &rerecorder);
43
44 // We'll keep the clipRect call from above, and the outer two drawRects, and the push/pop pair.
45 // If culling weren't working, we'd see 8 commands recorded here.
46 REPORTER_ASSERT(r, 5 == rerecord.count());
47}