commit-bot@chromium.org | c4b21e6 | 2014-04-11 18:33:31 +0000 | [diff] [blame] | 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 | |
commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 8 | #include "Test.h" |
commit-bot@chromium.org | 0a98d87 | 2014-05-19 15:15:24 +0000 | [diff] [blame] | 9 | #include "RecordTestUtils.h" |
commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 10 | |
| 11 | #include "SkDebugCanvas.h" |
Mike Klein | c11530e | 2014-06-24 11:29:06 -0400 | [diff] [blame] | 12 | #include "SkDrawPictureCallback.h" |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 13 | #include "SkDropShadowImageFilter.h" |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 14 | #include "SkImagePriv.h" |
commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 15 | #include "SkRecord.h" |
commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 16 | #include "SkRecordDraw.h" |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 17 | #include "SkRecordOpts.h" |
commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 18 | #include "SkRecorder.h" |
| 19 | #include "SkRecords.h" |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 20 | #include "SkSurface.h" |
commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 21 | |
| 22 | static const int W = 1920, H = 1080; |
| 23 | |
Mike Klein | c11530e | 2014-06-24 11:29:06 -0400 | [diff] [blame] | 24 | class JustOneDraw : public SkDrawPictureCallback { |
| 25 | public: |
| 26 | JustOneDraw() : fCalls(0) {} |
| 27 | |
| 28 | virtual bool abortDrawing() SK_OVERRIDE { return fCalls++ > 0; } |
| 29 | private: |
| 30 | int fCalls; |
| 31 | }; |
| 32 | |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 33 | DEF_TEST(RecordDraw_LazySaves, r) { |
| 34 | // Record two commands. |
| 35 | SkRecord record; |
| 36 | SkRecorder recorder(&record, W, H); |
| 37 | |
| 38 | REPORTER_ASSERT(r, 0 == record.count()); |
| 39 | recorder.save(); |
| 40 | REPORTER_ASSERT(r, 0 == record.count()); // the save was not recorded (yet) |
| 41 | recorder.drawColor(SK_ColorRED); |
| 42 | REPORTER_ASSERT(r, 1 == record.count()); |
| 43 | recorder.scale(2, 2); |
| 44 | REPORTER_ASSERT(r, 3 == record.count()); // now we see the save |
| 45 | recorder.restore(); |
| 46 | REPORTER_ASSERT(r, 4 == record.count()); |
| 47 | |
| 48 | assert_type<SkRecords::DrawPaint>(r, record, 0); |
| 49 | assert_type<SkRecords::Save> (r, record, 1); |
| 50 | assert_type<SkRecords::SetMatrix>(r, record, 2); |
| 51 | assert_type<SkRecords::Restore> (r, record, 3); |
| 52 | |
| 53 | recorder.save(); |
| 54 | recorder.save(); |
| 55 | recorder.restore(); |
| 56 | recorder.restore(); |
| 57 | REPORTER_ASSERT(r, 4 == record.count()); |
| 58 | } |
| 59 | |
Mike Klein | c11530e | 2014-06-24 11:29:06 -0400 | [diff] [blame] | 60 | DEF_TEST(RecordDraw_Abort, r) { |
| 61 | // Record two commands. |
| 62 | SkRecord record; |
| 63 | SkRecorder recorder(&record, W, H); |
| 64 | recorder.drawRect(SkRect::MakeWH(200, 300), SkPaint()); |
| 65 | recorder.clipRect(SkRect::MakeWH(100, 200)); |
| 66 | |
| 67 | SkRecord rerecord; |
| 68 | SkRecorder canvas(&rerecord, W, H); |
| 69 | |
| 70 | JustOneDraw callback; |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 71 | SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL/*bbh*/, &callback); |
Mike Klein | c11530e | 2014-06-24 11:29:06 -0400 | [diff] [blame] | 72 | |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 73 | REPORTER_ASSERT(r, 1 == count_instances_of_type<SkRecords::DrawRect>(rerecord)); |
| 74 | REPORTER_ASSERT(r, 0 == count_instances_of_type<SkRecords::ClipRect>(rerecord)); |
Mike Klein | c11530e | 2014-06-24 11:29:06 -0400 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | DEF_TEST(RecordDraw_Unbalanced, r) { |
| 78 | SkRecord record; |
| 79 | SkRecorder recorder(&record, W, H); |
| 80 | recorder.save(); // We won't balance this, but SkRecordDraw will for us. |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 81 | recorder.scale(2, 2); |
Mike Klein | c11530e | 2014-06-24 11:29:06 -0400 | [diff] [blame] | 82 | |
| 83 | SkRecord rerecord; |
| 84 | SkRecorder canvas(&rerecord, W, H); |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 85 | SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL/*bbh*/, NULL/*callback*/); |
Mike Klein | c11530e | 2014-06-24 11:29:06 -0400 | [diff] [blame] | 86 | |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 87 | int save_count = count_instances_of_type<SkRecords::Save>(rerecord); |
| 88 | int restore_count = count_instances_of_type<SkRecords::Save>(rerecord); |
| 89 | REPORTER_ASSERT(r, save_count == restore_count); |
Mike Klein | c11530e | 2014-06-24 11:29:06 -0400 | [diff] [blame] | 90 | } |
| 91 | |
commit-bot@chromium.org | 0a98d87 | 2014-05-19 15:15:24 +0000 | [diff] [blame] | 92 | DEF_TEST(RecordDraw_SetMatrixClobber, r) { |
| 93 | // Set up an SkRecord that just scales by 2x,3x. |
| 94 | SkRecord scaleRecord; |
commit-bot@chromium.org | a095041 | 2014-05-29 16:52:40 +0000 | [diff] [blame] | 95 | SkRecorder scaleCanvas(&scaleRecord, W, H); |
commit-bot@chromium.org | 0a98d87 | 2014-05-19 15:15:24 +0000 | [diff] [blame] | 96 | SkMatrix scale; |
| 97 | scale.setScale(2, 3); |
| 98 | scaleCanvas.setMatrix(scale); |
| 99 | |
| 100 | // Set up an SkRecord with an initial +20, +20 translate. |
| 101 | SkRecord translateRecord; |
commit-bot@chromium.org | a095041 | 2014-05-29 16:52:40 +0000 | [diff] [blame] | 102 | SkRecorder translateCanvas(&translateRecord, W, H); |
commit-bot@chromium.org | 0a98d87 | 2014-05-19 15:15:24 +0000 | [diff] [blame] | 103 | SkMatrix translate; |
| 104 | translate.setTranslate(20, 20); |
| 105 | translateCanvas.setMatrix(translate); |
| 106 | |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 107 | SkRecordDraw(scaleRecord, &translateCanvas, NULL, NULL, 0, NULL/*bbh*/, NULL/*callback*/); |
Mike Klein | c11530e | 2014-06-24 11:29:06 -0400 | [diff] [blame] | 108 | REPORTER_ASSERT(r, 4 == translateRecord.count()); |
| 109 | assert_type<SkRecords::SetMatrix>(r, translateRecord, 0); |
| 110 | assert_type<SkRecords::Save> (r, translateRecord, 1); |
| 111 | assert_type<SkRecords::SetMatrix>(r, translateRecord, 2); |
| 112 | assert_type<SkRecords::Restore> (r, translateRecord, 3); |
commit-bot@chromium.org | 0a98d87 | 2014-05-19 15:15:24 +0000 | [diff] [blame] | 113 | |
| 114 | // When we look at translateRecord now, it should have its first +20,+20 translate, |
| 115 | // then a 2x,3x scale that's been concatted with that +20,+20 translate. |
| 116 | const SkRecords::SetMatrix* setMatrix; |
| 117 | setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 0); |
| 118 | REPORTER_ASSERT(r, setMatrix->matrix == translate); |
| 119 | |
Mike Klein | c11530e | 2014-06-24 11:29:06 -0400 | [diff] [blame] | 120 | setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 2); |
commit-bot@chromium.org | 0a98d87 | 2014-05-19 15:15:24 +0000 | [diff] [blame] | 121 | SkMatrix expected = scale; |
| 122 | expected.postConcat(translate); |
| 123 | REPORTER_ASSERT(r, setMatrix->matrix == expected); |
| 124 | } |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 125 | |
| 126 | struct TestBBH : public SkBBoxHierarchy { |
mtklein | 4477c3c | 2014-10-27 10:27:10 -0700 | [diff] [blame] | 127 | virtual void insert(SkAutoTMalloc<SkRect>* boundsArray, int N) SK_OVERRIDE { |
| 128 | fEntries.setCount(N); |
| 129 | for (int i = 0; i < N; i++) { |
| 130 | Entry e = { (unsigned)i, (*boundsArray)[i] }; |
| 131 | fEntries[i] = e; |
| 132 | } |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 133 | } |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 134 | |
mtklein | 6bd4196 | 2014-10-02 07:41:56 -0700 | [diff] [blame] | 135 | virtual void search(const SkRect& query, SkTDArray<unsigned>* results) const SK_OVERRIDE {} |
tomhudson | 158fcaa | 2014-11-19 10:41:14 -0800 | [diff] [blame] | 136 | virtual size_t bytesUsed() const SK_OVERRIDE { return 0; } |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 137 | |
| 138 | struct Entry { |
mtklein | 6bd4196 | 2014-10-02 07:41:56 -0700 | [diff] [blame] | 139 | unsigned opIndex; |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 140 | SkRect bounds; |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 141 | }; |
mtklein | 6bd4196 | 2014-10-02 07:41:56 -0700 | [diff] [blame] | 142 | SkTDArray<Entry> fEntries; |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 143 | }; |
| 144 | |
mtklein | 937c9c7 | 2014-09-02 15:19:48 -0700 | [diff] [blame] | 145 | // Like a==b, with a little slop recognizing that float equality can be weird. |
| 146 | static bool sloppy_rect_eq(SkRect a, SkRect b) { |
| 147 | SkRect inset(a), outset(a); |
| 148 | inset.inset(1, 1); |
| 149 | outset.outset(1, 1); |
| 150 | return outset.contains(b) && !inset.contains(b); |
| 151 | } |
| 152 | |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 153 | // This test is not meant to make total sense yet. It's testing the status quo |
| 154 | // of SkRecordFillBounds(), which itself doesn't make total sense yet. |
| 155 | DEF_TEST(RecordDraw_BBH, r) { |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 156 | SkRecord record; |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 157 | SkRecorder recorder(&record, W, H); |
| 158 | recorder.save(); |
| 159 | recorder.clipRect(SkRect::MakeWH(400, 500)); |
| 160 | recorder.scale(2, 2); |
| 161 | recorder.drawRect(SkRect::MakeWH(320, 240), SkPaint()); |
| 162 | recorder.restore(); |
| 163 | |
mtklein | 937c9c7 | 2014-09-02 15:19:48 -0700 | [diff] [blame] | 164 | TestBBH bbh; |
robertphillips | 4d52afe | 2014-11-03 08:19:44 -0800 | [diff] [blame] | 165 | SkRecordFillBounds(SkRect::MakeWH(SkIntToScalar(W), SkIntToScalar(H)), record, &bbh); |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 166 | |
mtklein | 6bd4196 | 2014-10-02 07:41:56 -0700 | [diff] [blame] | 167 | REPORTER_ASSERT(r, bbh.fEntries.count() == 5); |
| 168 | for (int i = 0; i < bbh.fEntries.count(); i++) { |
| 169 | REPORTER_ASSERT(r, bbh.fEntries[i].opIndex == (unsigned)i); |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 170 | |
mtklein | 6bd4196 | 2014-10-02 07:41:56 -0700 | [diff] [blame] | 171 | REPORTER_ASSERT(r, sloppy_rect_eq(SkRect::MakeWH(400, 480), bbh.fEntries[i].bounds)); |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 172 | } |
| 173 | } |
mtklein | 00f30bd | 2014-09-02 12:03:31 -0700 | [diff] [blame] | 174 | |
mtklein | 937c9c7 | 2014-09-02 15:19:48 -0700 | [diff] [blame] | 175 | // A regression test for crbug.com/409110. |
| 176 | DEF_TEST(RecordDraw_TextBounds, r) { |
| 177 | SkRecord record; |
| 178 | SkRecorder recorder(&record, W, H); |
| 179 | |
| 180 | // Two Chinese characters in UTF-8. |
| 181 | const char text[] = { '\xe6', '\xbc', '\xa2', '\xe5', '\xad', '\x97' }; |
| 182 | const size_t bytes = SK_ARRAY_COUNT(text); |
| 183 | |
| 184 | const SkScalar xpos[] = { 10, 20 }; |
| 185 | recorder.drawPosTextH(text, bytes, xpos, 30, SkPaint()); |
| 186 | |
| 187 | const SkPoint pos[] = { {40, 50}, {60, 70} }; |
| 188 | recorder.drawPosText(text, bytes, pos, SkPaint()); |
| 189 | |
| 190 | TestBBH bbh; |
robertphillips | 4d52afe | 2014-11-03 08:19:44 -0800 | [diff] [blame] | 191 | SkRecordFillBounds(SkRect::MakeWH(SkIntToScalar(W), SkIntToScalar(H)), record, &bbh); |
mtklein | 6bd4196 | 2014-10-02 07:41:56 -0700 | [diff] [blame] | 192 | REPORTER_ASSERT(r, bbh.fEntries.count() == 2); |
mtklein | 937c9c7 | 2014-09-02 15:19:48 -0700 | [diff] [blame] | 193 | |
mtklein | 9a5380d | 2014-12-16 06:31:01 -0800 | [diff] [blame] | 194 | // We can make these next assertions confidently because SkRecordFillBounds |
| 195 | // builds its bounds by overestimating font metrics in a platform-independent way. |
| 196 | // If that changes, these tests will need to be more flexible. |
| 197 | REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[0].bounds, SkRect::MakeLTRB(0, 0, 140, 60))); |
| 198 | REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLTRB(0, 20, 180, 100))); |
mtklein | 937c9c7 | 2014-09-02 15:19:48 -0700 | [diff] [blame] | 199 | } |
| 200 | |
mtklein | 00f30bd | 2014-09-02 12:03:31 -0700 | [diff] [blame] | 201 | // Base test to ensure start/stop range is respected |
| 202 | DEF_TEST(RecordDraw_PartialStartStop, r) { |
| 203 | static const int kWidth = 10, kHeight = 10; |
| 204 | |
| 205 | SkRect r1 = { 0, 0, kWidth, kHeight }; |
| 206 | SkRect r2 = { 0, 0, kWidth, kHeight/2 }; |
| 207 | SkRect r3 = { 0, 0, kWidth/2, kHeight }; |
| 208 | SkPaint p; |
| 209 | |
| 210 | SkRecord record; |
| 211 | SkRecorder recorder(&record, kWidth, kHeight); |
| 212 | recorder.drawRect(r1, p); |
| 213 | recorder.drawRect(r2, p); |
| 214 | recorder.drawRect(r3, p); |
| 215 | |
| 216 | SkRecord rerecord; |
| 217 | SkRecorder canvas(&rerecord, kWidth, kHeight); |
reed | 8eddfb5 | 2014-12-04 07:50:14 -0800 | [diff] [blame] | 218 | SkRecordPartialDraw(record, &canvas, NULL, 0, 1, 2, SkMatrix::I()); // replay just drawRect of r2 |
mtklein | 00f30bd | 2014-09-02 12:03:31 -0700 | [diff] [blame] | 219 | |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 220 | REPORTER_ASSERT(r, 1 == count_instances_of_type<SkRecords::DrawRect>(rerecord)); |
| 221 | int index = find_first_instances_of_type<SkRecords::DrawRect>(rerecord); |
| 222 | const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, rerecord, index); |
mtklein | 00f30bd | 2014-09-02 12:03:31 -0700 | [diff] [blame] | 223 | REPORTER_ASSERT(r, drawRect->rect == r2); |
| 224 | } |
| 225 | |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 226 | // A regression test for crbug.com/415468 and skbug.com/2957. |
mtklein | 8e393bf | 2014-10-01 12:48:58 -0700 | [diff] [blame] | 227 | // |
| 228 | // This also now serves as a regression test for crbug.com/418417. We used to adjust the |
| 229 | // bounds for the saveLayer, clip, and restore to be greater than the bounds of the picture. |
| 230 | // (We were applying the saveLayer paint to the bounds after restore, which makes no sense.) |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 231 | DEF_TEST(RecordDraw_SaveLayerAffectsClipBounds, r) { |
| 232 | SkRecord record; |
| 233 | SkRecorder recorder(&record, 50, 50); |
| 234 | |
| 235 | // We draw a rectangle with a long drop shadow. We used to not update the clip |
| 236 | // bounds based on SaveLayer paints, so the drop shadow could be cut off. |
| 237 | SkPaint paint; |
sugoi | 234f036 | 2014-10-23 13:59:52 -0700 | [diff] [blame] | 238 | paint.setImageFilter(SkDropShadowImageFilter::Create(20, 0, 0, 0, SK_ColorBLACK, |
| 239 | SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode))->unref(); |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 240 | |
| 241 | recorder.saveLayer(NULL, &paint); |
| 242 | recorder.clipRect(SkRect::MakeWH(20, 40)); |
| 243 | recorder.drawRect(SkRect::MakeWH(20, 40), SkPaint()); |
| 244 | recorder.restore(); |
| 245 | |
mtklein | 8e393bf | 2014-10-01 12:48:58 -0700 | [diff] [blame] | 246 | // Under the original bug, the right edge value of the drawRect would be 20 less than asserted |
| 247 | // here because we intersected it with a clip that had not been adjusted for the drop shadow. |
| 248 | // |
| 249 | // The second bug showed up as adjusting the picture bounds (0,0,50,50) by the drop shadow too. |
| 250 | // The saveLayer, clipRect, and restore bounds were incorrectly (0,0,70,50). |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 251 | TestBBH bbh; |
robertphillips | 4d52afe | 2014-11-03 08:19:44 -0800 | [diff] [blame] | 252 | SkRecordFillBounds(SkRect::MakeWH(50, 50), record, &bbh); |
mtklein | 6bd4196 | 2014-10-02 07:41:56 -0700 | [diff] [blame] | 253 | REPORTER_ASSERT(r, bbh.fEntries.count() == 4); |
| 254 | REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[0].bounds, SkRect::MakeLTRB(0, 0, 50, 50))); |
| 255 | REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLTRB(0, 0, 50, 50))); |
| 256 | REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[2].bounds, SkRect::MakeLTRB(0, 0, 40, 40))); |
| 257 | REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[3].bounds, SkRect::MakeLTRB(0, 0, 50, 50))); |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 258 | } |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 259 | |
robertphillips | 4d52afe | 2014-11-03 08:19:44 -0800 | [diff] [blame] | 260 | // When a saveLayer provides an explicit bound and has a complex paint (e.g., one that |
| 261 | // affects transparent black), that bound should serve to shrink the area of the required |
| 262 | // backing store. |
| 263 | DEF_TEST(RecordDraw_SaveLayerBoundsAffectsClipBounds, r) { |
| 264 | SkRecord record; |
| 265 | SkRecorder recorder(&record, 50, 50); |
| 266 | |
| 267 | SkPaint p; |
| 268 | p.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 269 | |
| 270 | SkRect bounds = SkRect::MakeLTRB(10, 10, 40, 40); |
| 271 | recorder.saveLayer(&bounds, &p); |
| 272 | recorder.drawRect(SkRect::MakeLTRB(20, 20, 30, 30), SkPaint()); |
| 273 | recorder.restore(); |
| 274 | |
| 275 | TestBBH bbh; |
| 276 | SkRecordFillBounds(SkRect::MakeWH(50, 50), record, &bbh); |
| 277 | REPORTER_ASSERT(r, bbh.fEntries.count() == 3); |
reed | d990e2f | 2014-12-22 11:58:30 -0800 | [diff] [blame] | 278 | if (!SkCanvas::Internal_Private_GetIgnoreSaveLayerBounds()) { |
| 279 | REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[0].bounds, SkRect::MakeLTRB(10, 10, 40, 40))); |
| 280 | REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLTRB(20, 20, 30, 30))); |
| 281 | REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[2].bounds, SkRect::MakeLTRB(10, 10, 40, 40))); |
| 282 | } |
robertphillips | 4d52afe | 2014-11-03 08:19:44 -0800 | [diff] [blame] | 283 | } |
| 284 | |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 285 | DEF_TEST(RecordDraw_drawImage, r){ |
| 286 | class SkCanvasMock : public SkCanvas { |
| 287 | public: |
mtklein | ad8aa1d | 2014-11-11 18:52:02 -0800 | [diff] [blame] | 288 | SkCanvasMock(int width, int height) : SkCanvas(width, height) { |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 289 | this->resetTestValues(); |
| 290 | } |
reed | e87e383 | 2015-01-05 04:49:38 -0800 | [diff] [blame] | 291 | virtual ~SkCanvasMock() {} |
| 292 | virtual void drawImage(const SkImage* image, SkScalar left, SkScalar top, |
| 293 | const SkPaint* paint = NULL) SK_OVERRIDE { |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 294 | |
| 295 | fDrawImageCalled = true; |
| 296 | } |
| 297 | |
reed | e87e383 | 2015-01-05 04:49:38 -0800 | [diff] [blame] | 298 | virtual void drawImageRect(const SkImage* image, const SkRect* src, |
| 299 | const SkRect& dst, |
| 300 | const SkPaint* paint = NULL) SK_OVERRIDE { |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 301 | fDrawImageRectCalled = true; |
| 302 | } |
| 303 | |
| 304 | void resetTestValues() { |
| 305 | fDrawImageCalled = fDrawImageRectCalled = false; |
| 306 | } |
| 307 | |
| 308 | bool fDrawImageCalled; |
| 309 | bool fDrawImageRectCalled; |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 310 | }; |
| 311 | |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 312 | SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(10, 10)); |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 313 | surface->getCanvas()->clear(SK_ColorGREEN); |
| 314 | SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
| 315 | |
| 316 | SkCanvasMock canvas(10, 10); |
| 317 | |
| 318 | { |
| 319 | SkRecord record; |
| 320 | SkRecorder recorder(&record, 10, 10); |
| 321 | recorder.drawImage(image, 0, 0); |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 322 | SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL, 0); |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 323 | } |
| 324 | REPORTER_ASSERT(r, canvas.fDrawImageCalled); |
| 325 | canvas.resetTestValues(); |
| 326 | |
| 327 | { |
| 328 | SkRecord record; |
| 329 | SkRecorder recorder(&record, 10, 10); |
| 330 | recorder.drawImageRect(image, 0, SkRect::MakeWH(10, 10)); |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 331 | SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL, 0); |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 332 | } |
| 333 | REPORTER_ASSERT(r, canvas.fDrawImageRectCalled); |
| 334 | |
| 335 | } |