Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkData.h" | 9 #include "SkData.h" |
| 10 #include "SkDevice.h" | 10 #include "SkDevice.h" |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 654 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { | 654 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { |
| 655 for (auto& mode : modes) { | 655 for (auto& mode : modes) { |
| 656 SkAutoTUnref<SkSurface> surface( | 656 SkAutoTUnref<SkSurface> surface( |
| 657 surface_func(context, kPremul_SkAlphaType, nullptr)); | 657 surface_func(context, kPremul_SkAlphaType, nullptr)); |
| 658 test_func(reporter, surface, mode); | 658 test_func(reporter, surface, mode); |
| 659 } | 659 } |
| 660 } | 660 } |
| 661 } | 661 } |
| 662 } | 662 } |
| 663 #endif | 663 #endif |
| 664 | |
| 665 static void check_rowbytes_remain_consistent(SkSurface* surface, skiatest::Repor ter* reporter) { | |
| 666 SkImageInfo info; | |
| 667 size_t rowBytes; | |
| 668 REPORTER_ASSERT(reporter, surface->peekPixels(&info, &rowBytes)); | |
| 669 | |
| 670 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); | |
| 671 SkImageInfo im_info; | |
| 672 size_t im_rowbytes; | |
| 673 REPORTER_ASSERT(reporter, image->peekPixels(&im_info, &im_rowbytes)); | |
| 674 | |
| 675 REPORTER_ASSERT(reporter, rowBytes == im_rowbytes); | |
| 676 | |
| 677 // trigger a copy-on-write | |
| 678 surface->getCanvas()->drawPaint(SkPaint()); | |
| 679 SkAutoTUnref<SkImage> image2(surface->newImageSnapshot()); | |
| 680 REPORTER_ASSERT(reporter, image->uniqueID() != image2->uniqueID()); | |
| 681 | |
| 682 SkImageInfo im_info2; | |
| 683 size_t im_rowbytes2; | |
| 684 REPORTER_ASSERT(reporter, image2->peekPixels(&im_info2, &im_rowbytes2)); | |
| 685 | |
| 686 REPORTER_ASSERT(reporter, im_rowbytes2 == im_rowbytes); | |
|
bsalomon
2016/01/29 13:59:25
Should we doc this behavior with the SkSurface fac
reed1
2016/01/30 00:52:48
Done.
| |
| 687 } | |
| 688 | |
| 689 DEF_TEST(surface_rowbytes, reporter) { | |
| 690 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); | |
| 691 | |
| 692 SkAutoTUnref<SkSurface> surf0(SkSurface::NewRaster(info)); | |
| 693 check_rowbytes_remain_consistent(surf0, reporter); | |
| 694 | |
| 695 // specify a larger rowbytes | |
| 696 SkAutoTUnref<SkSurface> surf1(SkSurface::NewRaster(info, 500, nullptr)); | |
| 697 check_rowbytes_remain_consistent(surf1, reporter); | |
| 698 | |
| 699 // Try some illegal rowByte values | |
| 700 SkSurface* s = SkSurface::NewRaster(info, 396, nullptr); // needs to be a t least 400 | |
| 701 REPORTER_ASSERT(reporter, nullptr == s); | |
| 702 s = SkSurface::NewRaster(info, 1 << 30, nullptr); // allocation to large | |
| 703 REPORTER_ASSERT(reporter, nullptr == s); | |
| 704 } | |
| OLD | NEW |