| commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 1 | #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 |  | 
|  | 10 | static const int W = 1920, H = 1080; | 
|  | 11 |  | 
|  | 12 | DEF_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 |  | 
|  | 42 | DEF_TEST(RecordDraw_Clipping, r) { | 
|  | 43 | SkRecord record; | 
|  | 44 | SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H); | 
|  | 45 |  | 
| commit-bot@chromium.org | ff2de7c | 2014-04-10 02:26:33 +0000 | [diff] [blame] | 46 | // 9 draw commands. | 
| commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 47 | recorder.save(); | 
|  | 48 | recorder.clipRect(SkRect::MakeLTRB(0, 0, 100, 100)); | 
|  | 49 | recorder.drawRect(SkRect::MakeLTRB(20, 20, 40, 40), SkPaint()); | 
|  | 50 | recorder.save(); | 
| commit-bot@chromium.org | ff2de7c | 2014-04-10 02:26:33 +0000 | [diff] [blame] | 51 | // This first clipRect makes the clip empty, so the next two commands do nothing. | 
| commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 52 | recorder.clipRect(SkRect::MakeLTRB(200, 200, 300, 300)); | 
| commit-bot@chromium.org | ff2de7c | 2014-04-10 02:26:33 +0000 | [diff] [blame] | 53 | recorder.clipRect(SkRect::MakeLTRB(210, 210, 250, 250));              // Skipped | 
|  | 54 | recorder.drawRect(SkRect::MakeLTRB(220, 220, 240, 240), SkPaint());   // Skipped | 
| commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 55 | recorder.restore(); | 
|  | 56 | recorder.restore(); | 
|  | 57 |  | 
|  | 58 | // Same deal as above: we need full SkCanvas semantics for clip skipping to work. | 
|  | 59 | SkRecord rerecord; | 
|  | 60 | SkRecorder rerecorder(SkRecorder::kReadWrite_Mode, &rerecord, W, H); | 
|  | 61 | SkRecordDraw(record, &rerecorder); | 
|  | 62 |  | 
| commit-bot@chromium.org | ff2de7c | 2014-04-10 02:26:33 +0000 | [diff] [blame] | 63 | // All commands except the two marked // Skipped above will be preserved. | 
| commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 64 | REPORTER_ASSERT(r, 7 == rerecord.count()); | 
|  | 65 | } |