Index: tests/ImageTest.cpp |
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp |
index 2ec1f342b360f8f93649a34458de56165cdf4f36..96a9c51134fe185d3d05f66768a4107666895dab 100644 |
--- a/tests/ImageTest.cpp |
+++ b/tests/ImageTest.cpp |
@@ -737,4 +737,122 @@ DEF_GPUTEST_FOR_NATIVE_CONTEXT(SkImage_NewFromTexture, reporter, context) { |
refImg.reset(nullptr); // force a release of the image |
REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); |
} |
+ |
+static void check_images_same(skiatest::Reporter* reporter, const SkImage* a, const SkImage* b) { |
+ if (a->width() != b->width() || a->height() != b->height()) { |
+ ERRORF(reporter, "Images must have the same size"); |
+ return; |
+ } |
+ if (a->isOpaque() != b->isOpaque()) { |
+ ERRORF(reporter, "Images must have the same opaquness"); |
+ return; |
+ } |
+ |
+ SkImageInfo info = SkImageInfo::MakeN32Premul(a->width(), a->height()); |
+ SkAutoPixmapStorage apm; |
+ SkAutoPixmapStorage bpm; |
+ |
+ apm.alloc(info); |
+ bpm.alloc(info); |
+ |
+ if (!a->readPixels(apm, 0, 0)) { |
+ ERRORF(reporter, "Could not read image a's pixels"); |
+ return; |
+ } |
+ if (!b->readPixels(bpm, 0, 0)) { |
+ ERRORF(reporter, "Could not read image b's pixels"); |
+ return; |
+ } |
+ |
+ for (auto y = 0; y < info.height(); ++y) { |
+ for (auto x = 0; x < info.width(); ++x) { |
+ uint32_t pixelA = *apm.addr32(x, y); |
+ uint32_t pixelB = *bpm.addr32(x, y); |
+ if (pixelA != pixelB) { |
+ ERRORF(reporter, "Expected image pixels to be the same. At %d,%d 0x%08x != 0x%08x", |
+ x, y, pixelA, pixelB); |
+ return; |
+ } |
+ } |
+ } |
+} |
+ |
+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); |
robertphillips
2016/03/08 18:43:10
stray ';' ?
bsalomon
2016/03/08 19:49:32
Done.
|
+ 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.fSrcRect = SkRect::MakeIWH(image->width(), image->height()); |
+ params.fDstRect = params.fSrcRect; |
+ params.fQuality = kLow_SkFilterQuality; |
+ params.fViewMatrix = SkMatrix::I(); |
+ |
+ size_t size = image->getDeferredTextureImageSize(*proxy, ¶ms, 1); |
+ |
+ static const char *const kFS[] = { "fail", "succeed" }; |
+ REPORTER_ASSERT_MESSAGE(reporter, SkToBool(size) == testCase.fExpectation, |
+ "This image was expected to %s but did not.", |
+ kFS[testCase.fExpectation]); |
+ if (size) { |
+ void* storage = sk_malloc_throw(size); |
robertphillips
2016/03/08 18:43:10
td -> dti ?
bsalomon
2016/03/08 19:49:32
other changes obsoleted this (the type is gone).
|
+ const SkImage::DeferredTextureImage* td; |
+ td = image->createDeferredTextureImageInClientStorage(*proxy, ¶ms, 1, storage, |
+ size/2); |
+ REPORTER_ASSERT_MESSAGE(reporter, !td, "Should fail when allocation is undersized."); |
+ |
+ td = image->createDeferredTextureImageInClientStorage(*proxy, ¶ms, 1, nullptr, |
+ size); |
+ REPORTER_ASSERT_MESSAGE(reporter, !td, "Should fail when allocation is nullptr."); |
+ td = image->createDeferredTextureImageInClientStorage(*proxy, ¶ms, 1, storage, |
+ size); |
+ if (!td) { |
+ ERRORF(reporter, "deferred image size succeeded but creation failed."); |
+ } else { |
+ for (auto budgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { |
+ SkAutoTUnref<SkImage> newImage( |
+ SkImage::NewFromDeferredTextureImage(context, *td, 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::NewFromDeferredTextureImage( |
+ otherContextInfo.fGrContext, *td, budgeted)); |
+ REPORTER_ASSERT(reporter, !newImage2); |
+ glContext->makeCurrent(); |
+ } |
+ } |
+ sk_free(storage); |
+ } |
+ } |
+} |
#endif |