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>
This commit is contained in:
Brian Osman 2017-02-07 12:31:02 -05:00 committed by Skia Commit-Bot
parent 76fff8661f
commit e8827d254f
3 changed files with 45 additions and 39 deletions

View File

@ -428,11 +428,8 @@ private:
}; };
DEF_GM( return new ScaleGeneratorGM; ) DEF_GM( return new ScaleGeneratorGM; )
DEF_SIMPLE_GM(new_texture_image, canvas, 225, 60) { DEF_SIMPLE_GM(new_texture_image, canvas, 280, 60) {
GrContext* context = nullptr; GrContext* context = canvas->getGrContext();
#if SK_SUPPORT_GPU
context = canvas->getGrContext();
#endif
if (!context) { if (!context) {
skiagm::GM::DrawGpuOnlyMessage(canvas); skiagm::GM::DrawGpuOnlyMessage(canvas);
return; return;
@ -468,6 +465,12 @@ DEF_SIMPLE_GM(new_texture_image, canvas, 225, 60) {
sk_tool_utils::EncodeImageToData(bmp, SkEncodedImageFormat::kPNG, 100)); sk_tool_utils::EncodeImageToData(bmp, SkEncodedImageFormat::kPNG, 100));
return SkImage::MakeFromEncoded(std::move(src)); 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. // Create a picture image.
[render_image] { [render_image] {
SkPictureRecorder recorder; SkPictureRecorder recorder;
@ -495,10 +498,7 @@ DEF_SIMPLE_GM(new_texture_image, canvas, 225, 60) {
canvas->translate(kPad, kPad); canvas->translate(kPad, kPad);
for (auto factory : imageFactories) { for (auto factory : imageFactories) {
auto image(factory()); auto image(factory());
if (!image) { if (image) {
continue;
}
if (context) {
sk_sp<SkImage> texImage(image->makeTextureImage(context, sk_sp<SkImage> texImage(image->makeTextureImage(context,
canvas->imageInfo().colorSpace())); canvas->imageInfo().colorSpace()));
if (texImage) { if (texImage) {

View File

@ -326,7 +326,7 @@ public:
* Ensures that an image is backed by a texture (when GrContext is non-null), suitable for use * 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 * 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 * 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; sk_sp<SkImage> makeTextureImage(GrContext*, SkColorSpace* dstColorSpace) const;

View File

@ -484,38 +484,44 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeTextureImage, reporter, contextIn
} }
}; };
SkColorSpace* legacyColorSpace = nullptr; sk_sp<SkColorSpace> dstColorSpaces[] ={
for (auto factory : imageFactories) { nullptr,
sk_sp<SkImage> image(factory()); SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named),
if (!image) { };
ERRORF(reporter, "Error creating image.");
continue;
}
GrTexture* origTexture = as_IB(image)->peekTexture();
sk_sp<SkImage> texImage(image->makeTextureImage(context, legacyColorSpace)); for (auto& dstColorSpace : dstColorSpaces) {
if (!texImage) { for (auto factory : imageFactories) {
// We execpt to fail if image comes from a different GrContext. sk_sp<SkImage> image(factory());
if (!origTexture || origTexture->getContext() == context) { if (!image) {
ERRORF(reporter, "makeTextureImage failed."); ERRORF(reporter, "Error creating image.");
continue;
} }
continue; GrTexture* origTexture = as_IB(image)->peekTexture();
}
GrTexture* copyTexture = as_IB(texImage)->peekTexture(); sk_sp<SkImage> texImage(image->makeTextureImage(context, dstColorSpace.get()));
if (!copyTexture) { if (!texImage) {
ERRORF(reporter, "makeTextureImage returned non-texture image."); // We execpt to fail if image comes from a different GrContext.
continue; if (!origTexture || origTexture->getContext() == context) {
} ERRORF(reporter, "makeTextureImage failed.");
if (origTexture) { }
if (origTexture != copyTexture) { continue;
ERRORF(reporter, "makeTextureImage made unnecessary texture copy."); }
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.");
} }
} }
} }