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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/image/SkImage_Gpu.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ImageTest.cpp
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index aaf601d042f49eb8c2bd4d03fad0bfe019543e56..9dfbe3695ba51c8ef76f9be5da14f3e6e5e0c7a6 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -822,4 +822,75 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(NewTextureFromPixmap, reporter, context) {
}
}
+DEF_GPUTEST_FOR_NATIVE_CONTEXT(DeferredTextureImage, reporter, context, glContext) {
+ SkAutoTUnref<GrContextThreadSafeProxy> proxy(context->threadSafeProxy());
+
+ GrContextFactory otherFactory;
+ GrContextFactory::ContextInfo otherContextInfo =
+ otherFactory.getContextInfo(GrContextFactory::kNative_GLContextType);
+
+ glContext->makeCurrent();
+ REPORTER_ASSERT(reporter, proxy);
+ struct {
+ std::function<SkImage *()> fImageFactory;
+ bool fExpectation;
+ } testCases[] = {
+ { create_image, true },
+ { create_codec_image, true },
+ { create_data_image, true },
+ { create_picture_image, false },
+ { [context] { return create_gpu_image(context); }, false },
+ // Create a texture image in a another GrContext.
+ { [glContext, otherContextInfo] {
+ otherContextInfo.fGLContext->makeCurrent();
+ SkImage *otherContextImage = create_gpu_image(otherContextInfo.fGrContext);
+ glContext->makeCurrent();
+ return otherContextImage;
+ }, false },
+ };
+
+
+ for (auto testCase : testCases) {
+ SkAutoTUnref<SkImage> image(testCase.fImageFactory());
+
+ // This isn't currently used in the implementation, just set any old values.
+ SkImage::DeferredTextureImageUsageParams params;
+ params.fQuality = kLow_SkFilterQuality;
+ params.fMatrix = SkMatrix::I();
+
+ size_t size = image->getDeferredTextureImageData(*proxy, &params, 1, nullptr);
+
+ static const char *const kFS[] = { "fail", "succeed" };
+ if (SkToBool(size) != testCase.fExpectation) {
+ ERRORF(reporter, "This image was expected to %s but did not.",
+ kFS[testCase.fExpectation]);
+ }
+ if (size) {
+ void* buffer = sk_malloc_throw(size);
+ void* misaligned = reinterpret_cast<void*>(reinterpret_cast<intptr_t>(buffer) + 3);
+ if (image->getDeferredTextureImageData(*proxy, &params, 1, misaligned)) {
+ ERRORF(reporter, "Should fail when buffer is misaligned.");
+ }
+ if (!image->getDeferredTextureImageData(*proxy, &params, 1, buffer)) {
+ ERRORF(reporter, "deferred image size succeeded but creation failed.");
+ } else {
+ for (auto budgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) {
+ SkAutoTUnref<SkImage> newImage(
+ SkImage::NewFromDeferredTextureImageData(context, buffer, budgeted));
+ REPORTER_ASSERT(reporter, SkToBool(newImage));
+ if (newImage) {
+ check_images_same(reporter, image, newImage);
+ }
+ // The other context should not be able to create images from texture data
+ // created by the original context.
+ SkAutoTUnref<SkImage> newImage2(SkImage::NewFromDeferredTextureImageData(
+ otherContextInfo.fGrContext, buffer, budgeted));
+ REPORTER_ASSERT(reporter, !newImage2);
+ glContext->makeCurrent();
+ }
+ }
+ sk_free(buffer);
+ }
+ }
+}
#endif
« 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