mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-08-09 20:24:14 +00:00
[client] overlay: rework the interface to avoid possible race conditions
This commit is contained in:
@@ -628,7 +628,6 @@ struct Overlay
|
||||
{
|
||||
const struct LG_OverlayOps * ops;
|
||||
void * udata;
|
||||
int windowCount;
|
||||
};
|
||||
|
||||
void app_registerOverlay(const struct LG_OverlayOps * ops, void * params)
|
||||
@@ -650,43 +649,40 @@ void app_registerOverlay(const struct LG_OverlayOps * ops, void * params)
|
||||
|
||||
int app_renderOverlay(struct Rect * rects, int maxRects)
|
||||
{
|
||||
int windowCount = 0;
|
||||
int totalRects = 0;
|
||||
bool totalDamage = false;
|
||||
struct Overlay * overlay;
|
||||
|
||||
// get the total window count
|
||||
for (ll_reset(g_state.overlays);
|
||||
ll_walk(g_state.overlays, (void **)&overlay); )
|
||||
{
|
||||
overlay->windowCount = overlay->ops->getWindowCount(overlay->udata, false);
|
||||
windowCount += overlay->windowCount;
|
||||
}
|
||||
|
||||
// return -1 if there are no windows to render
|
||||
if (windowCount == 0)
|
||||
return -1;
|
||||
|
||||
if (windowCount > maxRects)
|
||||
{
|
||||
rects = NULL;
|
||||
windowCount = 0;
|
||||
}
|
||||
igNewFrame();
|
||||
|
||||
// render the overlays
|
||||
igNewFrame();
|
||||
for (ll_reset(g_state.overlays);
|
||||
ll_walk(g_state.overlays, (void **)&overlay); )
|
||||
{
|
||||
if (overlay->windowCount == 0)
|
||||
const int written =
|
||||
overlay->ops->render(overlay->udata, false, rects, maxRects);
|
||||
|
||||
if (!totalDamage)
|
||||
continue;
|
||||
|
||||
overlay->ops->render(overlay->udata, false, rects);
|
||||
if (rects)
|
||||
rects += overlay->windowCount;
|
||||
if (written == -1)
|
||||
{
|
||||
// out of rects, return that the entire surface is damaged
|
||||
totalDamage = true;
|
||||
rects = NULL;
|
||||
maxRects = 0;
|
||||
totalRects = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
maxRects -= written;
|
||||
rects += written;
|
||||
}
|
||||
}
|
||||
|
||||
igRender();
|
||||
|
||||
return windowCount;
|
||||
return totalDamage ? -1 : totalRects;
|
||||
}
|
||||
|
||||
void app_freeOverlays(void)
|
||||
|
@@ -32,14 +32,13 @@ static void fps_free(void * udata)
|
||||
{
|
||||
}
|
||||
|
||||
static int fps_getWindowCount(void * udata, bool interactive)
|
||||
static int fps_render(void * udata, bool interactive, struct Rect * windowRects,
|
||||
int maxRects)
|
||||
{
|
||||
return g_state.showFPS ? 1 : 0;
|
||||
}
|
||||
if (!g_state.showFPS)
|
||||
return 0;
|
||||
|
||||
static void fps_render(void * udata, bool interactive, struct Rect * windowRects)
|
||||
{
|
||||
const ImVec2 pos = {0.0f, 0.0f};
|
||||
ImVec2 pos = {0.0f, 0.0f};
|
||||
igSetNextWindowBgAlpha(0.6f);
|
||||
igSetNextWindowPos(pos, 0, pos);
|
||||
|
||||
@@ -55,18 +54,21 @@ static void fps_render(void * udata, bool interactive, struct Rect * windowRects
|
||||
atomic_load_explicit(&g_state.fps, memory_order_relaxed),
|
||||
atomic_load_explicit(&g_state.ups, memory_order_relaxed));
|
||||
|
||||
if (windowRects)
|
||||
if (maxRects == 0)
|
||||
{
|
||||
ImVec2 pos, size;
|
||||
igGetWindowPos(&pos);
|
||||
igGetWindowSize(&size);
|
||||
windowRects[0].x = pos.x;
|
||||
windowRects[0].y = pos.y;
|
||||
windowRects[0].w = size.x;
|
||||
windowRects[0].h = size.y;
|
||||
return -1;
|
||||
igEnd();
|
||||
}
|
||||
|
||||
ImVec2 size;
|
||||
igGetWindowPos(&pos);
|
||||
igGetWindowSize(&size);
|
||||
windowRects[0].x = pos.x;
|
||||
windowRects[0].y = pos.y;
|
||||
windowRects[0].w = size.x;
|
||||
windowRects[0].h = size.y;
|
||||
igEnd();
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct LG_OverlayOps LGOverlayFPS =
|
||||
@@ -74,6 +76,5 @@ struct LG_OverlayOps LGOverlayFPS =
|
||||
.name = "FPS",
|
||||
.init = fps_init,
|
||||
.free = fps_free,
|
||||
.getWindowCount = fps_getWindowCount,
|
||||
.render = fps_render
|
||||
};
|
||||
|
@@ -54,11 +54,6 @@ static void graphs_free(void * udata)
|
||||
ll_free(gs.graphs);
|
||||
}
|
||||
|
||||
static int graphs_getWindowCount(void * udata, bool interactive)
|
||||
{
|
||||
return g_state.showTiming ? 1 : 0;
|
||||
}
|
||||
|
||||
struct BufferMetrics
|
||||
{
|
||||
float min;
|
||||
@@ -91,9 +86,13 @@ static bool rbCalcMetrics(int index, void * value_, void * udata_)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void graphs_render(void * udata, bool interactive, struct Rect * windowRects)
|
||||
static int graphs_render(void * udata, bool interactive,
|
||||
struct Rect * windowRects, int maxRects)
|
||||
{
|
||||
const ImVec2 pos = {0.0f, 0.0f};
|
||||
if (!g_state.showTiming)
|
||||
return 0;
|
||||
|
||||
ImVec2 pos = {0.0f, 0.0f};
|
||||
igSetNextWindowBgAlpha(0.4f);
|
||||
igSetNextWindowPos(pos, 0, pos);
|
||||
|
||||
@@ -139,18 +138,22 @@ static void graphs_render(void * udata, bool interactive, struct Rect * windowRe
|
||||
sizeof(float));
|
||||
};
|
||||
|
||||
if (windowRects)
|
||||
if (maxRects == 0)
|
||||
{
|
||||
ImVec2 pos, size;
|
||||
igGetWindowPos(&pos);
|
||||
igGetWindowSize(&size);
|
||||
windowRects[0].x = pos.x;
|
||||
windowRects[0].y = pos.y;
|
||||
windowRects[0].w = size.x;
|
||||
windowRects[0].h = size.y;
|
||||
igEnd();
|
||||
return -1;
|
||||
}
|
||||
|
||||
ImVec2 size;
|
||||
igGetWindowPos(&pos);
|
||||
igGetWindowSize(&size);
|
||||
windowRects[0].x = pos.x;
|
||||
windowRects[0].y = pos.y;
|
||||
windowRects[0].w = size.x;
|
||||
windowRects[0].h = size.y;
|
||||
|
||||
igEnd();
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct LG_OverlayOps LGOverlayGraphs =
|
||||
@@ -158,7 +161,6 @@ struct LG_OverlayOps LGOverlayGraphs =
|
||||
.name = "Graphs",
|
||||
.init = graphs_init,
|
||||
.free = graphs_free,
|
||||
.getWindowCount = graphs_getWindowCount,
|
||||
.render = graphs_render
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user