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

Side by Side Diff: tests/ImageTest.cpp

Issue 2007113008: Add prescale option to deferred params (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: build fix Created 4 years, 6 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 "DMGpuSupport.h" 11 #include "DMGpuSupport.h"
11 12
12 #include "SkAutoPixmapStorage.h" 13 #include "SkAutoPixmapStorage.h"
13 #include "SkBitmap.h" 14 #include "SkBitmap.h"
14 #include "SkCanvas.h" 15 #include "SkCanvas.h"
15 #include "SkData.h" 16 #include "SkData.h"
16 #include "SkImageEncoder.h" 17 #include "SkImageEncoder.h"
17 #include "SkImageGenerator.h" 18 #include "SkImageGenerator.h"
18 #include "SkImage_Base.h" 19 #include "SkImage_Base.h"
19 #include "SkPicture.h" 20 #include "SkPicture.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 SkPaint paint; 61 SkPaint paint;
61 paint.setColor(SK_ColorBLACK); 62 paint.setColor(SK_ColorBLACK);
62 canvas->drawRect(SkRect::MakeXYWH(5, 5, 10, 10), paint); 63 canvas->drawRect(SkRect::MakeXYWH(5, 5, 10, 10), paint);
63 } 64 }
64 static sk_sp<SkImage> create_image() { 65 static sk_sp<SkImage> create_image() {
65 const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); 66 const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType);
66 auto surface(SkSurface::MakeRaster(info)); 67 auto surface(SkSurface::MakeRaster(info));
67 draw_image_test_pattern(surface->getCanvas()); 68 draw_image_test_pattern(surface->getCanvas());
68 return surface->makeImageSnapshot(); 69 return surface->makeImageSnapshot();
69 } 70 }
71 static sk_sp<SkImage> create_image_large() {
72 const SkImageInfo info = SkImageInfo::MakeN32(32000, 32, kOpaque_SkAlphaType );
73 auto surface(SkSurface::MakeRaster(info));
74 surface->getCanvas()->clear(SK_ColorWHITE);
75 SkPaint paint;
76 paint.setColor(SK_ColorBLACK);
77 surface->getCanvas()->drawRect(SkRect::MakeXYWH(4000, 2, 28000, 30), paint);
78 return surface->makeImageSnapshot();
79 }
70 80
71 static SkData* create_image_data(SkImageInfo* info) { 81 static SkData* create_image_data(SkImageInfo* info) {
72 *info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); 82 *info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType);
73 const size_t rowBytes = info->minRowBytes(); 83 const size_t rowBytes = info->minRowBytes();
74 SkAutoTUnref<SkData> data(SkData::NewUninitialized(rowBytes * info->height() )); 84 SkAutoTUnref<SkData> data(SkData::NewUninitialized(rowBytes * info->height() ));
75 { 85 {
76 SkBitmap bm; 86 SkBitmap bm;
77 bm.installPixels(*info, data->writable_data(), rowBytes); 87 bm.installPixels(*info, data->writable_data(), rowBytes);
78 SkCanvas canvas(bm); 88 SkCanvas canvas(bm);
79 draw_image_test_pattern(&canvas); 89 draw_image_test_pattern(&canvas);
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 sk_gpu_test::TestContext* testContext = ctxInfo.testContext(); 840 sk_gpu_test::TestContext* testContext = ctxInfo.testContext();
831 SkAutoTUnref<GrContextThreadSafeProxy> proxy(context->threadSafeProxy()); 841 SkAutoTUnref<GrContextThreadSafeProxy> proxy(context->threadSafeProxy());
832 842
833 GrContextFactory otherFactory; 843 GrContextFactory otherFactory;
834 ContextInfo otherContextInfo = 844 ContextInfo otherContextInfo =
835 otherFactory.getContextInfo(GrContextFactory::kNativeGL_ContextType); 845 otherFactory.getContextInfo(GrContextFactory::kNativeGL_ContextType);
836 846
837 testContext->makeCurrent(); 847 testContext->makeCurrent();
838 REPORTER_ASSERT(reporter, proxy); 848 REPORTER_ASSERT(reporter, proxy);
839 struct { 849 struct {
840 std::function<sk_sp<SkImage> ()> fImageFactory; 850 std::function<sk_sp<SkImage> ()> fImageFactory;
841 bool fExpectation; 851 std::vector<SkImage::DeferredTextureImageUsageParams> fParams;
852 SkFilterQuality fExpectedQuality;
853 int fExpectedScaleFact or;
854 bool fExpectation;
842 } testCases[] = { 855 } testCases[] = {
843 { create_image, true }, 856 { create_image, {{}}, kNone_SkFilterQuality, 1, true },
844 { create_codec_image, true }, 857 { create_codec_image, {{}}, kNone_SkFilterQuality, 1, true },
845 { create_data_image, true }, 858 { create_data_image, {{}}, kNone_SkFilterQuality, 1, true },
846 { create_picture_image, false }, 859 { create_picture_image, {{}}, kNone_SkFilterQuality, 1, false },
847 { [context] { return create_gpu_image(context); }, false }, 860 { [context] { return create_gpu_image(context); }, {{}}, kNone_SkFilterQ uality, 1, false },
848 // Create a texture image in a another GrContext. 861 // Create a texture image in a another GrContext.
849 { [testContext, otherContextInfo] { 862 { [testContext, otherContextInfo] {
850 otherContextInfo.testContext()->makeCurrent(); 863 otherContextInfo.testContext()->makeCurrent();
851 sk_sp<SkImage> otherContextImage = create_gpu_image(otherContextInfo .grContext()); 864 sk_sp<SkImage> otherContextImage = create_gpu_image(otherContextInfo .grContext());
852 testContext->makeCurrent(); 865 testContext->makeCurrent();
853 return otherContextImage; 866 return otherContextImage;
854 }, false }, 867 }, {{}}, kNone_SkFilterQuality, 1, false },
868 // Create an image that is too large to upload.
869 { create_image_large, {{}}, kNone_SkFilterQuality, 1, false },
870 // Create an image that is too large, but is scaled to an acceptable siz e.
871 { create_image_large, {{SkMatrix::I(), kMedium_SkFilterQuality, 4}},
872 kMedium_SkFilterQuality, 16, true},
873 // Create an image with multiple low filter qualities, make sure we roun d up.
874 { create_image_large, {{SkMatrix::I(), kNone_SkFilterQuality, 4},
875 {SkMatrix::I(), kMedium_SkFilterQuality, 4}},
876 kMedium_SkFilterQuality, 16, true},
877 // Create an image with multiple prescale levels, make sure we chose the minimum scale.
878 { create_image_large, {{SkMatrix::I(), kMedium_SkFilterQuality, 5},
879 {SkMatrix::I(), kMedium_SkFilterQuality, 4}},
880 kMedium_SkFilterQuality, 16, true},
855 }; 881 };
856 882
857 883
858 for (auto testCase : testCases) { 884 for (auto testCase : testCases) {
859 sk_sp<SkImage> image(testCase.fImageFactory()); 885 sk_sp<SkImage> image(testCase.fImageFactory());
860 886 size_t size = image->getDeferredTextureImageData(*proxy, testCase.fParam s.data(),
861 // This isn't currently used in the implementation, just set any old val ues. 887 static_cast<int>(testCa se.fParams.size()),
862 SkImage::DeferredTextureImageUsageParams params; 888 nullptr);
863 params.fQuality = kLow_SkFilterQuality;
864 params.fMatrix = SkMatrix::I();
865
866 size_t size = image->getDeferredTextureImageData(*proxy, &params, 1, nul lptr);
867 889
868 static const char *const kFS[] = { "fail", "succeed" }; 890 static const char *const kFS[] = { "fail", "succeed" };
869 if (SkToBool(size) != testCase.fExpectation) { 891 if (SkToBool(size) != testCase.fExpectation) {
870 ERRORF(reporter, "This image was expected to %s but did not.", 892 ERRORF(reporter, "This image was expected to %s but did not.",
871 kFS[testCase.fExpectation]); 893 kFS[testCase.fExpectation]);
872 } 894 }
873 if (size) { 895 if (size) {
874 void* buffer = sk_malloc_throw(size); 896 void* buffer = sk_malloc_throw(size);
875 void* misaligned = reinterpret_cast<void*>(reinterpret_cast<intptr_t >(buffer) + 3); 897 void* misaligned = reinterpret_cast<void*>(reinterpret_cast<intptr_t >(buffer) + 3);
876 if (image->getDeferredTextureImageData(*proxy, &params, 1, misaligne d)) { 898 if (image->getDeferredTextureImageData(*proxy, testCase.fParams.data (),
899 static_cast<int>(testCase.fPa rams.size()),
900 misaligned)) {
877 ERRORF(reporter, "Should fail when buffer is misaligned."); 901 ERRORF(reporter, "Should fail when buffer is misaligned.");
878 } 902 }
879 if (!image->getDeferredTextureImageData(*proxy, &params, 1, buffer)) { 903 if (!image->getDeferredTextureImageData(*proxy, testCase.fParams.dat a(),
904 static_cast<int>(testCase.fP arams.size()),
905 buffer)) {
880 ERRORF(reporter, "deferred image size succeeded but creation fai led."); 906 ERRORF(reporter, "deferred image size succeeded but creation fai led.");
881 } else { 907 } else {
882 for (auto budgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { 908 for (auto budgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) {
883 sk_sp<SkImage> newImage( 909 sk_sp<SkImage> newImage(
884 SkImage::MakeFromDeferredTextureImageData(context, buffe r, budgeted)); 910 SkImage::MakeFromDeferredTextureImageData(context, buffe r, budgeted));
885 REPORTER_ASSERT(reporter, newImage != nullptr); 911 REPORTER_ASSERT(reporter, newImage != nullptr);
886 if (newImage) { 912 if (newImage) {
887 check_images_same(reporter, image.get(), newImage.get()) ; 913 // Scale the image in software for comparison.
914 SkImageInfo scaled_info = SkImageInfo::MakeN32(
915 image->width() / testCase.fExpectedScaleFactor,
916 image->height() / testCase.fExpectedScaleFactor,
917 image->isOpaque() ? kOpaque_SkAlphaType : kPremu l_SkAlphaType);
918 SkAutoPixmapStorage scaled;
919 scaled.alloc(scaled_info);
920 image->scalePixels(scaled, testCase.fExpectedQuality);
921 sk_sp<SkImage> scaledImage = SkImage::MakeRasterCopy(sca led);
922 check_images_same(reporter, scaledImage.get(), newImage. get());
888 } 923 }
889 // The other context should not be able to create images fro m texture data 924 // The other context should not be able to create images fro m texture data
890 // created by the original context. 925 // created by the original context.
891 sk_sp<SkImage> newImage2(SkImage::MakeFromDeferredTextureIma geData( 926 sk_sp<SkImage> newImage2(SkImage::MakeFromDeferredTextureIma geData(
892 otherContextInfo.grContext(), buffer, budgeted)); 927 otherContextInfo.grContext(), buffer, budgeted));
893 REPORTER_ASSERT(reporter, !newImage2); 928 REPORTER_ASSERT(reporter, !newImage2);
894 testContext->makeCurrent(); 929 testContext->makeCurrent();
895 } 930 }
896 } 931 }
897 sk_free(buffer); 932 sk_free(buffer);
898 } 933 }
899 } 934 }
900 } 935 }
901 #endif 936 #endif
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