Chromium Code Reviews| 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 #if 0 | |
| 33 DEF_TEST(RecordDraw_Abort, r) { | 34 DEF_TEST(RecordDraw_Abort, r) { |
| 34 // Record two commands. | 35 // Record two commands. |
| 35 SkRecord record; | 36 SkRecord record; |
| 36 SkRecorder recorder(&record, W, H); | 37 SkRecorder recorder(&record, W, H); |
| 37 recorder.drawRect(SkRect::MakeWH(200, 300), SkPaint()); | 38 recorder.drawRect(SkRect::MakeWH(200, 300), SkPaint()); |
| 38 recorder.clipRect(SkRect::MakeWH(100, 200)); | 39 recorder.clipRect(SkRect::MakeWH(100, 200)); |
| 39 | 40 |
| 40 SkRecord rerecord; | 41 SkRecord rerecord; |
| 41 SkRecorder canvas(&rerecord, W, H); | 42 SkRecorder canvas(&rerecord, W, H); |
| 42 | 43 |
| 43 JustOneDraw callback; | 44 JustOneDraw callback; |
| 44 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL/*bbh*/, &callback); | 45 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL/*bbh*/, &callback); |
| 45 | 46 |
| 46 REPORTER_ASSERT(r, 3 == rerecord.count()); | 47 REPORTER_ASSERT(r, 3 == rerecord.count()); |
| 47 assert_type<SkRecords::Save> (r, rerecord, 0); | 48 assert_type<SkRecords::Save> (r, rerecord, 0); |
| 48 assert_type<SkRecords::DrawRect>(r, rerecord, 1); | 49 assert_type<SkRecords::DrawRect>(r, rerecord, 1); |
| 49 assert_type<SkRecords::Restore> (r, rerecord, 2); | 50 assert_type<SkRecords::Restore> (r, rerecord, 2); |
| 50 } | 51 } |
| 52 #endif | |
| 51 | 53 |
| 52 DEF_TEST(RecordDraw_Unbalanced, r) { | 54 DEF_TEST(RecordDraw_Unbalanced, r) { |
| 53 SkRecord record; | 55 SkRecord record; |
| 54 SkRecorder recorder(&record, W, H); | 56 SkRecorder recorder(&record, W, H); |
| 55 recorder.save(); // We won't balance this, but SkRecordDraw will for us. | 57 recorder.save(); // We won't balance this, but SkRecordDraw will for us. |
|
robertphillips
2014/12/10 18:43:53
Add a draw here to bring this test back?
| |
| 56 | 58 |
| 57 SkRecord rerecord; | 59 SkRecord rerecord; |
| 58 SkRecorder canvas(&rerecord, W, H); | 60 SkRecorder canvas(&rerecord, W, H); |
| 59 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL/*bbh*/, NULL/*callback*/); | 61 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL/*bbh*/, NULL/*callback*/); |
| 60 | 62 |
| 63 // the finished rerecord should be balanaced (equal number of saves and rest ores. | |
| 64 // a cheap check for that in this case is to see that the total count is eve n. | |
| 65 REPORTER_ASSERT(r, (rerecord.count() & 1) == 0); | |
| 66 | |
| 67 #if 0 | |
| 61 REPORTER_ASSERT(r, 4 == rerecord.count()); | 68 REPORTER_ASSERT(r, 4 == rerecord.count()); |
| 62 assert_type<SkRecords::Save> (r, rerecord, 0); | 69 assert_type<SkRecords::Save> (r, rerecord, 0); |
| 63 assert_type<SkRecords::Save> (r, rerecord, 1); | 70 assert_type<SkRecords::Save> (r, rerecord, 1); |
| 64 assert_type<SkRecords::Restore> (r, rerecord, 2); | 71 assert_type<SkRecords::Restore> (r, rerecord, 2); |
| 65 assert_type<SkRecords::Restore> (r, rerecord, 3); | 72 assert_type<SkRecords::Restore> (r, rerecord, 3); |
| 73 #endif | |
| 66 } | 74 } |
| 67 | 75 |
| 68 DEF_TEST(RecordDraw_SetMatrixClobber, r) { | 76 DEF_TEST(RecordDraw_SetMatrixClobber, r) { |
| 69 // Set up an SkRecord that just scales by 2x,3x. | 77 // Set up an SkRecord that just scales by 2x,3x. |
| 70 SkRecord scaleRecord; | 78 SkRecord scaleRecord; |
| 71 SkRecorder scaleCanvas(&scaleRecord, W, H); | 79 SkRecorder scaleCanvas(&scaleRecord, W, H); |
| 72 SkMatrix scale; | 80 SkMatrix scale; |
| 73 scale.setScale(2, 3); | 81 scale.setScale(2, 3); |
| 74 scaleCanvas.setMatrix(scale); | 82 scaleCanvas.setMatrix(scale); |
| 75 | 83 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 SkRecordFillBounds(SkRect::MakeWH(SkIntToScalar(W), SkIntToScalar(H)), recor d, &bbh); | 175 SkRecordFillBounds(SkRect::MakeWH(SkIntToScalar(W), SkIntToScalar(H)), recor d, &bbh); |
| 168 REPORTER_ASSERT(r, bbh.fEntries.count() == 2); | 176 REPORTER_ASSERT(r, bbh.fEntries.count() == 2); |
| 169 | 177 |
| 170 // We can make these next assertions confidently because SkRecordFillBounds | 178 // We can make these next assertions confidently because SkRecordFillBounds |
| 171 // builds its bounds by overestimating font metrics in a platform-independen t way. | 179 // builds its bounds by overestimating font metrics in a platform-independen t way. |
| 172 // If that changes, these tests will need to be more flexible. | 180 // If that changes, these tests will need to be more flexible. |
| 173 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[0].bounds, SkRect::MakeLTRB(0 , 0, 140, 60))); | 181 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))); | 182 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLTRB(0 , 20, 180, 100))); |
| 175 } | 183 } |
| 176 | 184 |
| 185 #if 0 | |
| 177 // Base test to ensure start/stop range is respected | 186 // Base test to ensure start/stop range is respected |
| 178 DEF_TEST(RecordDraw_PartialStartStop, r) { | 187 DEF_TEST(RecordDraw_PartialStartStop, r) { |
| 179 static const int kWidth = 10, kHeight = 10; | 188 static const int kWidth = 10, kHeight = 10; |
| 180 | 189 |
| 181 SkRect r1 = { 0, 0, kWidth, kHeight }; | 190 SkRect r1 = { 0, 0, kWidth, kHeight }; |
| 182 SkRect r2 = { 0, 0, kWidth, kHeight/2 }; | 191 SkRect r2 = { 0, 0, kWidth, kHeight/2 }; |
| 183 SkRect r3 = { 0, 0, kWidth/2, kHeight }; | 192 SkRect r3 = { 0, 0, kWidth/2, kHeight }; |
| 184 SkPaint p; | 193 SkPaint p; |
| 185 | 194 |
| 186 SkRecord record; | 195 SkRecord record; |
| 187 SkRecorder recorder(&record, kWidth, kHeight); | 196 SkRecorder recorder(&record, kWidth, kHeight); |
| 188 recorder.drawRect(r1, p); | 197 recorder.drawRect(r1, p); |
| 189 recorder.drawRect(r2, p); | 198 recorder.drawRect(r2, p); |
| 190 recorder.drawRect(r3, p); | 199 recorder.drawRect(r3, p); |
| 191 | 200 |
| 192 SkRecord rerecord; | 201 SkRecord rerecord; |
| 193 SkRecorder canvas(&rerecord, kWidth, kHeight); | 202 SkRecorder canvas(&rerecord, kWidth, kHeight); |
| 194 SkRecordPartialDraw(record, &canvas, NULL, 0, 1, 2, SkMatrix::I()); // repla y just drawRect of r2 | 203 SkRecordPartialDraw(record, &canvas, NULL, 0, 1, 2, SkMatrix::I()); // repla y just drawRect of r2 |
| 195 | 204 |
|
robertphillips
2014/12/10 18:43:53
The main point of this test is that only r2 gets d
| |
| 196 REPORTER_ASSERT(r, 3 == rerecord.count()); | 205 REPORTER_ASSERT(r, 3 == rerecord.count()); |
| 197 assert_type<SkRecords::Save> (r, rerecord, 0); | 206 assert_type<SkRecords::Save> (r, rerecord, 0); |
| 198 assert_type<SkRecords::DrawRect> (r, rerecord, 1); | 207 assert_type<SkRecords::DrawRect> (r, rerecord, 1); |
| 199 assert_type<SkRecords::Restore> (r, rerecord, 2); | 208 assert_type<SkRecords::Restore> (r, rerecord, 2); |
| 200 | 209 |
| 201 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re record, 1); | 210 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re record, 1); |
| 202 REPORTER_ASSERT(r, drawRect->rect == r2); | 211 REPORTER_ASSERT(r, drawRect->rect == r2); |
| 203 } | 212 } |
| 213 #endif | |
| 204 | 214 |
| 205 // A regression test for crbug.com/415468 and skbug.com/2957. | 215 // A regression test for crbug.com/415468 and skbug.com/2957. |
| 206 // | 216 // |
| 207 // This also now serves as a regression test for crbug.com/418417. We used to a djust the | 217 // This also now serves as a regression test for crbug.com/418417. We used to a djust the |
| 208 // bounds for the saveLayer, clip, and restore to be greater than the bounds of the picture. | 218 // 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 make s no sense.) | 219 // (We were applying the saveLayer paint to the bounds after restore, which make s no sense.) |
| 210 DEF_TEST(RecordDraw_SaveLayerAffectsClipBounds, r) { | 220 DEF_TEST(RecordDraw_SaveLayerAffectsClipBounds, r) { |
| 211 SkRecord record; | 221 SkRecord record; |
| 212 SkRecorder recorder(&record, 50, 50); | 222 SkRecorder recorder(&record, 50, 50); |
| 213 | 223 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 | 313 |
| 304 { | 314 { |
| 305 SkRecord record; | 315 SkRecord record; |
| 306 SkRecorder recorder(&record, 10, 10); | 316 SkRecorder recorder(&record, 10, 10); |
| 307 recorder.drawImageRect(image, 0, SkRect::MakeWH(10, 10)); | 317 recorder.drawImageRect(image, 0, SkRect::MakeWH(10, 10)); |
| 308 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL, 0); | 318 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL, 0); |
| 309 } | 319 } |
| 310 REPORTER_ASSERT(r, canvas.fDrawImageRectCalled); | 320 REPORTER_ASSERT(r, canvas.fDrawImageRectCalled); |
| 311 | 321 |
| 312 } | 322 } |
| OLD | NEW |