| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkBlurImageFilter.h" | 8 #include "SkBlurImageFilter.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 context.fReporter = reporter; | 1267 context.fReporter = reporter; |
| 1268 SkSetErrorCallback(assert_one_parse_error_cb, &context); | 1268 SkSetErrorCallback(assert_one_parse_error_cb, &context); |
| 1269 SkMemoryStream pictureStream(picture1); | 1269 SkMemoryStream pictureStream(picture1); |
| 1270 SkClearLastError(); | 1270 SkClearLastError(); |
| 1271 SkAutoUnref pictureFromStream(SkPicture::CreateFromStream(&pictureStream, NU
LL)); | 1271 SkAutoUnref pictureFromStream(SkPicture::CreateFromStream(&pictureStream, NU
LL)); |
| 1272 REPORTER_ASSERT(reporter, pictureFromStream.get() != NULL); | 1272 REPORTER_ASSERT(reporter, pictureFromStream.get() != NULL); |
| 1273 SkClearLastError(); | 1273 SkClearLastError(); |
| 1274 SkSetErrorCallback(NULL, NULL); | 1274 SkSetErrorCallback(NULL, NULL); |
| 1275 } | 1275 } |
| 1276 | 1276 |
| 1277 static void test_clone_empty(skiatest::Reporter* reporter) { | |
| 1278 // This is a regression test for crbug.com/172062 | |
| 1279 // Before the fix, we used to crash accessing a null pointer when we | |
| 1280 // had a picture with no paints. This test passes by not crashing. | |
| 1281 { | |
| 1282 SkPictureRecorder recorder; | |
| 1283 recorder.beginRecording(1, 1); | |
| 1284 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | |
| 1285 SkAutoTUnref<SkPicture> destPicture(picture->clone()); | |
| 1286 REPORTER_ASSERT(reporter, NULL != destPicture); | |
| 1287 } | |
| 1288 } | |
| 1289 | |
| 1290 static void test_draw_empty(skiatest::Reporter* reporter) { | 1277 static void test_draw_empty(skiatest::Reporter* reporter) { |
| 1291 SkBitmap result; | 1278 SkBitmap result; |
| 1292 make_bm(&result, 2, 2, SK_ColorBLACK, false); | 1279 make_bm(&result, 2, 2, SK_ColorBLACK, false); |
| 1293 | 1280 |
| 1294 SkCanvas canvas(result); | 1281 SkCanvas canvas(result); |
| 1295 | 1282 |
| 1296 { | 1283 { |
| 1297 // stock SkPicture | 1284 // stock SkPicture |
| 1298 SkPictureRecorder recorder; | 1285 SkPictureRecorder recorder; |
| 1299 recorder.beginRecording(1, 1); | 1286 recorder.beginRecording(1, 1); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1549 | 1536 |
| 1550 // both pictures should have different ids | 1537 // both pictures should have different ids |
| 1551 REPORTER_ASSERT(reporter, hasData->uniqueID() != empty.uniqueID()); | 1538 REPORTER_ASSERT(reporter, hasData->uniqueID() != empty.uniqueID()); |
| 1552 | 1539 |
| 1553 // test out copy constructor | 1540 // test out copy constructor |
| 1554 SkPicture copyWithData(*hasData); | 1541 SkPicture copyWithData(*hasData); |
| 1555 REPORTER_ASSERT(reporter, hasData->uniqueID() == copyWithData.uniqueID()); | 1542 REPORTER_ASSERT(reporter, hasData->uniqueID() == copyWithData.uniqueID()); |
| 1556 | 1543 |
| 1557 SkPicture emptyCopy(empty); | 1544 SkPicture emptyCopy(empty); |
| 1558 REPORTER_ASSERT(reporter, empty.uniqueID() != emptyCopy.uniqueID()); | 1545 REPORTER_ASSERT(reporter, empty.uniqueID() != emptyCopy.uniqueID()); |
| 1559 | |
| 1560 // test out clone | |
| 1561 { | |
| 1562 SkAutoTUnref<SkPicture> cloneWithData(hasData->clone()); | |
| 1563 REPORTER_ASSERT(reporter, hasData->uniqueID() == cloneWithData->uniqueID
()); | |
| 1564 | |
| 1565 SkAutoTUnref<SkPicture> emptyClone(empty.clone()); | |
| 1566 REPORTER_ASSERT(reporter, empty.uniqueID() != emptyClone->uniqueID()); | |
| 1567 } | |
| 1568 } | 1546 } |
| 1569 | 1547 |
| 1570 DEF_TEST(Picture, reporter) { | 1548 DEF_TEST(Picture, reporter) { |
| 1571 #ifdef SK_DEBUG | 1549 #ifdef SK_DEBUG |
| 1572 test_deleting_empty_playback(); | 1550 test_deleting_empty_playback(); |
| 1573 test_serializing_empty_picture(); | 1551 test_serializing_empty_picture(); |
| 1574 #else | 1552 #else |
| 1575 test_bad_bitmap(); | 1553 test_bad_bitmap(); |
| 1576 #endif | 1554 #endif |
| 1577 test_unbalanced_save_restores(reporter); | 1555 test_unbalanced_save_restores(reporter); |
| 1578 test_peephole(); | 1556 test_peephole(); |
| 1579 #if SK_SUPPORT_GPU | 1557 #if SK_SUPPORT_GPU |
| 1580 test_gpu_veto(reporter); | 1558 test_gpu_veto(reporter); |
| 1581 #endif | 1559 #endif |
| 1582 test_gatherpixelrefs(reporter); | 1560 test_gatherpixelrefs(reporter); |
| 1583 test_gatherpixelrefsandrects(reporter); | 1561 test_gatherpixelrefsandrects(reporter); |
| 1584 test_bitmap_with_encoded_data(reporter); | 1562 test_bitmap_with_encoded_data(reporter); |
| 1585 test_clone_empty(reporter); | |
| 1586 test_draw_empty(reporter); | 1563 test_draw_empty(reporter); |
| 1587 test_clip_bound_opt(reporter); | 1564 test_clip_bound_opt(reporter); |
| 1588 test_clip_expansion(reporter); | 1565 test_clip_expansion(reporter); |
| 1589 test_hierarchical(reporter); | 1566 test_hierarchical(reporter); |
| 1590 test_gen_id(reporter); | 1567 test_gen_id(reporter); |
| 1591 } | 1568 } |
| 1592 | 1569 |
| 1593 #if SK_SUPPORT_GPU | 1570 #if SK_SUPPORT_GPU |
| 1594 DEF_GPUTEST(GPUPicture, reporter, factory) { | 1571 DEF_GPUTEST(GPUPicture, reporter, factory) { |
| 1595 test_gpu_picture_optimization(reporter, factory); | 1572 test_gpu_picture_optimization(reporter, factory); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1622 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1599 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
| 1623 } | 1600 } |
| 1624 | 1601 |
| 1625 DEF_TEST(Canvas_EmptyBitmap, r) { | 1602 DEF_TEST(Canvas_EmptyBitmap, r) { |
| 1626 SkBitmap dst; | 1603 SkBitmap dst; |
| 1627 dst.allocN32Pixels(10, 10); | 1604 dst.allocN32Pixels(10, 10); |
| 1628 SkCanvas canvas(dst); | 1605 SkCanvas canvas(dst); |
| 1629 | 1606 |
| 1630 test_draw_bitmaps(&canvas); | 1607 test_draw_bitmaps(&canvas); |
| 1631 } | 1608 } |
| OLD | NEW |