From 3fb2b008a208cfdef4faf60e7ab3a16ee5923b42 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Wed, 18 Oct 2023 16:27:46 +0200 Subject: [PATCH] LibWeb/Painting: Do not paint paths not visible in viewport Painting optimization to do less unnecessary work --- .../LibWeb/Painting/RecordingPainter.cpp | 16 ++++++++++++++++ .../Libraries/LibWeb/Painting/RecordingPainter.h | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/Userland/Libraries/LibWeb/Painting/RecordingPainter.cpp b/Userland/Libraries/LibWeb/Painting/RecordingPainter.cpp index 1a584cd5d1..2cc992db5d 100644 --- a/Userland/Libraries/LibWeb/Painting/RecordingPainter.cpp +++ b/Userland/Libraries/LibWeb/Painting/RecordingPainter.cpp @@ -87,6 +87,8 @@ CommandResult DrawTextRun::execute(CommandExecutionState& state) const CommandResult FillPathUsingColor::execute(CommandExecutionState& state) const { + if (state.would_be_fully_clipped_by_painter(bounding_rect)) + return CommandResult::Continue; auto& painter = state.painter(); Gfx::AntiAliasingPainter aa_painter(painter); if (aa_translation.has_value()) @@ -97,6 +99,8 @@ CommandResult FillPathUsingColor::execute(CommandExecutionState& state) const CommandResult FillPathUsingPaintStyle::execute(CommandExecutionState& state) const { + if (state.would_be_fully_clipped_by_painter(bounding_rect)) + return CommandResult::Continue; auto& painter = state.painter(); Gfx::AntiAliasingPainter aa_painter(painter); if (aa_translation.has_value()) @@ -107,6 +111,8 @@ CommandResult FillPathUsingPaintStyle::execute(CommandExecutionState& state) con CommandResult StrokePathUsingColor::execute(CommandExecutionState& state) const { + if (state.would_be_fully_clipped_by_painter(bounding_rect)) + return CommandResult::Continue; auto& painter = state.painter(); Gfx::AntiAliasingPainter aa_painter(painter); if (aa_translation.has_value()) @@ -117,6 +123,8 @@ CommandResult StrokePathUsingColor::execute(CommandExecutionState& state) const CommandResult StrokePathUsingPaintStyle::execute(CommandExecutionState& state) const { + if (state.would_be_fully_clipped_by_painter(bounding_rect)) + return CommandResult::Continue; auto& painter = state.painter(); Gfx::AntiAliasingPainter aa_painter(painter); if (aa_translation.has_value()) @@ -526,7 +534,9 @@ void RecordingPainter::fill_rect(Gfx::IntRect const& rect, Color color) void RecordingPainter::fill_path(FillPathUsingColorParams params) { + auto bounding_rect = params.path.bounding_box().translated(params.translation.value_or({})).to_type(); push_command(FillPathUsingColor { + .bounding_rect = bounding_rect, .path = params.path, .color = params.color, .winding_rule = params.winding_rule, @@ -536,7 +546,9 @@ void RecordingPainter::fill_path(FillPathUsingColorParams params) void RecordingPainter::fill_path(FillPathUsingPaintStyleParams params) { + auto bounding_rect = params.path.bounding_box().translated(params.translation.value_or({})).to_type(); push_command(FillPathUsingPaintStyle { + .bounding_rect = bounding_rect, .path = params.path, .paint_style = params.paint_style, .winding_rule = params.winding_rule, @@ -547,7 +559,9 @@ void RecordingPainter::fill_path(FillPathUsingPaintStyleParams params) void RecordingPainter::stroke_path(StrokePathUsingColorParams params) { + auto bounding_rect = params.path.bounding_box().translated(params.translation.value_or({})).to_type(); push_command(StrokePathUsingColor { + .bounding_rect = bounding_rect, .path = params.path, .color = params.color, .thickness = params.thickness, @@ -557,7 +571,9 @@ void RecordingPainter::stroke_path(StrokePathUsingColorParams params) void RecordingPainter::stroke_path(StrokePathUsingPaintStyleParams params) { + auto bounding_rect = params.path.bounding_box().translated(params.translation.value_or({})).to_type(); push_command(StrokePathUsingPaintStyle { + .bounding_rect = bounding_rect, .path = params.path, .paint_style = params.paint_style, .thickness = params.thickness, diff --git a/Userland/Libraries/LibWeb/Painting/RecordingPainter.h b/Userland/Libraries/LibWeb/Painting/RecordingPainter.h index f4742c8b9b..3af89ecea3 100644 --- a/Userland/Libraries/LibWeb/Painting/RecordingPainter.h +++ b/Userland/Libraries/LibWeb/Painting/RecordingPainter.h @@ -194,6 +194,7 @@ struct FillRectWithRoundedCorners { }; struct FillPathUsingColor { + Gfx::IntRect bounding_rect; Gfx::Path path; Color color; Gfx::Painter::WindingRule winding_rule; @@ -203,6 +204,7 @@ struct FillPathUsingColor { }; struct FillPathUsingPaintStyle { + Gfx::IntRect bounding_rect; Gfx::Path path; NonnullRefPtr paint_style; Gfx::Painter::WindingRule winding_rule; @@ -213,6 +215,7 @@ struct FillPathUsingPaintStyle { }; struct StrokePathUsingColor { + Gfx::IntRect bounding_rect; Gfx::Path path; Color color; float thickness; @@ -222,6 +225,7 @@ struct StrokePathUsingColor { }; struct StrokePathUsingPaintStyle { + Gfx::IntRect bounding_rect; Gfx::Path path; NonnullRefPtr paint_style; float thickness;