Add compilation flag for HIDPI workaround

The HIDPI workaround is enabled by default. Expose a flag to be able to
disable it.
This commit is contained in:
Romain Vimont 2019-11-06 19:23:15 +01:00
parent 78d9d82091
commit 73c0f3ee05
4 changed files with 16 additions and 0 deletions

View File

@ -115,6 +115,9 @@ conf.set('WINDOWS_NOCONSOLE', get_option('windows_noconsole'))
# run a server debugger and wait for a client to be attached # run a server debugger and wait for a client to be attached
conf.set('SERVER_DEBUGGER', get_option('server_debugger')) conf.set('SERVER_DEBUGGER', get_option('server_debugger'))
# enable a workaround for bug #15
conf.set('HIDPI_WORKAROUND', get_option('hidpi_workaround'))
configure_file(configuration: conf, output: 'config.h') configure_file(configuration: conf, output: 'config.h')
src_dir = include_directories('src') src_dir = include_directories('src')

View File

@ -134,6 +134,7 @@ create_texture(SDL_Renderer *renderer, struct size frame_size) {
frame_size.width, frame_size.height); frame_size.width, frame_size.height);
} }
#ifdef HIDPI_WORKAROUND
static void static void
screen_get_sizes(struct screen *screen, struct screen_sizes *out) { screen_get_sizes(struct screen *screen, struct screen_sizes *out) {
int ww, wh, dw, dh; int ww, wh, dw, dh;
@ -144,6 +145,7 @@ screen_get_sizes(struct screen *screen, struct screen_sizes *out) {
out->window.width = dw; out->window.width = dw;
out->window.height = dh; out->window.height = dh;
} }
#endif
// This may be called more than once to work around SDL bugs // This may be called more than once to work around SDL bugs
static bool static bool
@ -167,7 +169,9 @@ screen_init_renderer_and_texture(struct screen *screen) {
return false; return false;
} }
#ifdef HIDPI_WORKAROUND
screen_get_sizes(screen, &screen->sizes); screen_get_sizes(screen, &screen->sizes);
#endif
return true; return true;
} }
@ -298,6 +302,7 @@ screen_update_frame(struct screen *screen, struct video_buffer *vb) {
return true; return true;
} }
#ifdef HIDPI_WORKAROUND
// workaround for <https://github.com/Genymobile/scrcpy/issues/15> // workaround for <https://github.com/Genymobile/scrcpy/issues/15>
static inline bool static inline bool
screen_fix_hidpi(struct screen *screen) { screen_fix_hidpi(struct screen *screen) {
@ -318,14 +323,19 @@ screen_fix_hidpi(struct screen *screen) {
screen->renderer = NULL; screen->renderer = NULL;
return false; return false;
} }
LOGI("Renderer reset after hidpi scaling changed");
} }
return true; return true;
} }
#endif
void void
screen_window_resized(struct screen *screen) { screen_window_resized(struct screen *screen) {
#ifdef HIDPI_WORKAROUND
screen_fix_hidpi(screen); screen_fix_hidpi(screen);
#endif
screen_render(screen); screen_render(screen);
} }

View File

@ -20,10 +20,12 @@ struct screen {
bool has_frame; bool has_frame;
bool fullscreen; bool fullscreen;
bool no_window; bool no_window;
#ifdef HIDPI_WORKAROUND
struct screen_sizes { struct screen_sizes {
struct size window; struct size window;
struct size drawable; struct size drawable;
} sizes; } sizes;
#endif
}; };
#define SCREEN_INITIALIZER { \ #define SCREEN_INITIALIZER { \

View File

@ -5,3 +5,4 @@ option('windows_noconsole', type: 'boolean', value: false, description: 'Disable
option('prebuilt_server', type: 'string', description: 'Path of the prebuilt server') option('prebuilt_server', type: 'string', description: 'Path of the prebuilt server')
option('portable', type: 'boolean', value: false, description: 'Use scrcpy-server from the same directory as the scrcpy executable') option('portable', type: 'boolean', value: false, description: 'Use scrcpy-server from the same directory as the scrcpy executable')
option('server_debugger', type: 'boolean', value: false, description: 'Run a server debugger and wait for a client to be attached') option('server_debugger', type: 'boolean', value: false, description: 'Run a server debugger and wait for a client to be attached')
option('hidpi_workaround', type: 'boolean', value: true, description: 'Enable a workaround for bug #15')