From 0a97de85c901234f359f985599a9db593e107b9a Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Fri, 1 Aug 2025 04:49:12 +0200 Subject: [PATCH] LibWeb: Move item no-op check from display list player to recorder If item doesn't produce any output then let's skip appending it to the display list. --- .../LibWeb/Painting/DisplayListPlayerSkia.cpp | 25 +------------------ .../LibWeb/Painting/DisplayListRecorder.cpp | 15 +++++++++-- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/Libraries/LibWeb/Painting/DisplayListPlayerSkia.cpp b/Libraries/LibWeb/Painting/DisplayListPlayerSkia.cpp index bdb808ea182..29e9bcc08c3 100644 --- a/Libraries/LibWeb/Painting/DisplayListPlayerSkia.cpp +++ b/Libraries/LibWeb/Painting/DisplayListPlayerSkia.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Aliaksandr Kalenik + * Copyright (c) 2024-2025, Aliaksandr Kalenik * Copyright (c) 2025, Jelle Raaijmakers * * SPDX-License-Identifier: BSD-2-Clause @@ -662,10 +662,6 @@ void DisplayListPlayerSkia::fill_path_using_paint_style(FillPathUsingPaintStyle void DisplayListPlayerSkia::stroke_path_using_color(StrokePathUsingColor const& command) { - // Skia treats zero thickness as a special case and will draw a hairline, while we want to draw nothing. - if (!command.thickness) - return; - auto& canvas = surface().canvas(); SkPaint paint; paint.setAntiAlias(true); @@ -683,10 +679,6 @@ void DisplayListPlayerSkia::stroke_path_using_color(StrokePathUsingColor const& void DisplayListPlayerSkia::stroke_path_using_paint_style(StrokePathUsingPaintStyle const& command) { - // Skia treats zero thickness as a special case and will draw a hairline, while we want to draw nothing. - if (!command.thickness) - return; - auto path = to_skia_path(command.path); path.offset(command.aa_translation.x(), command.aa_translation.y()); auto paint = paint_style_to_skia_paint(*command.paint_style, command.bounding_rect().to_type()); @@ -703,10 +695,6 @@ void DisplayListPlayerSkia::stroke_path_using_paint_style(StrokePathUsingPaintSt void DisplayListPlayerSkia::draw_ellipse(DrawEllipse const& command) { - // Skia treats zero thickness as a special case and will draw a hairline, while we want to draw nothing. - if (!command.thickness) - return; - auto const& rect = command.rect; auto& canvas = surface().canvas(); SkPaint paint; @@ -729,10 +717,6 @@ void DisplayListPlayerSkia::fill_ellipse(FillEllipse const& command) void DisplayListPlayerSkia::draw_line(DrawLine const& command) { - // Skia treats zero thickness as a special case and will draw a hairline, while we want to draw nothing. - if (!command.thickness) - return; - auto from = to_skia_point(command.from); auto to = to_skia_point(command.to); auto& canvas = surface().canvas(); @@ -890,10 +874,6 @@ void DisplayListPlayerSkia::paint_conic_gradient(PaintConicGradient const& comma void DisplayListPlayerSkia::draw_triangle_wave(DrawTriangleWave const& command) { - // Skia treats zero thickness as a special case and will draw a hairline, while we want to draw nothing. - if (!command.thickness) - return; - // FIXME: Support more than horizontal waves if (command.p1.y() != command.p2.y()) { dbgln("FIXME: Support more than horizontal waves"); @@ -972,9 +952,6 @@ void DisplayListPlayerSkia::add_rounded_rect_clip(AddRoundedRectClip const& comm void DisplayListPlayerSkia::add_mask(AddMask const& command) { auto const& rect = command.rect; - if (rect.is_empty()) - return; - auto mask_surface = Gfx::PaintingSurface::create_with_size(m_context, rect.size(), Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied); ScrollStateSnapshot scroll_state_snapshot; diff --git a/Libraries/LibWeb/Painting/DisplayListRecorder.cpp b/Libraries/LibWeb/Painting/DisplayListRecorder.cpp index 01a68ee2284..ac5addb4f07 100644 --- a/Libraries/LibWeb/Painting/DisplayListRecorder.cpp +++ b/Libraries/LibWeb/Painting/DisplayListRecorder.cpp @@ -41,6 +41,8 @@ void DisplayListRecorder::add_rounded_rect_clip(CornerRadii corner_radii, Gfx::I void DisplayListRecorder::add_mask(RefPtr display_list, Gfx::IntRect rect) { + if (rect.is_empty()) + return; APPEND(AddMask { move(display_list), rect }); } @@ -88,6 +90,9 @@ void DisplayListRecorder::fill_path(FillPathUsingPaintStyleParams params) void DisplayListRecorder::stroke_path(StrokePathUsingColorParams params) { + // Skia treats zero thickness as a special case and will draw a hairline, while we want to draw nothing. + if (!params.thickness) + return; if (params.color.alpha() == 0) return; auto aa_translation = params.translation.value_or(Gfx::FloatPoint {}); @@ -113,6 +118,9 @@ void DisplayListRecorder::stroke_path(StrokePathUsingColorParams params) void DisplayListRecorder::stroke_path(StrokePathUsingPaintStyleParams params) { + // Skia treats zero thickness as a special case and will draw a hairline, while we want to draw nothing. + if (!params.thickness) + return; auto aa_translation = params.translation.value_or(Gfx::FloatPoint {}); auto path_bounding_rect = params.path.bounding_box().translated(aa_translation); // Increase path bounding box by `thickness` to account for stroke. @@ -137,7 +145,7 @@ void DisplayListRecorder::stroke_path(StrokePathUsingPaintStyleParams params) void DisplayListRecorder::draw_ellipse(Gfx::IntRect const& a_rect, Color color, int thickness) { - if (a_rect.is_empty() || color.alpha() == 0) + if (a_rect.is_empty() || color.alpha() == 0 || !thickness) return; APPEND(DrawEllipse { .rect = a_rect, @@ -228,7 +236,7 @@ void DisplayListRecorder::draw_repeated_immutable_bitmap(Gfx::IntRect dst_rect, void DisplayListRecorder::draw_line(Gfx::IntPoint from, Gfx::IntPoint to, Color color, int thickness, Gfx::LineStyle style, Color alternate_color) { - if (color.alpha() == 0) + if (color.alpha() == 0 || !thickness) return; APPEND(DrawLine { .color = color, @@ -419,6 +427,9 @@ void DisplayListRecorder::fill_rect_with_rounded_corners(Gfx::IntRect const& a_r void DisplayListRecorder::draw_triangle_wave(Gfx::IntPoint a_p1, Gfx::IntPoint a_p2, Color color, int amplitude, int thickness = 1) { + // Skia treats zero thickness as a special case and will draw a hairline, while we want to draw nothing. + if (!thickness) + return; if (color.alpha() == 0) return; APPEND(DrawTriangleWave {