commit-bot@chromium.org | 73fffeb | 2014-05-05 21:59:52 +0000 | [diff] [blame] | 1 | #include "Test.h" |
| 2 | |
| 3 | #include "SkRecord.h" |
| 4 | #include "SkRecordPattern.h" |
| 5 | #include "SkRecorder.h" |
| 6 | #include "SkRecords.h" |
| 7 | |
| 8 | using namespace SkRecords; |
| 9 | typedef Pattern3<Is<Save>, |
| 10 | Is<ClipRect>, |
| 11 | Is<Restore> > |
| 12 | SaveClipRectRestore; |
| 13 | |
| 14 | DEF_TEST(RecordPattern_Simple, r) { |
| 15 | SaveClipRectRestore pattern; |
| 16 | |
| 17 | SkRecord record; |
| 18 | REPORTER_ASSERT(r, !pattern.match(&record, 0)); |
| 19 | |
commit-bot@chromium.org | a095041 | 2014-05-29 16:52:40 +0000 | [diff] [blame] | 20 | SkRecorder recorder(&record, 1920, 1200); |
commit-bot@chromium.org | 73fffeb | 2014-05-05 21:59:52 +0000 | [diff] [blame] | 21 | |
| 22 | // Build up a save-clip-restore block. The pattern will match only it's complete. |
| 23 | recorder.save(); |
| 24 | REPORTER_ASSERT(r, !pattern.match(&record, 0)); |
| 25 | |
| 26 | recorder.clipRect(SkRect::MakeWH(300, 200)); |
| 27 | REPORTER_ASSERT(r, !pattern.match(&record, 0)); |
| 28 | |
| 29 | recorder.restore(); |
| 30 | REPORTER_ASSERT(r, pattern.match(&record, 0)); |
| 31 | REPORTER_ASSERT(r, pattern.first<Save>() != NULL); |
| 32 | REPORTER_ASSERT(r, pattern.second<ClipRect>() != NULL); |
| 33 | REPORTER_ASSERT(r, pattern.third<Restore>() != NULL); |
| 34 | } |
| 35 | |
| 36 | DEF_TEST(RecordPattern_StartingIndex, r) { |
| 37 | SaveClipRectRestore pattern; |
| 38 | |
| 39 | SkRecord record; |
commit-bot@chromium.org | a095041 | 2014-05-29 16:52:40 +0000 | [diff] [blame] | 40 | SkRecorder recorder(&record, 1920, 1200); |
commit-bot@chromium.org | 73fffeb | 2014-05-05 21:59:52 +0000 | [diff] [blame] | 41 | |
| 42 | // There will be two save-clipRect-restore blocks [0,3) and [3,6). |
| 43 | for (int i = 0; i < 2; i++) { |
| 44 | recorder.save(); |
| 45 | recorder.clipRect(SkRect::MakeWH(300, 200)); |
| 46 | recorder.restore(); |
| 47 | } |
| 48 | |
| 49 | // We should match only at 0 and 3. Going over the length should fail gracefully. |
| 50 | for (unsigned i = 0; i < 8; i++) { |
| 51 | if (i == 0 || i == 3) { |
| 52 | REPORTER_ASSERT(r, pattern.match(&record, i) == i + 3); |
| 53 | } else { |
| 54 | REPORTER_ASSERT(r, !pattern.match(&record, i)); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | DEF_TEST(RecordPattern_DontMatchSubsequences, r) { |
| 60 | SaveClipRectRestore pattern; |
| 61 | |
| 62 | SkRecord record; |
commit-bot@chromium.org | a095041 | 2014-05-29 16:52:40 +0000 | [diff] [blame] | 63 | SkRecorder recorder(&record, 1920, 1200); |
commit-bot@chromium.org | 73fffeb | 2014-05-05 21:59:52 +0000 | [diff] [blame] | 64 | |
| 65 | recorder.save(); |
| 66 | recorder.clipRect(SkRect::MakeWH(300, 200)); |
| 67 | recorder.drawRect(SkRect::MakeWH(600, 300), SkPaint()); |
| 68 | recorder.restore(); |
| 69 | |
| 70 | REPORTER_ASSERT(r, !pattern.match(&record, 0)); |
| 71 | } |
| 72 | |
| 73 | DEF_TEST(RecordPattern_Star, r) { |
| 74 | Pattern3<Is<Save>, Star<Is<ClipRect> >, Is<Restore> > pattern; |
| 75 | |
| 76 | SkRecord record; |
commit-bot@chromium.org | a095041 | 2014-05-29 16:52:40 +0000 | [diff] [blame] | 77 | SkRecorder recorder(&record, 1920, 1200); |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 78 | int index = 0; |
commit-bot@chromium.org | 73fffeb | 2014-05-05 21:59:52 +0000 | [diff] [blame] | 79 | |
| 80 | recorder.save(); |
| 81 | recorder.clipRect(SkRect::MakeWH(300, 200)); |
| 82 | recorder.restore(); |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 83 | REPORTER_ASSERT(r, pattern.match(&record, index)); |
| 84 | index += 3; |
commit-bot@chromium.org | 73fffeb | 2014-05-05 21:59:52 +0000 | [diff] [blame] | 85 | |
| 86 | recorder.save(); |
| 87 | recorder.clipRect(SkRect::MakeWH(300, 200)); |
| 88 | recorder.clipRect(SkRect::MakeWH(100, 100)); |
| 89 | recorder.restore(); |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 90 | REPORTER_ASSERT(r, pattern.match(&record, index)); |
commit-bot@chromium.org | 73fffeb | 2014-05-05 21:59:52 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | DEF_TEST(RecordPattern_Complex, r) { |
| 94 | Pattern3<Is<Save>, |
| 95 | Star<Not<Or3<Is<Save>, |
| 96 | Is<Restore>, |
| 97 | IsDraw> > >, |
| 98 | Is<Restore> > pattern; |
| 99 | |
| 100 | SkRecord record; |
commit-bot@chromium.org | a095041 | 2014-05-29 16:52:40 +0000 | [diff] [blame] | 101 | SkRecorder recorder(&record, 1920, 1200); |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 102 | unsigned start, begin, end; |
commit-bot@chromium.org | 73fffeb | 2014-05-05 21:59:52 +0000 | [diff] [blame] | 103 | |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 104 | start = record.count(); |
commit-bot@chromium.org | 73fffeb | 2014-05-05 21:59:52 +0000 | [diff] [blame] | 105 | recorder.save(); |
| 106 | recorder.clipRect(SkRect::MakeWH(300, 200)); |
| 107 | recorder.restore(); |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 108 | REPORTER_ASSERT(r, pattern.match(&record, 0) == record.count()); |
| 109 | end = start; |
| 110 | REPORTER_ASSERT(r, pattern.search(&record, &begin, &end)); |
| 111 | REPORTER_ASSERT(r, begin == start); |
| 112 | REPORTER_ASSERT(r, end == record.count()); |
commit-bot@chromium.org | 73fffeb | 2014-05-05 21:59:52 +0000 | [diff] [blame] | 113 | |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 114 | start = record.count(); |
commit-bot@chromium.org | 73fffeb | 2014-05-05 21:59:52 +0000 | [diff] [blame] | 115 | recorder.save(); |
| 116 | recorder.clipRect(SkRect::MakeWH(300, 200)); |
| 117 | recorder.drawRect(SkRect::MakeWH(100, 3000), SkPaint()); |
| 118 | recorder.restore(); |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 119 | REPORTER_ASSERT(r, !pattern.match(&record, start)); |
| 120 | end = start; |
| 121 | REPORTER_ASSERT(r, !pattern.search(&record, &begin, &end)); |
commit-bot@chromium.org | 73fffeb | 2014-05-05 21:59:52 +0000 | [diff] [blame] | 122 | |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 123 | start = record.count(); |
commit-bot@chromium.org | 73fffeb | 2014-05-05 21:59:52 +0000 | [diff] [blame] | 124 | recorder.save(); |
commit-bot@chromium.org | 73fffeb | 2014-05-05 21:59:52 +0000 | [diff] [blame] | 125 | recorder.clipRect(SkRect::MakeWH(300, 200)); |
| 126 | recorder.clipRect(SkRect::MakeWH(100, 400)); |
commit-bot@chromium.org | 73fffeb | 2014-05-05 21:59:52 +0000 | [diff] [blame] | 127 | recorder.restore(); |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 128 | REPORTER_ASSERT(r, pattern.match(&record, start) == record.count()); |
| 129 | end = start; |
commit-bot@chromium.org | 73fffeb | 2014-05-05 21:59:52 +0000 | [diff] [blame] | 130 | REPORTER_ASSERT(r, pattern.search(&record, &begin, &end)); |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 131 | REPORTER_ASSERT(r, begin == start); |
| 132 | REPORTER_ASSERT(r, end == record.count()); |
commit-bot@chromium.org | 73fffeb | 2014-05-05 21:59:52 +0000 | [diff] [blame] | 133 | |
| 134 | REPORTER_ASSERT(r, !pattern.search(&record, &begin, &end)); |
| 135 | } |
commit-bot@chromium.org | 1b54646 | 2014-05-06 21:32:19 +0000 | [diff] [blame] | 136 | |
| 137 | DEF_TEST(RecordPattern_SaveLayerIsNotADraw, r) { |
| 138 | Pattern1<IsDraw> pattern; |
| 139 | |
| 140 | SkRecord record; |
commit-bot@chromium.org | a095041 | 2014-05-29 16:52:40 +0000 | [diff] [blame] | 141 | SkRecorder recorder(&record, 1920, 1200); |
commit-bot@chromium.org | 1b54646 | 2014-05-06 21:32:19 +0000 | [diff] [blame] | 142 | recorder.saveLayer(NULL, NULL); |
| 143 | |
| 144 | REPORTER_ASSERT(r, !pattern.match(&record, 0)); |
| 145 | } |