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