Skip to content

Truly independent web browser

LibGfx+LibCompositing+Compositor: Remove Gfx::Filter

Aliaksandr Kalenik67fe150b2591
diff --git a/Libraries/LibCompositing/DisplayList/AccumulatedVisualContext.cpp b/Libraries/LibCompositing/DisplayList/AccumulatedVisualContext.cpp
index e3f706dd209..5243867c297 100644
--- a/Libraries/LibCompositing/DisplayList/AccumulatedVisualContext.cpp
+++ b/Libraries/LibCompositing/DisplayList/AccumulatedVisualContext.cpp
@@ -226,13 +226,13 @@ bool AccumulatedVisualContextTree::has_unisolated_destination_reading_effect() c
return Compositing::RustFFI::visual_context_tree_has_unisolated_destination_reading_effect(m_rust_tree);
}
-void AccumulatedVisualContextTree::for_each_effects_filter_bytes(Function<void(ReadonlyBytes)> const& visit) const
+void AccumulatedVisualContextTree::for_each_effects_filter_image_frame_id(Function<void(u64)> const& visit) const
{
- struct FilterBytesVisitor {
- Function<void(ReadonlyBytes)> const& visit;
+ struct ImageFrameIdVisitor {
+ Function<void(u64)> const& visit;
} visitor { visit };
- Compositing::RustFFI::visual_context_tree_for_each_effects_filter_bytes(m_rust_tree, &visitor, [](void* context, u8 const* bytes, size_t size) {
- static_cast<FilterBytesVisitor*>(context)->visit(ReadonlyBytes { bytes, size });
+ Compositing::RustFFI::visual_context_tree_for_each_effects_filter_image_frame_id(m_rust_tree, &visitor, [](void* context, u64 image_frame_id) {
+ static_cast<ImageFrameIdVisitor*>(context)->visit(image_frame_id);
});
}
diff --git a/Libraries/LibCompositing/DisplayList/AccumulatedVisualContext.h b/Libraries/LibCompositing/DisplayList/AccumulatedVisualContext.h
index 234b4b71ec2..5239398792e 100644
--- a/Libraries/LibCompositing/DisplayList/AccumulatedVisualContext.h
+++ b/Libraries/LibCompositing/DisplayList/AccumulatedVisualContext.h
@@ -94,7 +94,7 @@ public:
bool effect_is_isolated_by_layer(EffectNodeIndex) const;
bool has_unisolated_destination_reading_effect() const;
- void for_each_effects_filter_bytes(Function<void(ReadonlyBytes)> const&) const;
+ void for_each_effects_filter_image_frame_id(Function<void(u64)> const&) const;
private:
explicit AccumulatedVisualContextTree(void const* retained_tree);
diff --git a/Libraries/LibCompositing/DisplayList/DisplayListResourceStorage.cpp b/Libraries/LibCompositing/DisplayList/DisplayListResourceStorage.cpp
index 69bab8b6f6f..47764111b83 100644
--- a/Libraries/LibCompositing/DisplayList/DisplayListResourceStorage.cpp
+++ b/Libraries/LibCompositing/DisplayList/DisplayListResourceStorage.cpp
@@ -10,7 +10,6 @@
#include <LibCompositing/DisplayList/DisplayListResourceStorage.h>
#include <LibCompositing/RustFFI.h>
#include <LibGfx/Bitmap.h>
-#include <LibGfx/Filter.h>
#include <LibGfx/Font/Font.h>
#include <LibMediaCodecs/VideoFrame.h>
@@ -253,10 +252,8 @@ void DisplayListResourceStorage::collect_referenced_resources(
AccumulatedVisualContextTree const& visual_context_tree,
DisplayListResourceSet& referenced_resources) const
{
- visual_context_tree.for_each_effects_filter_bytes([&](ReadonlyBytes filter_bytes) {
- Gfx::for_each_filter_image_frame_id(filter_bytes, [&](u64 image_id) {
- referenced_resources.image_frames.set(ImageFrameResourceId { image_id }, AK::HashSetExistingEntryBehavior::Keep);
- });
+ visual_context_tree.for_each_effects_filter_image_frame_id([&](u64 image_id) {
+ referenced_resources.image_frames.set(ImageFrameResourceId { image_id }, AK::HashSetExistingEntryBehavior::Keep);
});
}
diff --git a/Libraries/LibCompositing/Rust/src/ffi.rs b/Libraries/LibCompositing/Rust/src/ffi.rs
index f472f0cb6d7..0a0c50ee223 100644
--- a/Libraries/LibCompositing/Rust/src/ffi.rs
+++ b/Libraries/LibCompositing/Rust/src/ffi.rs
@@ -599,13 +599,13 @@ pub unsafe extern "C" fn visual_context_tree_has_unisolated_destination_reading_
/// # Safety
///
-/// `tree` must be a live retained tree handle; `visit` is called synchronously with `context` for every
-/// filter and backdrop filter an effect node carries.
+/// `tree` must be a live retained tree handle; `visit` is called synchronously with `context` for the id
+/// of every image frame that a filter or backdrop filter of an effect node draws.
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn visual_context_tree_for_each_effects_filter_bytes(
+pub unsafe extern "C" fn visual_context_tree_for_each_effects_filter_image_frame_id(
tree: *const c_void,
context: *mut c_void,
- visit: unsafe extern "C" fn(*mut c_void, *const u8, usize),
+ visit: unsafe extern "C" fn(*mut c_void, u64),
) {
let tree = unsafe { tree_from_handle(tree) };
for node in &tree.effect_nodes {
@@ -614,8 +614,11 @@ pub unsafe extern "C" fn visual_context_tree_for_each_effects_filter_bytes(
};
let backdrop_filter_bytes = effects.backdrop_filter.as_ref().map(|backdrop| &backdrop.filter);
for filter_bytes in effects.filter.iter().chain(backdrop_filter_bytes) {
- // SAFETY: The C++ visitor reads the bytes synchronously.
- unsafe { visit(context, filter_bytes.as_ptr(), filter_bytes.len()) };
+ let Some(filter) = libgfx_rust::filter::Filter::deserialize(filter_bytes) else {
+ continue;
+ };
+ // SAFETY: The caller guarantees `visit` accepts `context`.
+ filter.for_each_image_frame_id(&mut |id| unsafe { visit(context, id) });
}
}
}
diff --git a/Libraries/LibGfx/CMakeLists.txt b/Libraries/LibGfx/CMakeLists.txt
index d01ab110629..b877e598a29 100644
--- a/Libraries/LibGfx/CMakeLists.txt
+++ b/Libraries/LibGfx/CMakeLists.txt
@@ -8,7 +8,6 @@ set(SOURCES
ColorSpace.cpp
CornerRadii.cpp
Cursor.cpp
- Filter.cpp
Font/FaceDescription.cpp
Font/Font.cpp
Font/FontCatalog.cpp
diff --git a/Libraries/LibGfx/Filter.cpp b/Libraries/LibGfx/Filter.cpp
deleted file mode 100644
index 7a66e410493..00000000000
--- a/Libraries/LibGfx/Filter.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2025, Lucien Fiorini <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibGfx/Filter.h>
-#include <LibIPC/Decoder.h>
-#include <LibIPC/Encoder.h>
-#include <RustFFI.h>
-
-namespace Gfx {
-
-Filter::Filter(ByteBuffer serialized_bytes)
- : m_serialized_bytes(move(serialized_bytes))
-{
-}
-
-void for_each_filter_image_frame_id(ReadonlyBytes serialized_filter, Function<void(u64)> const& visit)
-{
- FFI::ladybird_gfx_filter_for_each_image_frame_id(
- serialized_filter.data(),
- serialized_filter.size(),
- [](void const* context, u64 image_frame_id) {
- (*static_cast<Function<void(u64)> const*>(context))(image_frame_id);
- },
- &visit);
-}
-
-}
-
-namespace IPC {
-
-template<>
-ErrorOr<void> encode(Encoder& encoder, Gfx::Filter const& filter)
-{
- return encoder.encode(filter.serialized_bytes());
-}
-
-template<>
-ErrorOr<Gfx::Filter> decode(Decoder& decoder)
-{
- return Gfx::Filter { TRY(decoder.decode<ByteBuffer>()) };
-}
-
-}
diff --git a/Libraries/LibGfx/Filter.h b/Libraries/LibGfx/Filter.h
deleted file mode 100644
index 57933bb46f0..00000000000
--- a/Libraries/LibGfx/Filter.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2024-2025, Lucien Fiorini <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <AK/ByteBuffer.h>
-#include <AK/Error.h>
-#include <AK/Function.h>
-#include <AK/Types.h>
-#include <LibGfx/Forward.h>
-#include <LibIPC/Forward.h>
-
-namespace Gfx {
-
-// An image filter graph in the serialized form painting hands across the FFI, the display list and
-// IPC. Graphs are built on the Rust side; this side carries them and reads them into Skia.
-class Filter {
-public:
- explicit Filter(ByteBuffer serialized_bytes);
-
- ReadonlyBytes serialized_bytes() const { return m_serialized_bytes; }
- ByteBuffer take_serialized_bytes() && { return move(m_serialized_bytes); }
-
-private:
- ByteBuffer m_serialized_bytes;
-};
-
-// Visits the id of every image frame a serialized filter graph draws. Bytes that do not hold a
-// filter graph visit nothing.
-void for_each_filter_image_frame_id(ReadonlyBytes serialized_filter, Function<void(u64)> const&);
-
-}
-
-namespace IPC {
-
-template<>
-ErrorOr<void> encode(Encoder&, Gfx::Filter const&);
-
-template<>
-ErrorOr<Gfx::Filter> decode(Decoder&);
-
-}
diff --git a/Libraries/LibGfx/Rust/src/filter.rs b/Libraries/LibGfx/Rust/src/filter.rs
index e4a75727fa2..7f35bf675a1 100644
--- a/Libraries/LibGfx/Rust/src/filter.rs
+++ b/Libraries/LibGfx/Rust/src/filter.rs
@@ -16,8 +16,6 @@
//! type, colors are their ARGB32 value, and a color table is a `u32` length of 256 followed by the
//! table.
-use std::ffi::c_void;
-
use crate::{
Color, ColorFilterType, CompositingAndBlendingOperator, FloatRect, IntRect, IntSize, InterpolationColorSpace,
ScalingMode,
@@ -1074,37 +1072,12 @@ impl Reader<'_> {
}
}
-/// Visits the id of every image frame a serialized filter draws, for a C++ caller that holds only
-/// the bytes. Bytes that do not hold a filter visit nothing.
-///
-/// # Safety
-///
-/// `bytes` must point to `count` readable bytes, and `visit` must accept `context`.
-#[unsafe(no_mangle)]
-pub unsafe extern "C" fn ladybird_gfx_filter_for_each_image_frame_id(
- bytes: *const u8,
- count: usize,
- visit: unsafe extern "C" fn(*const c_void, u64),
- context: *const c_void,
-) {
- let bytes = if count == 0 {
- &[]
- } else {
- // SAFETY: The caller guarantees `count` readable bytes.
- unsafe { ak::slice_from_raw_parts(bytes, count) }
- };
- if let Some(filter) = Filter::deserialize(bytes) {
- // SAFETY: The caller guarantees `visit` accepts `context`.
- filter.for_each_image_frame_id(&mut |id| unsafe { visit(context, id) });
- }
-}
-
#[cfg(test)]
mod tests {
use super::*;
- // The serialized form of every_operation_filter(). Tests/LibGfx/TestFilter.cpp checks the same
- // bytes against the C++ codec, so the two sides cannot drift apart without a test noticing.
+ // The serialized form of every_operation_filter(). The Skia filter reader of the compositor
+ // decodes the same layout, so a change that breaks this test needs the same change there.
const EVERY_OPERATION_FILTER_BYTES: &str = concat!(
"01020103332211ff0000003f010000010e0000c03f000020c0010c2a0000000000000001000000020000000300000004",
"00000005000000060000000700000008000000010000000000803e0000003f0000403f0000803f130000000d04000000",
diff --git a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp b/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
index 7aaf8935e36..ebd41e891cf 100644
--- a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
+++ b/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
@@ -12,7 +12,6 @@
#include <LibCore/ElapsedTimer.h>
#include <LibCore/Environment.h>
#include <LibGfx/CornerRadii.h>
-#include <LibGfx/Filter.h>
#include <LibGfx/GradientInterpolation.h>
#include <LibGfx/Matrix4x4.h>
#include <LibGfx/Path.h>
diff --git a/Services/Compositor/Canvas2DCommandPlayer.cpp b/Services/Compositor/Canvas2DCommandPlayer.cpp
index b7dbf553563..66f6717c094 100644
--- a/Services/Compositor/Canvas2DCommandPlayer.cpp
+++ b/Services/Compositor/Canvas2DCommandPlayer.cpp
@@ -15,7 +15,6 @@
#include <LibGfx/Bitmap.h>
#include <LibGfx/Color.h>
#include <LibGfx/DecodedImageFrame.h>
-#include <LibGfx/Filter.h>
#include <LibGfx/PaintStyle.h>
#include <LibGfx/Path.h>
#include <core/SkCanvas.h>
@@ -85,11 +84,14 @@ Gfx::Path Canvas2DCommandPlayer::path_from(DisplayListDataSpan path_data) const
return Gfx::Path::from_serialized_bytes(inline_data(path_data));
}
-Optional<Gfx::Filter> Canvas2DCommandPlayer::filter_from(Canvas2DCompositing const& compositing) const
+sk_sp<SkImageFilter> Canvas2DCommandPlayer::image_filter_from(Canvas2DCompositing const& compositing) const
{
if (!compositing.has_filter)
- return {};
- return Gfx::Filter { MUST(ByteBuffer::copy(inline_data(compositing.filter))) };
+ return nullptr;
+ return Gfx::to_skia_image_filter(inline_data(compositing.filter), [](u64) -> Gfx::DecodedImageFrame const& {
+ // A canvas filter comes from CSS filter functions, which draw no images.
+ VERIFY_NOT_REACHED();
+ });
}
RefPtr<Gfx::PaintStyle> Canvas2DCommandPlayer::paint_style_from(Canvas2DPaint const& paint) const
@@ -144,7 +146,7 @@ void Canvas2DCommandPlayer::play_command(Canvas2DFillPath const& command)
auto paint_style = paint_style_from(command.paint);
if (!paint_style)
return;
- m_painter->fill_path(path, *paint_style, filter_from(command.compositing), command.compositing.global_alpha, command.compositing.compositing_and_blending_operator, command.winding_rule);
+ m_painter->fill_path(path, *paint_style, image_filter_from(command.compositing), command.compositing.global_alpha, command.compositing.compositing_and_blending_operator, command.winding_rule);
}
void Canvas2DCommandPlayer::play_command(Canvas2DStrokePath const& command)
@@ -159,7 +161,7 @@ void Canvas2DCommandPlayer::play_command(Canvas2DStrokePath const& command)
auto paint_style = paint_style_from(command.paint);
if (!paint_style)
return;
- m_painter->stroke_path(path, *paint_style, filter_from(command.compositing), command.thickness, command.compositing.global_alpha, command.compositing.compositing_and_blending_operator, command.cap_style, command.join_style, command.miter_limit, dash_array, command.dash_offset);
+ m_painter->stroke_path(path, *paint_style, image_filter_from(command.compositing), command.thickness, command.compositing.global_alpha, command.compositing.compositing_and_blending_operator, command.cap_style, command.join_style, command.miter_limit, dash_array, command.dash_offset);
}
void Canvas2DCommandPlayer::play_command(Canvas2DDrawGlyphRun const& command)
@@ -180,7 +182,7 @@ void Canvas2DCommandPlayer::play_command(Canvas2DDrawGlyphRun const& command)
glyphs.ensure_capacity(tape_glyphs.size());
for (auto const& glyph : tape_glyphs)
glyphs.unchecked_append({ .position = glyph.position, .glyph_id = glyph.glyph_id });
- m_painter->draw_glyph_run(*font, sk_font.release_value(), glyphs, command.translation, *paint_style, filter_from(command.compositing), command.compositing.global_alpha, command.compositing.compositing_and_blending_operator);
+ m_painter->draw_glyph_run(*font, sk_font.release_value(), glyphs, command.translation, *paint_style, image_filter_from(command.compositing), command.compositing.global_alpha, command.compositing.compositing_and_blending_operator);
}
void Canvas2DCommandPlayer::play_command(Canvas2DClearRect const& command)
@@ -193,7 +195,7 @@ void Canvas2DCommandPlayer::play_command(Canvas2DDrawImageFrame const& command)
auto const* frame = m_resolvers.image_frame(command.frame_id.value());
if (!frame)
return;
- m_painter->draw_bitmap(command.dst_rect, *frame, command.src_rect, command.scaling_mode, filter_from(command.compositing), command.compositing.global_alpha, command.compositing.compositing_and_blending_operator);
+ m_painter->draw_bitmap(command.dst_rect, *frame, command.src_rect, command.scaling_mode, image_filter_from(command.compositing), command.compositing.global_alpha, command.compositing.compositing_and_blending_operator);
}
void Canvas2DCommandPlayer::play_command(Canvas2DDrawCanvas const& command)
@@ -224,8 +226,7 @@ void Canvas2DCommandPlayer::play_command(Canvas2DDrawVideoFrame const& command)
void Canvas2DCommandPlayer::draw_image(SkImage const& image, Gfx::FloatRect const& dst_rect, Gfx::IntRect const& src_rect, Gfx::ScalingMode scaling_mode, Canvas2DCompositing const& compositing)
{
SkPaint paint;
- if (auto filter = filter_from(compositing); filter.has_value())
- paint.setImageFilter(Gfx::to_skia_image_filter(filter.value()));
+ paint.setImageFilter(image_filter_from(compositing));
paint.setAlpha(static_cast<u8>(compositing.global_alpha * 255));
paint.setBlender(Gfx::to_skia_blender(compositing.compositing_and_blending_operator));
diff --git a/Services/Compositor/Canvas2DCommandPlayer.h b/Services/Compositor/Canvas2DCommandPlayer.h
index d342f329b25..7bbf3ad57c9 100644
--- a/Services/Compositor/Canvas2DCommandPlayer.h
+++ b/Services/Compositor/Canvas2DCommandPlayer.h
@@ -15,13 +15,13 @@
#include <AK/Span.h>
#include <Compositor/Forward.h>
#include <LibCompositing/DisplayList/DisplayListCommandsGenerated.h>
-#include <LibGfx/Filter.h>
#include <LibGfx/Forward.h>
#include <LibGfx/PaintStyle.h>
#include <LibGfx/Rect.h>
#include <LibGfx/ScalingMode.h>
class SkImage;
+class SkImageFilter;
template<typename T>
class sk_sp;
@@ -67,7 +67,7 @@ private:
ReadonlyBytes inline_data(Compositing::DisplayListDataSpan) const;
Gfx::Path path_from(Compositing::DisplayListDataSpan) const;
- Optional<Gfx::Filter> filter_from(Compositing::Canvas2DCompositing const&) const;
+ sk_sp<SkImageFilter> image_filter_from(Compositing::Canvas2DCompositing const&) const;
RefPtr<Gfx::PaintStyle> paint_style_from(Compositing::Canvas2DPaint const&) const;
NonnullRefPtr<Gfx::PaintingSurface> m_surface;
diff --git a/Services/Compositor/PainterSkia.cpp b/Services/Compositor/PainterSkia.cpp
index f75e58f4fbb..24706785df6 100644
--- a/Services/Compositor/PainterSkia.cpp
+++ b/Services/Compositor/PainterSkia.cpp
@@ -15,7 +15,6 @@
#include <Compositor/PainterSkia.h>
#include <Compositor/SkiaUtils.h>
#include <LibGfx/DecodedImageFrame.h>
-#include <LibGfx/Filter.h>
#include <LibGfx/Font/Font.h>
#include <core/SkCanvas.h>
@@ -131,19 +130,12 @@ static void apply_paint_style(SkPaint& paint, PaintStyle const& style)
}
}
-static void apply_filter(SkPaint& paint, Gfx::Filter const& filter)
-{
- paint.setImageFilter(to_skia_image_filter(filter));
-}
-
-static SkPaint to_skia_paint(Gfx::PaintStyle const& style, Optional<Gfx::Filter const&> filter)
+static SkPaint to_skia_paint(Gfx::PaintStyle const& style, sk_sp<SkImageFilter> image_filter)
{
SkPaint paint;
apply_paint_style(paint, style);
-
- if (filter.has_value())
- apply_filter(paint, move(filter.value()));
+ paint.setImageFilter(move(image_filter));
return paint;
}
@@ -173,13 +165,10 @@ void PainterSkia::fill_rect(Gfx::FloatRect const& rect, Color color)
canvas.drawRect(to_skia_rect(rect), paint);
}
-void PainterSkia::draw_bitmap(Gfx::FloatRect const& dst_rect, Gfx::DecodedImageFrame const& source, Gfx::IntRect const& src_rect, Gfx::ScalingMode scaling_mode, Optional<Gfx::Filter> filter, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator)
+void PainterSkia::draw_bitmap(Gfx::FloatRect const& dst_rect, Gfx::DecodedImageFrame const& source, Gfx::IntRect const& src_rect, Gfx::ScalingMode scaling_mode, sk_sp<SkImageFilter> image_filter, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator)
{
SkPaint paint;
-
- if (filter.has_value())
- apply_filter(paint, filter.value());
-
+ paint.setImageFilter(move(image_filter));
paint.setAlpha(static_cast<u8>(global_alpha * 255));
paint.setBlender(to_skia_blender(compositing_and_blending_operator));
@@ -230,14 +219,14 @@ void PainterSkia::stroke_path(Gfx::Path const& path, Gfx::Color color, float thi
canvas.drawPath(sk_path, paint);
}
-void PainterSkia::stroke_path(Gfx::Path const& path, Gfx::PaintStyle const& paint_style, Optional<Gfx::Filter> filter, float thickness, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::Path::CapStyle const& cap_style, Gfx::Path::JoinStyle const& join_style, float miter_limit, Vector<float> const& dash_array, float dash_offset)
+void PainterSkia::stroke_path(Gfx::Path const& path, Gfx::PaintStyle const& paint_style, sk_sp<SkImageFilter> image_filter, float thickness, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::Path::CapStyle const& cap_style, Gfx::Path::JoinStyle const& join_style, float miter_limit, Vector<float> const& dash_array, float dash_offset)
{
// Skia treats zero thickness as a special case and will draw a hairline, while we want to draw nothing.
if (thickness <= 0)
return;
auto sk_path = to_skia_path(path);
- auto paint = to_skia_paint(paint_style, filter);
+ auto paint = to_skia_paint(paint_style, move(image_filter));
paint.setAntiAlias(true);
float alpha = paint.getAlphaf();
paint.setAlphaf(alpha * global_alpha);
@@ -265,11 +254,11 @@ void PainterSkia::fill_path(Gfx::Path const& path, Gfx::Color color, Gfx::Windin
canvas.drawPath(sk_path, paint);
}
-void PainterSkia::fill_path(Gfx::Path const& path, Gfx::PaintStyle const& paint_style, Optional<Gfx::Filter> filter, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::WindingRule winding_rule)
+void PainterSkia::fill_path(Gfx::Path const& path, Gfx::PaintStyle const& paint_style, sk_sp<SkImageFilter> image_filter, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::WindingRule winding_rule)
{
auto sk_path = to_skia_path(path);
sk_path.setFillType(to_skia_path_fill_type(winding_rule));
- auto paint = to_skia_paint(paint_style, filter);
+ auto paint = to_skia_paint(paint_style, move(image_filter));
paint.setAntiAlias(true);
float alpha = paint.getAlphaf();
paint.setAlphaf(alpha * global_alpha);
@@ -278,7 +267,7 @@ void PainterSkia::fill_path(Gfx::Path const& path, Gfx::PaintStyle const& paint_
canvas.drawPath(sk_path, paint);
}
-void PainterSkia::draw_glyph_run(Font const& font, SkFont sk_font, ReadonlySpan<CanvasGlyph> glyphs, FloatPoint translation, PaintStyle const& style, Optional<Filter> filter, float global_alpha, CompositingAndBlendingOperator compositing_and_blending_operator)
+void PainterSkia::draw_glyph_run(Font const& font, SkFont sk_font, ReadonlySpan<CanvasGlyph> glyphs, FloatPoint translation, PaintStyle const& style, sk_sp<SkImageFilter> image_filter, float global_alpha, CompositingAndBlendingOperator compositing_and_blending_operator)
{
if (glyphs.is_empty() || font.is_invisible())
return;
@@ -298,7 +287,7 @@ void PainterSkia::draw_glyph_run(Font const& font, SkFont sk_font, ReadonlySpan<
glyph_positions.unchecked_append({ glyph.position.x(), glyph.position.y() + font_ascent });
}
- auto paint = to_skia_paint(style, filter);
+ auto paint = to_skia_paint(style, move(image_filter));
paint.setAlphaf(paint.getAlphaf() * global_alpha);
paint.setBlender(to_skia_blender(compositing_and_blending_operator));
diff --git a/Services/Compositor/PainterSkia.h b/Services/Compositor/PainterSkia.h
index 71df1d40e0a..ae12ace1cf2 100644
--- a/Services/Compositor/PainterSkia.h
+++ b/Services/Compositor/PainterSkia.h
@@ -11,7 +11,6 @@
#include <AK/Span.h>
#include <Compositor/PaintingSurface.h>
#include <LibGfx/CompositingAndBlendingOperator.h>
-#include <LibGfx/Filter.h>
#include <LibGfx/Forward.h>
#include <LibGfx/PaintStyle.h>
#include <LibGfx/Path.h>
@@ -20,6 +19,9 @@
#include <LibGfx/WindingRule.h>
class SkFont;
+class SkImageFilter;
+template<typename T>
+class sk_sp;
namespace Gfx {
@@ -37,12 +39,12 @@ public:
void clear_rect(Gfx::FloatRect const&, Color);
void fill_rect(Gfx::FloatRect const&, Color);
- void draw_bitmap(Gfx::FloatRect const& dst_rect, Gfx::DecodedImageFrame const& source, Gfx::IntRect const& src_rect, Gfx::ScalingMode, Optional<Gfx::Filter>, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator);
+ void draw_bitmap(Gfx::FloatRect const& dst_rect, Gfx::DecodedImageFrame const& source, Gfx::IntRect const& src_rect, Gfx::ScalingMode, sk_sp<SkImageFilter>, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator);
void stroke_path(Gfx::Path const&, Gfx::Color, float thickness, float blur_radius, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::Path::CapStyle, Gfx::Path::JoinStyle, float miter_limit, Vector<float> const& dash_array, float dash_offset);
- void stroke_path(Gfx::Path const&, Gfx::PaintStyle const&, Optional<Gfx::Filter>, float thickness, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::Path::CapStyle const&, Gfx::Path::JoinStyle const&, float miter_limit, Vector<float> const&, float dash_offset);
+ void stroke_path(Gfx::Path const&, Gfx::PaintStyle const&, sk_sp<SkImageFilter>, float thickness, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::Path::CapStyle const&, Gfx::Path::JoinStyle const&, float miter_limit, Vector<float> const&, float dash_offset);
void fill_path(Gfx::Path const&, Gfx::Color, Gfx::WindingRule, float blur_radius, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator);
- void fill_path(Gfx::Path const&, Gfx::PaintStyle const&, Optional<Gfx::Filter>, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::WindingRule);
- void draw_glyph_run(Font const&, SkFont, ReadonlySpan<CanvasGlyph>, FloatPoint translation, PaintStyle const&, Optional<Filter>, float global_alpha, CompositingAndBlendingOperator);
+ void fill_path(Gfx::Path const&, Gfx::PaintStyle const&, sk_sp<SkImageFilter>, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::WindingRule);
+ void draw_glyph_run(Font const&, SkFont, ReadonlySpan<CanvasGlyph>, FloatPoint translation, PaintStyle const&, sk_sp<SkImageFilter>, float global_alpha, CompositingAndBlendingOperator);
void set_transform(Gfx::AffineTransform const&);
void save();
void restore();
diff --git a/Services/Compositor/SkiaUtils.cpp b/Services/Compositor/SkiaUtils.cpp
index 811d11696ef..0f517485fbb 100644
--- a/Services/Compositor/SkiaUtils.cpp
+++ b/Services/Compositor/SkiaUtils.cpp
@@ -12,7 +12,6 @@
#include <LibGfx/ColorFilterType.h>
#include <LibGfx/ColorSpace.h>
#include <LibGfx/DecodedImageFrame.h>
-#include <LibGfx/Filter.h>
#include <LibGfx/InterpolationColorSpace.h>
#include <LibGfx/RustFFI.h>
#include <core/SkBitmap.h>
@@ -426,14 +425,6 @@ sk_sp<SkImageFilter> to_skia_image_filter(ReadonlyBytes serialized_filter, Funct
return SkiaFilterReader { serialized_filter, image_frame }.read_graph();
}
-sk_sp<SkImageFilter> to_skia_image_filter(Gfx::Filter const& filter)
-{
- return to_skia_image_filter(filter.serialized_bytes(), [](u64) -> DecodedImageFrame const& {
- // A graph carried as a Gfx::Filter comes from CSS filter functions, which draw no images.
- VERIFY_NOT_REACHED();
- });
-}
-
sk_sp<SkImage> sk_image_from_bitmap(Bitmap const& bitmap, ColorSpace const& color_space)
{
auto info = SkImageInfo::Make(bitmap.width(), bitmap.height(), to_skia_color_type(bitmap.format()), to_skia_alpha_type(bitmap.format(), bitmap.alpha_type()), to_skia_color_space(color_space));
diff --git a/Services/Compositor/SkiaUtils.h b/Services/Compositor/SkiaUtils.h
index 813d7db2ee5..7a32da403bc 100644
--- a/Services/Compositor/SkiaUtils.h
+++ b/Services/Compositor/SkiaUtils.h
@@ -12,7 +12,6 @@
#include <AK/Function.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/CompositingAndBlendingOperator.h>
-#include <LibGfx/Filter.h>
#include <LibGfx/PaintStyle.h>
#include <LibGfx/Path.h>
#include <LibGfx/ScalingMode.h>
@@ -143,7 +142,6 @@ 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);
-sk_sp<SkImageFilter> to_skia_image_filter(Gfx::Filter const& filter);
sk_sp<SkBlender> to_skia_blender(Gfx::CompositingAndBlendingOperator compositing_and_blending_operator);
// The returned SkImage references the source bitmap's pixels without copying; the caller
diff --git a/Tests/Compositor/CMakeLists.txt b/Tests/Compositor/CMakeLists.txt
index 4ed71e06048..0b2172e2e85 100644
--- a/Tests/Compositor/CMakeLists.txt
+++ b/Tests/Compositor/CMakeLists.txt
@@ -12,7 +12,7 @@ foreach(source IN LISTS TEST_SOURCES)
endforeach()
# These drive Skia directly, and the compositor keeps its Skia dependency private.
-foreach(source IN ITEMS BenchmarkForceDarkImageFilter.cpp TestFilter.cpp TestForceDarkImageFilter.cpp TestPaintingSurface.cpp TestYUVData.cpp)
+foreach(source IN ITEMS BenchmarkForceDarkImageFilter.cpp TestForceDarkImageFilter.cpp TestPaintingSurface.cpp TestYUVData.cpp)
ladybird_test("${source}" Compositor LIBS compositorservice LibCompositing LibGfx skia)
endforeach()
diff --git a/Tests/Compositor/TestFilter.cpp b/Tests/Compositor/TestFilter.cpp
deleted file mode 100644
index 285341bd5a5..00000000000
--- a/Tests/Compositor/TestFilter.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 2026-present, the Ladybird developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <AK/Hex.h>
-#include <Compositor/SkiaUtils.h>
-#include <LibGfx/Bitmap.h>
-#include <LibGfx/DecodedImageFrame.h>
-#include <LibGfx/Filter.h>
-#include <LibTest/TestCase.h>
-
-// A graph with every filter operation once, drawing an image frame under id 42, as the Rust codec in
-// LibGfx/Rust/src/filter.rs serializes it. That codec checks the same bytes, so a change to the layout on either
-// side fails one of the tests.
-static constexpr StringView EVERY_OPERATION_FILTER_BYTES = "01020103332211ff0000003f010000010e0000c03f000020c0010c2a0000000000000001000000020000000300000004"
- "00000005000000060000000700000008000000010000000000803e0000003f0000403f0000803f130000000d04000000"
- "01050000803f000000400000404000ff007f0106000080400000a0400107020000000000003f00000104011100000000"
- "cdcccc3dcdcc4c3e030000000000e0401000000008000000010f0000803f0000803f0110000000400000004000000020"
- "41000000000300000001090100010000fffefdfcfbfaf9f8f7f6f5f4f3f2f1f0efeeedecebeae9e8e7e6e5e4e3e2e1e0"
- "dfdedddcdbdad9d8d7d6d5d4d3d2d1d0cfcecdcccbcac9c8c7c6c5c4c3c2c1c0bfbebdbcbbbab9b8b7b6b5b4b3b2b1b0"
- "afaeadacabaaa9a8a7a6a5a4a3a2a1a09f9e9d9c9b9a999897969594939291908f8e8d8c8b8a89888786858483828180"
- "7f7e7d7c7b7a797877767574737271706f6e6d6c6b6a696867666564636261605f5e5d5c5b5a59585756555453525150"
- "4f4e4d4c4b4a494847464544434241403f3e3d3c3b3a393837363534333231302f2e2d2c2b2a29282726252423222120"
- "1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a090807060504030201000000000108000000000000003f000080"
- "3f0000c03f0000004000002040000040400000604000008040000090400000a0400000b0400000c0400000d0400000e0"
- "400000f04000000041000008410000104100001841010a9a99993e010b0000b4420112010000000000000000"sv;
-
-static constexpr u64 FIXTURE_IMAGE_FRAME_ID = 42;
-
-static ByteBuffer every_operation_filter_bytes()
-{
- return MUST(decode_hex(EVERY_OPERATION_FILTER_BYTES));
-}
-
-TEST_CASE(the_shared_bytes_name_the_image_frames_they_draw)
-{
- auto bytes = every_operation_filter_bytes();
- Vector<u64> image_frame_ids;
- Gfx::for_each_filter_image_frame_id(bytes.bytes(), [&](u64 id) { image_frame_ids.append(id); });
- EXPECT_EQ(image_frame_ids.size(), 1u);
- EXPECT_EQ(image_frame_ids.first(), FIXTURE_IMAGE_FRAME_ID);
-
- image_frame_ids.clear();
- Gfx::for_each_filter_image_frame_id(bytes.bytes().trim(bytes.size() - 1), [&](u64 id) { image_frame_ids.append(id); });
- EXPECT(image_frame_ids.is_empty());
-}
-
-TEST_CASE(the_shared_bytes_build_a_skia_image_filter)
-{
- auto bitmap = MUST(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, { 1, 1 }));
- Gfx::DecodedImageFrame frame { *bitmap };
- auto bytes = every_operation_filter_bytes();
- size_t image_lookups = 0;
- auto image_filter = Gfx::to_skia_image_filter(bytes.bytes(), [&](u64 id) -> Gfx::DecodedImageFrame const& {
- EXPECT_EQ(id, FIXTURE_IMAGE_FRAME_ID);
- ++image_lookups;
- return frame;
- });
- EXPECT(image_filter != nullptr);
- EXPECT_EQ(image_lookups, 1u);
-}