From 2ebdbf217e2a6dca64802c3a224eb3841f1f3c4f Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Fri, 8 Feb 2019 15:12:29 -0500 Subject: [PATCH] Create mipmaps for images when uploading them on the IO thread (flutter/engine#7751) This does several things: - It adds CPU time on the IO thread, but avoids GPU time on the GPU thread. - For images that are never drawn with mipmaps, it adds about 33% memory overhead. For images that are drawn with mipmaps, it saves an entire copy of the base level. - It fixes https://github.com/flutter/flutter/issues/24517, which is a driver bug related to mip-mapping and cross-context images. Overall, I think the tradeoff is good, but I'm curious to see what benchmarks look like. --- engine/src/flutter/lib/ui/painting/codec.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/lib/ui/painting/codec.cc b/engine/src/flutter/lib/ui/painting/codec.cc index 0555d8269ce..0b1de9c2c78 100644 --- a/engine/src/flutter/lib/ui/painting/codec.cc +++ b/engine/src/flutter/lib/ui/painting/codec.cc @@ -70,7 +70,7 @@ static sk_sp DecodeImage(fml::WeakPtr context, // This indicates that we do not want a "linear blending" decode. sk_sp dstColorSpace = nullptr; return SkImage::MakeCrossContextFromEncoded( - context.get(), std::move(buffer), false, dstColorSpace.get(), true); + context.get(), std::move(buffer), true, dstColorSpace.get(), true); } else { // Defer decoding until time of draw later on the GPU thread. Can happen // when GL operations are currently forbidden such as in the background @@ -131,7 +131,7 @@ fml::RefPtr InitCodecUncompressed( sk_sp skImage; if (context) { SkPixmap pixmap(image_info.sk_info, buffer->data(), image_info.row_bytes); - skImage = SkImage::MakeCrossContextFromPixmap(context.get(), pixmap, false, + skImage = SkImage::MakeCrossContextFromPixmap(context.get(), pixmap, true, nullptr, true); } else { skImage = SkImage::MakeRasterData(image_info.sk_info, std::move(buffer), @@ -455,7 +455,7 @@ sk_sp MultiFrameCodec::GetNextFrameImage( // This indicates that we do not want a "linear blending" decode. sk_sp dstColorSpace = nullptr; return SkImage::MakeCrossContextFromPixmap(resourceContext.get(), pixmap, - false, dstColorSpace.get()); + true, dstColorSpace.get()); } else { // Defer decoding until time of draw later on the GPU thread. Can happen // when GL operations are currently forbidden such as in the background