summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMacDue <macdue@dueutil.tech>2022-09-26 00:01:31 +0100
committerAndreas Kling <kling@serenityos.org>2022-09-26 01:38:30 +0200
commitf6264523b9ef1b82ff3e7869c21bc0c819403aef (patch)
tree56fae311c084090f7e3c43f8d5cd0344cafd1803
parentbbaa05fcf9a2a7b9515319b102a234be930824cd (diff)
downloadserenity-f6264523b9ef1b82ff3e7869c21bc0c819403aef.zip
LibWeb: Fix destination bitmap edge clip case in transform painting
This fixes an edge case, where the destination rect falls partly outside the painter, so is clipped to a smaller size in `get_region_bitmap()` (which needs to be accounted for with an extra offset).
-rw-r--r--Userland/Libraries/LibWeb/Painting/StackingContext.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp
index 445c7c1821..8d525f2fe1 100644
--- a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp
+++ b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp
@@ -303,12 +303,18 @@ void StackingContext::paint(PaintContext& context) const
// to the size of the source (which could add some artefacts, though just scaling the bitmap already does that).
// We need to copy the background at the destination because a bunch of our rendering effects now rely on
// being able to sample the painter (see border radii, shadows, filters, etc).
+ Gfx::FloatPoint destination_clipped_fixup {};
auto try_get_scaled_destination_bitmap = [&]() -> ErrorOr<NonnullRefPtr<Gfx::Bitmap>> {
- auto bitmap = TRY(context.painter().get_region_bitmap(destination_rect, Gfx::BitmapFormat::BGRA8888, destination_rect));
+ Gfx::IntRect actual_destination_rect;
+ auto bitmap = TRY(context.painter().get_region_bitmap(destination_rect, Gfx::BitmapFormat::BGRA8888, actual_destination_rect));
+ // get_region_bitmap() may clip to a smaller region if the requested rect goes outside the painter, so we need to account for that.
+ destination_clipped_fixup = Gfx::FloatPoint { destination_rect.location() - actual_destination_rect.location() };
+ destination_rect = actual_destination_rect;
if (source_rect.size() != transformed_destination_rect.size()) {
- bitmap = TRY(bitmap->scaled(
- static_cast<float>(source_rect.width()) / transformed_destination_rect.width(),
- static_cast<float>(source_rect.height()) / transformed_destination_rect.height()));
+ auto sx = static_cast<float>(source_rect.width()) / transformed_destination_rect.width();
+ auto sy = static_cast<float>(source_rect.height()) / transformed_destination_rect.height();
+ bitmap = TRY(bitmap->scaled(sx, sy));
+ destination_clipped_fixup.scale_by(sx, sy);
}
return bitmap;
};
@@ -318,13 +324,12 @@ void StackingContext::paint(PaintContext& context) const
return;
auto bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
Gfx::Painter painter(bitmap);
- painter.translate(-paintable().absolute_paint_rect().location().to_rounded<int>());
+ painter.translate((-paintable().absolute_paint_rect().location() + destination_clipped_fixup).to_rounded<int>());
auto paint_context = context.clone(painter);
paint_internal(paint_context);
- // NOTE: If the destination and source rects are the same size, we round the source rect to ensure that it's pixel-aligned.
- if (transformed_destination_rect.size() == source_rect.size())
- context.painter().draw_scaled_bitmap(destination_rect, *bitmap, bitmap->rect(), opacity);
+ if (destination_rect.size() == bitmap->size())
+ context.painter().blit(destination_rect.location(), *bitmap, bitmap->rect(), opacity);
else
context.painter().draw_scaled_bitmap(destination_rect, *bitmap, bitmap->rect(), opacity, Gfx::Painter::ScalingMode::BilinearBlend);
} else {