mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
Have WindowManager::invalidate() unite dirty rects that intersect each other.
This is kinda primitive but it avoids double-draw when slowly dragging stuff.
This commit is contained in:
parent
c43903eebd
commit
e4cb9b2985
Notes:
sideshowbarker
2024-07-19 16:03:25 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/e4cb9b29857
3 changed files with 27 additions and 2 deletions
|
@ -20,3 +20,13 @@ void Rect::intersect(const Rect& other)
|
|||
m_size.setWidth((r - l) + 1);
|
||||
m_size.setHeight((b - t) + 1);
|
||||
}
|
||||
|
||||
Rect Rect::united(const Rect& other) const
|
||||
{
|
||||
Rect rect;
|
||||
rect.set_left(min(left(), other.left()));
|
||||
rect.set_top(min(top(), other.top()));
|
||||
rect.set_right(max(right(), other.right()));
|
||||
rect.set_bottom(max(bottom(), other.bottom()));
|
||||
return rect;
|
||||
}
|
||||
|
|
|
@ -88,12 +88,12 @@ public:
|
|||
|
||||
void set_right(int right)
|
||||
{
|
||||
setWidth(right - x());
|
||||
setWidth(right - x() + 1);
|
||||
}
|
||||
|
||||
void set_bottom(int bottom)
|
||||
{
|
||||
setHeight(bottom - y());
|
||||
setHeight(bottom - y() + 1);
|
||||
}
|
||||
|
||||
bool intersects(const Rect& other) const
|
||||
|
@ -132,6 +132,8 @@ public:
|
|||
return r;
|
||||
}
|
||||
|
||||
Rect united(const Rect&) const;
|
||||
|
||||
private:
|
||||
Point m_location;
|
||||
Size m_size;
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include "Process.h"
|
||||
#include "MemoryManager.h"
|
||||
|
||||
//#define DEBUG_FLUSH_YELLOW
|
||||
|
||||
static const int windowTitleBarHeight = 16;
|
||||
|
||||
static inline Rect titleBarRectForWindow(const Rect& window)
|
||||
|
@ -327,6 +329,12 @@ void WindowManager::invalidate(const Rect& a_rect)
|
|||
for (auto& r : m_invalidated_rects) {
|
||||
if (r.contains(rect))
|
||||
return;
|
||||
if (r.intersects(rect)) {
|
||||
// Unite with the existing dirty rect.
|
||||
// FIXME: It would be much nicer to compute the exact rects needing repaint.
|
||||
r = r.united(rect);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_invalidated_rects.append(rect);
|
||||
|
@ -350,6 +358,11 @@ void WindowManager::flush(const Rect& a_rect)
|
|||
const RGBA32* back_ptr = m_back_bitmap->scanline(rect.y()) + rect.x();
|
||||
size_t pitch = m_back_bitmap->pitch();
|
||||
|
||||
#ifdef DEBUG_FLUSH_YELLOW
|
||||
Painter p(*m_front_bitmap);
|
||||
p.fill_rect(rect, Color::Yellow);
|
||||
#endif
|
||||
|
||||
for (int y = 0; y < rect.height(); ++y) {
|
||||
fast_dword_copy(front_ptr, back_ptr, rect.width());
|
||||
front_ptr = (RGBA32*)((byte*)front_ptr + pitch);
|
||||
|
|
Loading…
Add table
Reference in a new issue