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

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

Powered by Google App Engine
This is Rietveld 408576698