This commit is contained in:
Saksham Mittal 2024-11-21 14:30:17 +00:00 committed by GitHub
commit 47b2bd93a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 58 additions and 31 deletions

View file

@ -27,6 +27,7 @@
#include <LibGfx/Size.h> #include <LibGfx/Size.h>
#include <LibGfx/TextAlignment.h> #include <LibGfx/TextAlignment.h>
#include <LibGfx/TextLayout.h> #include <LibGfx/TextLayout.h>
#include <LibWeb/CSS/ComputedValues.h>
#include <LibWeb/CSS/Enums.h> #include <LibWeb/CSS/Enums.h>
#include <LibWeb/Painting/BorderRadiiData.h> #include <LibWeb/Painting/BorderRadiiData.h>
#include <LibWeb/Painting/BorderRadiusCornerClipper.h> #include <LibWeb/Painting/BorderRadiusCornerClipper.h>
@ -118,7 +119,6 @@ struct StackingContextTransform {
struct PushStackingContext { struct PushStackingContext {
float opacity; float opacity;
CSS::ResolvedFilter filter;
// The bounding box of the source paintable (pre-transform). // The bounding box of the source paintable (pre-transform).
Gfx::IntRect source_paintable_rect; Gfx::IntRect source_paintable_rect;
// A translation to be applied after the stacking context has been transformed. // A translation to be applied after the stacking context has been transformed.
@ -398,6 +398,11 @@ struct ApplyOpacity {
float opacity; float opacity;
}; };
struct ApplyFilters {
float opacity;
CSS::ResolvedFilter filter;
};
struct ApplyTransform { struct ApplyTransform {
Gfx::FloatPoint origin; Gfx::FloatPoint origin;
Gfx::FloatMatrix4x4 matrix; Gfx::FloatMatrix4x4 matrix;
@ -453,6 +458,7 @@ using Command = Variant<
PaintNestedDisplayList, PaintNestedDisplayList,
PaintScrollBar, PaintScrollBar,
ApplyOpacity, ApplyOpacity,
ApplyFilters,
ApplyTransform, ApplyTransform,
ApplyMaskBitmap>; ApplyMaskBitmap>;

View file

@ -122,6 +122,7 @@ void DisplayListPlayer::execute(DisplayList& display_list)
else HANDLE_COMMAND(PaintScrollBar, paint_scrollbar) else HANDLE_COMMAND(PaintScrollBar, paint_scrollbar)
else HANDLE_COMMAND(PaintNestedDisplayList, paint_nested_display_list) else HANDLE_COMMAND(PaintNestedDisplayList, paint_nested_display_list)
else HANDLE_COMMAND(ApplyOpacity, apply_opacity) else HANDLE_COMMAND(ApplyOpacity, apply_opacity)
else HANDLE_COMMAND(ApplyFilters, apply_filters)
else HANDLE_COMMAND(ApplyTransform, apply_transform) else HANDLE_COMMAND(ApplyTransform, apply_transform)
else HANDLE_COMMAND(ApplyMaskBitmap, apply_mask_bitmap) else HANDLE_COMMAND(ApplyMaskBitmap, apply_mask_bitmap)
else VERIFY_NOT_REACHED(); else VERIFY_NOT_REACHED();

View file

@ -76,6 +76,7 @@ private:
virtual void paint_nested_display_list(PaintNestedDisplayList const&) = 0; virtual void paint_nested_display_list(PaintNestedDisplayList const&) = 0;
virtual void paint_scrollbar(PaintScrollBar const&) = 0; virtual void paint_scrollbar(PaintScrollBar const&) = 0;
virtual void apply_opacity(ApplyOpacity const&) = 0; virtual void apply_opacity(ApplyOpacity const&) = 0;
virtual void apply_filters(ApplyFilters const&) = 0;
virtual void apply_transform(ApplyTransform const&) = 0; virtual void apply_transform(ApplyTransform const&) = 0;
virtual void apply_mask_bitmap(ApplyMaskBitmap const&) = 0; virtual void apply_mask_bitmap(ApplyMaskBitmap const&) = 0;
virtual bool would_be_fully_clipped_by_painter(Gfx::IntRect) const = 0; virtual bool would_be_fully_clipped_by_painter(Gfx::IntRect) const = 0;

View file

@ -396,33 +396,7 @@ void DisplayListPlayerSkia::push_stacking_context(PushStackingContext const& com
.translate(-command.transform.origin); .translate(-command.transform.origin);
auto matrix = to_skia_matrix(new_transform); auto matrix = to_skia_matrix(new_transform);
if (!command.filter.is_none()) { if (command.opacity < 1) {
sk_sp<SkImageFilter> image_filter;
auto append_filter = [&image_filter](auto new_filter) {
if (image_filter)
image_filter = SkImageFilters::Compose(new_filter, image_filter);
else
image_filter = new_filter;
};
// Apply filters in order
for (auto const& filter_function : command.filter.filters)
append_filter(to_skia_image_filter(filter_function));
// We apply opacity as a color filter here so we only need to save and restore a single layer.
if (command.opacity < 1) {
append_filter(to_skia_image_filter(CSS::ResolvedFilter::FilterFunction {
CSS::ResolvedFilter::Color {
CSS::FilterOperation::Color::Type::Opacity,
command.opacity,
},
}));
}
SkPaint paint;
paint.setImageFilter(image_filter);
canvas.saveLayer(nullptr, &paint);
} else if (command.opacity < 1) {
auto source_paintable_rect = to_skia_rect(command.source_paintable_rect); auto source_paintable_rect = to_skia_rect(command.source_paintable_rect);
SkRect dest; SkRect dest;
matrix.mapRect(&dest, source_paintable_rect); matrix.mapRect(&dest, source_paintable_rect);
@ -1103,6 +1077,41 @@ void DisplayListPlayerSkia::apply_opacity(ApplyOpacity const& command)
canvas.saveLayer(nullptr, &paint); canvas.saveLayer(nullptr, &paint);
} }
void DisplayListPlayerSkia::apply_filters(ApplyFilters const& command)
{
if (command.filter.is_none()) {
return;
}
sk_sp<SkImageFilter> image_filter;
auto append_filter = [&image_filter](auto new_filter) {
if (image_filter)
image_filter = SkImageFilters::Compose(new_filter, image_filter);
else
image_filter = new_filter;
};
// Apply filters in order
for (auto filter : command.filter.filters) {
append_filter(to_skia_image_filter(filter));
}
// We apply opacity as a color filter here so we only need to save and restore a single layer.
if (command.opacity < 1) {
append_filter(to_skia_image_filter(CSS::ResolvedFilter::FilterFunction {
CSS::ResolvedFilter::Color {
CSS::FilterOperation::Color::Type::Opacity,
command.opacity,
},
}));
}
SkPaint paint;
paint.setImageFilter(image_filter);
auto& canvas = surface().canvas();
canvas.saveLayer(nullptr, &paint);
return;
}
void DisplayListPlayerSkia::apply_transform(ApplyTransform const& command) void DisplayListPlayerSkia::apply_transform(ApplyTransform const& command)
{ {
auto affine_transform = Gfx::extract_2d_affine_transform(command.matrix); auto affine_transform = Gfx::extract_2d_affine_transform(command.matrix);

View file

@ -63,6 +63,7 @@ private:
void paint_scrollbar(PaintScrollBar const&) override; void paint_scrollbar(PaintScrollBar const&) override;
void paint_nested_display_list(PaintNestedDisplayList const&) override; void paint_nested_display_list(PaintNestedDisplayList const&) override;
void apply_opacity(ApplyOpacity const&) override; void apply_opacity(ApplyOpacity const&) override;
void apply_filters(ApplyFilters const&) override;
void apply_transform(ApplyTransform const&) override; void apply_transform(ApplyTransform const&) override;
void apply_mask_bitmap(ApplyMaskBitmap const&) override; void apply_mask_bitmap(ApplyMaskBitmap const&) override;

View file

@ -285,7 +285,6 @@ void DisplayListRecorder::push_stacking_context(PushStackingContextParams params
{ {
append(PushStackingContext { append(PushStackingContext {
.opacity = params.opacity, .opacity = params.opacity,
.filter = params.filter,
.source_paintable_rect = params.source_paintable_rect, .source_paintable_rect = params.source_paintable_rect,
.transform = { .transform = {
.origin = params.transform.origin, .origin = params.transform.origin,
@ -398,6 +397,11 @@ void DisplayListRecorder::apply_opacity(float opacity)
append(ApplyOpacity { .opacity = opacity }); append(ApplyOpacity { .opacity = opacity });
} }
void DisplayListRecorder::apply_filters(float opacity, CSS::ResolvedFilter filter)
{
append(ApplyFilters { .opacity = opacity, .filter = filter });
}
void DisplayListRecorder::apply_transform(Gfx::FloatPoint origin, Gfx::FloatMatrix4x4 matrix) void DisplayListRecorder::apply_transform(Gfx::FloatPoint origin, Gfx::FloatMatrix4x4 matrix)
{ {
append(ApplyTransform { append(ApplyTransform {

View file

@ -111,7 +111,6 @@ public:
struct PushStackingContextParams { struct PushStackingContextParams {
float opacity; float opacity;
CSS::ResolvedFilter filter;
bool is_fixed_position; bool is_fixed_position;
Gfx::IntRect source_paintable_rect; Gfx::IntRect source_paintable_rect;
StackingContextTransform transform; StackingContextTransform transform;
@ -140,6 +139,7 @@ public:
void paint_scrollbar(int scroll_frame_id, Gfx::IntRect, CSSPixelFraction scroll_size, bool vertical); void paint_scrollbar(int scroll_frame_id, Gfx::IntRect, CSSPixelFraction scroll_size, bool vertical);
void apply_opacity(float opacity); void apply_opacity(float opacity);
void apply_filters(float opacity, CSS::ResolvedFilter filter);
void apply_transform(Gfx::FloatPoint origin, Gfx::FloatMatrix4x4); void apply_transform(Gfx::FloatPoint origin, Gfx::FloatMatrix4x4);
void apply_mask_bitmap(Gfx::IntPoint origin, Gfx::ImmutableBitmap const&, Gfx::Bitmap::MaskKind); void apply_mask_bitmap(Gfx::IntPoint origin, Gfx::ImmutableBitmap const&, Gfx::Bitmap::MaskKind);

View file

@ -382,6 +382,10 @@ void PaintableBox::paint(PaintContext& context, PaintPhase phase) const
} }
} }
if (phase == PaintPhase::Foreground) {
context.display_list_recorder().apply_filters(this->computed_values().opacity(), this->computed_values().filter());
}
auto scrollbar_width = computed_values().scrollbar_width(); auto scrollbar_width = computed_values().scrollbar_width();
if (phase == PaintPhase::Overlay && scrollbar_width != CSS::ScrollbarWidth::None) { if (phase == PaintPhase::Overlay && scrollbar_width != CSS::ScrollbarWidth::None) {
if (auto scrollbar_data = compute_scrollbar_data(ScrollDirection::Vertical); scrollbar_data.has_value()) { if (auto scrollbar_data = compute_scrollbar_data(ScrollDirection::Vertical); scrollbar_data.has_value()) {

View file

@ -70,6 +70,8 @@ void SVGSVGPaintable::paint_descendants(PaintContext& context, PaintableBox cons
context.display_list_recorder().apply_opacity(computed_values.opacity()); context.display_list_recorder().apply_opacity(computed_values.opacity());
} }
context.display_list_recorder().apply_filters(paintable.computed_values().opacity(), paintable.computed_values().filter());
if (svg_box.has_css_transform()) { if (svg_box.has_css_transform()) {
auto transform_matrix = svg_box.transform(); auto transform_matrix = svg_box.transform();
Gfx::FloatPoint transform_origin = svg_box.transform_origin().template to_type<float>(); Gfx::FloatPoint transform_origin = svg_box.transform_origin().template to_type<float>();

View file

@ -301,7 +301,6 @@ void StackingContext::paint(PaintContext& context) const
DisplayListRecorder::PushStackingContextParams push_stacking_context_params { DisplayListRecorder::PushStackingContextParams push_stacking_context_params {
.opacity = opacity, .opacity = opacity,
.filter = paintable_box().computed_values().filter(),
.is_fixed_position = paintable_box().is_fixed_position(), .is_fixed_position = paintable_box().is_fixed_position(),
.source_paintable_rect = source_paintable_rect, .source_paintable_rect = source_paintable_rect,
.transform = { .transform = {