OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 <functional> | 8 #include <functional> |
9 #include <initializer_list> | 9 #include <initializer_list> |
10 #include <vector> | 10 #include <vector> |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 } | 164 } |
165 #endif | 165 #endif |
166 | 166 |
167 static void test_encode(skiatest::Reporter* reporter, SkImage* image) { | 167 static void test_encode(skiatest::Reporter* reporter, SkImage* image) { |
168 const SkIRect ir = SkIRect::MakeXYWH(5, 5, 10, 10); | 168 const SkIRect ir = SkIRect::MakeXYWH(5, 5, 10, 10); |
169 sk_sp<SkData> origEncoded(image->encode()); | 169 sk_sp<SkData> origEncoded(image->encode()); |
170 REPORTER_ASSERT(reporter, origEncoded); | 170 REPORTER_ASSERT(reporter, origEncoded); |
171 REPORTER_ASSERT(reporter, origEncoded->size() > 0); | 171 REPORTER_ASSERT(reporter, origEncoded->size() > 0); |
172 | 172 |
173 sk_sp<SkImage> decoded(SkImage::MakeFromEncoded(origEncoded)); | 173 sk_sp<SkImage> decoded(SkImage::MakeFromEncoded(origEncoded)); |
| 174 if (!decoded) { |
| 175 ERRORF(reporter, "failed to decode image!"); |
| 176 return; |
| 177 } |
174 REPORTER_ASSERT(reporter, decoded); | 178 REPORTER_ASSERT(reporter, decoded); |
175 assert_equal(reporter, image, nullptr, decoded.get()); | 179 assert_equal(reporter, image, nullptr, decoded.get()); |
176 | 180 |
177 // Now see if we can instantiate an image from a subset of the surface/origE
ncoded | 181 // Now see if we can instantiate an image from a subset of the surface/origE
ncoded |
178 | 182 |
179 decoded = SkImage::MakeFromEncoded(origEncoded, &ir); | 183 decoded = SkImage::MakeFromEncoded(origEncoded, &ir); |
180 REPORTER_ASSERT(reporter, decoded); | 184 REPORTER_ASSERT(reporter, decoded); |
181 assert_equal(reporter, image, &ir, decoded.get()); | 185 assert_equal(reporter, image, &ir, decoded.get()); |
182 } | 186 } |
183 | 187 |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 static bool has_pixels(const SkPMColor pixels[], int count, SkPMColor expected)
{ | 596 static bool has_pixels(const SkPMColor pixels[], int count, SkPMColor expected)
{ |
593 for (int i = 0; i < count; ++i) { | 597 for (int i = 0; i < count; ++i) { |
594 if (pixels[i] != expected) { | 598 if (pixels[i] != expected) { |
595 return false; | 599 return false; |
596 } | 600 } |
597 } | 601 } |
598 return true; | 602 return true; |
599 } | 603 } |
600 | 604 |
601 static void test_read_pixels(skiatest::Reporter* reporter, SkImage* image) { | 605 static void test_read_pixels(skiatest::Reporter* reporter, SkImage* image) { |
| 606 if (!image) { |
| 607 ERRORF(reporter, "Failed to create image!"); |
| 608 return; |
| 609 } |
602 const SkPMColor expected = SkPreMultiplyColor(SK_ColorWHITE); | 610 const SkPMColor expected = SkPreMultiplyColor(SK_ColorWHITE); |
603 const SkPMColor notExpected = ~expected; | 611 const SkPMColor notExpected = ~expected; |
604 | 612 |
605 const int w = 2, h = 2; | 613 const int w = 2, h = 2; |
606 const size_t rowBytes = w * sizeof(SkPMColor); | 614 const size_t rowBytes = w * sizeof(SkPMColor); |
607 SkPMColor pixels[w*h]; | 615 SkPMColor pixels[w*h]; |
608 | 616 |
609 SkImageInfo info; | 617 SkImageInfo info; |
610 | 618 |
611 info = SkImageInfo::MakeUnknown(w, h); | 619 info = SkImageInfo::MakeUnknown(w, h); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 SkAutoLockPixels alp(bitmap); | 685 SkAutoLockPixels alp(bitmap); |
678 REPORTER_ASSERT(reporter, bitmap.getPixels()); | 686 REPORTER_ASSERT(reporter, bitmap.getPixels()); |
679 | 687 |
680 const SkImageInfo info = SkImageInfo::MakeN32(1, 1, bitmap.alphaType()); | 688 const SkImageInfo info = SkImageInfo::MakeN32(1, 1, bitmap.alphaType()); |
681 SkPMColor imageColor; | 689 SkPMColor imageColor; |
682 REPORTER_ASSERT(reporter, image->readPixels(info, &imageColor, sizeof(SkPMCo
lor), 0, 0)); | 690 REPORTER_ASSERT(reporter, image->readPixels(info, &imageColor, sizeof(SkPMCo
lor), 0, 0)); |
683 REPORTER_ASSERT(reporter, imageColor == *bitmap.getAddr32(0, 0)); | 691 REPORTER_ASSERT(reporter, imageColor == *bitmap.getAddr32(0, 0)); |
684 } | 692 } |
685 | 693 |
686 static void test_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* imag
e, SkImage::LegacyBitmapMode mode) { | 694 static void test_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* imag
e, SkImage::LegacyBitmapMode mode) { |
| 695 if (!image) { |
| 696 ERRORF(reporter, "Failed to create image."); |
| 697 return; |
| 698 } |
687 SkBitmap bitmap; | 699 SkBitmap bitmap; |
688 REPORTER_ASSERT(reporter, image->asLegacyBitmap(&bitmap, mode)); | 700 REPORTER_ASSERT(reporter, image->asLegacyBitmap(&bitmap, mode)); |
689 check_legacy_bitmap(reporter, image, bitmap, mode); | 701 check_legacy_bitmap(reporter, image, bitmap, mode); |
690 | 702 |
691 // Test subsetting to exercise the rowBytes logic. | 703 // Test subsetting to exercise the rowBytes logic. |
692 SkBitmap tmp; | 704 SkBitmap tmp; |
693 REPORTER_ASSERT(reporter, bitmap.extractSubset(&tmp, SkIRect::MakeWH(image->
width() / 2, | 705 REPORTER_ASSERT(reporter, bitmap.extractSubset(&tmp, SkIRect::MakeWH(image->
width() / 2, |
694 image->
height() / 2))); | 706 image->
height() / 2))); |
695 sk_sp<SkImage> subsetImage(SkImage::MakeFromBitmap(tmp)); | 707 sk_sp<SkImage> subsetImage(SkImage::MakeFromBitmap(tmp)); |
696 REPORTER_ASSERT(reporter, subsetImage.get()); | 708 REPORTER_ASSERT(reporter, subsetImage.get()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 SkImage::kRW_LegacyBitmapMode, | 740 SkImage::kRW_LegacyBitmapMode, |
729 }; | 741 }; |
730 for (auto& mode : modes) { | 742 for (auto& mode : modes) { |
731 sk_sp<SkImage> image(create_gpu_image(ctxInfo.grContext())); | 743 sk_sp<SkImage> image(create_gpu_image(ctxInfo.grContext())); |
732 test_legacy_bitmap(reporter, image.get(), mode); | 744 test_legacy_bitmap(reporter, image.get(), mode); |
733 } | 745 } |
734 } | 746 } |
735 #endif | 747 #endif |
736 | 748 |
737 static void test_peek(skiatest::Reporter* reporter, SkImage* image, bool expectP
eekSuccess) { | 749 static void test_peek(skiatest::Reporter* reporter, SkImage* image, bool expectP
eekSuccess) { |
| 750 if (!image) { |
| 751 ERRORF(reporter, "Failed to create image!"); |
| 752 return; |
| 753 } |
738 SkPixmap pm; | 754 SkPixmap pm; |
739 bool success = image->peekPixels(&pm); | 755 bool success = image->peekPixels(&pm); |
740 REPORTER_ASSERT(reporter, expectPeekSuccess == success); | 756 REPORTER_ASSERT(reporter, expectPeekSuccess == success); |
741 if (success) { | 757 if (success) { |
742 const SkImageInfo& info = pm.info(); | 758 const SkImageInfo& info = pm.info(); |
743 REPORTER_ASSERT(reporter, 20 == info.width()); | 759 REPORTER_ASSERT(reporter, 20 == info.width()); |
744 REPORTER_ASSERT(reporter, 20 == info.height()); | 760 REPORTER_ASSERT(reporter, 20 == info.height()); |
745 REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType()); | 761 REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType()); |
746 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() || | 762 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() || |
747 kOpaque_SkAlphaType == info.alphaType()); | 763 kOpaque_SkAlphaType == info.alphaType()); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 kMedium_SkFilterQuality, 16, true}, | 935 kMedium_SkFilterQuality, 16, true}, |
920 // Create an image with multiple prescale levels, make sure we chose the
minimum scale. | 936 // Create an image with multiple prescale levels, make sure we chose the
minimum scale. |
921 { create_image_large, {{SkMatrix::I(), kMedium_SkFilterQuality, 5}, | 937 { create_image_large, {{SkMatrix::I(), kMedium_SkFilterQuality, 5}, |
922 {SkMatrix::I(), kMedium_SkFilterQuality, 4}}, | 938 {SkMatrix::I(), kMedium_SkFilterQuality, 4}}, |
923 kMedium_SkFilterQuality, 16, true}, | 939 kMedium_SkFilterQuality, 16, true}, |
924 }; | 940 }; |
925 | 941 |
926 | 942 |
927 for (auto testCase : testCases) { | 943 for (auto testCase : testCases) { |
928 sk_sp<SkImage> image(testCase.fImageFactory()); | 944 sk_sp<SkImage> image(testCase.fImageFactory()); |
| 945 if (!image) { |
| 946 ERRORF(reporter, "Failed to create image!"); |
| 947 continue; |
| 948 } |
| 949 |
929 size_t size = image->getDeferredTextureImageData(*proxy, testCase.fParam
s.data(), | 950 size_t size = image->getDeferredTextureImageData(*proxy, testCase.fParam
s.data(), |
930 static_cast<int>(testCa
se.fParams.size()), | 951 static_cast<int>(testCa
se.fParams.size()), |
931 nullptr, SkSourceGammaT
reatment::kIgnore); | 952 nullptr, SkSourceGammaT
reatment::kIgnore); |
932 static const char *const kFS[] = { "fail", "succeed" }; | 953 static const char *const kFS[] = { "fail", "succeed" }; |
933 if (SkToBool(size) != testCase.fExpectation) { | 954 if (SkToBool(size) != testCase.fExpectation) { |
934 ERRORF(reporter, "This image was expected to %s but did not.", | 955 ERRORF(reporter, "This image was expected to %s but did not.", |
935 kFS[testCase.fExpectation]); | 956 kFS[testCase.fExpectation]); |
936 } | 957 } |
937 if (size) { | 958 if (size) { |
938 void* buffer = sk_malloc_throw(size); | 959 void* buffer = sk_malloc_throw(size); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1023 SkBitmap bm1; | 1044 SkBitmap bm1; |
1024 bm1.allocPixels(SkImageInfo::MakeN32(256, 256, kUnpremul_SkAlphaType)); | 1045 bm1.allocPixels(SkImageInfo::MakeN32(256, 256, kUnpremul_SkAlphaType)); |
1025 bm0.readPixels(bm1.info(), bm1.getPixels(), bm1.rowBytes(), 0, 0); | 1046 bm0.readPixels(bm1.info(), bm1.getPixels(), bm1.rowBytes(), 0, 0); |
1026 | 1047 |
1027 SkBitmap bm2; | 1048 SkBitmap bm2; |
1028 bm2.allocPixels(SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType)); | 1049 bm2.allocPixels(SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType)); |
1029 bm1.readPixels(bm2.info(), bm2.getPixels(), bm2.rowBytes(), 0, 0); | 1050 bm1.readPixels(bm2.info(), bm2.getPixels(), bm2.rowBytes(), 0, 0); |
1030 | 1051 |
1031 REPORTER_ASSERT(reporter, equal(bm0, bm2)); | 1052 REPORTER_ASSERT(reporter, equal(bm0, bm2)); |
1032 } | 1053 } |
OLD | NEW |