From 89150582643f1ef4893a0cdeaadf5886e5cde76d Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Mon, 20 Mar 2017 16:54:28 -0400 Subject: [PATCH] readpixels GM uses GPU image in GPU configs This now demonstrates that readPixels does not do color sapce conversion in Ganesh (and fails completely for unpremul F16). Next: fix those issues. BUG=skia:5853 Change-Id: If3bd1882249ae85b4738ef72e16cfb87b06b9363 Reviewed-on: https://skia-review.googlesource.com/9904 Commit-Queue: Brian Osman Reviewed-by: Matt Sarett --- gm/readpixels.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/gm/readpixels.cpp b/gm/readpixels.cpp index dd84506268..f757a497b8 100644 --- a/gm/readpixels.cpp +++ b/gm/readpixels.cpp @@ -132,7 +132,9 @@ static void draw_image(SkCanvas* canvas, SkImage* image, SkColorType dstColorTyp dstColorSpace = fix_for_colortype(dstColorSpace.get(), dstColorType); SkImageInfo dstInfo = SkImageInfo::Make(image->width(), image->height(), dstColorType, dstAlphaType, dstColorSpace); - image->readPixels(dstInfo, data->writable_data(), rowBytes, 0, 0, hint); + if (!image->readPixels(dstInfo, data->writable_data(), rowBytes, 0, 0, hint)) { + memset(data->writable_data(), 0, rowBytes * image->height()); + } // SkImage must be premul, so manually premul the data if we unpremul'd during readPixels if (kUnpremul_SkAlphaType == dstAlphaType) { @@ -193,11 +195,16 @@ protected: for (SkColorType srcColorType : colorTypes) { canvas->save(); sk_sp image = make_raster_image(srcColorType); - for (SkColorType dstColorType : colorTypes) { - for (SkAlphaType dstAlphaType : alphaTypes) { - draw_image(canvas, image.get(), dstColorType, dstAlphaType, - dstColorSpace, SkImage::kAllow_CachingHint); - canvas->translate((float) kWidth, 0.0f); + if (GrContext* context = canvas->getGrContext()) { + image = image->makeTextureImage(context, canvas->imageInfo().colorSpace()); + } + if (image) { + for (SkColorType dstColorType : colorTypes) { + for (SkAlphaType dstAlphaType : alphaTypes) { + draw_image(canvas, image.get(), dstColorType, dstAlphaType, + dstColorSpace, SkImage::kAllow_CachingHint); + canvas->translate((float)kWidth, 0.0f); + } } } canvas->restore();