ImageDecoder: Pass decoded images as Gfx::Bitmap over IPC

Before this change, we were passing them as Gfx::ShareableBitmap. The
problem is that shareable bitmaps keep their underlying file descriptor
open, so that they can be shared again with someone else.

When a Gfx::Bitmap is decoded from an IPC message, the file descriptor
is closed and recovered immediately.

This fixes an issue where we'd accumulate one file descriptor for every
image decoded. This eventually led to descriptor starvation after enough
images were loaded and still referenced at the same time.

(cherry picked from commit 166e603c5eb0a103eea148baf97a075fe5fea964)
This commit is contained in:
Andreas Kling
2024-07-17 19:14:44 +02:00
committed by Nico Weber
parent 1270daca0e
commit 8a7d9a7b68
5 changed files with 9 additions and 9 deletions

View File

@@ -60,7 +60,7 @@ NonnullRefPtr<Core::Promise<DecodedImage>> Client::decode_image(ReadonlyBytes en
return promise;
}
void Client::did_decode_image(i64 image_id, bool is_animated, u32 loop_count, Vector<Gfx::ShareableBitmap> const& bitmaps, Vector<u32> const& durations, Gfx::FloatPoint scale)
void Client::did_decode_image(i64 image_id, bool is_animated, u32 loop_count, Vector<Optional<NonnullRefPtr<Gfx::Bitmap>>> const& bitmaps, Vector<u32> const& durations, Gfx::FloatPoint scale)
{
VERIFY(!bitmaps.is_empty());
@@ -77,13 +77,13 @@ void Client::did_decode_image(i64 image_id, bool is_animated, u32 loop_count, Ve
image.scale = scale;
image.frames.ensure_capacity(bitmaps.size());
for (size_t i = 0; i < bitmaps.size(); ++i) {
if (!bitmaps[i].is_valid()) {
if (!bitmaps[i].has_value()) {
dbgln("ImageDecoderClient: Invalid bitmap for request {} at index {}", image_id, i);
promise->reject(Error::from_string_literal("Invalid bitmap"));
return;
}
image.frames.empend(*bitmaps[i].bitmap(), durations[i]);
image.frames.empend(*bitmaps[i], durations[i]);
}
promise->resolve(move(image));