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_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) {

View File

@ -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;

View File

@ -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.");
}
}
}