From f3b7712ea222efd30c076dba011154b0394ce2ae Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 24 Apr 2020 23:31:21 +0200 Subject: [PATCH] Add a mechanism to report errors on event handling This paves the way to workaround HiDPI issues, which may recreate the renderer and texture (which may fail) on window event. --- app/src/scrcpy.c | 8 +++++++- app/src/screen.c | 4 +++- app/src/screen.h | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index d557b208..e0bbc569 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -128,6 +128,7 @@ enum event_result { EVENT_RESULT_CONTINUE, EVENT_RESULT_STOPPED_BY_USER, EVENT_RESULT_STOPPED_BY_EOS, + EVENT_RESULT_STOPPED_BY_ERROR, }; static enum event_result @@ -150,7 +151,9 @@ handle_event(SDL_Event *event, bool control) { } break; case SDL_WINDOWEVENT: - screen_handle_window_event(&screen, &event->window); + if (!screen_handle_window_event(&screen, &event->window)) { + return EVENT_RESULT_STOPPED_BY_ERROR; + } break; case SDL_TEXTINPUT: if (!control) { @@ -222,6 +225,9 @@ event_loop(bool display, bool control) { case EVENT_RESULT_STOPPED_BY_EOS: LOGW("Device disconnected"); return false; + case EVENT_RESULT_STOPPED_BY_ERROR: + LOGC("Stopping due to unrecoverable error"); + return false; case EVENT_RESULT_CONTINUE: break; } diff --git a/app/src/screen.c b/app/src/screen.c index ff95c840..974935d5 100644 --- a/app/src/screen.c +++ b/app/src/screen.c @@ -518,7 +518,7 @@ screen_resize_to_pixel_perfect(struct screen *screen) { content_size.height); } -void +bool screen_handle_window_event(struct screen *screen, const SDL_WindowEvent *event) { switch (event->event) { @@ -558,6 +558,8 @@ screen_handle_window_event(struct screen *screen, apply_windowed_size(screen); break; } + + return true; } struct point diff --git a/app/src/screen.h b/app/src/screen.h index 85514279..c52b7cb8 100644 --- a/app/src/screen.h +++ b/app/src/screen.h @@ -111,7 +111,8 @@ void screen_set_rotation(struct screen *screen, unsigned rotation); // react to window events -void +// return true on success, false on unrecoverable error +bool screen_handle_window_event(struct screen *screen, const SDL_WindowEvent *event); // convert point from window coordinates to frame coordinates