mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 11:47:45 +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
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.setWidth((r - l) + 1);
|
||||||
m_size.setHeight((b - t) + 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)
|
void set_right(int right)
|
||||||
{
|
{
|
||||||
setWidth(right - x());
|
setWidth(right - x() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_bottom(int bottom)
|
void set_bottom(int bottom)
|
||||||
{
|
{
|
||||||
setHeight(bottom - y());
|
setHeight(bottom - y() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool intersects(const Rect& other) const
|
bool intersects(const Rect& other) const
|
||||||
|
@ -132,6 +132,8 @@ public:
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rect united(const Rect&) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Point m_location;
|
Point m_location;
|
||||||
Size m_size;
|
Size m_size;
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#include "Process.h"
|
#include "Process.h"
|
||||||
#include "MemoryManager.h"
|
#include "MemoryManager.h"
|
||||||
|
|
||||||
|
//#define DEBUG_FLUSH_YELLOW
|
||||||
|
|
||||||
static const int windowTitleBarHeight = 16;
|
static const int windowTitleBarHeight = 16;
|
||||||
|
|
||||||
static inline Rect titleBarRectForWindow(const Rect& window)
|
static inline Rect titleBarRectForWindow(const Rect& window)
|
||||||
|
@ -327,6 +329,12 @@ void WindowManager::invalidate(const Rect& a_rect)
|
||||||
for (auto& r : m_invalidated_rects) {
|
for (auto& r : m_invalidated_rects) {
|
||||||
if (r.contains(rect))
|
if (r.contains(rect))
|
||||||
return;
|
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);
|
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();
|
const RGBA32* back_ptr = m_back_bitmap->scanline(rect.y()) + rect.x();
|
||||||
size_t pitch = m_back_bitmap->pitch();
|
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) {
|
for (int y = 0; y < rect.height(); ++y) {
|
||||||
fast_dword_copy(front_ptr, back_ptr, rect.width());
|
fast_dword_copy(front_ptr, back_ptr, rect.width());
|
||||||
front_ptr = (RGBA32*)((byte*)front_ptr + pitch);
|
front_ptr = (RGBA32*)((byte*)front_ptr + pitch);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue