From 4a8d1fcafbf4e876c7a81721494818923e679eab Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Wed, 11 Jul 2018 12:33:36 -0700 Subject: [PATCH] Convert lazy SkImages to raster images when extracting pixel data (flutter/engine#5713) Fixes https://github.com/flutter/flutter/issues/19214 --- .../flutter/lib/ui/painting/image_encoding.cc | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/lib/ui/painting/image_encoding.cc b/engine/src/flutter/lib/ui/painting/image_encoding.cc index 00c9b79fe56..dd4b8d1cf2d 100644 --- a/engine/src/flutter/lib/ui/painting/image_encoding.cc +++ b/engine/src/flutter/lib/ui/painting/image_encoding.cc @@ -57,12 +57,23 @@ void InvokeDataCallback(std::unique_ptr callback, sk_sp ConvertToRasterImageIfNecessary(sk_sp image, GrContext* context) { - if (context == nullptr) { - // The context was null (software rendering contexts) so the image is likely - // already a raster image. Nothing more to do. + SkPixmap pixmap; + if (image->peekPixels(&pixmap)) { + // This is already a raster image. return image; } + if (sk_sp raster_image = image->makeRasterImage()) { + // The image can be converted to a raster image. + return raster_image; + } + + // Cross-context images do not support makeRasterImage. Convert these images + // by drawing them into a surface. + if (context == nullptr) { + return nullptr; + } + TRACE_EVENT0("flutter", __FUNCTION__); // Create a GPU surface with the context and then do a device to host copy of