From 17fb82d49b50246ec6f18896048c4c2a1f4a9fe9 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Sun, 26 Nov 2023 16:29:40 +0100 Subject: [PATCH] LibAccelGfx+LibWeb: Discard painting of commands outside of viewport --- Userland/Libraries/LibAccelGfx/Painter.cpp | 3 +++ Userland/Libraries/LibAccelGfx/Painter.h | 3 +++ .../LibWeb/Painting/PaintingCommandExecutorGPU.cpp | 6 +++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibAccelGfx/Painter.cpp b/Userland/Libraries/LibAccelGfx/Painter.cpp index 356d1606c24..25867205c0a 100644 --- a/Userland/Libraries/LibAccelGfx/Painter.cpp +++ b/Userland/Libraries/LibAccelGfx/Painter.cpp @@ -550,11 +550,13 @@ void Painter::restore() void Painter::set_clip_rect(Gfx::IntRect rect) { + state().clip_rect = transform().map(rect); GL::enable_scissor_test(transform().map(rect)); } void Painter::clear_clip_rect() { + state().clip_rect = { { 0, 0 }, m_target_canvas->size() }; GL::disable_scissor_test(); } @@ -569,6 +571,7 @@ void Painter::set_target_canvas(NonnullRefPtr canvas) m_target_canvas = canvas; canvas->bind(); GL::set_viewport({ 0, 0, canvas->size().width(), canvas->size().height() }); + state().clip_rect = { { 0, 0 }, m_target_canvas->size() }; } void Painter::flush(Gfx::Bitmap& bitmap) diff --git a/Userland/Libraries/LibAccelGfx/Painter.h b/Userland/Libraries/LibAccelGfx/Painter.h index 34a768f5a4d..cde3f519b38 100644 --- a/Userland/Libraries/LibAccelGfx/Painter.h +++ b/Userland/Libraries/LibAccelGfx/Painter.h @@ -43,6 +43,8 @@ public: void set_transform(Gfx::AffineTransform const& transform) { state().transform = transform; } void translate(Gfx::FloatPoint translation) { state().transform.translate(translation); } + Gfx::IntRect const& clip_rect() const { return state().clip_rect; } + void fill_rect(Gfx::FloatRect, Gfx::Color); void fill_rect(Gfx::IntRect, Gfx::Color); @@ -88,6 +90,7 @@ private: struct State { Gfx::AffineTransform transform; + Gfx::IntRect clip_rect; }; [[nodiscard]] State& state() { return m_state_stack.last(); } diff --git a/Userland/Libraries/LibWeb/Painting/PaintingCommandExecutorGPU.cpp b/Userland/Libraries/LibWeb/Painting/PaintingCommandExecutorGPU.cpp index 45adb4b0851..7bf9520b4c5 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintingCommandExecutorGPU.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintingCommandExecutorGPU.cpp @@ -306,10 +306,10 @@ CommandResult PaintingCommandExecutorGPU::paint_borders(DevicePixelRect const& b return CommandResult::Continue; } -bool PaintingCommandExecutorGPU::would_be_fully_clipped_by_painter(Gfx::IntRect) const +bool PaintingCommandExecutorGPU::would_be_fully_clipped_by_painter(Gfx::IntRect rect) const { - // FIXME - return false; + auto translation = painter().transform().translation().to_type(); + return !painter().clip_rect().intersects(rect.translated(translation)); } void PaintingCommandExecutorGPU::prepare_glyph_texture(HashMap> const& unique_glyphs)