Do not init SDL video subsystem if no display

The SDL video subsystem is not necessary if we don't display the video.

Move the sdl_init_and_configure() function from screen.c to scrcpy.c,
because it is not only related to the screen display.
This commit is contained in:
Romain Vimont 2019-03-03 01:40:03 +01:00
parent 8595862005
commit 6baed8a06f
3 changed files with 38 additions and 35 deletions

View file

@ -42,6 +42,40 @@ static struct input_manager input_manager = {
.control = true,
};
// init SDL and set appropriate hints
static bool
sdl_init_and_configure(bool display) {
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);
if (!display) {
return true;
}
// Use the best available scale quality
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2")) {
LOGW("Could not enable bilinear filtering");
}
#ifdef SCRCPY_SDL_HAS_HINT_MOUSE_FOCUS_CLICKTHROUGH
// Handle a click to gain focus as any other click
if (!SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1")) {
LOGW("Could not enable mouse focus clickthrough");
}
#endif
// Do not disable the screensaver when scrcpy is running
SDL_EnableScreenSaver();
return true;
}
#if defined(__APPLE__) || defined(__WINDOWS__)
# define CONTINUOUS_RESIZING_WORKAROUND
#endif
@ -240,7 +274,10 @@ scrcpy(const struct scrcpy_options *options) {
bool ret = true;
if (!sdl_init_and_configure()) {
bool display = !options->no_display;
bool control = !options->no_control;
if (!sdl_init_and_configure(display)) {
ret = false;
goto finally_destroy_server;
}
@ -264,9 +301,6 @@ scrcpy(const struct scrcpy_options *options) {
goto finally_destroy_server;
}
bool display = !options->no_display;
bool control = !options->no_control;
input_manager.control = control;
struct decoder *dec = NULL;

View file

@ -13,33 +13,6 @@
#define DISPLAY_MARGINS 96
bool
sdl_init_and_configure(void) {
if (SDL_Init(SDL_INIT_VIDEO)) {
LOGC("Could not initialize SDL: %s", SDL_GetError());
return false;
}
atexit(SDL_Quit);
// Use the best available scale quality
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2")) {
LOGW("Could not enable bilinear filtering");
}
#ifdef SCRCPY_SDL_HAS_HINT_MOUSE_FOCUS_CLICKTHROUGH
// Handle a click to gain focus as any other click
if (!SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1")) {
LOGW("Could not enable mouse focus clickthrough");
}
#endif
// Do not disable the screensaver when scrcpy is running
SDL_EnableScreenSaver();
return true;
}
// get the window size in a struct size
static struct size
get_native_window_size(SDL_Window *window) {

View file

@ -38,10 +38,6 @@ struct screen {
.no_window = false, \
}
// init SDL and set appropriate hints
bool
sdl_init_and_configure(void);
// initialize default values
void
screen_init(struct screen *screen);