Truly independent web browser
LibGfx+LibWeb+LibCompositing+Compositor: Mirror backdrop blurs
Andreas Klingd30a3810fe0b
diff --git a/Libraries/LibCompositing/Rust/src/display_list/commands.rs b/Libraries/LibCompositing/Rust/src/display_list/commands.rsindex b52454b4c18..68033b420b5 100644--- a/Libraries/LibCompositing/Rust/src/display_list/commands.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/commands.rs@@ -262,6 +262,9 @@ pub struct ReplayLayer {pub backdrop_corner_radii: CornerRadii,/// The color the backdrop is read over, transparent unless the parent layer is the root isolation layer.pub backdrop_base_color: Color,+ /// Where a blur() in the backdrop filter mirrors: the region as the clips around the box leave it, in the+ /// effect's space. None when the filter holds no such blur.+ pub backdrop_blur_edge: OptionalFloatRect,pub effect: EffectNodeIndex,/// Bounds of everything replay draws into the layer, in the effect's space, when known.pub content_bounds: OptionalFloatRect,diff --git a/Libraries/LibCompositing/Rust/src/display_list/damage.rs b/Libraries/LibCompositing/Rust/src/display_list/damage.rsindex b0d77088e8c..17641c23557 100644--- a/Libraries/LibCompositing/Rust/src/display_list/damage.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/damage.rs@@ -957,7 +957,7 @@ impl DamageAccumulator {self.add_command_damage(command, chains.new_side());}- // A backdrop filter reads the pixels around its region, so damage beneath the region changes it+ // A backdrop filter can read the pixels around its region, so damage beneath the region changes it// wherever the filter carries that damage in. The whole region then changes as content of the// backdrop's effect: that effect's own filter and the filters above it spread it further, and it// can carry the damage on to the backdrop filters above it.diff --git a/Libraries/LibCompositing/Rust/src/display_list/replay.rs b/Libraries/LibCompositing/Rust/src/display_list/replay.rsindex 6aaaec8d994..942737b6017 100644--- a/Libraries/LibCompositing/Rust/src/display_list/replay.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/replay.rs@@ -13,7 +13,9 @@ use crate::display_list::commands::{};use crate::display_list::depth_sorted_plan::{DepthSortedReplayStepKind, build_depth_sorted_replay_plan};use crate::display_list::effect_clip_plan::EffectClipPlan;-use crate::display_list::effect_geometry::{EffectGeometry, Extent, SpaceMatrices, compute_effect_geometry};+use crate::display_list::effect_geometry::{+ EffectGeometry, Extent, SpaceMatrices, compute_effect_geometry, map_rect_between_spaces,+};use crate::display_list::ffi_bytes::FfiBytes;use crate::display_list::nested_records::span_bytes;use crate::visual_context::queries::TreeCullingScratch;@@ -21,6 +23,7 @@ use crate::visual_context::{ClipNodeData, ContextRef, EffectNodeData, SpatialData, SpatialNode, VisualContextTree, device_offset_for_index,resolve_leaf_to_context_matrices, should_cull_back_face,};+use libgfx_rust::filter::Filter;use libgfx_rust::path::Path;use libgfx_rust::{AffineTransform, Color, CornerRadii, FloatMatrix4x4, FloatPoint, FloatRect, FloatVector3, IntRect, WindingRule,@@ -332,6 +335,7 @@ fn replay_layer_of(backdrop_region,backdrop_corner_radii,backdrop_base_color: Color::TRANSPARENT,+ backdrop_blur_edge: OptionalFloatRect::none(),effect,content_bounds: OptionalFloatRect::from(content_bounds),}@@ -584,6 +588,7 @@ impl<Painter: ReplayPainter> ReplayDriver<'_, Painter> {EffectNodeData::Effects(effects) if backdrop_is_drawn_by_masks(tree, effect) => {let mut layer = replay_layer_of(effects, effect, None);layer.backdrop_base_color = self.backdrop_base_color(mask_effect);+ layer.backdrop_blur_edge = self.backdrop_blur_edge(effect);Some(layer)}_ => None,@@ -591,6 +596,43 @@ impl<Painter: ReplayPainter> ReplayDriver<'_, Painter> {})}+ // https://drafts.csswg.org/filter-effects-2/#backdrop-filter-operation+ // If the filter functions list includes a blur() filter, the filter will be applied with edgeMode="mirror", with+ // the edge defined by the clipped, transformed border box of the element.+ // The clips come from the effect's clip chain and not from the canvas, whose clip also holds the rect a partial+ // repaint is limited to, and whose bounds lose the shape of a clip that turns along with the box.+ fn backdrop_blur_edge(&self, effect: EffectNodeIndex) -> OptionalFloatRect {+ let tree = self.tree;+ let node = &tree.effect_nodes[effect.0 as usize];+ let EffectNodeData::Effects(effects) = &node.data else {+ return OptionalFloatRect::none();+ };+ let Some(backdrop) = effects+ .backdrop_filter+ .as_ref()+ .filter(|backdrop| Filter::serialized_has_mirroring_blur(&backdrop.filter))+ else {+ return OptionalFloatRect::none();+ };+ let mut edge = backdrop.region.to_float();+ let mut clip = self.effect_clips.output_clip(effect);+ while !clip.is_none() {+ let clip_node = &tree.clip_nodes[clip.0 as usize];+ let clip_rect = match &clip_node.data {+ ClipNodeData::Rect(data) if data.mode == ClipMode::Intersect => Some(data.rect),+ ClipNodeData::Path(path) => Some(path.bounding_rect.to_float()),+ _ => None,+ };+ if let Some(clip_rect) = clip_rect+ .and_then(|rect| map_rect_between_spaces(&mut &self.palette, rect, clip_node.spatial, node.spatial))+ {+ edge = edge.intersected(clip_rect);+ }+ clip = clip_node.parent;+ }+ OptionalFloatRect::from(Some(edge))+ }+// https://drafts.fxtf.org/filter-effects-2/#BackdropRoot// The root element group is a backdrop root, yet engines read the canvas surface below it into the backdrop, see// https://github.com/w3c/fxtf-drafts/issues/557. Skia reads a backdrop from the parent layer only, so a layer@@ -779,6 +821,7 @@ impl<Painter: ReplayPainter> ReplayDriver<'_, Painter> {layer.blend_mode = libgfx_rust::CompositingAndBlendingOperator::Normal;} else if effects.backdrop_filter.is_some() {layer.backdrop_base_color = self.backdrop_base_color(effect);+ layer.backdrop_blur_edge = self.backdrop_blur_edge(effect);}self.painter.push_layer(&layer);}diff --git a/Libraries/LibGfx/Rust/src/filter.rs b/Libraries/LibGfx/Rust/src/filter.rsindex 7f35bf675a1..9758982af26 100644--- a/Libraries/LibGfx/Rust/src/filter.rs+++ b/Libraries/LibGfx/Rust/src/filter.rs@@ -138,6 +138,8 @@ pub enum Filter {Blur {radius_x: f32,radius_y: f32,+ /// Whether this is a blur() filter function, which mirrors at the edge of a backdrop.+ mirrors_at_backdrop_edge: bool,input: Option<Box<Filter>>,},ColorFilter {@@ -214,10 +216,23 @@ impl Filter {}}+ /// The blur() filter function, which unlike [`Self::gaussian_blur`] mirrors at the edge of a+ /// backdrop.pub fn blur(radius_x: f32, radius_y: f32, input: Option<Filter>) -> Self {Self::Blur {radius_x,radius_y,+ mirrors_at_backdrop_edge: true,+ input: input.map(Box::new),+ }+ }++ /// A blur that reads its input as it is, such as an feGaussianBlur primitive.+ pub fn gaussian_blur(radius_x: f32, radius_y: f32, input: Option<Filter>) -> Self {+ Self::Blur {+ radius_x,+ radius_y,+ mirrors_at_backdrop_edge: false,input: input.map(Box::new),}}@@ -343,6 +358,27 @@ impl Filter {}}+ /// Whether the graph holds a blur that mirrors at the edge of a backdrop.+ fn has_mirroring_blur(&self) -> bool {+ if matches!(+ self,+ Self::Blur {+ mirrors_at_backdrop_edge: true,+ ..+ }+ ) {+ return true;+ }+ let mut found = false;+ self.for_each_input(&mut |input| found = found || input.has_mirroring_blur());+ found+ }++ /// [`Self::has_mirroring_blur`] for a serialized graph. Bytes that do not hold a graph have none.+ pub fn serialized_has_mirroring_blur(bytes: &[u8]) -> bool {+ Self::deserialize(bytes).is_some_and(|filter| filter.has_mirroring_blur())+ }+/// [`Self::may_affect_output_bounds`] for a serialized graph, answered without building it./// Bytes that do not hold a graph are assumed to affect the bounds.pub fn serialized_may_affect_output_bounds(bytes: &[u8]) -> bool {@@ -455,6 +491,7 @@ impl Filter {radius_x,radius_y,input,+ ..} => input_bounds(input).outset(gaussian_reach(*radius_x), gaussian_reach(*radius_y)),Self::DropShadow {offset_x,@@ -783,9 +820,15 @@ impl Writer<'_> {Filter::Blur {radius_x,radius_y,+ mirrors_at_backdrop_edge,input,+ } => {+ self.f32(*radius_x);+ self.f32(*radius_y);+ self.bool(*mirrors_at_backdrop_edge);+ self.optional_filter(input.as_deref());}- | Filter::Erode {+ Filter::Erode {radius_x,radius_y,input,@@ -993,6 +1036,7 @@ impl Reader<'_> {FilterOperationType::Blur => Filter::Blur {radius_x: self.f32()?,radius_y: self.f32()?,+ mirrors_at_backdrop_edge: self.bool()?,input: self.optional_input()?,},FilterOperationType::ColorFilter => Filter::ColorFilter {@@ -1081,7 +1125,7 @@ mod tests {const EVERY_OPERATION_FILTER_BYTES: &str = concat!("01020103332211ff0000003f010000010e0000c03f000020c0010c2a0000000000000001000000020000000300000004","00000005000000060000000700000008000000010000000000803e0000003f0000403f0000803f130000000d04000000",- "01050000803f000000400000404000ff007f0106000080400000a0400107020000000000003f00000104011100000000",+ "01050000803f000000400000404000ff007f0106000080400000a040010107020000000000003f00000104011100000000","cdcccc3dcdcc4c3e030000000000e0401000000008000000010f0000803f0000803f0110000000400000004000000020","41000000000300000001090100010000fffefdfcfbfaf9f8f7f6f5f4f3f2f1f0efeeedecebeae9e8e7e6e5e4e3e2e1e0","dfdedddcdbdad9d8d7d6d5d4d3d2d1d0cfcecdcccbcac9c8c7c6c5c4c3c2c1c0bfbebdbcbbbab9b8b7b6b5b4b3b2b1b0",diff --git a/Libraries/LibWeb/Rust/src/painting/svg_filter.rs b/Libraries/LibWeb/Rust/src/painting/svg_filter.rsindex ba4d4e7d00a..12d26f41b68 100644--- a/Libraries/LibWeb/Rust/src/painting/svg_filter.rs+++ b/Libraries/LibWeb/Rust/src/painting/svg_filter.rs@@ -237,11 +237,11 @@ impl SvgFilterGraphBuilder {})}}- FfiSvgFilterPrimitiveKind::GaussianBlur => in_space(Filter::Blur {- radius_x: values.std_deviation_x * self.scale,- radius_y: values.std_deviation_y * self.scale,- input: boxed(self.resolve_input_in(&primitive.in1, space)),- }),+ FfiSvgFilterPrimitiveKind::GaussianBlur => in_space(Filter::gaussian_blur(+ values.std_deviation_x * self.scale,+ values.std_deviation_y * self.scale,+ self.resolve_input_in(&primitive.in1, space),+ )),FfiSvgFilterPrimitiveKind::ColorMatrix => {let input = self.resolve_input_in(&primitive.in1, space);let matrix_values = primitive.color_matrix_values;@@ -341,11 +341,11 @@ impl SvgFilterGraphBuilder {matrix: ALPHA_ONLY_MATRIX,input: boxed(input.clone()),};- let blurred = Filter::Blur {- radius_x: values.std_deviation_x * self.scale,- radius_y: values.std_deviation_y * self.scale,- input: Some(Box::new(alpha)),- };+ let blurred = Filter::gaussian_blur(+ values.std_deviation_x * self.scale,+ values.std_deviation_y * self.scale,+ Some(alpha),+ );// 2. Offset the result of step 1 by dx and dy as specified on the feDropShadow element,// equivalent to applying an feOffset with these parameters://@@ -504,15 +504,15 @@ mod tests {Some(Filter::ColorSpaceConversion {source_color_space: InterpolationColorSpace::LinearRGB,destination_color_space: InterpolationColorSpace::SRGB,- input: Some(Box::new(Filter::Blur {- radius_x: 4.0,- radius_y: 4.0,- input: Some(Box::new(Filter::ColorSpaceConversion {+ input: Some(Box::new(Filter::gaussian_blur(+ 4.0,+ 4.0,+ Some(Filter::ColorSpaceConversion {source_color_space: InterpolationColorSpace::SRGB,destination_color_space: InterpolationColorSpace::LinearRGB,input: None,- })),- })),+ }),+ ))),}));}@@ -522,8 +522,8 @@ mod tests {let mut merge = primitive(FfiSvgFilterPrimitiveKind::Merge, InterpolationColorSpace::SRGB);merge.merge_inputs = vec![name("first"), name("SourceAlpha"), name("missing")];- let first_blur = Filter::blur(1.0, 1.0, None);- let second_blur = Filter::blur(2.0, 2.0, Some(first_blur.clone()));+ let first_blur = Filter::gaussian_blur(1.0, 1.0, None);+ let second_blur = Filter::gaussian_blur(2.0, 2.0, Some(first_blur.clone()));assert_eq!(graph([blur("SourceGraphic", 1.0, "first"), blur("", 2.0, ""), merge], 1.0),Some(Filter::Merge {@@ -550,7 +550,7 @@ mod tests {assert_eq!(graph([matrix()], 1.0), None);assert_eq!(graph([blur("SourceGraphic", 1.0, ""), matrix()], 1.0),- Some(Filter::blur(1.0, 1.0, None))+ Some(Filter::gaussian_blur(1.0, 1.0, None)));}@@ -569,14 +569,14 @@ mod tests {background: Some(Box::new(Filter::Offset {dx: 1.0,dy: 2.0,- input: Some(Box::new(Filter::Blur {- radius_x: 3.0,- radius_y: 3.0,- input: Some(Box::new(Filter::ColorMatrix {+ input: Some(Box::new(Filter::gaussian_blur(+ 3.0,+ 3.0,+ Some(Filter::ColorMatrix {matrix: ALPHA_ONLY_MATRIX,input: None,- })),- })),+ }),+ ))),})),foreground: Some(Box::new(Filter::Flood {color: Color::from_rgb(0, 0, 0),diff --git a/Services/Compositor/DisplayListPlayerSkia.cpp b/Services/Compositor/DisplayListPlayerSkia.cppindex 268fbd142eb..110d317527a 100644--- a/Services/Compositor/DisplayListPlayerSkia.cpp+++ b/Services/Compositor/DisplayListPlayerSkia.cpp@@ -1571,13 +1571,43 @@ void DisplayListPlayerSkia::push_layer(ReplayLayer const& layer)canvas.saveLayer(SkCanvas::SaveLayerRec(nullptr, &paint, backdrop_image_filter(layer, true).get(), 0));}-// With `limited_to_region`, the filtered backdrop is cropped to the rounded region inside the filter-// graph, which also bounds what the filter reads.+// Replay gives the edge as the clips around the box leave it. What lies beyond the surface cannot be read, so the edge+// stops there too, which keeps a box larger than the surface cheap to read. Skia keeps only whole pixels of a mirroring+// crop, so the edge has to span the pixels it touches; otherwise, a region thinner than a pixel would vanish.+static Gfx::FloatRect backdrop_blur_edge_on_surface(SkCanvas const& canvas, Gfx::FloatRect clipped_region)+{+ auto const& matrix = canvas.getTotalMatrix();+ SkMatrix inverse;+ if (!matrix.invert(&inverse))+ return clipped_region;+ auto edge = to_skia_rect(clipped_region);+ auto surface_bounds = SkRect::Make(canvas.getBaseLayerSize());+ if (matrix.rectStaysRect()) {+ edge = SkRect::Make(matrix.mapRect(edge).roundOut());+ if (!edge.intersect(surface_bounds))+ return {};+ edge = inverse.mapRect(edge);+ } else {+ if (!edge.intersect(inverse.mapRect(surface_bounds)))+ return {};+ // Skia picks the pixels of a turned box in a space of its own, so only their largest possible size is known.+ if (auto scale = matrix.getMinScale(); scale > 0) {+ auto pixel = 1 / scale;+ edge.outset(edge.width() < 2 * pixel ? pixel : 0, edge.height() < 2 * pixel ? pixel : 0);+ }+ }+ return { edge.x(), edge.y(), edge.width(), edge.height() };+}++// With `limited_to_region`, the filtered backdrop is cropped to the rounded region inside the filter graph.sk_sp<SkImageFilter> DisplayListPlayerSkia::backdrop_image_filter(ReplayLayer const& layer, bool limited_to_region){ReadonlyBytes filter_bytes { layer.backdrop_filter_bytes, layer.backdrop_filter_bytes_size };- return raster_cache().backdrop_image_filter(active_visual_context_tree().structural_epoch(), layer, limited_to_region, [&] {- auto image_filter = image_filter_from_bytes(filter_bytes);+ Optional<Gfx::FloatRect> blur_edge;+ if (layer.backdrop_blur_edge.has_value())+ blur_edge = backdrop_blur_edge_on_surface(surface().canvas(), *layer.backdrop_blur_edge);+ return raster_cache().backdrop_image_filter(active_visual_context_tree().structural_epoch(), layer, blur_edge, limited_to_region, [&] {+ auto image_filter = image_filter_from_bytes(filter_bytes, blur_edge);if (layer.backdrop_base_color.alpha() != 0) {auto base = SkImageFilters::Shader(SkShaders::Color(to_skia_color(layer.backdrop_base_color)));image_filter = SkImageFilters::Compose(move(image_filter), SkImageFilters::Blend(SkBlendMode::kSrcOver, move(base), nullptr));@@ -1607,11 +1637,9 @@ sk_sp<SkImageFilter> DisplayListPlayerSkia::layer_image_filter(ReplayLayer const});}-sk_sp<SkImageFilter> DisplayListPlayerSkia::image_filter_from_bytes(ReadonlyBytes filter_bytes)+sk_sp<SkImageFilter> DisplayListPlayerSkia::image_filter_from_bytes(ReadonlyBytes filter_bytes, Optional<Gfx::FloatRect> blur_edge){- return Gfx::to_skia_image_filter(filter_bytes, [&](u64 image_id) -> Gfx::DecodedImageFrame const& {- return resource_storage().image_frame(ImageFrameResourceId { image_id });- });+ return Gfx::to_skia_image_filter(filter_bytes, [&](u64 image_id) -> Gfx::DecodedImageFrame const& { return resource_storage().image_frame(ImageFrameResourceId { image_id }); }, blur_edge);}// A mask that applies to a box's filtered backdrop starts its layer with that backdrop, read from thediff --git a/Services/Compositor/DisplayListPlayerSkia.h b/Services/Compositor/DisplayListPlayerSkia.hindex 34234eba3ae..77f90f06e3b 100644--- a/Services/Compositor/DisplayListPlayerSkia.h+++ b/Services/Compositor/DisplayListPlayerSkia.h@@ -9,6 +9,7 @@#include <AK/Function.h>#include <AK/NonnullOwnPtr.h>#include <AK/NonnullRefPtr.h>+#include <AK/Optional.h>#include <AK/RefPtr.h>#include <Compositor/CompositedContext.h>#include <Compositor/DisplayListPlayer.h>@@ -17,6 +18,7 @@#include <LibCompositing/DisplayList/DisplayList.h>#include <LibCompositing/DisplayList/DisplayListCommand.h>#include <LibGfx/Forward.h>+#include <LibGfx/Rect.h>class GrDirectContext;class SkColorFilter;@@ -80,7 +82,7 @@ private:SkPaint paint_style_to_skia_paint(Compositing::DisplayListPaintStyle const&, Gfx::FloatRect const& bounding_rect);sk_sp<SkImageFilter> layer_image_filter(Compositing::ReplayLayer const&);sk_sp<SkImageFilter> backdrop_image_filter(Compositing::ReplayLayer const&, bool limited_to_region);- sk_sp<SkImageFilter> image_filter_from_bytes(ReadonlyBytes);+ sk_sp<SkImageFilter> image_filter_from_bytes(ReadonlyBytes, Optional<Gfx::FloatRect> blur_edge = {});Gfx::Path path_from_data(Compositing::DisplayListDataSpan) const;sk_sp<SkImage> rasterize_records_into_tile(ReadonlyBytes tile_records, Gfx::IntRect tile_rect);ReadonlySpan<Color> gradient_colors(Compositing::DisplayListGradientColorStops) const;diff --git a/Services/Compositor/DisplayListRasterCache.cpp b/Services/Compositor/DisplayListRasterCache.cppindex ddce7953542..3ef2ce1dd91 100644--- a/Services/Compositor/DisplayListRasterCache.cpp+++ b/Services/Compositor/DisplayListRasterCache.cpp@@ -44,6 +44,7 @@ struct DisplayListRasterCache::LayerImageFilterCache {struct BackdropEntry {ByteBuffer filter_bytes;Gfx::IntRect region;+ Optional<Gfx::FloatRect> blur_edge;Gfx::CornerRadii corner_radii;Gfx::Color base_color;bool limited_to_region { false };@@ -204,19 +205,20 @@ sk_sp<SkImageFilter> DisplayListRasterCache::layer_image_filter(u64 tree_structureturn image_filter;}-sk_sp<SkImageFilter> DisplayListRasterCache::backdrop_image_filter(u64 tree_structural_epoch, ReplayLayer const& layer, bool limited_to_region, Function<sk_sp<SkImageFilter>()> const& create)+sk_sp<SkImageFilter> DisplayListRasterCache::backdrop_image_filter(u64 tree_structural_epoch, ReplayLayer const& layer, Optional<Gfx::FloatRect> blur_edge, bool limited_to_region, Function<sk_sp<SkImageFilter>()> const& create){ReadonlyBytes filter_bytes { layer.backdrop_filter_bytes, layer.backdrop_filter_bytes_size };auto& entries = ensure_layer_image_filter_cache(tree_structural_epoch).backdrop_entries_by_tree_structural_epoch_and_effect.ensure(tree_structural_epoch);if (auto cached = entries.get(layer.effect.value()); cached.has_value()&& cached->filter_bytes.bytes() == filter_bytes&& cached->region == layer.backdrop_region+ && cached->blur_edge == blur_edge&& cached->corner_radii == layer.backdrop_corner_radii&& cached->base_color == layer.backdrop_base_color&& cached->limited_to_region == limited_to_region)return cached->image_filter;auto image_filter = create();- entries.set(layer.effect.value(), LayerImageFilterCache::BackdropEntry { MUST(ByteBuffer::copy(filter_bytes)), layer.backdrop_region, layer.backdrop_corner_radii, layer.backdrop_base_color, limited_to_region, image_filter });+ entries.set(layer.effect.value(), LayerImageFilterCache::BackdropEntry { MUST(ByteBuffer::copy(filter_bytes)), layer.backdrop_region, blur_edge, layer.backdrop_corner_radii, layer.backdrop_base_color, limited_to_region, image_filter });return image_filter;}diff --git a/Services/Compositor/DisplayListRasterCache.h b/Services/Compositor/DisplayListRasterCache.hindex 9a3d7984ddd..b0f7ab7cec2 100644--- a/Services/Compositor/DisplayListRasterCache.h+++ b/Services/Compositor/DisplayListRasterCache.h@@ -86,7 +86,7 @@ public:sk_sp<SkTextBlob> text_blob(Compositing::DisplayListResourceStorage const&, Compositing::FontResourceId, float scale, ReadonlySpan<Compositing::DisplayListGlyph>, u8 font_smoothing);sk_sp<SkImageFilter> layer_image_filter(u64 tree_structural_epoch, Compositing::ReplayLayer const&, Function<sk_sp<SkImageFilter>()> const& create);- sk_sp<SkImageFilter> backdrop_image_filter(u64 tree_structural_epoch, Compositing::ReplayLayer const&, bool limited_to_region, Function<sk_sp<SkImageFilter>()> const& create);+ sk_sp<SkImageFilter> backdrop_image_filter(u64 tree_structural_epoch, Compositing::ReplayLayer const&, Optional<Gfx::FloatRect> blur_edge, bool limited_to_region, Function<sk_sp<SkImageFilter>()> const& create);// The Skia path for a path that stays the same for as long as it has this identity. Keeping one Skia path lets// the caches that are keyed on it work.diff --git a/Services/Compositor/SkiaUtils.cpp b/Services/Compositor/SkiaUtils.cppindex 9b244e0618d..5c0aadb71b9 100644--- a/Services/Compositor/SkiaUtils.cpp+++ b/Services/Compositor/SkiaUtils.cpp@@ -58,10 +58,11 @@ namespace {// layout is defined by the filter module of libgfx_rust, whose codec is the other reader of it.class SkiaFilterReader {public:- SkiaFilterReader(ReadonlyBytes bytes, Function<DecodedImageFrame const&(u64)> const& image_frame)+ SkiaFilterReader(ReadonlyBytes bytes, Function<DecodedImageFrame const&(u64)> const& image_frame, Optional<FloatRect> blur_edge): m_bytes(bytes), m_stream(bytes), m_image_frame(image_frame)+ , m_blur_edge(blur_edge){}@@ -123,6 +124,7 @@ private:ReadonlyBytes m_bytes;FixedMemoryStream m_stream;Function<DecodedImageFrame const&(u64)> const& m_image_frame;+ Optional<FloatRect> m_blur_edge;};sk_sp<SkImageFilter> SkiaFilterReader::filter()@@ -200,7 +202,10 @@ sk_sp<SkImageFilter> SkiaFilterReader::filter()case FilterOperationType::Blur: {auto radius_x = value<float>();auto radius_y = value<float>();+ auto mirrors_at_backdrop_edge = value<bool>();auto input = optional_filter();+ if (mirrors_at_backdrop_edge && m_blur_edge.has_value())+ input = SkImageFilters::Crop(to_skia_rect(*m_blur_edge), SkTileMode::kMirror, move(input));return SkImageFilters::Blur(radius_x, radius_y, input);}case FilterOperationType::ColorFilter: {@@ -424,9 +429,9 @@ sk_sp<SkImageFilter> SkiaFilterReader::filter()}-sk_sp<SkImageFilter> to_skia_image_filter(ReadonlyBytes serialized_filter, Function<DecodedImageFrame const&(u64)> const& image_frame)+sk_sp<SkImageFilter> to_skia_image_filter(ReadonlyBytes serialized_filter, Function<DecodedImageFrame const&(u64)> const& image_frame, Optional<FloatRect> blur_edge){- return SkiaFilterReader { serialized_filter, image_frame }.read_graph();+ return SkiaFilterReader { serialized_filter, image_frame, blur_edge }.read_graph();}sk_sp<SkImage> sk_image_from_bitmap(Bitmap const& bitmap, ColorSpace const& color_space)diff --git a/Services/Compositor/SkiaUtils.h b/Services/Compositor/SkiaUtils.hindex 71ca0e157fa..be3b0774d9d 100644--- a/Services/Compositor/SkiaUtils.h+++ b/Services/Compositor/SkiaUtils.h@@ -10,6 +10,7 @@#include <AK/Assertions.h>#include <AK/Function.h>+#include <AK/Optional.h>#include <LibGfx/Bitmap.h>#include <LibGfx/CompositingAndBlendingOperator.h>#include <LibGfx/PaintStyle.h>@@ -142,7 +143,8 @@ SkPath to_skia_path(PathData const&);SkPath to_skia_path(Path const& path);// Builds the SkImageFilter tree a serialized filter graph describes; `image_frame` supplies the// frames the graph names by id.-sk_sp<SkImageFilter> to_skia_image_filter(ReadonlyBytes serialized_filter, Function<DecodedImageFrame const&(u64)> const& image_frame);+// With `blur_edge`, every blur() filter function reads its input mirrored at that rect, not what lies outside it.+sk_sp<SkImageFilter> to_skia_image_filter(ReadonlyBytes serialized_filter, Function<DecodedImageFrame const&(u64)> const& image_frame, Optional<FloatRect> blur_edge = {});sk_sp<SkBlender> to_skia_blender(Gfx::CompositingAndBlendingOperator compositing_and_blending_operator);// The returned SkImage references the source bitmap's pixels without copying; the callerdiff --git a/Tests/LibWeb/Ref/expected/visual-context/backdrop-filter-blur-in-rotated-clip-ref.html b/Tests/LibWeb/Ref/expected/visual-context/backdrop-filter-blur-in-rotated-clip-ref.htmlnew file mode 100644index 00000000000..030060e855f--- /dev/null+++ b/Tests/LibWeb/Ref/expected/visual-context/backdrop-filter-blur-in-rotated-clip-ref.html@@ -0,0 +1,36 @@+<!DOCTYPE html>+<style>+body {+ margin: 0;+ background: black;+}+.rotated {+ position: absolute;+ left: 100px;+ top: 100px;+ width: 200px;+ height: 200px;+ transform: rotate(20deg);+}+.neighbor {+ position: absolute;+ left: 50px;+ top: 40px;+ width: 100px;+ height: 16px;+ background: white;+}+.clip {+ position: absolute;+ left: 50px;+ top: 60px;+ width: 100px;+ height: 40px;+ overflow: hidden;+}+</style>+<div class="rotated">+ <div class="neighbor"></div>+ <div class="clip">+ </div>+</div>diff --git a/Tests/LibWeb/Ref/expected/visual-context/backdrop-filter-blur-mirrors-at-border-box-ref.html b/Tests/LibWeb/Ref/expected/visual-context/backdrop-filter-blur-mirrors-at-border-box-ref.htmlnew file mode 100644index 00000000000..dfe2a419722--- /dev/null+++ b/Tests/LibWeb/Ref/expected/visual-context/backdrop-filter-blur-mirrors-at-border-box-ref.html@@ -0,0 +1,37 @@+<!DOCTYPE html>+<style>+body {+ margin: 0;+ background: blue;+}+.clip {+ position: absolute;+ left: 100px;+ top: 100px;+ width: 100px;+ height: 100px;+ overflow: hidden;+}+.blurred {+ position: absolute;+ left: -100px;+ top: -100px;+ width: 300px;+ height: 300px;+ background: blue;+ filter: blur(24px);+}+.strip {+ position: absolute;+ left: 80px;+ top: 0;+ width: 40px;+ height: 300px;+ background: red;+}+</style>+<div class="clip">+ <div class="blurred">+ <div class="strip"></div>+ </div>+</div>diff --git a/Tests/LibWeb/Ref/expected/visual-context/backdrop-filter-blur-of-thin-and-huge-boxes-ref.html b/Tests/LibWeb/Ref/expected/visual-context/backdrop-filter-blur-of-thin-and-huge-boxes-ref.htmlnew file mode 100644index 00000000000..2f1c570610f--- /dev/null+++ b/Tests/LibWeb/Ref/expected/visual-context/backdrop-filter-blur-of-thin-and-huge-boxes-ref.html@@ -0,0 +1,15 @@+<!DOCTYPE html>+<style>+body {+ margin: 0;+ background: black;+}+.filtered {+ position: absolute;+ backdrop-filter: invert(1);+}+</style>+<div class="filtered" style="left: 20px; top: 20px; width: 100px; height: 1px; transform: translateY(0.5px)"></div>+<div class="filtered" style="left: 20px; top: 40px; width: 100px; height: 1px; transform: scaleY(0.5)"></div>+<div class="filtered" style="left: 20px; top: 80px; width: 100px; height: 1px; transform: rotate(30deg) scaleY(0.5)"></div>+<div class="filtered" style="left: 200px; top: 20px; width: 100px; height: 60000px"></div>diff --git a/Tests/LibWeb/Ref/expected/visual-context/backdrop-filter-blur-reads-only-border-box-ref.html b/Tests/LibWeb/Ref/expected/visual-context/backdrop-filter-blur-reads-only-border-box-ref.htmlnew file mode 100644index 00000000000..7f8adfb9d21--- /dev/null+++ b/Tests/LibWeb/Ref/expected/visual-context/backdrop-filter-blur-reads-only-border-box-ref.html@@ -0,0 +1,24 @@+<!DOCTYPE html>+<style>+body {+ margin: 0;+ background: black;+}+.neighbor {+ position: absolute;+ width: 50px;+ height: 40px;+ background: white;+}+</style>+<div class="neighbor" style="left: 50px; top: 20px"></div>+<div class="neighbor" style="left: 200px; top: 20px"></div>+<div class="neighbor" style="left: 50px; top: 100px"></div>+<div class="neighbor" style="left: 200px; top: 100px"></div>+<div class="neighbor" style="left: 50px; top: 180px"></div>+<div class="neighbor" style="left: 200px; top: 180px"></div>+<div class="neighbor" style="left: 50px; top: 260px"></div>+<div class="neighbor" style="left: 200px; top: 260px"></div>+<div class="neighbor" style="left: 50px; top: 340px"></div>+<div class="neighbor" style="left: 200px; top: 340px"></div>+<div class="neighbor" style="left: 100px; top: 420px; width: 100px; height: 20px"></div>diff --git a/Tests/LibWeb/Ref/expected/visual-context/backdrop-filter-gaussian-blur-does-not-mirror-ref.html b/Tests/LibWeb/Ref/expected/visual-context/backdrop-filter-gaussian-blur-does-not-mirror-ref.htmlnew file mode 100644index 00000000000..c198a16806f--- /dev/null+++ b/Tests/LibWeb/Ref/expected/visual-context/backdrop-filter-gaussian-blur-does-not-mirror-ref.html@@ -0,0 +1,38 @@+<!DOCTYPE html>+<style>+body {+ margin: 0;+ background: blue;+}+.clip {+ position: absolute;+ left: 100px;+ top: 100px;+ width: 100px;+ height: 100px;+ overflow: hidden;+}+.blurred {+ position: absolute;+ left: -100px;+ top: -100px;+ width: 300px;+ height: 300px;+ background: blue;+ filter: blur(24px);+}+.strip {+ position: absolute;+ left: 100px;+ top: 0;+ width: 20px;+ height: 300px;+ background: red;+}+</style>+<div class="strip"></div>+<div class="clip">+ <div class="blurred">+ <div class="strip"></div>+ </div>+</div>diff --git a/Tests/LibWeb/Ref/input/visual-context/backdrop-filter-blur-in-rotated-clip.html b/Tests/LibWeb/Ref/input/visual-context/backdrop-filter-blur-in-rotated-clip.htmlnew file mode 100644index 00000000000..7fe56166b7b--- /dev/null+++ b/Tests/LibWeb/Ref/input/visual-context/backdrop-filter-blur-in-rotated-clip.html@@ -0,0 +1,48 @@+<!DOCTYPE html>+<link rel="match" href="../../expected/visual-context/backdrop-filter-blur-in-rotated-clip-ref.html">+<style>+body {+ margin: 0;+ background: black;+}+.rotated {+ position: absolute;+ left: 100px;+ top: 100px;+ width: 200px;+ height: 200px;+ transform: rotate(20deg);+}+.neighbor {+ position: absolute;+ left: 50px;+ top: 40px;+ width: 100px;+ height: 16px;+ background: white;+}+.clip {+ position: absolute;+ left: 50px;+ top: 60px;+ width: 100px;+ height: 40px;+ overflow: hidden;+}+.filtered {+ position: absolute;+ left: 0;+ top: -20px;+ width: 100px;+ height: 60px;+ backdrop-filter: blur(20px);+}+</style>+<!-- The white box lies inside the filtered box but outside the clip, which turns along with both, so+ it stays out of the black backdrop that the clip leaves visible. -->+<div class="rotated">+ <div class="neighbor"></div>+ <div class="clip">+ <div class="filtered"></div>+ </div>+</div>diff --git a/Tests/LibWeb/Ref/input/visual-context/backdrop-filter-blur-mirrors-at-border-box.html b/Tests/LibWeb/Ref/input/visual-context/backdrop-filter-blur-mirrors-at-border-box.htmlnew file mode 100644index 00000000000..25ef93290ed--- /dev/null+++ b/Tests/LibWeb/Ref/input/visual-context/backdrop-filter-blur-mirrors-at-border-box.html@@ -0,0 +1,28 @@+<!DOCTYPE html>+<link rel="match" href="../../expected/visual-context/backdrop-filter-blur-mirrors-at-border-box-ref.html">+<style>+body {+ margin: 0;+ background: blue;+}+.strip {+ position: absolute;+ left: 100px;+ top: 100px;+ width: 20px;+ height: 100px;+ background: red;+}+.filtered {+ position: absolute;+ left: 100px;+ top: 100px;+ width: 100px;+ height: 100px;+ backdrop-filter: blur(24px);+}+</style>+<!-- The red strip lies against the left edge of the box. Mirrored at that edge it blurs as a strip twice+ as wide, which the reference spells out. Clamping or dropping the edge pixels looks different. -->+<div class="strip"></div>+<div class="filtered"></div>diff --git a/Tests/LibWeb/Ref/input/visual-context/backdrop-filter-blur-of-thin-and-huge-boxes.html b/Tests/LibWeb/Ref/input/visual-context/backdrop-filter-blur-of-thin-and-huge-boxes.htmlnew file mode 100644index 00000000000..995a5bf1a76--- /dev/null+++ b/Tests/LibWeb/Ref/input/visual-context/backdrop-filter-blur-of-thin-and-huge-boxes.html@@ -0,0 +1,18 @@+<!DOCTYPE html>+<link rel="match" href="../../expected/visual-context/backdrop-filter-blur-of-thin-and-huge-boxes-ref.html">+<style>+body {+ margin: 0;+ background: black;+}+.filtered {+ position: absolute;+ backdrop-filter: blur(1px) invert(1);+}+</style>+<!-- Blurring the uniform black backdrop changes nothing, so each box shows it inverted, however thin the box+ is in device pixels and however far it reaches beyond the viewport. -->+<div class="filtered" style="left: 20px; top: 20px; width: 100px; height: 1px; transform: translateY(0.5px)"></div>+<div class="filtered" style="left: 20px; top: 40px; width: 100px; height: 1px; transform: scaleY(0.5)"></div>+<div class="filtered" style="left: 20px; top: 80px; width: 100px; height: 1px; transform: rotate(30deg) scaleY(0.5)"></div>+<div class="filtered" style="left: 200px; top: 20px; width: 100px; height: 60000px"></div>diff --git a/Tests/LibWeb/Ref/input/visual-context/backdrop-filter-blur-reads-only-border-box.html b/Tests/LibWeb/Ref/input/visual-context/backdrop-filter-blur-reads-only-border-box.htmlnew file mode 100644index 00000000000..10d8b995dec--- /dev/null+++ b/Tests/LibWeb/Ref/input/visual-context/backdrop-filter-blur-reads-only-border-box.html@@ -0,0 +1,43 @@+<!DOCTYPE html>+<link rel="match" href="../../expected/visual-context/backdrop-filter-blur-reads-only-border-box-ref.html">+<style>+body {+ margin: 0;+ background: black;+}+.neighbor {+ position: absolute;+ width: 50px;+ height: 40px;+ background: white;+}+.filtered {+ position: absolute;+ left: 100px;+ width: 100px;+ height: 40px;+ backdrop-filter: blur(20px);+}+</style>+<!-- The blur mirrors at the border box and reads nothing outside it, so the white boxes next to each+ filtered box stay out of its black backdrop, on the paths with and without an effects layer, under a+ mask, and where an ancestor clips the box so that the white box above it is inside the box but clipped away. -->+<div class="neighbor" style="left: 50px; top: 20px"></div>+<div class="neighbor" style="left: 200px; top: 20px"></div>+<div class="neighbor" style="left: 50px; top: 100px"></div>+<div class="neighbor" style="left: 200px; top: 100px"></div>+<div class="neighbor" style="left: 50px; top: 180px"></div>+<div class="neighbor" style="left: 200px; top: 180px"></div>+<div class="neighbor" style="left: 50px; top: 260px"></div>+<div class="neighbor" style="left: 200px; top: 260px"></div>+<div class="neighbor" style="left: 50px; top: 340px"></div>+<div class="neighbor" style="left: 200px; top: 340px"></div>+<div class="neighbor" style="left: 100px; top: 420px; width: 100px; height: 20px"></div>+<div class="filtered" style="top: 20px"></div>+<div class="filtered" style="top: 100px; border-radius: 10px"></div>+<div class="filtered" style="top: 180px; opacity: 0.5"></div>+<div class="filtered" style="top: 260px; transform: translateX(1px) scaleX(0.98)"></div>+<div class="filtered" style="top: 340px; mask-image: linear-gradient(black, black)"></div>+<div style="position: absolute; left: 100px; top: 440px; width: 100px; height: 40px; overflow: hidden">+ <div class="filtered" style="left: 0; top: -20px; height: 60px"></div>+</div>diff --git a/Tests/LibWeb/Ref/input/visual-context/backdrop-filter-gaussian-blur-does-not-mirror.html b/Tests/LibWeb/Ref/input/visual-context/backdrop-filter-gaussian-blur-does-not-mirror.htmlnew file mode 100644index 00000000000..c402f0a7b21--- /dev/null+++ b/Tests/LibWeb/Ref/input/visual-context/backdrop-filter-gaussian-blur-does-not-mirror.html@@ -0,0 +1,33 @@+<!DOCTYPE html>+<link rel="match" href="../../expected/visual-context/backdrop-filter-gaussian-blur-does-not-mirror-ref.html">+<style>+body {+ margin: 0;+ background: blue;+}+.strip {+ position: absolute;+ left: 100px;+ top: 0;+ width: 20px;+ height: 300px;+ background: red;+}+.filtered {+ position: absolute;+ left: 100px;+ top: 100px;+ width: 100px;+ height: 100px;+ backdrop-filter: url(#blur);+}+</style>+<!-- Only the blur() function mirrors at the box. An feGaussianBlur reads the blue beyond the left edge+ of the box as it is, as in the reference. -->+<svg width="0" height="0" style="position: absolute">+ <filter id="blur" color-interpolation-filters="sRGB">+ <feGaussianBlur stdDeviation="24" />+ </filter>+</svg>+<div class="strip"></div>+<div class="filtered"></div>