mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:57:35 +00:00
LibGUI+WindowServer: Improve window resizing performance
The old `GUI::Window` resizing behavior created a new backing store for each resize event (i.e. every visible window size). This caused a lot of trashing and on my machine, caused up to 25% of CPU time spent in creating new backing stores. The new behavior is a bit more sensible: * If the window size is shrinking, the backing store is already large enough to contain the entire window - so we don't create a new one. * If the window size is growing, as soon as the backing store can no longer contain the window, it is inflated with a large margin (of an arbitrary chosen 64 pixels) in both directions to accommodate some leeway in resizing before an even larger backing store is required. * When the user stops resizing the window, the backing store is resized to the exact dimensions of the window. For me, this brings the CPU time for creating backing stores down to 0%.
This commit is contained in:
parent
45e85d20b6
commit
634d1e0197
8 changed files with 73 additions and 39 deletions
|
@ -386,6 +386,10 @@ void Compositor::compose()
|
|||
});
|
||||
}
|
||||
|
||||
auto update_window_rect = window_rect.intersected(rect);
|
||||
if (update_window_rect.is_empty())
|
||||
return;
|
||||
|
||||
auto clear_window_rect = [&](const Gfx::IntRect& clear_rect) {
|
||||
auto fill_color = wm.palette().window();
|
||||
if (!window.is_opaque())
|
||||
|
@ -394,7 +398,7 @@ void Compositor::compose()
|
|||
};
|
||||
|
||||
if (!backing_store) {
|
||||
clear_window_rect(window_rect.intersected(rect));
|
||||
clear_window_rect(update_window_rect);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -407,7 +411,7 @@ void Compositor::compose()
|
|||
// it was previously, and fill the rest of the window with its
|
||||
// background color.
|
||||
Gfx::IntRect backing_rect;
|
||||
backing_rect.set_size(backing_store->size());
|
||||
backing_rect.set_size(window.backing_store_visible_size());
|
||||
switch (WindowManager::the().resize_direction_of_window(window)) {
|
||||
case ResizeDirection::None:
|
||||
case ResizeDirection::Right:
|
||||
|
@ -434,8 +438,7 @@ void Compositor::compose()
|
|||
break;
|
||||
}
|
||||
|
||||
Gfx::IntRect dirty_rect_in_backing_coordinates = rect.intersected(window_rect)
|
||||
.intersected(backing_rect)
|
||||
Gfx::IntRect dirty_rect_in_backing_coordinates = update_window_rect.intersected(backing_rect)
|
||||
.translated(-backing_rect.location());
|
||||
|
||||
if (!dirty_rect_in_backing_coordinates.is_empty()) {
|
||||
|
@ -459,7 +462,7 @@ void Compositor::compose()
|
|||
}
|
||||
}
|
||||
|
||||
for (auto background_rect : window_rect.shatter(backing_rect))
|
||||
for (auto background_rect : update_window_rect.shatter(backing_rect))
|
||||
clear_window_rect(background_rect);
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue