mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 05:39:11 +00:00
LibWeb/Painting: Apply clip and mask operations that are off-screen
These operations should still apply even if they are off screen, because they affect painting of things outside of their bounding rectangles. This commit makes us always apply these, regardless of if they are in the visible region. However, if they are outside that region, we replace them with simple clip-rect commands, which have the same effect (not painting anything) but are cheaper than computing a full mask bitmap.
This commit is contained in:
parent
3e5476c9e0
commit
a6822986bb
Notes:
github-actions[bot]
2024-11-13 15:11:18 +00:00
Author: https://github.com/AtkinsSJ
Commit: a6822986bb
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2312
Reviewed-by: https://github.com/kalenikaliaksandr ✅
4 changed files with 83 additions and 0 deletions
|
@ -24,6 +24,17 @@ static Optional<Gfx::IntRect> command_bounding_rectangle(Command const& command)
|
|||
});
|
||||
}
|
||||
|
||||
static bool command_is_clip_or_mask(Command const& command)
|
||||
{
|
||||
return command.visit(
|
||||
[&](auto const& command) -> bool {
|
||||
if constexpr (requires { command.is_clip_or_mask(); })
|
||||
return command.is_clip_or_mask();
|
||||
else
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
void DisplayListPlayer::execute(DisplayList& display_list)
|
||||
{
|
||||
auto const& commands = display_list.commands();
|
||||
|
@ -60,6 +71,15 @@ void DisplayListPlayer::execute(DisplayList& display_list)
|
|||
|
||||
auto bounding_rect = command_bounding_rectangle(command);
|
||||
if (bounding_rect.has_value() && (bounding_rect->is_empty() || would_be_fully_clipped_by_painter(*bounding_rect))) {
|
||||
// Any clip or mask that's located outside of the visible region is equivalent to a simple clip-rect,
|
||||
// so replace it with one to avoid doing unnecessary work.
|
||||
if (command_is_clip_or_mask(command)) {
|
||||
if (command.has<AddClipRect>()) {
|
||||
add_clip_rect(command.get<AddClipRect>());
|
||||
} else {
|
||||
add_clip_rect({ bounding_rect.release_value() });
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue