[client] app: init/destroy imgui context on run/shutdown

This commit is contained in:
Geoffrey McRae 2021-07-08 14:05:42 +10:00
parent f08163fd72
commit bcffd70270
2 changed files with 15 additions and 13 deletions

View File

@ -56,8 +56,6 @@
#include "ll.h" #include "ll.h"
#include "egl_dynprocs.h" #include "egl_dynprocs.h"
#include "cimgui.h"
// forwards // forwards
static int cursorThread(void * unused); static int cursorThread(void * unused);
static int renderThread(void * unused); static int renderThread(void * unused);
@ -99,21 +97,12 @@ static void lgInit(void)
static int renderThread(void * unused) static int renderThread(void * unused)
{ {
/* setup imgui */
igCreateContext(NULL);
ImGuiIO * io = igGetIO();
unsigned char *text_pixels = NULL;
int text_w, text_h;
ImFontAtlas_GetTexDataAsRGBA32(io->Fonts, &text_pixels,
&text_w, &text_h, NULL);
if (!g_state.lgr->render_startup(g_state.lgrData)) if (!g_state.lgr->render_startup(g_state.lgrData))
{ {
g_state.state = APP_STATE_SHUTDOWN; g_state.state = APP_STATE_SHUTDOWN;
/* unblock threads waiting on the condition */ /* unblock threads waiting on the condition */
lgSignalEvent(e_startup); lgSignalEvent(e_startup);
igDestroyContext(NULL);
return 1; return 1;
} }
@ -144,7 +133,7 @@ static int renderThread(void * unused)
.x = g_state.windowW, .x = g_state.windowW,
.y = g_state.windowH .y = g_state.windowH
}; };
io->DisplaySize = displaySize; g_state.io->DisplaySize = displaySize;
if (g_state.lgr) if (g_state.lgr)
g_state.lgr->on_resize(g_state.lgrData, g_state.windowW, g_state.windowH, g_state.lgr->on_resize(g_state.lgrData, g_state.windowW, g_state.windowH,
@ -211,7 +200,6 @@ static int renderThread(void * unused)
g_state.lgr = NULL; g_state.lgr = NULL;
LG_LOCK_FREE(g_state.lgrLock); LG_LOCK_FREE(g_state.lgrLock);
igDestroyContext(NULL);
return 0; return 0;
} }
@ -701,6 +689,14 @@ static int lg_run(void)
g_state.showFPS = g_params.showFPS; g_state.showFPS = g_params.showFPS;
/* setup imgui */
igCreateContext(NULL);
g_state.io = igGetIO();
unsigned char *text_pixels = NULL;
int text_w, text_h;
ImFontAtlas_GetTexDataAsRGBA32(g_state.io->Fonts, &text_pixels,
&text_w, &text_h, NULL);
// 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())
@ -1067,6 +1063,8 @@ static void lg_shutdown(void)
g_state.ds->free(); g_state.ds->free();
ivshmemClose(&g_state.shm); ivshmemClose(&g_state.shm);
igDestroyContext(NULL);
} }
int main(int argc, char * argv[]) int main(int argc, char * argv[])

View File

@ -33,6 +33,8 @@
#include "spice/spice.h" #include "spice/spice.h"
#include <lgmp/client.h> #include <lgmp/client.h>
#include "cimgui.h"
enum RunState enum RunState
{ {
APP_STATE_RUNNING, APP_STATE_RUNNING,
@ -44,6 +46,8 @@ struct AppState
{ {
enum RunState state; enum RunState state;
ImGuiIO * io;
struct LG_DisplayServerOps * ds; struct LG_DisplayServerOps * ds;
bool dsInitialized; bool dsInitialized;