Metrics: Added io.MetricsActiveAllocations, moving away from the cross-context global counters than we previously used. (#1565, #1599, #586)

This commit is contained in:
omar 2018-08-15 16:28:39 -07:00
parent 4e33aeed82
commit 8972ebae73
3 changed files with 9 additions and 5 deletions

View File

@ -70,6 +70,7 @@ Other Changes:
- Metrics: Changed io.MetricsActiveWindows to reflect the number of active windows (!= from visible windows), which is useful
for lazy/idle render mechanisms as new windows are typically not visible for one frame.
- Metrics: Added io.MetricsRenderWindow to reflect the number of visible windows.
- Metrics: Added io.MetricsActiveAllocations, moving away from the cross-context global counters than we previously used. (#1565, #1599, #586)
- Demo: Added basic Drag and Drop demo. (#143)
- Demo: Clarified the use of IsItemHovered()/IsItemActive() right after being in the "Active, Focused, Hovered & Focused Tests" section.
- Examples: Tweaked the main.cpp of each example.

View File

@ -933,7 +933,7 @@ static void SetClipboardTextFn_DefaultImpl(void* user_data, const ch
static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y);
//-----------------------------------------------------------------------------
// Context
// Context and Memory Allocators
//-----------------------------------------------------------------------------
// Current context pointer. Implicitly used by all ImGui functions. Always assumed to be != NULL.
@ -960,7 +960,6 @@ static void FreeWrapper(void* ptr, void* user_data) { (void)user_data;
static void* (*GImAllocatorAllocFunc)(size_t size, void* user_data) = MallocWrapper;
static void (*GImAllocatorFreeFunc)(void* ptr, void* user_data) = FreeWrapper;
static void* GImAllocatorUserData = NULL;
static size_t GImAllocatorActiveAllocationsCount = 0;
//-----------------------------------------------------------------------------
// User facing structures
@ -2845,13 +2844,16 @@ float ImGui::CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)
void* ImGui::MemAlloc(size_t size)
{
GImAllocatorActiveAllocationsCount++;
if (ImGuiContext* ctx = GImGui)
ctx->IO.MetricsActiveAllocations++;
return GImAllocatorAllocFunc(size, GImAllocatorUserData);
}
void ImGui::MemFree(void* ptr)
{
if (ptr) GImAllocatorActiveAllocationsCount--;
if (ptr)
if (ImGuiContext* ctx = GImGui)
ctx->IO.MetricsActiveAllocations--;
return GImAllocatorFreeFunc(ptr, GImAllocatorUserData);
}
@ -14032,7 +14034,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
ImGui::Text("%d vertices, %d indices (%d triangles)", io.MetricsRenderVertices, io.MetricsRenderIndices, io.MetricsRenderIndices / 3);
ImGui::Text("%d active windows (%d visible)", io.MetricsActiveWindows, io.MetricsRenderWindows);
ImGui::Text("%d allocations", (int)GImAllocatorActiveAllocationsCount);
ImGui::Text("%d allocations", io.MetricsActiveAllocations);
ImGui::Checkbox("Show clipping rectangles when hovering draw commands", &show_draw_cmd_clip_rects);
ImGui::Checkbox("Ctrl shows window begin order", &show_window_begin_order);

View File

@ -1161,6 +1161,7 @@ struct ImGuiIO
int MetricsRenderIndices; // Indices output during last call to Render() = number of triangles * 3
int MetricsRenderWindows; // Number of visible windows
int MetricsActiveWindows; // Number of active windows
int MetricsActiveAllocations; // Number of active allocations, updated by MemAlloc/MemFree based on current context. May be off if you have multiple imgui contexts.
ImVec2 MouseDelta; // Mouse delta. Note that this is zero if either current or previous position are invalid (-FLT_MAX,-FLT_MAX), so a disappearing/reappearing mouse won't have a huge delta.
//------------------------------------------------------------------