LibWeb: Do not deform bitmaps partially outside the img-box

Instead of trying to manually determine which parts of a bitmap fall
within the box of the `<img>` element, just draw the whole bitmap and
let Skia clip the draw-area to the correct rectangle.

This fixes a bug where the entire bitmap was squashed into the rectangle
of the image box instead of being clipped.

With this change, image rendering is now correct enough to import some
of the WPT tests for object-fit and object-position. To get some good
coverage I have imported all tests for the `<img>` tag. I also wanted to
import a subset of the tests for the `<object>` tag, since those are
passing as well now. Unfortunately, they are flaky for unknown reasons.
This commit is contained in:
InvalidUsernameException 2025-02-04 21:51:51 +01:00 committed by Alexander Kalenik
parent 389a63d6bf
commit e055927ead
Notes: github-actions[bot] 2025-03-05 15:33:54 +00:00
36 changed files with 1752 additions and 22 deletions

View file

@ -149,7 +149,8 @@ void ImageStyleValue::paint(PaintContext& context, DevicePixelRect const& dest_r
{
if (auto const* b = bitmap(m_current_frame_index, dest_rect.size().to_type<int>()); b != nullptr) {
auto scaling_mode = to_gfx_scaling_mode(image_rendering, b->rect(), dest_rect.to_type<int>());
context.display_list_recorder().draw_scaled_immutable_bitmap(dest_rect.to_type<int>(), *b, b->rect(), scaling_mode);
auto dest_int_rect = dest_rect.to_type<int>();
context.display_list_recorder().draw_scaled_immutable_bitmap(dest_int_rect, dest_int_rect, *b, scaling_mode);
}
}