From c6d97111097514cdf333689900abafd57ad354ec Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 28 Apr 2022 19:10:45 +0200 Subject: [PATCH 1/4] Create OTG window with HIGHDPI flag This will avoid poor quality with HiDPI displays. PR #3219 --- app/src/usb/screen_otg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/usb/screen_otg.c b/app/src/usb/screen_otg.c index 561a84ca41..93b0ba6e38 100644 --- a/app/src/usb/screen_otg.c +++ b/app/src/usb/screen_otg.c @@ -72,7 +72,7 @@ sc_screen_otg_init(struct sc_screen_otg *screen, int width = 256; int height = 256; - uint32_t window_flags = 0; + uint32_t window_flags = SDL_WINDOW_ALLOW_HIGHDPI; if (params->always_on_top) { window_flags |= SDL_WINDOW_ALWAYS_ON_TOP; } From fc8942aa03dd18b20d6b2e450b13ba56d2c3489e Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 25 Apr 2022 18:44:42 +0200 Subject: [PATCH 2/4] Apply requested window size in OTG mode Fixes #3099 PR #3219 --- app/src/usb/scrcpy_otg.c | 2 ++ app/src/usb/screen_otg.c | 9 +++++++-- app/src/usb/screen_otg.h | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/usb/scrcpy_otg.c b/app/src/usb/scrcpy_otg.c index db5e64d881..052facffa3 100644 --- a/app/src/usb/scrcpy_otg.c +++ b/app/src/usb/scrcpy_otg.c @@ -162,6 +162,8 @@ scrcpy_otg(struct scrcpy_options *options) { .always_on_top = options->always_on_top, .window_x = options->window_x, .window_y = options->window_y, + .window_width = options->window_width, + .window_height = options->window_height, .window_borderless = options->window_borderless, }; diff --git a/app/src/usb/screen_otg.c b/app/src/usb/screen_otg.c index 93b0ba6e38..450cbe1e9c 100644 --- a/app/src/usb/screen_otg.c +++ b/app/src/usb/screen_otg.c @@ -69,8 +69,8 @@ sc_screen_otg_init(struct sc_screen_otg *screen, ? params->window_x : (int) SDL_WINDOWPOS_UNDEFINED; int y = params->window_y != SC_WINDOW_POSITION_UNDEFINED ? params->window_y : (int) SDL_WINDOWPOS_UNDEFINED; - int width = 256; - int height = 256; + int width = params->window_width ? params->window_width : 256; + int height = params->window_height ? params->window_height : 256; uint32_t window_flags = SDL_WINDOW_ALLOW_HIGHDPI; if (params->always_on_top) { @@ -97,6 +97,11 @@ sc_screen_otg_init(struct sc_screen_otg *screen, if (icon) { SDL_SetWindowIcon(screen->window, icon); + if (!SDL_RenderSetLogicalSize(screen->renderer, icon->w, icon->h)) { + LOGW("Could not set renderer logical size: %s", SDL_GetError()); + // don't fail + } + screen->texture = SDL_CreateTextureFromSurface(screen->renderer, icon); scrcpy_icon_destroy(icon); if (!screen->texture) { diff --git a/app/src/usb/screen_otg.h b/app/src/usb/screen_otg.h index 0973ce59e1..a0acf40bda 100644 --- a/app/src/usb/screen_otg.h +++ b/app/src/usb/screen_otg.h @@ -29,6 +29,8 @@ struct sc_screen_otg_params { bool always_on_top; int16_t window_x; // accepts SC_WINDOW_POSITION_UNDEFINED int16_t window_y; // accepts SC_WINDOW_POSITION_UNDEFINED + uint16_t window_width; + uint16_t window_height; bool window_borderless; }; From 436b368f9df4469274502f29626586b48db44a0c Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 28 Apr 2022 19:11:42 +0200 Subject: [PATCH 3/4] Make OTG window resizable PR #3219 --- app/src/usb/screen_otg.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/usb/screen_otg.c b/app/src/usb/screen_otg.c index 450cbe1e9c..abdfc9a43f 100644 --- a/app/src/usb/screen_otg.c +++ b/app/src/usb/screen_otg.c @@ -72,7 +72,8 @@ sc_screen_otg_init(struct sc_screen_otg *screen, int width = params->window_width ? params->window_width : 256; int height = params->window_height ? params->window_height : 256; - uint32_t window_flags = SDL_WINDOW_ALLOW_HIGHDPI; + uint32_t window_flags = SDL_WINDOW_ALLOW_HIGHDPI + | SDL_WINDOW_RESIZABLE; if (params->always_on_top) { window_flags |= SDL_WINDOW_ALWAYS_ON_TOP; } From 854a56e58893da352410d6e01708704f550fd6e4 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 28 Apr 2022 19:12:37 +0200 Subject: [PATCH 4/4] Enable linear filtering in OTG mode This improves the icon quality with non-standard window size. PR #3219 --- app/src/usb/scrcpy_otg.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/usb/scrcpy_otg.c b/app/src/usb/scrcpy_otg.c index 052facffa3..ebcfa36fb6 100644 --- a/app/src/usb/scrcpy_otg.c +++ b/app/src/usb/scrcpy_otg.c @@ -55,6 +55,10 @@ scrcpy_otg(struct scrcpy_options *options) { const char *serial = options->serial; + if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1")) { + LOGW("Could not enable linear filtering"); + } + // Minimal SDL initialization if (SDL_Init(SDL_INIT_EVENTS)) { LOGE("Could not initialize SDL: %s", SDL_GetError());