Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: tests/ImageTest.cpp

Issue 2242883004: Store mipmap levels in deferred texture image (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixing opening brace location. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/image/SkImage_Gpu.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 870 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 881
882 testContext->makeCurrent(); 882 testContext->makeCurrent();
883 REPORTER_ASSERT(reporter, proxy); 883 REPORTER_ASSERT(reporter, proxy);
884 struct { 884 struct {
885 std::function<sk_sp<SkImage> ()> fImageFactory; 885 std::function<sk_sp<SkImage> ()> fImageFactory;
886 std::vector<SkImage::DeferredTextureImageUsageParams> fParams; 886 std::vector<SkImage::DeferredTextureImageUsageParams> fParams;
887 SkFilterQuality fExpectedQuality; 887 SkFilterQuality fExpectedQuality;
888 int fExpectedScaleFact or; 888 int fExpectedScaleFact or;
889 bool fExpectation; 889 bool fExpectation;
890 } testCases[] = { 890 } testCases[] = {
891 { create_image, {{}}, kNone_SkFilterQuality, 1, true }, 891 { create_image, {{SkMatrix::I(), kNone_SkFilterQuality, 0}},
892 { create_codec_image, {{}}, kNone_SkFilterQuality, 1, true }, 892 kNone_SkFilterQuality, 1, true },
893 { create_data_image, {{}}, kNone_SkFilterQuality, 1, true }, 893 { create_codec_image, {{SkMatrix::I(), kNone_SkFilterQuality, 0}},
894 { create_picture_image, {{}}, kNone_SkFilterQuality, 1, false }, 894 kNone_SkFilterQuality, 1, true },
895 { [context] { return create_gpu_image(context); }, {{}}, kNone_SkFilterQ uality, 1, false }, 895 { create_data_image, {{SkMatrix::I(), kNone_SkFilterQuality, 0}},
896 kNone_SkFilterQuality, 1, true },
897 { create_picture_image, {{SkMatrix::I(), kNone_SkFilterQuality, 0}},
898 kNone_SkFilterQuality, 1, false },
899 { [context] { return create_gpu_image(context); },
900 {{SkMatrix::I(), kNone_SkFilterQuality, 0}},
901 kNone_SkFilterQuality, 1, false },
896 // Create a texture image in a another GrContext. 902 // Create a texture image in a another GrContext.
897 { [testContext, otherContextInfo] { 903 { [testContext, otherContextInfo] {
898 otherContextInfo.testContext()->makeCurrent(); 904 otherContextInfo.testContext()->makeCurrent();
899 sk_sp<SkImage> otherContextImage = create_gpu_image(otherContextInfo .grContext()); 905 sk_sp<SkImage> otherContextImage = create_gpu_image(otherContextInfo .grContext());
900 testContext->makeCurrent(); 906 testContext->makeCurrent();
901 return otherContextImage; 907 return otherContextImage;
902 }, {{}}, kNone_SkFilterQuality, 1, false }, 908 }, {{SkMatrix::I(), kNone_SkFilterQuality, 0}},
909 kNone_SkFilterQuality, 1, false },
903 // Create an image that is too large to upload. 910 // Create an image that is too large to upload.
904 { create_image_large, {{}}, kNone_SkFilterQuality, 1, false }, 911 { create_image_large, {{SkMatrix::I(), kNone_SkFilterQuality, 0}},
912 kNone_SkFilterQuality, 1, false },
905 // Create an image that is too large, but is scaled to an acceptable siz e. 913 // Create an image that is too large, but is scaled to an acceptable siz e.
906 { create_image_large, {{SkMatrix::I(), kMedium_SkFilterQuality, 4}}, 914 { create_image_large, {{SkMatrix::I(), kMedium_SkFilterQuality, 4}},
907 kMedium_SkFilterQuality, 16, true}, 915 kMedium_SkFilterQuality, 16, true},
908 // Create an image with multiple low filter qualities, make sure we roun d up. 916 // Create an image with multiple low filter qualities, make sure we roun d up.
909 { create_image_large, {{SkMatrix::I(), kNone_SkFilterQuality, 4}, 917 { create_image_large, {{SkMatrix::I(), kNone_SkFilterQuality, 4},
910 {SkMatrix::I(), kMedium_SkFilterQuality, 4}}, 918 {SkMatrix::I(), kMedium_SkFilterQuality, 4}},
911 kMedium_SkFilterQuality, 16, true}, 919 kMedium_SkFilterQuality, 16, true},
912 // Create an image with multiple prescale levels, make sure we chose the minimum scale. 920 // Create an image with multiple prescale levels, make sure we chose the minimum scale.
913 { create_image_large, {{SkMatrix::I(), kMedium_SkFilterQuality, 5}, 921 { create_image_large, {{SkMatrix::I(), kMedium_SkFilterQuality, 5},
914 {SkMatrix::I(), kMedium_SkFilterQuality, 4}}, 922 {SkMatrix::I(), kMedium_SkFilterQuality, 4}},
915 kMedium_SkFilterQuality, 16, true}, 923 kMedium_SkFilterQuality, 16, true},
916 }; 924 };
917 925
918 926
919 for (auto testCase : testCases) { 927 for (auto testCase : testCases) {
920 sk_sp<SkImage> image(testCase.fImageFactory()); 928 sk_sp<SkImage> image(testCase.fImageFactory());
921 size_t size = image->getDeferredTextureImageData(*proxy, testCase.fParam s.data(), 929 size_t size = image->getDeferredTextureImageData(*proxy, testCase.fParam s.data(),
922 static_cast<int>(testCa se.fParams.size()), 930 static_cast<int>(testCa se.fParams.size()),
923 nullptr); 931 nullptr, SkSourceGammaT reatment::kIgnore);
924
925 static const char *const kFS[] = { "fail", "succeed" }; 932 static const char *const kFS[] = { "fail", "succeed" };
926 if (SkToBool(size) != testCase.fExpectation) { 933 if (SkToBool(size) != testCase.fExpectation) {
927 ERRORF(reporter, "This image was expected to %s but did not.", 934 ERRORF(reporter, "This image was expected to %s but did not.",
928 kFS[testCase.fExpectation]); 935 kFS[testCase.fExpectation]);
929 } 936 }
930 if (size) { 937 if (size) {
931 void* buffer = sk_malloc_throw(size); 938 void* buffer = sk_malloc_throw(size);
932 void* misaligned = reinterpret_cast<void*>(reinterpret_cast<intptr_t >(buffer) + 3); 939 void* misaligned = reinterpret_cast<void*>(reinterpret_cast<intptr_t >(buffer) + 3);
933 if (image->getDeferredTextureImageData(*proxy, testCase.fParams.data (), 940 if (image->getDeferredTextureImageData(*proxy, testCase.fParams.data (),
934 static_cast<int>(testCase.fPa rams.size()), 941 static_cast<int>(testCase.fPa rams.size()),
935 misaligned)) { 942 misaligned, SkSourceGammaTrea tment::kIgnore)) {
936 ERRORF(reporter, "Should fail when buffer is misaligned."); 943 ERRORF(reporter, "Should fail when buffer is misaligned.");
937 } 944 }
938 if (!image->getDeferredTextureImageData(*proxy, testCase.fParams.dat a(), 945 if (!image->getDeferredTextureImageData(*proxy, testCase.fParams.dat a(),
939 static_cast<int>(testCase.fP arams.size()), 946 static_cast<int>(testCase.fP arams.size()),
940 buffer)) { 947 buffer, SkSourceGammaTreatme nt::kIgnore)) {
941 ERRORF(reporter, "deferred image size succeeded but creation fai led."); 948 ERRORF(reporter, "deferred image size succeeded but creation fai led.");
942 } else { 949 } else {
943 for (auto budgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { 950 for (auto budgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) {
944 sk_sp<SkImage> newImage( 951 sk_sp<SkImage> newImage(
945 SkImage::MakeFromDeferredTextureImageData(context, buffe r, budgeted)); 952 SkImage::MakeFromDeferredTextureImageData(context, buffe r, budgeted));
946 REPORTER_ASSERT(reporter, newImage != nullptr); 953 REPORTER_ASSERT(reporter, newImage != nullptr);
947 if (newImage) { 954 if (newImage) {
948 // Scale the image in software for comparison. 955 // Scale the image in software for comparison.
949 SkImageInfo scaled_info = SkImageInfo::MakeN32( 956 SkImageInfo scaled_info = SkImageInfo::MakeN32(
950 image->width() / testCase.fE xpectedScaleFactor, 957 image->width() / testCase.fE xpectedScaleFactor,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 SkBitmap bm1; 1023 SkBitmap bm1;
1017 bm1.allocPixels(SkImageInfo::MakeN32(256, 256, kUnpremul_SkAlphaType)); 1024 bm1.allocPixels(SkImageInfo::MakeN32(256, 256, kUnpremul_SkAlphaType));
1018 bm0.readPixels(bm1.info(), bm1.getPixels(), bm1.rowBytes(), 0, 0); 1025 bm0.readPixels(bm1.info(), bm1.getPixels(), bm1.rowBytes(), 0, 0);
1019 1026
1020 SkBitmap bm2; 1027 SkBitmap bm2;
1021 bm2.allocPixels(SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType)); 1028 bm2.allocPixels(SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType));
1022 bm1.readPixels(bm2.info(), bm2.getPixels(), bm2.rowBytes(), 0, 0); 1029 bm1.readPixels(bm2.info(), bm2.getPixels(), bm2.rowBytes(), 0, 0);
1023 1030
1024 REPORTER_ASSERT(reporter, equal(bm0, bm2)); 1031 REPORTER_ASSERT(reporter, equal(bm0, bm2));
1025 } 1032 }
OLDNEW
« no previous file with comments | « src/image/SkImage_Gpu.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698