Skip to content

Truly independent web browser

Compositor: Stop reallocating backing stores at every resize step

Andreas Kling2a22f1ec3398
diff --git a/Services/Compositor/BackingStoreManager.cpp b/Services/Compositor/BackingStoreManager.cpp
index c1b7cd35336..1cf9ce86067 100644
--- a/Services/Compositor/BackingStoreManager.cpp
+++ b/Services/Compositor/BackingStoreManager.cpp
@@ -107,25 +107,26 @@ Optional<BackingStoreManager::Allocation> BackingStoreManager::resize_backing_st
if (viewport_size.is_empty())
return {};
- auto minimum_needed_size = viewport_size;
- bool force_reallocate = false;
+ auto allocation_size = viewport_size;
+ bool needs_allocation = m_allocated_size.is_empty();
if (window_resize_in_progress == Compositing::WindowResizingInProgress::Yes) {
- // Pad the minimum needed size so that we don't have to keep reallocating backing stores while the window is being resized.
- minimum_needed_size = { viewport_size.width() + 256, viewport_size.height() + 256 };
+ // Pad the backing stores we allocate so that we don't have to keep reallocating them while the window is being
+ // resized. Ones that still hold the viewport are kept.
+ allocation_size = { viewport_size.width() + 256, viewport_size.height() + 256 };
+ needs_allocation |= !m_allocated_size.contains(viewport_size);
} else {
// If we're not in the middle of a resize, we can shrink the backing store size to match the viewport size.
- minimum_needed_size = viewport_size;
- force_reallocate = m_allocated_size != minimum_needed_size;
+ needs_allocation |= m_allocated_size != viewport_size;
}
- if (force_reallocate || m_allocated_size.is_empty() || !m_allocated_size.contains(minimum_needed_size)) {
- m_allocated_size = minimum_needed_size;
+ if (needs_allocation) {
+ m_allocated_size = allocation_size;
auto buffer_count = backing_store_count_for(should_publish);
Vector<i32> bitmap_ids;
bitmap_ids.ensure_capacity(buffer_count);
for (size_t i = 0; i < buffer_count; ++i)
bitmap_ids.append(m_next_bitmap_id++);
- return Allocation { .size = minimum_needed_size, .bitmap_ids = move(bitmap_ids) };
+ return Allocation { .size = allocation_size, .bitmap_ids = move(bitmap_ids) };
}
return {};