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