diff options
author | Brian Osman <brianosman@google.com> | 2017-02-07 11:23:28 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-02-07 16:58:07 +0000 |
commit | 041f7dfc577822f1e97721a865f86a9a02660cf9 (patch) | |
tree | e97779c04ea0d2059cbd6291de3cbfbf27c1cc61 /tests/ImageTest.cpp | |
parent | 2bb94e814726cbe8e0a6a5763e262a5ccea9313c (diff) |
Bring back SkImage::makeTextureImage
Ensures that an image is GPU backed on the passed-in GrContxt. The new
version requires a destination color space (intended usage of the image),
so we can make a proper decision about decoded format.
This reverts commit d263413a2a92cafe3fd3b051c67d00206c9a0e4d.
BUG=skia:
Change-Id: Ibccddbafc301779559592045ed5a5fa9264e7432
Reviewed-on: https://skia-review.googlesource.com/8116
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
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) { |