1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:37:45 +00:00

LibWeb: Convert backdrop-filter painting to new pixel units

This commit is contained in:
Sam Atkins 2022-11-25 17:15:23 +00:00 committed by Linus Groh
parent 0bf4089af9
commit 7c8eecbaa5
3 changed files with 7 additions and 6 deletions

View file

@ -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 // This performs the backdrop filter operation: https://drafts.fxtf.org/filter-effects-2/#backdrop-filter-operation
auto backdrop_region = backdrop_rect.to_rounded<int>(); 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: 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 {}; Gfx::IntRect actual_region {};
// FIXME: Go through the steps to find the "Backdrop Root Image" // FIXME: Go through the steps to find the "Backdrop Root Image"
// https://drafts.fxtf.org/filter-effects-2/#BackdropRoot // 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. // 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<int>(), Gfx::BitmapFormat::BGRA8888, actual_region);
if (actual_region.is_empty()) if (actual_region.is_empty())
return; return;
if (maybe_backdrop_bitmap.is_error()) { 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. // 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. // 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<DevicePixels>(), 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. // FIXME: 5. Draw all of element B, including its background, border, and any children elements, into T.

View file

@ -14,6 +14,6 @@ namespace Web::Painting {
void apply_filter_list(Gfx::Bitmap& target_bitmap, Layout::Node const& node, Span<CSS::FilterFunction const> filter_list); void apply_filter_list(Gfx::Bitmap& target_bitmap, Layout::Node const& node, Span<CSS::FilterFunction const> 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&);
} }

View file

@ -234,7 +234,7 @@ void PaintableBox::paint_backdrop_filter(PaintContext& context) const
{ {
auto& backdrop_filter = computed_values().backdrop_filter(); auto& backdrop_filter = computed_values().backdrop_filter();
if (!backdrop_filter.is_none()) 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<CSSPixels>(), normalized_border_radii_data(), backdrop_filter);
} }
void PaintableBox::paint_background(PaintContext& context) const void PaintableBox::paint_background(PaintContext& context) const