Coalesce animated image frame data into a single shared memory region (#37058)

This makes servo use less file descriptors for animated images and
avoids the crash described in
https://github.com/servo/servo/issues/36792.

Doing this also forces the end users to be more explicit about whether
they want to deal with all image frames or just the first one.
Previously, `Image::bytes` silently returned only the data for the first
frame. With this change there's now a `frames` method which returns an
iterator over all frames in the image.

Testing: No tests - this simply reduces the number of fds used. Servo
doesn't currently display animated gifs anyways.
Fixes: https://github.com/servo/servo/issues/36792

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2025-05-20 22:40:46 +02:00 committed by GitHub
parent d5e02d27be
commit 384d8f1ff8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 75 additions and 36 deletions

View file

@ -1709,7 +1709,8 @@ impl Handler {
"Unexpected screenshot pixel format"
);
let rgb = RgbaImage::from_raw(img.width, img.height, img.bytes().to_vec()).unwrap();
let rgb =
RgbaImage::from_raw(img.width, img.height, img.first_frame().bytes.to_vec()).unwrap();
let mut png_data = Cursor::new(Vec::new());
DynamicImage::ImageRgba8(rgb)
.write_to(&mut png_data, ImageFormat::Png)