| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "Test.h" | 8 #include "Test.h" |
| 9 #include "RecordTestUtils.h" | 9 #include "RecordTestUtils.h" |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 class JustOneDraw : public SkDrawPictureCallback { | 24 class JustOneDraw : public SkDrawPictureCallback { |
| 25 public: | 25 public: |
| 26 JustOneDraw() : fCalls(0) {} | 26 JustOneDraw() : fCalls(0) {} |
| 27 | 27 |
| 28 virtual bool abortDrawing() SK_OVERRIDE { return fCalls++ > 0; } | 28 virtual bool abortDrawing() SK_OVERRIDE { return fCalls++ > 0; } |
| 29 private: | 29 private: |
| 30 int fCalls; | 30 int fCalls; |
| 31 }; | 31 }; |
| 32 | 32 |
| 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 (ye
t) | |
| 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 | |
| 60 DEF_TEST(RecordDraw_Abort, r) { | 33 DEF_TEST(RecordDraw_Abort, r) { |
| 61 // Record two commands. | 34 // Record two commands. |
| 62 SkRecord record; | 35 SkRecord record; |
| 63 SkRecorder recorder(&record, W, H); | 36 SkRecorder recorder(&record, W, H); |
| 64 recorder.drawRect(SkRect::MakeWH(200, 300), SkPaint()); | 37 recorder.drawRect(SkRect::MakeWH(200, 300), SkPaint()); |
| 65 recorder.clipRect(SkRect::MakeWH(100, 200)); | 38 recorder.clipRect(SkRect::MakeWH(100, 200)); |
| 66 | 39 |
| 67 SkRecord rerecord; | 40 SkRecord rerecord; |
| 68 SkRecorder canvas(&rerecord, W, H); | 41 SkRecorder canvas(&rerecord, W, H); |
| 69 | 42 |
| 70 JustOneDraw callback; | 43 JustOneDraw callback; |
| 71 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL/*bbh*/, &callback); | 44 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL/*bbh*/, &callback); |
| 72 | 45 |
| 73 REPORTER_ASSERT(r, 1 == count_instances_of_type<SkRecords::DrawRect>(rerecor
d)); | 46 REPORTER_ASSERT(r, 3 == rerecord.count()); |
| 74 REPORTER_ASSERT(r, 0 == count_instances_of_type<SkRecords::ClipRect>(rerecor
d)); | 47 assert_type<SkRecords::Save> (r, rerecord, 0); |
| 48 assert_type<SkRecords::DrawRect>(r, rerecord, 1); |
| 49 assert_type<SkRecords::Restore> (r, rerecord, 2); |
| 75 } | 50 } |
| 76 | 51 |
| 77 DEF_TEST(RecordDraw_Unbalanced, r) { | 52 DEF_TEST(RecordDraw_Unbalanced, r) { |
| 78 SkRecord record; | 53 SkRecord record; |
| 79 SkRecorder recorder(&record, W, H); | 54 SkRecorder recorder(&record, W, H); |
| 80 recorder.save(); // We won't balance this, but SkRecordDraw will for us. | 55 recorder.save(); // We won't balance this, but SkRecordDraw will for us. |
| 81 recorder.scale(2, 2); | |
| 82 | 56 |
| 83 SkRecord rerecord; | 57 SkRecord rerecord; |
| 84 SkRecorder canvas(&rerecord, W, H); | 58 SkRecorder canvas(&rerecord, W, H); |
| 85 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL/*bbh*/, NULL/*callback*/); | 59 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL/*bbh*/, NULL/*callback*/); |
| 86 | 60 |
| 87 int save_count = count_instances_of_type<SkRecords::Save>(rerecord); | 61 REPORTER_ASSERT(r, 4 == rerecord.count()); |
| 88 int restore_count = count_instances_of_type<SkRecords::Save>(rerecord); | 62 assert_type<SkRecords::Save> (r, rerecord, 0); |
| 89 REPORTER_ASSERT(r, save_count == restore_count); | 63 assert_type<SkRecords::Save> (r, rerecord, 1); |
| 64 assert_type<SkRecords::Restore> (r, rerecord, 2); |
| 65 assert_type<SkRecords::Restore> (r, rerecord, 3); |
| 90 } | 66 } |
| 91 | 67 |
| 92 DEF_TEST(RecordDraw_SetMatrixClobber, r) { | 68 DEF_TEST(RecordDraw_SetMatrixClobber, r) { |
| 93 // Set up an SkRecord that just scales by 2x,3x. | 69 // Set up an SkRecord that just scales by 2x,3x. |
| 94 SkRecord scaleRecord; | 70 SkRecord scaleRecord; |
| 95 SkRecorder scaleCanvas(&scaleRecord, W, H); | 71 SkRecorder scaleCanvas(&scaleRecord, W, H); |
| 96 SkMatrix scale; | 72 SkMatrix scale; |
| 97 scale.setScale(2, 3); | 73 scale.setScale(2, 3); |
| 98 scaleCanvas.setMatrix(scale); | 74 scaleCanvas.setMatrix(scale); |
| 99 | 75 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 SkRecord record; | 186 SkRecord record; |
| 211 SkRecorder recorder(&record, kWidth, kHeight); | 187 SkRecorder recorder(&record, kWidth, kHeight); |
| 212 recorder.drawRect(r1, p); | 188 recorder.drawRect(r1, p); |
| 213 recorder.drawRect(r2, p); | 189 recorder.drawRect(r2, p); |
| 214 recorder.drawRect(r3, p); | 190 recorder.drawRect(r3, p); |
| 215 | 191 |
| 216 SkRecord rerecord; | 192 SkRecord rerecord; |
| 217 SkRecorder canvas(&rerecord, kWidth, kHeight); | 193 SkRecorder canvas(&rerecord, kWidth, kHeight); |
| 218 SkRecordPartialDraw(record, &canvas, NULL, 0, 1, 2, SkMatrix::I()); // repla
y just drawRect of r2 | 194 SkRecordPartialDraw(record, &canvas, NULL, 0, 1, 2, SkMatrix::I()); // repla
y just drawRect of r2 |
| 219 | 195 |
| 220 REPORTER_ASSERT(r, 1 == count_instances_of_type<SkRecords::DrawRect>(rerecor
d)); | 196 REPORTER_ASSERT(r, 3 == rerecord.count()); |
| 221 int index = find_first_instances_of_type<SkRecords::DrawRect>(rerecord); | 197 assert_type<SkRecords::Save> (r, rerecord, 0); |
| 222 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re
record, index); | 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, re
record, 1); |
| 223 REPORTER_ASSERT(r, drawRect->rect == r2); | 202 REPORTER_ASSERT(r, drawRect->rect == r2); |
| 224 } | 203 } |
| 225 | 204 |
| 226 // A regression test for crbug.com/415468 and skbug.com/2957. | 205 // A regression test for crbug.com/415468 and skbug.com/2957. |
| 227 // | 206 // |
| 228 // This also now serves as a regression test for crbug.com/418417. We used to a
djust the | 207 // This also now serves as a regression test for crbug.com/418417. We used to a
djust the |
| 229 // bounds for the saveLayer, clip, and restore to be greater than the bounds of
the picture. | 208 // 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 make
s no sense.) | 209 // (We were applying the saveLayer paint to the bounds after restore, which make
s no sense.) |
| 231 DEF_TEST(RecordDraw_SaveLayerAffectsClipBounds, r) { | 210 DEF_TEST(RecordDraw_SaveLayerAffectsClipBounds, r) { |
| 232 SkRecord record; | 211 SkRecord record; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 | 303 |
| 325 { | 304 { |
| 326 SkRecord record; | 305 SkRecord record; |
| 327 SkRecorder recorder(&record, 10, 10); | 306 SkRecorder recorder(&record, 10, 10); |
| 328 recorder.drawImageRect(image, 0, SkRect::MakeWH(10, 10)); | 307 recorder.drawImageRect(image, 0, SkRect::MakeWH(10, 10)); |
| 329 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL, 0); | 308 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL, 0); |
| 330 } | 309 } |
| 331 REPORTER_ASSERT(r, canvas.fDrawImageRectCalled); | 310 REPORTER_ASSERT(r, canvas.fDrawImageRectCalled); |
| 332 | 311 |
| 333 } | 312 } |
| OLD | NEW |