blob: 6468e72c9d5c6d2f3e1e5e686f2932c45e95cca3 [file] [log] [blame]
commit-bot@chromium.orgd9ce2be2014-04-09 23:30:28 +00001#include "Test.h"
2
3#include "SkDebugCanvas.h"
4#include "SkRecord.h"
5#include "SkRecordCulling.h"
6#include "SkRecordDraw.h"
7#include "SkRecorder.h"
8#include "SkRecords.h"
9
10static const int W = 1920, H = 1080;
11
12DEF_TEST(RecordDraw_Culling, r) {
13 // Record these 7 drawing commands verbatim.
14 SkRecord record;
15 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H);
16
17 recorder.pushCull(SkRect::MakeWH(100, 100));
18 recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint());
19 recorder.drawRect(SkRect::MakeWH(30, 30), SkPaint());
20 recorder.pushCull(SkRect::MakeWH(5, 5));
21 recorder.drawRect(SkRect::MakeWH(1, 1), SkPaint());
22 recorder.popCull();
23 recorder.popCull();
24
25 // Take a pass over to match up pushCulls and popCulls.
26 SkRecordAnnotateCullingPairs(&record);
27
28 // Rerecord into another SkRecord using full SkCanvas semantics,
29 // tracking clips and allowing SkRecordDraw's quickReject() calls to work.
30 SkRecord rerecord;
31 SkRecorder rerecorder(SkRecorder::kReadWrite_Mode, &rerecord, W, H);
32 // This clip intersects the outer cull, but allows us to quick reject the inner one.
33 rerecorder.clipRect(SkRect::MakeLTRB(20, 20, 200, 200));
34
35 SkRecordDraw(record, &rerecorder);
36
37 // We'll keep the clipRect call from above, and the outer two drawRects, and the push/pop pair.
38 // If culling weren't working, we'd see 8 commands recorded here.
39 REPORTER_ASSERT(r, 5 == rerecord.count());
40}
41
42DEF_TEST(RecordDraw_Clipping, r) {
43 SkRecord record;
44 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H);
45
46 // 8 draw commands.
47 // The inner clipRect makes the clip empty, so the inner drawRect does nothing.
48 recorder.save();
49 recorder.clipRect(SkRect::MakeLTRB(0, 0, 100, 100));
50 recorder.drawRect(SkRect::MakeLTRB(20, 20, 40, 40), SkPaint());
51 recorder.save();
52 recorder.clipRect(SkRect::MakeLTRB(200, 200, 300, 300));
53 recorder.drawRect(SkRect::MakeLTRB(220, 220, 240, 240), SkPaint());
54 recorder.restore();
55 recorder.restore();
56
57 // Same deal as above: we need full SkCanvas semantics for clip skipping to work.
58 SkRecord rerecord;
59 SkRecorder rerecorder(SkRecorder::kReadWrite_Mode, &rerecord, W, H);
60 SkRecordDraw(record, &rerecorder);
61
62 // All commands except the drawRect will be preserved.
63 REPORTER_ASSERT(r, 7 == rerecord.count());
64}