RecordDrawTest.cpp revision 705b1ff617ffe672e65d53bcaf3b690e8bb6b025
1/*
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
8#include "Test.h"
9
10#include "SkDebugCanvas.h"
11#include "SkRecord.h"
12#include "SkRecordOpts.h"
13#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}
48