[client] overlay/graphs: allow the graph to have a custom title format

This commit is contained in:
Geoffrey McRae 2022-01-17 22:08:56 +11:00
parent 42ed0d7638
commit 464fee3e20
7 changed files with 43 additions and 24 deletions

View File

@ -86,7 +86,8 @@ bool waylandPresentationInit(void)
if (wlWm.presentation)
{
wlWm.photonTimings = ringbuffer_new(256, sizeof(float));
wlWm.photonGraph = app_registerGraph("PHOTON", wlWm.photonTimings, 0.0f, 30.0f);
wlWm.photonGraph = app_registerGraph("PHOTON", wlWm.photonTimings,
0.0f, 30.0f, NULL);
wp_presentation_add_listener(wlWm.presentation, &presentationListener, NULL);
}
return true;

View File

@ -110,8 +110,11 @@ void app_invalidateOverlay(bool renderTwice);
struct OverlayGraph;
typedef struct OverlayGraph * GraphHandle;
typedef const char * (*GraphFormatFn)(const char * name,
float min, float max, float avg, float freq, float last);
GraphHandle app_registerGraph(const char * name, RingBuffer buffer, float min, float max);
GraphHandle app_registerGraph(const char * name, RingBuffer buffer,
float min, float max, GraphFormatFn formatFn);
void app_unregisterGraph(GraphHandle handle);
void app_overlayConfigRegister(const char * title,

View File

@ -258,7 +258,8 @@ static bool egl_create(LG_Renderer ** renderer, const LG_RendererParams params,
this->desktopDamage[0].count = -1;
this->importTimings = ringbuffer_new(256, sizeof(float));
this->importGraph = app_registerGraph("IMPORT", this->importTimings, 0.0f, 5.0f);
this->importGraph = app_registerGraph("IMPORT", this->importTimings,
0.0f, 5.0f, NULL);
*needsOpenGL = false;
return true;

View File

@ -695,9 +695,10 @@ void app_releaseAllKeybinds(void)
}
}
GraphHandle app_registerGraph(const char * name, RingBuffer buffer, float min, float max)
GraphHandle app_registerGraph(const char * name, RingBuffer buffer,
float min, float max, GraphFormatFn formatFn)
{
return overlayGraph_register(name, buffer, min, max);
return overlayGraph_register(name, buffer, min, max, formatFn);
}
void app_unregisterGraph(GraphHandle handle)

View File

@ -1031,9 +1031,9 @@ static int lg_run(void)
g_state.renderTimings = ringbuffer_new(256, sizeof(float));
g_state.uploadTimings = ringbuffer_new(256, sizeof(float));
g_state.renderDuration = ringbuffer_new(256, sizeof(float));
overlayGraph_register("FRAME" , g_state.renderTimings , 0.0f, 50.0f);
overlayGraph_register("UPLOAD", g_state.uploadTimings , 0.0f, 50.0f);
overlayGraph_register("RENDER", g_state.renderDuration, 0.0f, 10.0f);
overlayGraph_register("FRAME" , g_state.renderTimings , 0.0f, 50.0f, NULL);
overlayGraph_register("UPLOAD", g_state.uploadTimings , 0.0f, 50.0f, NULL);
overlayGraph_register("RENDER", g_state.renderDuration, 0.0f, 10.0f, NULL);
initImGuiKeyMap(g_state.io->KeyMap);

View File

@ -36,11 +36,12 @@ static struct GraphState gs = {0};
struct OverlayGraph
{
const char * name;
RingBuffer buffer;
bool enabled;
float min;
float max;
const char * name;
RingBuffer buffer;
bool enabled;
float min;
float max;
GraphFormatFn formatFn;
};
@ -93,6 +94,7 @@ struct BufferMetrics
float sum;
float avg;
float freq;
float last;
};
static bool rbCalcMetrics(int index, void * value_, void * udata_)
@ -115,6 +117,7 @@ static bool rbCalcMetrics(int index, void * value_, void * udata_)
udata->max = *value;
udata->sum += *value;
udata->last = *value;
return true;
}
@ -170,10 +173,18 @@ static int graphs_render(void * udata, bool interactive,
metrics.freq = 1000.0f / metrics.avg;
}
char title[64];
snprintf(title, sizeof(title),
"%s: min:%4.2f max:%4.2f avg:%4.2f/%4.2fHz",
graph->name, metrics.min, metrics.max, metrics.avg, metrics.freq);
const char * title;
if (graph->formatFn)
title = graph->formatFn(graph->name,
metrics.min, metrics.max, metrics.avg, metrics.freq, metrics.last);
else
{
static char _title[64];
snprintf(_title, sizeof(_title),
"%s: min:%4.2f max:%4.2f avg:%4.2f/%4.2fHz",
graph->name, metrics.min, metrics.max, metrics.avg, metrics.freq);
title = _title;
}
igPlotLines_FloatPtr(
"",
@ -201,14 +212,16 @@ struct LG_OverlayOps LGOverlayGraphs =
.render = graphs_render
};
GraphHandle overlayGraph_register(const char * name, RingBuffer buffer, float min, float max)
GraphHandle overlayGraph_register(const char * name, RingBuffer buffer,
float min, float max, GraphFormatFn formatFn)
{
struct OverlayGraph * graph = malloc(sizeof(*graph));
graph->name = name;
graph->buffer = buffer;
graph->enabled = true;
graph->min = min;
graph->max = max;
graph->name = name;
graph->buffer = buffer;
graph->enabled = true;
graph->min = min;
graph->max = max;
graph->formatFn = formatFn;
ll_push(gs.graphs, graph);
return graph;
}

View File

@ -43,7 +43,7 @@ extern struct LG_OverlayOps LGOverlayMsg;
void overlayAlert_show(LG_MsgAlert type, const char * fmt, va_list args);
GraphHandle overlayGraph_register(const char * name, RingBuffer buffer,
float min, float max);
float min, float max, GraphFormatFn formatFn);
void overlayGraph_unregister();
void overlayGraph_iterate(void (*callback)(GraphHandle handle, const char * name,
bool * enabled, void * udata), void * udata);