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

Side by Side Diff: tests/ImageTest.cpp

Issue 1776693002: Add deferred texture upload API. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase on sk_skp Created 4 years, 9 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 "DMGpuSupport.h" 10 #include "DMGpuSupport.h"
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 SkBudge ted::kNo)); 815 SkBudge ted::kNo));
816 if (!texImage) { 816 if (!texImage) {
817 ERRORF(reporter, "NewTextureFromPixmap failed."); 817 ERRORF(reporter, "NewTextureFromPixmap failed.");
818 } else { 818 } else {
819 check_images_same(reporter, image, texImage); 819 check_images_same(reporter, image, texImage);
820 } 820 }
821 } 821 }
822 } 822 }
823 } 823 }
824 824
825 DEF_GPUTEST_FOR_NATIVE_CONTEXT(DeferredTextureImage, reporter, context, glContex t) {
826 SkAutoTUnref<GrContextThreadSafeProxy> proxy(context->threadSafeProxy());
827
828 GrContextFactory otherFactory;
829 GrContextFactory::ContextInfo otherContextInfo =
830 otherFactory.getContextInfo(GrContextFactory::kNative_GLContextType);
831
832 glContext->makeCurrent();
833 REPORTER_ASSERT(reporter, proxy);
834 struct {
835 std::function<SkImage *()> fImageFactory;
836 bool fExpectation;
837 } testCases[] = {
838 { create_image, true },
839 { create_codec_image, true },
840 { create_data_image, true },
841 { create_picture_image, false },
842 { [context] { return create_gpu_image(context); }, false },
843 // Create a texture image in a another GrContext.
844 { [glContext, otherContextInfo] {
845 otherContextInfo.fGLContext->makeCurrent();
846 SkImage *otherContextImage = create_gpu_image(otherContextInfo.fGrCo ntext);
847 glContext->makeCurrent();
848 return otherContextImage;
849 }, false },
850 };
851
852
853 for (auto testCase : testCases) {
854 SkAutoTUnref<SkImage> image(testCase.fImageFactory());
855
856 // This isn't currently used in the implementation, just set any old val ues.
857 SkImage::DeferredTextureImageUsageParams params;
858 params.fQuality = kLow_SkFilterQuality;
859 params.fMatrix = SkMatrix::I();
860
861 size_t size = image->getDeferredTextureImageData(*proxy, &params, 1, nul lptr);
862
863 static const char *const kFS[] = { "fail", "succeed" };
864 if (SkToBool(size) != testCase.fExpectation) {
865 ERRORF(reporter, "This image was expected to %s but did not.",
866 kFS[testCase.fExpectation]);
867 }
868 if (size) {
869 void* buffer = sk_malloc_throw(size);
870 void* misaligned = reinterpret_cast<void*>(reinterpret_cast<intptr_t >(buffer) + 3);
871 if (image->getDeferredTextureImageData(*proxy, &params, 1, misaligne d)) {
872 ERRORF(reporter, "Should fail when buffer is misaligned.");
873 }
874 if (!image->getDeferredTextureImageData(*proxy, &params, 1, buffer)) {
875 ERRORF(reporter, "deferred image size succeeded but creation fai led.");
876 } else {
877 for (auto budgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) {
878 SkAutoTUnref<SkImage> newImage(
879 SkImage::NewFromDeferredTextureImageData(context, buffer , budgeted));
880 REPORTER_ASSERT(reporter, SkToBool(newImage));
881 if (newImage) {
882 check_images_same(reporter, image, newImage);
883 }
884 // The other context should not be able to create images fro m texture data
885 // created by the original context.
886 SkAutoTUnref<SkImage> newImage2(SkImage::NewFromDeferredText ureImageData(
887 otherContextInfo.fGrContext, buffer, budgeted));
888 REPORTER_ASSERT(reporter, !newImage2);
889 glContext->makeCurrent();
890 }
891 }
892 sk_free(buffer);
893 }
894 }
895 }
825 #endif 896 #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