Group screen parameters into a struct

The function screen_init_rendering had too many parameters.
This commit is contained in:
Romain Vimont 2021-02-25 22:00:34 +01:00
parent 955da3b578
commit 597c54f049
3 changed files with 54 additions and 35 deletions

View file

@ -384,12 +384,20 @@ scrcpy(const struct scrcpy_options *options) {
screen_init(&screen, &video_buffer, &fps_counter); screen_init(&screen, &video_buffer, &fps_counter);
if (!screen_init_rendering(&screen, window_title, frame_size, struct screen_params screen_params = {
options->always_on_top, options->window_x, .window_title = window_title,
options->window_y, options->window_width, .frame_size = frame_size,
options->window_height, .always_on_top = options->always_on_top,
options->window_borderless, .window_x = options->window_x,
options->rotation, options->mipmaps)) { .window_y = options->window_y,
.window_width = options->window_width,
.window_height = options->window_height,
.window_borderless = options->window_borderless,
.rotation = options->rotation,
.mipmaps = options->mipmaps,
};
if (!screen_init_rendering(&screen, &screen_params)) {
goto end; goto end;
} }

View file

@ -259,26 +259,25 @@ create_texture(struct screen *screen) {
} }
bool bool
screen_init_rendering(struct screen *screen, const char *window_title, screen_init_rendering(struct screen *screen,
struct size frame_size, bool always_on_top, const struct screen_params *params) {
int16_t window_x, int16_t window_y, uint16_t window_width, screen->frame_size = params->frame_size;
uint16_t window_height, bool window_borderless, screen->rotation = params->rotation;
uint8_t rotation, bool mipmaps) { if (screen->rotation) {
screen->frame_size = frame_size; LOGI("Initial display rotation set to %u", screen->rotation);
screen->rotation = rotation;
if (rotation) {
LOGI("Initial display rotation set to %u", rotation);
} }
struct size content_size = get_rotated_size(frame_size, screen->rotation); struct size content_size =
get_rotated_size(screen->frame_size, screen->rotation);
screen->content_size = content_size; screen->content_size = content_size;
struct size window_size = struct size window_size = get_initial_optimal_size(content_size,
get_initial_optimal_size(content_size, window_width, window_height); params->window_width,
params->window_height);
uint32_t window_flags = SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE; uint32_t window_flags = SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE;
#ifdef HIDPI_SUPPORT #ifdef HIDPI_SUPPORT
window_flags |= SDL_WINDOW_ALLOW_HIGHDPI; window_flags |= SDL_WINDOW_ALLOW_HIGHDPI;
#endif #endif
if (always_on_top) { if (params->always_on_top) {
#ifdef SCRCPY_SDL_HAS_WINDOW_ALWAYS_ON_TOP #ifdef SCRCPY_SDL_HAS_WINDOW_ALWAYS_ON_TOP
window_flags |= SDL_WINDOW_ALWAYS_ON_TOP; window_flags |= SDL_WINDOW_ALWAYS_ON_TOP;
#else #else
@ -286,15 +285,15 @@ screen_init_rendering(struct screen *screen, const char *window_title,
"(compile with SDL >= 2.0.5 to enable it)"); "(compile with SDL >= 2.0.5 to enable it)");
#endif #endif
} }
if (window_borderless) { if (params->window_borderless) {
window_flags |= SDL_WINDOW_BORDERLESS; window_flags |= SDL_WINDOW_BORDERLESS;
} }
int x = window_x != SC_WINDOW_POSITION_UNDEFINED int x = params->window_x != SC_WINDOW_POSITION_UNDEFINED
? window_x : (int) SDL_WINDOWPOS_UNDEFINED; ? params->window_x : (int) SDL_WINDOWPOS_UNDEFINED;
int y = window_y != SC_WINDOW_POSITION_UNDEFINED int y = params->window_y != SC_WINDOW_POSITION_UNDEFINED
? window_y : (int) SDL_WINDOWPOS_UNDEFINED; ? params->window_y : (int) SDL_WINDOWPOS_UNDEFINED;
screen->window = SDL_CreateWindow(window_title, x, y, screen->window = SDL_CreateWindow(params->window_title, x, y,
window_size.width, window_size.height, window_size.width, window_size.height,
window_flags); window_flags);
if (!screen->window) { if (!screen->window) {
@ -325,7 +324,7 @@ screen_init_rendering(struct screen *screen, const char *window_title,
LOGI("OpenGL version: %s", gl->version); LOGI("OpenGL version: %s", gl->version);
if (mipmaps) { if (params->mipmaps) {
bool supports_mipmaps = bool supports_mipmaps =
sc_opengl_version_at_least(gl, 3, 0, /* OpenGL 3.0+ */ sc_opengl_version_at_least(gl, 3, 0, /* OpenGL 3.0+ */
2, 0 /* OpenGL ES 2.0+ */); 2, 0 /* OpenGL ES 2.0+ */);
@ -339,7 +338,7 @@ screen_init_rendering(struct screen *screen, const char *window_title,
} else { } else {
LOGI("Trilinear filtering disabled"); LOGI("Trilinear filtering disabled");
} }
} else if (mipmaps) { } else if (params->mipmaps) {
LOGD("Trilinear filtering disabled (not an OpenGL renderer)"); LOGD("Trilinear filtering disabled (not an OpenGL renderer)");
} }
@ -351,8 +350,8 @@ screen_init_rendering(struct screen *screen, const char *window_title,
LOGW("Could not load icon"); LOGW("Could not load icon");
} }
LOGI("Initial texture: %" PRIu16 "x%" PRIu16, frame_size.width, LOGI("Initial texture: %" PRIu16 "x%" PRIu16, params->frame_size.width,
frame_size.height); params->frame_size.height);
screen->texture = create_texture(screen); screen->texture = create_texture(screen);
if (!screen->texture) { if (!screen->texture) {
LOGC("Could not create texture: %s", SDL_GetError()); LOGC("Could not create texture: %s", SDL_GetError());

View file

@ -38,19 +38,31 @@ struct screen {
bool mipmaps; bool mipmaps;
}; };
struct screen_params {
const char *window_title;
struct size frame_size;
bool always_on_top;
int16_t window_x;
int16_t window_y;
uint16_t window_width; // accepts SC_WINDOW_POSITION_UNDEFINED
uint16_t window_height; // accepts SC_WINDOW_POSITION_UNDEFINED
bool window_borderless;
uint8_t rotation;
bool mipmaps;
};
// initialize default values // initialize default values
void void
screen_init(struct screen *screen, struct video_buffer *vb, screen_init(struct screen *screen, struct video_buffer *vb,
struct fps_counter *fps_counter); struct fps_counter *fps_counter);
// initialize screen, create window, renderer and texture (window is hidden) // initialize screen, create window, renderer and texture (window is hidden)
// window_x and window_y accept SC_WINDOW_POSITION_UNDEFINED
bool bool
screen_init_rendering(struct screen *screen, const char *window_title, screen_init_rendering(struct screen *screen,
struct size frame_size, bool always_on_top, const struct screen_params *params);
int16_t window_x, int16_t window_y, uint16_t window_width,
uint16_t window_height, bool window_borderless,
uint8_t rotation, bool mipmaps);
// show the window // show the window
void void