diff options
Diffstat (limited to 'tests/ImageTest.cpp')
-rw-r--r-- | tests/ImageTest.cpp | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index 76ddd9600f..500efef0d6 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -457,6 +457,69 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(c, reporter, ctxInfo) { } } +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeTextureImage, reporter, contextInfo) { + GrContext* context = contextInfo.grContext(); + sk_gpu_test::TestContext* testContext = contextInfo.testContext(); + + GrContextFactory otherFactory; + GrContextFactory::ContextType otherContextType = + GrContextFactory::NativeContextTypeForBackend(testContext->backend()); + ContextInfo otherContextInfo = otherFactory.getContextInfo(otherContextType); + testContext->makeCurrent(); + + std::function<sk_sp<SkImage>()> imageFactories[] = { + create_image, + create_codec_image, + create_data_image, + // Create an image from a picture. + create_picture_image, + // Create a texture image. + [context] { return create_gpu_image(context); }, + // Create a texture image in a another GrContext. + [testContext, otherContextInfo] { + otherContextInfo.testContext()->makeCurrent(); + sk_sp<SkImage> otherContextImage = create_gpu_image(otherContextInfo.grContext()); + testContext->makeCurrent(); + return otherContextImage; + } + }; + + SkColorSpace* legacyColorSpace = nullptr; + for (auto factory : imageFactories) { + sk_sp<SkImage> image(factory()); + if (!image) { + ERRORF(reporter, "Error creating image."); + continue; + } + GrTexture* origTexture = as_IB(image)->peekTexture(); + + sk_sp<SkImage> texImage(image->makeTextureImage(context, legacyColorSpace)); + if (!texImage) { + // We execpt to fail if image comes from a different GrContext. + if (!origTexture || origTexture->getContext() == context) { + ERRORF(reporter, "makeTextureImage failed."); + } + continue; + } + GrTexture* copyTexture = as_IB(texImage)->peekTexture(); + if (!copyTexture) { + ERRORF(reporter, "makeTextureImage returned non-texture image."); + continue; + } + if (origTexture) { + if (origTexture != copyTexture) { + ERRORF(reporter, "makeTextureImage made unnecessary texture copy."); + } + } + if (image->width() != texImage->width() || image->height() != texImage->height()) { + ERRORF(reporter, "makeTextureImage changed the image size."); + } + if (image->alphaType() != texImage->alphaType()) { + ERRORF(reporter, "makeTextureImage changed image alpha type."); + } + } +} + DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeNonTextureImage, reporter, contextInfo) { GrContext* context = contextInfo.grContext(); @@ -467,11 +530,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeNonTextureImage, reporter, contex create_picture_image, [context] { return create_gpu_image(context); }, }; + SkColorSpace* legacyColorSpace = nullptr; for (auto factory : imageFactories) { sk_sp<SkImage> image = factory(); if (!image->isTextureBacked()) { REPORTER_ASSERT(reporter, image->makeNonTextureImage().get() == image.get()); - continue; + if (!(image = image->makeTextureImage(context, legacyColorSpace))) { + continue; + } } auto rasterImage = image->makeNonTextureImage(); if (!rasterImage) { |