From e8827d254f48ce12df8cd280df3e427170519f47 Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Tue, 7 Feb 2017 12:31:02 -0500 Subject: Address feedback on makeTextureImage BUG=skia: Whitespace change in public API. Change-Id: Iaab7b0ed6b157b1c246eae5f0f0440b0ae4d72ab Reviewed-on: https://skia-review.googlesource.com/8130 Reviewed-by: Brian Osman Reviewed-by: Robert Phillips Commit-Queue: Brian Osman --- gm/image.cpp | 18 +++++++------- include/core/SkImage.h | 2 +- tests/ImageTest.cpp | 64 +++++++++++++++++++++++++++----------------------- 3 files changed, 45 insertions(+), 39 deletions(-) diff --git a/gm/image.cpp b/gm/image.cpp index 1a4b712491..2b92dfd60e 100644 --- a/gm/image.cpp +++ b/gm/image.cpp @@ -428,11 +428,8 @@ private: }; DEF_GM( return new ScaleGeneratorGM; ) -DEF_SIMPLE_GM(new_texture_image, canvas, 225, 60) { - GrContext* context = nullptr; -#if SK_SUPPORT_GPU - context = canvas->getGrContext(); -#endif +DEF_SIMPLE_GM(new_texture_image, canvas, 280, 60) { + GrContext* context = canvas->getGrContext(); if (!context) { skiagm::GM::DrawGpuOnlyMessage(canvas); return; @@ -468,6 +465,12 @@ DEF_SIMPLE_GM(new_texture_image, canvas, 225, 60) { sk_tool_utils::EncodeImageToData(bmp, SkEncodedImageFormat::kPNG, 100)); return SkImage::MakeFromEncoded(std::move(src)); }, + // Create YUV encoded image. + [bmp] { + sk_sp src( + sk_tool_utils::EncodeImageToData(bmp, SkEncodedImageFormat::kJPEG, 100)); + return SkImage::MakeFromEncoded(std::move(src)); + }, // Create a picture image. [render_image] { SkPictureRecorder recorder; @@ -495,10 +498,7 @@ DEF_SIMPLE_GM(new_texture_image, canvas, 225, 60) { canvas->translate(kPad, kPad); for (auto factory : imageFactories) { auto image(factory()); - if (!image) { - continue; - } - if (context) { + if (image) { sk_sp texImage(image->makeTextureImage(context, canvas->imageInfo().colorSpace())); if (texImage) { diff --git a/include/core/SkImage.h b/include/core/SkImage.h index 532708a3d0..cb025468f0 100644 --- a/include/core/SkImage.h +++ b/include/core/SkImage.h @@ -326,7 +326,7 @@ public: * Ensures that an image is backed by a texture (when GrContext is non-null), suitable for use * with surfaces that have the supplied destination color space. If no transformation is * required, the returned image may be the same as this image. If this image is from a - * different GrContext, this will fail. + * different GrContext, this will fail. */ sk_sp makeTextureImage(GrContext*, SkColorSpace* dstColorSpace) const; diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index 500efef0d6..67ddd6cdf5 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -484,38 +484,44 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeTextureImage, reporter, contextIn } }; - SkColorSpace* legacyColorSpace = nullptr; - for (auto factory : imageFactories) { - sk_sp image(factory()); - if (!image) { - ERRORF(reporter, "Error creating image."); - continue; - } - GrTexture* origTexture = as_IB(image)->peekTexture(); + sk_sp dstColorSpaces[] ={ + nullptr, + SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named), + }; - sk_sp 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."); + for (auto& dstColorSpace : dstColorSpaces) { + for (auto factory : imageFactories) { + sk_sp image(factory()); + if (!image) { + ERRORF(reporter, "Error creating image."); + continue; } - 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."); + GrTexture* origTexture = as_IB(image)->peekTexture(); + + sk_sp texImage(image->makeTextureImage(context, dstColorSpace.get())); + 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."); } - } - 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."); } } } -- cgit v1.2.3