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.
This commit is contained in:
Aliaksandr Kalenik 2025-08-01 04:49:12 +02:00 committed by Alexander Kalenik
commit 0a97de85c9
Notes: github-actions[bot] 2025-08-01 09:27:27 +00:00
2 changed files with 14 additions and 26 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
* Copyright (c) 2024-2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
* Copyright (c) 2025, Jelle Raaijmakers <jelle@ladybird.org>
*
* 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<float>());
@ -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;

View file

@ -41,6 +41,8 @@ void DisplayListRecorder::add_rounded_rect_clip(CornerRadii corner_radii, Gfx::I
void DisplayListRecorder::add_mask(RefPtr<DisplayList> 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 {