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 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 { create_image_large, {{SkMatrix::I(), kMedium_SkFilterQuality, 5}, | 914 { create_image_large, {{SkMatrix::I(), kMedium_SkFilterQuality, 5}, |
915 {SkMatrix::I(), kMedium_SkFilterQuality, 4}}, | 915 {SkMatrix::I(), kMedium_SkFilterQuality, 4}}, |
916 kMedium_SkFilterQuality, 16, true}, | 916 kMedium_SkFilterQuality, 16, true}, |
917 }; | 917 }; |
918 | 918 |
919 | 919 |
920 for (auto testCase : testCases) { | 920 for (auto testCase : testCases) { |
921 sk_sp<SkImage> image(testCase.fImageFactory()); | 921 sk_sp<SkImage> image(testCase.fImageFactory()); |
922 size_t size = image->getDeferredTextureImageData(*proxy, testCase.fParam
s.data(), | 922 size_t size = image->getDeferredTextureImageData(*proxy, testCase.fParam
s.data(), |
923 static_cast<int>(testCa
se.fParams.size()), | 923 static_cast<int>(testCa
se.fParams.size()), |
924 nullptr, SkSourceGammaT
reatment::kIgnore); | 924 nullptr); |
| 925 |
925 static const char *const kFS[] = { "fail", "succeed" }; | 926 static const char *const kFS[] = { "fail", "succeed" }; |
926 if (SkToBool(size) != testCase.fExpectation) { | 927 if (SkToBool(size) != testCase.fExpectation) { |
927 ERRORF(reporter, "This image was expected to %s but did not.", | 928 ERRORF(reporter, "This image was expected to %s but did not.", |
928 kFS[testCase.fExpectation]); | 929 kFS[testCase.fExpectation]); |
929 } | 930 } |
930 if (size) { | 931 if (size) { |
931 void* buffer = sk_malloc_throw(size); | 932 void* buffer = sk_malloc_throw(size); |
932 void* misaligned = reinterpret_cast<void*>(reinterpret_cast<intptr_t
>(buffer) + 3); | 933 void* misaligned = reinterpret_cast<void*>(reinterpret_cast<intptr_t
>(buffer) + 3); |
933 if (image->getDeferredTextureImageData(*proxy, testCase.fParams.data
(), | 934 if (image->getDeferredTextureImageData(*proxy, testCase.fParams.data
(), |
934 static_cast<int>(testCase.fPa
rams.size()), | 935 static_cast<int>(testCase.fPa
rams.size()), |
935 misaligned, SkSourceGammaTrea
tment::kIgnore)) { | 936 misaligned)) { |
936 ERRORF(reporter, "Should fail when buffer is misaligned."); | 937 ERRORF(reporter, "Should fail when buffer is misaligned."); |
937 } | 938 } |
938 if (!image->getDeferredTextureImageData(*proxy, testCase.fParams.dat
a(), | 939 if (!image->getDeferredTextureImageData(*proxy, testCase.fParams.dat
a(), |
939 static_cast<int>(testCase.fP
arams.size()), | 940 static_cast<int>(testCase.fP
arams.size()), |
940 buffer, SkSourceGammaTreatme
nt::kIgnore)) { | 941 buffer)) { |
941 ERRORF(reporter, "deferred image size succeeded but creation fai
led."); | 942 ERRORF(reporter, "deferred image size succeeded but creation fai
led."); |
942 } else { | 943 } else { |
943 for (auto budgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { | 944 for (auto budgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { |
944 sk_sp<SkImage> newImage( | 945 sk_sp<SkImage> newImage( |
945 SkImage::MakeFromDeferredTextureImageData(context, buffe
r, budgeted)); | 946 SkImage::MakeFromDeferredTextureImageData(context, buffe
r, budgeted)); |
946 REPORTER_ASSERT(reporter, newImage != nullptr); | 947 REPORTER_ASSERT(reporter, newImage != nullptr); |
947 if (newImage) { | 948 if (newImage) { |
948 // Scale the image in software for comparison. | 949 // Scale the image in software for comparison. |
949 SkImageInfo scaled_info = SkImageInfo::MakeN32( | 950 SkImageInfo scaled_info = SkImageInfo::MakeN32( |
950 image->width() / testCase.fExpectedScaleFactor, | 951 image->width() / testCase.fExpectedScaleFactor, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 SkBitmap bm1; | 1017 SkBitmap bm1; |
1017 bm1.allocPixels(SkImageInfo::MakeN32(256, 256, kUnpremul_SkAlphaType)); | 1018 bm1.allocPixels(SkImageInfo::MakeN32(256, 256, kUnpremul_SkAlphaType)); |
1018 bm0.readPixels(bm1.info(), bm1.getPixels(), bm1.rowBytes(), 0, 0); | 1019 bm0.readPixels(bm1.info(), bm1.getPixels(), bm1.rowBytes(), 0, 0); |
1019 | 1020 |
1020 SkBitmap bm2; | 1021 SkBitmap bm2; |
1021 bm2.allocPixels(SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType)); | 1022 bm2.allocPixels(SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType)); |
1022 bm1.readPixels(bm2.info(), bm2.getPixels(), bm2.rowBytes(), 0, 0); | 1023 bm1.readPixels(bm2.info(), bm2.getPixels(), bm2.rowBytes(), 0, 0); |
1023 | 1024 |
1024 REPORTER_ASSERT(reporter, equal(bm0, bm2)); | 1025 REPORTER_ASSERT(reporter, equal(bm0, bm2)); |
1025 } | 1026 } |
OLD | NEW |