From 688477ff6521af87f925da80d9519b334bbb6736 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 31 Oct 2021 12:03:35 +0100 Subject: [PATCH] Move SDL initialization Inline SDL initialization in scrcpy(). This will allow to split minimal initialization and video initialization. --- app/src/scrcpy.c | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index 0c2dc5b3..042cf43c 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -111,22 +111,8 @@ sdl_set_hints(const char *render_driver) { } } -// init SDL and set appropriate hints -static bool -sdl_init_and_configure(bool display, const char *render_driver, - bool disable_screensaver) { - if (display) { - sdl_set_hints(render_driver); - } - - uint32_t flags = display ? SDL_INIT_VIDEO : SDL_INIT_EVENTS; - if (SDL_Init(flags)) { - LOGC("Could not initialize SDL: %s", SDL_GetError()); - return false; - } - - atexit(SDL_Quit); - +static void +sdl_configure(bool display, bool disable_screensaver) { #ifdef _WIN32 // Clean up properly on Ctrl+C on Windows bool ok = SetConsoleCtrlHandler(windows_ctrl_handler, TRUE); @@ -136,7 +122,7 @@ sdl_init_and_configure(bool display, const char *render_driver, #endif // _WIN32 if (!display) { - return true; + return; } if (disable_screensaver) { @@ -146,8 +132,6 @@ sdl_init_and_configure(bool display, const char *render_driver, LOGD("Screensaver enabled"); SDL_EnableScreenSaver(); } - - return true; } static bool @@ -319,11 +303,20 @@ scrcpy(struct scrcpy_options *options) { server_started = true; - if (!sdl_init_and_configure(options->display, options->render_driver, - options->disable_screensaver)) { + if (options->display) { + sdl_set_hints(options->render_driver); + } + + uint32_t flags = options->display ? SDL_INIT_VIDEO : SDL_INIT_EVENTS; + if (SDL_Init(flags)) { + LOGC("Could not initialize SDL: %s", SDL_GetError()); goto end; } + atexit(SDL_Quit); + + sdl_configure(options->display, options->disable_screensaver); + char device_name[DEVICE_NAME_FIELD_LENGTH]; struct sc_size frame_size;