mirror of
https://github.com/ocornut/imgui.git
synced 2026-03-19 07:08:18 +00:00
Discard/GC of ImDrawList buffers for unused windows favor restoring them to ~Size*1.05 instead of Capacity when awakening again. (#9303)
+ made "GC now" button process even active windows.
This commit is contained in:
10
imgui.cpp
10
imgui.cpp
@@ -4633,11 +4633,12 @@ void ImGui::GcCompactTransientMiscBuffers()
|
||||
// Not freed:
|
||||
// - ImGuiWindow, ImGuiWindowSettings, Name, StateStorage, ColumnsStorage (may hold useful data)
|
||||
// This should have no noticeable visual effect. When the window reappear however, expect new allocation/buffer growth/copy cost.
|
||||
// FIXME: Consider exposing of elaborating GC policy, e.g. being able to trim excessive ImDrawList gaps. (#9303)
|
||||
void ImGui::GcCompactTransientWindowBuffers(ImGuiWindow* window)
|
||||
{
|
||||
window->MemoryCompacted = true;
|
||||
window->MemoryDrawListIdxCapacity = window->DrawList->IdxBuffer.Capacity;
|
||||
window->MemoryDrawListVtxCapacity = window->DrawList->VtxBuffer.Capacity;
|
||||
window->MemoryDrawListIdxCapacity = ImMin((int)(window->DrawList->IdxBuffer.Size * 1.05f), window->DrawList->IdxBuffer.Capacity);
|
||||
window->MemoryDrawListVtxCapacity = ImMin((int)(window->DrawList->VtxBuffer.Size * 1.05f), window->DrawList->VtxBuffer.Capacity);
|
||||
window->IDStack.clear();
|
||||
window->DrawList->_ClearFreeMemory();
|
||||
window->DC.ChildWindows.clear();
|
||||
@@ -5665,7 +5666,8 @@ void ImGui::NewFrame()
|
||||
|
||||
// Mark all windows as not visible and compact unused memory.
|
||||
IM_ASSERT(g.WindowsFocusOrder.Size <= g.Windows.Size);
|
||||
const float memory_compact_start_time = (g.GcCompactAll || g.IO.ConfigMemoryCompactTimer < 0.0f) ? FLT_MAX : (float)g.Time - g.IO.ConfigMemoryCompactTimer;
|
||||
const bool gc_all = (g.GcCompactAll || g.IO.ConfigMemoryCompactTimer < 0.0f);
|
||||
const float memory_compact_start_time = gc_all ? FLT_MAX : (float)g.Time - g.IO.ConfigMemoryCompactTimer;
|
||||
for (ImGuiWindow* window : g.Windows)
|
||||
{
|
||||
window->WasActive = window->Active;
|
||||
@@ -5675,7 +5677,7 @@ void ImGui::NewFrame()
|
||||
window->BeginCount = 0;
|
||||
|
||||
// Garbage collect transient buffers of recently unused windows
|
||||
if (!window->WasActive && !window->MemoryCompacted && window->LastTimeActive < memory_compact_start_time)
|
||||
if ((!window->WasActive || gc_all) && !window->MemoryCompacted && window->LastTimeActive < memory_compact_start_time)
|
||||
GcCompactTransientWindowBuffers(window);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user