mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-12-23 06:11:46 +00:00
[client] imgui: support registering new graphs
Currently, our struct ll doesn't support removing elements from the middle, so we will not be removing anything for now.
This commit is contained in:
parent
a4bf3c8088
commit
15bc6a1509
4 changed files with 68 additions and 54 deletions
|
@ -24,6 +24,7 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <linux/input.h>
|
#include <linux/input.h>
|
||||||
|
|
||||||
|
#include "common/ringbuffer.h"
|
||||||
#include "common/types.h"
|
#include "common/types.h"
|
||||||
#include "interface/displayserver.h"
|
#include "interface/displayserver.h"
|
||||||
|
|
||||||
|
@ -78,6 +79,9 @@ void app_glSetSwapInterval(int interval);
|
||||||
void app_glSwapBuffers(void);
|
void app_glSwapBuffers(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef struct ImGuiGraph * GraphHandle;
|
||||||
|
GraphHandle app_registerGraph(const char * name, RingBuffer buffer);
|
||||||
|
void app_unregisterGraph(GraphHandle handle);
|
||||||
bool app_renderImGui(void);
|
bool app_renderImGui(void);
|
||||||
|
|
||||||
void app_clipboardRelease(void);
|
void app_clipboardRelease(void);
|
||||||
|
|
110
client/src/app.c
110
client/src/app.c
|
@ -620,8 +620,33 @@ void app_showFPS(bool showFPS)
|
||||||
g_state.lgr->on_show_fps(g_state.lgrData, showFPS);
|
g_state.lgr->on_show_fps(g_state.lgrData, showFPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rbCalcMetrics(int index, float * value, float * udata)
|
struct ImGuiGraph
|
||||||
{
|
{
|
||||||
|
const char * name;
|
||||||
|
RingBuffer buffer;
|
||||||
|
bool enabled;
|
||||||
|
};
|
||||||
|
|
||||||
|
GraphHandle app_registerGraph(const char * name, RingBuffer buffer)
|
||||||
|
{
|
||||||
|
struct ImGuiGraph * graph = malloc(sizeof(struct ImGuiGraph));
|
||||||
|
graph->name = name;
|
||||||
|
graph->buffer = buffer;
|
||||||
|
graph->enabled = true;
|
||||||
|
ll_push(g_state.graphs, graph);
|
||||||
|
return graph;
|
||||||
|
}
|
||||||
|
|
||||||
|
void app_unregisterGraph(GraphHandle handle)
|
||||||
|
{
|
||||||
|
handle->enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool rbCalcMetrics(int index, void * value_, void * udata_)
|
||||||
|
{
|
||||||
|
float * value = value_;
|
||||||
|
float * udata = udata_;
|
||||||
|
|
||||||
if (index == 0)
|
if (index == 0)
|
||||||
{
|
{
|
||||||
udata[0] = *value;
|
udata[0] = *value;
|
||||||
|
@ -662,61 +687,40 @@ bool app_renderImGui(void)
|
||||||
ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoTitleBar
|
ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoTitleBar
|
||||||
);
|
);
|
||||||
|
|
||||||
|
GraphHandle graph;
|
||||||
float renderMetrics[4] = {};
|
for (ll_reset(g_state.graphs); ll_walk(g_state.graphs, (void **)&graph); )
|
||||||
float frameMetrics [4] = {};
|
|
||||||
ringbuffer_forEach(g_state.renderTimings, (RingBufferIterator)rbCalcMetrics,
|
|
||||||
renderMetrics);
|
|
||||||
ringbuffer_forEach(g_state.frameTimings , (RingBufferIterator)rbCalcMetrics,
|
|
||||||
frameMetrics);
|
|
||||||
|
|
||||||
if (renderMetrics[2] > 0.0f)
|
|
||||||
{
|
{
|
||||||
renderMetrics[2] /= ringbuffer_getCount(g_state.renderTimings);
|
if (!graph->enabled)
|
||||||
renderMetrics[3] = 1000.0f / renderMetrics[2];
|
continue;
|
||||||
|
|
||||||
|
float metrics[4] = {};
|
||||||
|
ringbuffer_forEach(graph->buffer, rbCalcMetrics, metrics);
|
||||||
|
|
||||||
|
if (metrics[2] > 0.0f)
|
||||||
|
{
|
||||||
|
metrics[2] /= ringbuffer_getCount(graph->buffer);
|
||||||
|
metrics[3] = 1000.0f / metrics[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
char title[64];
|
||||||
|
const ImVec2 size = {400.0f, 100.0f};
|
||||||
|
|
||||||
|
snprintf(title, sizeof(title),
|
||||||
|
"%s: min:%4.2f max:%4.2f avg:%4.2f/%4.2fHz",
|
||||||
|
graph->name, metrics[0], metrics[1], metrics[2], metrics[3]);
|
||||||
|
|
||||||
|
igPlotLinesFloatPtr(
|
||||||
|
"",
|
||||||
|
(float *)ringbuffer_getValues(graph->buffer),
|
||||||
|
ringbuffer_getLength(graph->buffer),
|
||||||
|
ringbuffer_getStart (graph->buffer),
|
||||||
|
title,
|
||||||
|
0.0f,
|
||||||
|
50.0f,
|
||||||
|
size,
|
||||||
|
sizeof(float));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frameMetrics[2] > 0.0f)
|
|
||||||
{
|
|
||||||
frameMetrics[2] /= ringbuffer_getCount(g_state.frameTimings );
|
|
||||||
frameMetrics[3] = 1000.0f / frameMetrics[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
char buffer[64];
|
|
||||||
const ImVec2 size = {400.0f, 100.0f};
|
|
||||||
|
|
||||||
snprintf(buffer, sizeof(buffer),
|
|
||||||
"RENDER: min:%4.2f max:%4.2f avg:%4.2f/%4.2fHz",
|
|
||||||
renderMetrics[0], renderMetrics[1], renderMetrics[2],
|
|
||||||
renderMetrics[3]);
|
|
||||||
|
|
||||||
igPlotLinesFloatPtr(
|
|
||||||
"",
|
|
||||||
(float *)ringbuffer_getValues(g_state.renderTimings),
|
|
||||||
ringbuffer_getLength(g_state.renderTimings),
|
|
||||||
ringbuffer_getStart (g_state.renderTimings),
|
|
||||||
buffer,
|
|
||||||
0.0f,
|
|
||||||
50.0f,
|
|
||||||
size,
|
|
||||||
sizeof(float));
|
|
||||||
|
|
||||||
snprintf(buffer, sizeof(buffer),
|
|
||||||
"UPLOAD: min:%4.2f max:%4.2f avg:%4.2f/%4.2fHz",
|
|
||||||
frameMetrics[0], frameMetrics[1], frameMetrics[2],
|
|
||||||
frameMetrics[3]);
|
|
||||||
|
|
||||||
igPlotLinesFloatPtr(
|
|
||||||
"",
|
|
||||||
(float *)ringbuffer_getValues(g_state.frameTimings),
|
|
||||||
ringbuffer_getLength(g_state.frameTimings),
|
|
||||||
ringbuffer_getStart (g_state.frameTimings),
|
|
||||||
buffer,
|
|
||||||
0.0f,
|
|
||||||
50.0f,
|
|
||||||
size,
|
|
||||||
sizeof(float));
|
|
||||||
|
|
||||||
igEnd();
|
igEnd();
|
||||||
|
|
||||||
igRender();
|
igRender();
|
||||||
|
|
|
@ -720,10 +720,15 @@ static int lg_run(void)
|
||||||
ImFontAtlas_GetTexDataAsRGBA32(g_state.io->Fonts, &text_pixels,
|
ImFontAtlas_GetTexDataAsRGBA32(g_state.io->Fonts, &text_pixels,
|
||||||
&text_w, &text_h, NULL);
|
&text_w, &text_h, NULL);
|
||||||
|
|
||||||
|
g_state.graphs = ll_new();
|
||||||
|
|
||||||
// initialize metrics ringbuffers
|
// initialize metrics ringbuffers
|
||||||
g_state.renderTimings = ringbuffer_new(256, sizeof(float));
|
g_state.renderTimings = ringbuffer_new(256, sizeof(float));
|
||||||
g_state.frameTimings = ringbuffer_new(256, sizeof(float));
|
g_state.frameTimings = ringbuffer_new(256, sizeof(float));
|
||||||
|
|
||||||
|
app_registerGraph("RENDER", g_state.renderTimings);
|
||||||
|
app_registerGraph("UPLOAD", g_state.frameTimings);
|
||||||
|
|
||||||
// search for the best displayserver ops to use
|
// search for the best displayserver ops to use
|
||||||
for(int i = 0; i < LG_DISPLAYSERVER_COUNT; ++i)
|
for(int i = 0; i < LG_DISPLAYSERVER_COUNT; ++i)
|
||||||
if (LG_DisplayServers[i]->probe())
|
if (LG_DisplayServers[i]->probe())
|
||||||
|
|
|
@ -47,7 +47,8 @@ struct AppState
|
||||||
{
|
{
|
||||||
enum RunState state;
|
enum RunState state;
|
||||||
|
|
||||||
ImGuiIO * io;
|
ImGuiIO * io;
|
||||||
|
struct ll * graphs;
|
||||||
|
|
||||||
struct LG_DisplayServerOps * ds;
|
struct LG_DisplayServerOps * ds;
|
||||||
bool dsInitialized;
|
bool dsInitialized;
|
||||||
|
|
Loading…
Reference in a new issue