From 7c8eecbaa5467ce3e708bf1fd72316dc7438d3ac Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 25 Nov 2022 17:15:23 +0000 Subject: [PATCH] LibWeb: Convert backdrop-filter painting to new pixel units --- Userland/Libraries/LibWeb/Painting/FilterPainting.cpp | 9 +++++---- Userland/Libraries/LibWeb/Painting/FilterPainting.h | 2 +- Userland/Libraries/LibWeb/Painting/PaintableBox.cpp | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibWeb/Painting/FilterPainting.cpp b/Userland/Libraries/LibWeb/Painting/FilterPainting.cpp index 793faefb35..c65ebe1bac 100644 --- a/Userland/Libraries/LibWeb/Painting/FilterPainting.cpp +++ b/Userland/Libraries/LibWeb/Painting/FilterPainting.cpp @@ -98,20 +98,21 @@ void apply_filter_list(Gfx::Bitmap& target_bitmap, Layout::Node const& node, Spa } } -void apply_backdrop_filter(PaintContext& context, Layout::Node const& node, Gfx::FloatRect const& backdrop_rect, BorderRadiiData const& border_radii_data, CSS::BackdropFilter const& backdrop_filter) +void apply_backdrop_filter(PaintContext& context, Layout::Node const& node, CSSPixelRect const& backdrop_rect, BorderRadiiData const& border_radii_data, CSS::BackdropFilter const& backdrop_filter) { // This performs the backdrop filter operation: https://drafts.fxtf.org/filter-effects-2/#backdrop-filter-operation - auto backdrop_region = backdrop_rect.to_rounded(); + auto backdrop_region = context.rounded_device_rect(backdrop_rect); // Note: The region bitmap can be smaller than the backdrop_region if it's at the edge of canvas. + // Note: This is in DevicePixels, but we use an IntRect because `get_region_bitmap()` below writes to it. Gfx::IntRect actual_region {}; // FIXME: Go through the steps to find the "Backdrop Root Image" // https://drafts.fxtf.org/filter-effects-2/#BackdropRoot // 1. Copy the Backdrop Root Image into a temporary buffer, such as a raster image. Call this buffer T’. - auto maybe_backdrop_bitmap = context.painter().get_region_bitmap(backdrop_region, Gfx::BitmapFormat::BGRA8888, actual_region); + auto maybe_backdrop_bitmap = context.painter().get_region_bitmap(backdrop_region.to_type(), Gfx::BitmapFormat::BGRA8888, actual_region); if (actual_region.is_empty()) return; if (maybe_backdrop_bitmap.is_error()) { @@ -125,7 +126,7 @@ void apply_backdrop_filter(PaintContext& context, Layout::Node const& node, Gfx: // FIXME: 3. If element B has any transforms (between B and the Backdrop Root), apply the inverse of those transforms to the contents of T’. // 4. Apply a clip to the contents of T’, using the border box of element B, including border-radius if specified. Note that the children of B are not considered for the sizing or location of this clip. - ScopedCornerRadiusClip corner_clipper { context, context.painter(), backdrop_region.to_type(), border_radii_data }; + ScopedCornerRadiusClip corner_clipper { context, context.painter(), backdrop_region, border_radii_data }; // FIXME: 5. Draw all of element B, including its background, border, and any children elements, into T’. diff --git a/Userland/Libraries/LibWeb/Painting/FilterPainting.h b/Userland/Libraries/LibWeb/Painting/FilterPainting.h index d4b3e693b6..23986e2d79 100644 --- a/Userland/Libraries/LibWeb/Painting/FilterPainting.h +++ b/Userland/Libraries/LibWeb/Painting/FilterPainting.h @@ -14,6 +14,6 @@ namespace Web::Painting { void apply_filter_list(Gfx::Bitmap& target_bitmap, Layout::Node const& node, Span filter_list); -void apply_backdrop_filter(PaintContext&, Layout::Node const&, Gfx::FloatRect const&, BorderRadiiData const&, CSS::BackdropFilter const&); +void apply_backdrop_filter(PaintContext&, Layout::Node const&, CSSPixelRect const&, BorderRadiiData const&, CSS::BackdropFilter const&); } diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index f628cba738..8ee411caa7 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -234,7 +234,7 @@ void PaintableBox::paint_backdrop_filter(PaintContext& context) const { auto& backdrop_filter = computed_values().backdrop_filter(); if (!backdrop_filter.is_none()) - Painting::apply_backdrop_filter(context, layout_node(), absolute_border_box_rect(), normalized_border_radii_data(), backdrop_filter); + Painting::apply_backdrop_filter(context, layout_node(), absolute_border_box_rect().to_type(), normalized_border_radii_data(), backdrop_filter); } void PaintableBox::paint_background(PaintContext& context) const