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 "DMGpuSupport.h" | 10 #include "DMGpuSupport.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 } | 154 } |
155 #endif | 155 #endif |
156 | 156 |
157 static void test_encode(skiatest::Reporter* reporter, SkImage* image) { | 157 static void test_encode(skiatest::Reporter* reporter, SkImage* image) { |
158 const SkIRect ir = SkIRect::MakeXYWH(5, 5, 10, 10); | 158 const SkIRect ir = SkIRect::MakeXYWH(5, 5, 10, 10); |
159 sk_sp<SkData> origEncoded(image->encode()); | 159 sk_sp<SkData> origEncoded(image->encode()); |
160 REPORTER_ASSERT(reporter, origEncoded); | 160 REPORTER_ASSERT(reporter, origEncoded); |
161 REPORTER_ASSERT(reporter, origEncoded->size() > 0); | 161 REPORTER_ASSERT(reporter, origEncoded->size() > 0); |
162 | 162 |
163 sk_sp<SkImage> decoded(SkImage::MakeFromEncoded(origEncoded)); | 163 sk_sp<SkImage> decoded(SkImage::MakeFromEncoded(origEncoded)); |
164 if (!decoded) { | |
165 ERRORF(reporter, "failed to decode image!"); | |
166 return; | |
167 } | |
168 REPORTER_ASSERT(reporter, decoded); | 164 REPORTER_ASSERT(reporter, decoded); |
169 assert_equal(reporter, image, nullptr, decoded.get()); | 165 assert_equal(reporter, image, nullptr, decoded.get()); |
170 | 166 |
171 // Now see if we can instantiate an image from a subset of the surface/origE
ncoded | 167 // Now see if we can instantiate an image from a subset of the surface/origE
ncoded |
172 | 168 |
173 decoded = SkImage::MakeFromEncoded(origEncoded, &ir); | 169 decoded = SkImage::MakeFromEncoded(origEncoded, &ir); |
174 REPORTER_ASSERT(reporter, decoded); | 170 REPORTER_ASSERT(reporter, decoded); |
175 assert_equal(reporter, image, &ir, decoded.get()); | 171 assert_equal(reporter, image, &ir, decoded.get()); |
176 } | 172 } |
177 | 173 |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 static bool has_pixels(const SkPMColor pixels[], int count, SkPMColor expected)
{ | 511 static bool has_pixels(const SkPMColor pixels[], int count, SkPMColor expected)
{ |
516 for (int i = 0; i < count; ++i) { | 512 for (int i = 0; i < count; ++i) { |
517 if (pixels[i] != expected) { | 513 if (pixels[i] != expected) { |
518 return false; | 514 return false; |
519 } | 515 } |
520 } | 516 } |
521 return true; | 517 return true; |
522 } | 518 } |
523 | 519 |
524 static void test_read_pixels(skiatest::Reporter* reporter, SkImage* image) { | 520 static void test_read_pixels(skiatest::Reporter* reporter, SkImage* image) { |
525 if (!image) { | |
526 ERRORF(reporter, "Failed to create image!"); | |
527 return; | |
528 } | |
529 const SkPMColor expected = SkPreMultiplyColor(SK_ColorWHITE); | 521 const SkPMColor expected = SkPreMultiplyColor(SK_ColorWHITE); |
530 const SkPMColor notExpected = ~expected; | 522 const SkPMColor notExpected = ~expected; |
531 | 523 |
532 const int w = 2, h = 2; | 524 const int w = 2, h = 2; |
533 const size_t rowBytes = w * sizeof(SkPMColor); | 525 const size_t rowBytes = w * sizeof(SkPMColor); |
534 SkPMColor pixels[w*h]; | 526 SkPMColor pixels[w*h]; |
535 | 527 |
536 SkImageInfo info; | 528 SkImageInfo info; |
537 | 529 |
538 info = SkImageInfo::MakeUnknown(w, h); | 530 info = SkImageInfo::MakeUnknown(w, h); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 SkAutoLockPixels alp(bitmap); | 596 SkAutoLockPixels alp(bitmap); |
605 REPORTER_ASSERT(reporter, bitmap.getPixels()); | 597 REPORTER_ASSERT(reporter, bitmap.getPixels()); |
606 | 598 |
607 const SkImageInfo info = SkImageInfo::MakeN32(1, 1, bitmap.alphaType()); | 599 const SkImageInfo info = SkImageInfo::MakeN32(1, 1, bitmap.alphaType()); |
608 SkPMColor imageColor; | 600 SkPMColor imageColor; |
609 REPORTER_ASSERT(reporter, image->readPixels(info, &imageColor, sizeof(SkPMCo
lor), 0, 0)); | 601 REPORTER_ASSERT(reporter, image->readPixels(info, &imageColor, sizeof(SkPMCo
lor), 0, 0)); |
610 REPORTER_ASSERT(reporter, imageColor == *bitmap.getAddr32(0, 0)); | 602 REPORTER_ASSERT(reporter, imageColor == *bitmap.getAddr32(0, 0)); |
611 } | 603 } |
612 | 604 |
613 static void test_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* imag
e, SkImage::LegacyBitmapMode mode) { | 605 static void test_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* imag
e, SkImage::LegacyBitmapMode mode) { |
614 if (!image) { | |
615 ERRORF(reporter, "Failed to create image."); | |
616 return; | |
617 } | |
618 SkBitmap bitmap; | 606 SkBitmap bitmap; |
619 REPORTER_ASSERT(reporter, image->asLegacyBitmap(&bitmap, mode)); | 607 REPORTER_ASSERT(reporter, image->asLegacyBitmap(&bitmap, mode)); |
620 check_legacy_bitmap(reporter, image, bitmap, mode); | 608 check_legacy_bitmap(reporter, image, bitmap, mode); |
621 | 609 |
622 // Test subsetting to exercise the rowBytes logic. | 610 // Test subsetting to exercise the rowBytes logic. |
623 SkBitmap tmp; | 611 SkBitmap tmp; |
624 REPORTER_ASSERT(reporter, bitmap.extractSubset(&tmp, SkIRect::MakeWH(image->
width() / 2, | 612 REPORTER_ASSERT(reporter, bitmap.extractSubset(&tmp, SkIRect::MakeWH(image->
width() / 2, |
625 image->
height() / 2))); | 613 image->
height() / 2))); |
626 sk_sp<SkImage> subsetImage(SkImage::MakeFromBitmap(tmp)); | 614 sk_sp<SkImage> subsetImage(SkImage::MakeFromBitmap(tmp)); |
627 REPORTER_ASSERT(reporter, subsetImage.get()); | 615 REPORTER_ASSERT(reporter, subsetImage.get()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 SkImage::kRW_LegacyBitmapMode, | 647 SkImage::kRW_LegacyBitmapMode, |
660 }; | 648 }; |
661 for (auto& mode : modes) { | 649 for (auto& mode : modes) { |
662 sk_sp<SkImage> image(create_gpu_image(ctxInfo.grContext())); | 650 sk_sp<SkImage> image(create_gpu_image(ctxInfo.grContext())); |
663 test_legacy_bitmap(reporter, image.get(), mode); | 651 test_legacy_bitmap(reporter, image.get(), mode); |
664 } | 652 } |
665 } | 653 } |
666 #endif | 654 #endif |
667 | 655 |
668 static void test_peek(skiatest::Reporter* reporter, SkImage* image, bool expectP
eekSuccess) { | 656 static void test_peek(skiatest::Reporter* reporter, SkImage* image, bool expectP
eekSuccess) { |
669 if (!image) { | |
670 ERRORF(reporter, "Failed to create image!"); | |
671 return; | |
672 } | |
673 SkPixmap pm; | 657 SkPixmap pm; |
674 bool success = image->peekPixels(&pm); | 658 bool success = image->peekPixels(&pm); |
675 REPORTER_ASSERT(reporter, expectPeekSuccess == success); | 659 REPORTER_ASSERT(reporter, expectPeekSuccess == success); |
676 if (success) { | 660 if (success) { |
677 const SkImageInfo& info = pm.info(); | 661 const SkImageInfo& info = pm.info(); |
678 REPORTER_ASSERT(reporter, 20 == info.width()); | 662 REPORTER_ASSERT(reporter, 20 == info.width()); |
679 REPORTER_ASSERT(reporter, 20 == info.height()); | 663 REPORTER_ASSERT(reporter, 20 == info.height()); |
680 REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType()); | 664 REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType()); |
681 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() || | 665 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() || |
682 kOpaque_SkAlphaType == info.alphaType()); | 666 kOpaque_SkAlphaType == info.alphaType()); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 otherContextInfo.testContext()->makeCurrent(); | 850 otherContextInfo.testContext()->makeCurrent(); |
867 sk_sp<SkImage> otherContextImage = create_gpu_image(otherContextInfo
.grContext()); | 851 sk_sp<SkImage> otherContextImage = create_gpu_image(otherContextInfo
.grContext()); |
868 testContext->makeCurrent(); | 852 testContext->makeCurrent(); |
869 return otherContextImage; | 853 return otherContextImage; |
870 }, false }, | 854 }, false }, |
871 }; | 855 }; |
872 | 856 |
873 | 857 |
874 for (auto testCase : testCases) { | 858 for (auto testCase : testCases) { |
875 sk_sp<SkImage> image(testCase.fImageFactory()); | 859 sk_sp<SkImage> image(testCase.fImageFactory()); |
876 if (!image) { | |
877 ERRORF(reporter, "Failed to create image!"); | |
878 continue; | |
879 } | |
880 | 860 |
881 // This isn't currently used in the implementation, just set any old val
ues. | 861 // This isn't currently used in the implementation, just set any old val
ues. |
882 SkImage::DeferredTextureImageUsageParams params; | 862 SkImage::DeferredTextureImageUsageParams params; |
883 params.fQuality = kLow_SkFilterQuality; | 863 params.fQuality = kLow_SkFilterQuality; |
884 params.fMatrix = SkMatrix::I(); | 864 params.fMatrix = SkMatrix::I(); |
885 | 865 |
886 size_t size = image->getDeferredTextureImageData(*proxy, ¶ms, 1, nul
lptr); | 866 size_t size = image->getDeferredTextureImageData(*proxy, ¶ms, 1, nul
lptr); |
887 | 867 |
888 static const char *const kFS[] = { "fail", "succeed" }; | 868 static const char *const kFS[] = { "fail", "succeed" }; |
889 if (SkToBool(size) != testCase.fExpectation) { | 869 if (SkToBool(size) != testCase.fExpectation) { |
(...skipping 22 matching lines...) Expand all Loading... |
912 otherContextInfo.grContext(), buffer, budgeted)); | 892 otherContextInfo.grContext(), buffer, budgeted)); |
913 REPORTER_ASSERT(reporter, !newImage2); | 893 REPORTER_ASSERT(reporter, !newImage2); |
914 testContext->makeCurrent(); | 894 testContext->makeCurrent(); |
915 } | 895 } |
916 } | 896 } |
917 sk_free(buffer); | 897 sk_free(buffer); |
918 } | 898 } |
919 } | 899 } |
920 } | 900 } |
921 #endif | 901 #endif |
OLD | NEW |