blob: 8c6635489e16f61e1ac3bbc40266bc43cfd380ab [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}
48
49DEF_TEST(RecordDraw_Clipping, r) {
50 SkRecord record;
51 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H);
52
commit-bot@chromium.org2e0c32a2014-04-28 16:19:45 +000053 // 8 draw commands.
commit-bot@chromium.orgd9ce2be2014-04-09 23:30:28 +000054 recorder.save();
55 recorder.clipRect(SkRect::MakeLTRB(0, 0, 100, 100));
56 recorder.drawRect(SkRect::MakeLTRB(20, 20, 40, 40), SkPaint());
57 recorder.save();
commit-bot@chromium.org2e0c32a2014-04-28 16:19:45 +000058 // This clipRect makes the clip empty, so the next command does nothing.
commit-bot@chromium.orgd9ce2be2014-04-09 23:30:28 +000059 recorder.clipRect(SkRect::MakeLTRB(200, 200, 300, 300));
commit-bot@chromium.orgff2de7c2014-04-10 02:26:33 +000060 recorder.drawRect(SkRect::MakeLTRB(220, 220, 240, 240), SkPaint()); // Skipped
commit-bot@chromium.orgd9ce2be2014-04-09 23:30:28 +000061 recorder.restore();
62 recorder.restore();
63
64 // Same deal as above: we need full SkCanvas semantics for clip skipping to work.
65 SkRecord rerecord;
66 SkRecorder rerecorder(SkRecorder::kReadWrite_Mode, &rerecord, W, H);
67 SkRecordDraw(record, &rerecorder);
68
commit-bot@chromium.org2e0c32a2014-04-28 16:19:45 +000069 // All commands except the one marked // Skipped will be preserved.
commit-bot@chromium.orgd9ce2be2014-04-09 23:30:28 +000070 REPORTER_ASSERT(r, 7 == rerecord.count());
71}