Simplify screen initialization

Use a single function to initialize the screen instance.
This commit is contained in:
Romain Vimont 2021-02-25 22:06:33 +01:00
parent 597c54f049
commit cc48b24324
3 changed files with 22 additions and 31 deletions

View file

@ -382,8 +382,6 @@ scrcpy(const struct scrcpy_options *options) {
const char *window_title =
options->window_title ? options->window_title : device_name;
screen_init(&screen, &video_buffer, &fps_counter);
struct screen_params screen_params = {
.window_title = window_title,
.frame_size = frame_size,
@ -397,7 +395,8 @@ scrcpy(const struct scrcpy_options *options) {
.mipmaps = options->mipmaps,
};
if (!screen_init_rendering(&screen, &screen_params)) {
if (!screen_init(&screen, &video_buffer, &fps_counter,
&screen_params)) {
goto end;
}

View file

@ -212,25 +212,6 @@ on_frame_skipped(struct video_buffer *vb, void *userdata) {
fps_counter_add_skipped_frame(screen->fps_counter);
}
void
screen_init(struct screen *screen, struct video_buffer *vb,
struct fps_counter *fps_counter) {
screen->vb = vb;
screen->fps_counter = fps_counter;
screen->resize_pending = false;
screen->has_frame = false;
screen->fullscreen = false;
screen->maximized = false;
static const struct video_buffer_callbacks cbs = {
.on_frame_available = on_frame_available,
.on_frame_skipped = on_frame_skipped,
};
video_buffer_set_consumer_callbacks(vb, &cbs, screen);
}
static inline SDL_Texture *
create_texture(struct screen *screen) {
SDL_Renderer *renderer = screen->renderer;
@ -259,8 +240,23 @@ create_texture(struct screen *screen) {
}
bool
screen_init_rendering(struct screen *screen,
const struct screen_params *params) {
screen_init(struct screen *screen, struct video_buffer *vb,
struct fps_counter *fps_counter,
const struct screen_params *params) {
screen->vb = vb;
screen->fps_counter = fps_counter;
screen->resize_pending = false;
screen->has_frame = false;
screen->fullscreen = false;
screen->maximized = false;
static const struct video_buffer_callbacks cbs = {
.on_frame_available = on_frame_available,
.on_frame_skipped = on_frame_skipped,
};
video_buffer_set_consumer_callbacks(vb, &cbs, screen);
screen->frame_size = params->frame_size;
screen->rotation = params->rotation;
if (screen->rotation) {

View file

@ -54,15 +54,11 @@ struct screen_params {
bool mipmaps;
};
// initialize default values
void
screen_init(struct screen *screen, struct video_buffer *vb,
struct fps_counter *fps_counter);
// initialize screen, create window, renderer and texture (window is hidden)
bool
screen_init_rendering(struct screen *screen,
const struct screen_params *params);
screen_init(struct screen *screen, struct video_buffer *vb,
struct fps_counter *fps_counter,
const struct screen_params *params);
// show the window
void