From fe43453f47c9581bce570a5ede6625ef82ab0a2d Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Tue, 16 Feb 2021 23:29:27 +0100 Subject: [PATCH] screen_on_new_frame --- app/src/scrcpy.c | 5 +---- app/src/screen.c | 12 ++++++++++++ app/src/screen.h | 5 +++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index ea8002b8..e0447ce1 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -271,10 +271,7 @@ decoder_on_new_frame(struct decoder *decoder, void *userdata) { (void) decoder; (void) userdata; - static SDL_Event new_frame_event = { - .type = EVENT_NEW_FRAME, - }; - SDL_PushEvent(&new_frame_event); + screen_on_new_frame(&screen); } bool diff --git a/app/src/screen.c b/app/src/screen.c index 1174593d..2ca35d44 100644 --- a/app/src/screen.c +++ b/app/src/screen.c @@ -647,3 +647,15 @@ screen_hidpi_scale_coords(struct screen *screen, int32_t *x, int32_t *y) { *x = (int64_t) *x * dw / ww; *y = (int64_t) *y * dh / wh; } + +void +screen_on_new_frame(struct screen *screen) { + (void) screen; + + static SDL_Event new_frame_event = { + .type = EVENT_NEW_FRAME, + }; + + // Post the event on the UI thread + SDL_PushEvent(&new_frame_event); +} diff --git a/app/src/screen.h b/app/src/screen.h index 171717ab..0230b819 100644 --- a/app/src/screen.h +++ b/app/src/screen.h @@ -137,4 +137,9 @@ screen_convert_drawable_to_frame_coords(struct screen *screen, void screen_hidpi_scale_coords(struct screen *screen, int32_t *x, int32_t *y); +// Notify the screen that a new frame is available in the video_buffer. +// Called from a separate thread. +void +screen_on_new_frame(struct screen *screen); + #endif