Skip to content

Commit b87e01e

Browse files
kalenikaliaksandrgmta
authored andcommitted
LibWeb: Skip recording display list items with color.alpha() == 0
Cuts display list size, mostly because now we avoid lots of FillRect previusly recorded for boxes with transparent background. Website | DisplayList Items Before | DisplayList Items After -------------|--------------------------|------------------------- ladybird.org | 1431 | 1117 null.com | 4714 | 4484 discord.com | 5360 | 4992
1 parent 46097c6 commit b87e01e

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

Libraries/LibWeb/Painting/DisplayListRecorder.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ void DisplayListRecorder::add_mask(RefPtr<DisplayList> display_list, Gfx::IntRec
4141

4242
void DisplayListRecorder::fill_rect(Gfx::IntRect const& rect, Color color)
4343
{
44-
if (rect.is_empty())
44+
if (rect.is_empty() || color.alpha() == 0)
4545
return;
4646
append(FillRect { rect, color });
4747
}
4848

4949
void DisplayListRecorder::fill_path(FillPathUsingColorParams params)
5050
{
51+
if (params.color.alpha() == 0)
52+
return;
5153
auto aa_translation = params.translation.value_or(Gfx::FloatPoint {});
5254
auto path_bounding_rect = params.path.bounding_box().translated(aa_translation);
5355
auto path_bounding_int_rect = enclosing_int_rect(path_bounding_rect);
@@ -81,6 +83,8 @@ void DisplayListRecorder::fill_path(FillPathUsingPaintStyleParams params)
8183

8284
void DisplayListRecorder::stroke_path(StrokePathUsingColorParams params)
8385
{
86+
if (params.color.alpha() == 0)
87+
return;
8488
auto aa_translation = params.translation.value_or(Gfx::FloatPoint {});
8589
auto path_bounding_rect = params.path.bounding_box().translated(aa_translation);
8690
// Increase path bounding box by `thickness` to account for stroke.
@@ -128,7 +132,7 @@ void DisplayListRecorder::stroke_path(StrokePathUsingPaintStyleParams params)
128132

129133
void DisplayListRecorder::draw_ellipse(Gfx::IntRect const& a_rect, Color color, int thickness)
130134
{
131-
if (a_rect.is_empty())
135+
if (a_rect.is_empty() || color.alpha() == 0)
132136
return;
133137
append(DrawEllipse {
134138
.rect = a_rect,
@@ -139,7 +143,7 @@ void DisplayListRecorder::draw_ellipse(Gfx::IntRect const& a_rect, Color color,
139143

140144
void DisplayListRecorder::fill_ellipse(Gfx::IntRect const& a_rect, Color color)
141145
{
142-
if (a_rect.is_empty())
146+
if (a_rect.is_empty() || color.alpha() == 0)
143147
return;
144148
append(FillEllipse { a_rect, color });
145149
}
@@ -174,7 +178,7 @@ void DisplayListRecorder::fill_rect_with_radial_gradient(Gfx::IntRect const& rec
174178

175179
void DisplayListRecorder::draw_rect(Gfx::IntRect const& rect, Color color, bool rough)
176180
{
177-
if (rect.is_empty())
181+
if (rect.is_empty() || color.alpha() == 0)
178182
return;
179183
append(DrawRect {
180184
.rect = rect,
@@ -219,6 +223,8 @@ void DisplayListRecorder::draw_repeated_immutable_bitmap(Gfx::IntRect dst_rect,
219223

220224
void DisplayListRecorder::draw_line(Gfx::IntPoint from, Gfx::IntPoint to, Color color, int thickness, Gfx::LineStyle style, Color alternate_color)
221225
{
226+
if (color.alpha() == 0)
227+
return;
222228
append(DrawLine {
223229
.color = color,
224230
.from = from,
@@ -231,7 +237,7 @@ void DisplayListRecorder::draw_line(Gfx::IntPoint from, Gfx::IntPoint to, Color
231237

232238
void DisplayListRecorder::draw_text(Gfx::IntRect const& rect, String raw_text, Gfx::Font const& font, Gfx::TextAlignment alignment, Color color)
233239
{
234-
if (rect.is_empty())
240+
if (rect.is_empty() || color.alpha() == 0)
235241
return;
236242

237243
auto glyph_run = Gfx::shape_text({}, 0, raw_text.code_points(), font, Gfx::GlyphRun::TextType::Ltr, {});
@@ -253,6 +259,8 @@ void DisplayListRecorder::draw_text(Gfx::IntRect const& rect, String raw_text, G
253259

254260
void DisplayListRecorder::draw_text_run(Gfx::FloatPoint baseline_start, Gfx::GlyphRun const& glyph_run, Color color, Gfx::IntRect const& rect, double scale, Orientation orientation)
255261
{
262+
if (color.alpha() == 0)
263+
return;
256264
append(DrawGlyphRun {
257265
.glyph_run = glyph_run,
258266
.scale = scale,
@@ -377,14 +385,14 @@ void DisplayListRecorder::fill_rect_with_rounded_corners(Gfx::IntRect const& rec
377385

378386
void DisplayListRecorder::fill_rect_with_rounded_corners(Gfx::IntRect const& a_rect, Color color, int radius)
379387
{
380-
if (a_rect.is_empty())
388+
if (a_rect.is_empty() || color.alpha() == 0)
381389
return;
382390
fill_rect_with_rounded_corners(a_rect, color, radius, radius, radius, radius);
383391
}
384392

385393
void DisplayListRecorder::fill_rect_with_rounded_corners(Gfx::IntRect const& a_rect, Color color, int top_left_radius, int top_right_radius, int bottom_right_radius, int bottom_left_radius)
386394
{
387-
if (a_rect.is_empty())
395+
if (a_rect.is_empty() || color.alpha() == 0)
388396
return;
389397
fill_rect_with_rounded_corners(a_rect, color,
390398
{ top_left_radius, top_left_radius },
@@ -395,6 +403,8 @@ void DisplayListRecorder::fill_rect_with_rounded_corners(Gfx::IntRect const& a_r
395403

396404
void DisplayListRecorder::draw_triangle_wave(Gfx::IntPoint a_p1, Gfx::IntPoint a_p2, Color color, int amplitude, int thickness = 1)
397405
{
406+
if (color.alpha() == 0)
407+
return;
398408
append(DrawTriangleWave {
399409
.p1 = a_p1,
400410
.p2 = a_p2,

0 commit comments

Comments
 (0)