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