diff options
author | Brian Osman <brianosman@google.com> | 2017-02-07 12:31:02 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-02-07 18:28:37 +0000 |
commit | e8827d254f48ce12df8cd280df3e427170519f47 (patch) | |
tree | a826be60d181dc637f75407672fcb299727f61b9 | |
parent | 76fff8661f6c3a9133ac9903e0e6d515234598ce (diff) |
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 <brianosman@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
-rw-r--r-- | gm/image.cpp | 18 | ||||
-rw-r--r-- | include/core/SkImage.h | 2 | ||||
-rw-r--r-- | 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<SkData> 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<SkImage> 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<SkImage> 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<SkImage> image(factory()); - if (!image) { - ERRORF(reporter, "Error creating image."); - continue; - } - GrTexture* origTexture = as_IB(image)->peekTexture(); + sk_sp<SkColorSpace> dstColorSpaces[] ={ + nullptr, + SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named), + }; - 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."); + for (auto& dstColorSpace : dstColorSpaces) { + for (auto factory : imageFactories) { + sk_sp<SkImage> 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<SkImage> 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."); } } } |