LibAccelGfx+LibWeb: Discard painting of commands outside of viewport

This commit is contained in:
Aliaksandr Kalenik 2023-11-26 16:29:40 +01:00 committed by Andreas Kling
parent c68a9b2cfe
commit 17fb82d49b
Notes: sideshowbarker 2024-07-17 05:21:12 +09:00
3 changed files with 9 additions and 3 deletions

View file

@ -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> 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)

View file

@ -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(); }

View file

@ -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<int>();
return !painter().clip_rect().intersects(rect.translated(translation));
}
void PaintingCommandExecutorGPU::prepare_glyph_texture(HashMap<Gfx::Font const*, HashTable<u32>> const& unique_glyphs)