Compare commits
4 Commits
master
...
fixhidpi.4
Author | SHA1 | Date | |
---|---|---|---|
|
97ee02ada6 | ||
|
42780d0b0e | ||
|
492668edd0 | ||
|
2f7586ad7f |
@ -109,15 +109,15 @@ conf.set('DEFAULT_MAX_SIZE', '0') # 0: unlimited
|
|||||||
# overridden by option --bit-rate
|
# overridden by option --bit-rate
|
||||||
conf.set('DEFAULT_BIT_RATE', '8000000') # 8Mbps
|
conf.set('DEFAULT_BIT_RATE', '8000000') # 8Mbps
|
||||||
|
|
||||||
# enable High DPI support
|
|
||||||
conf.set('HIDPI_SUPPORT', get_option('hidpi_support'))
|
|
||||||
|
|
||||||
# disable console on Windows
|
# disable console on Windows
|
||||||
conf.set('WINDOWS_NOCONSOLE', get_option('windows_noconsole'))
|
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')
|
||||||
|
@ -145,9 +145,11 @@ handle_event(SDL_Event *event, bool control) {
|
|||||||
case SDL_WINDOWEVENT:
|
case SDL_WINDOWEVENT:
|
||||||
switch (event->window.event) {
|
switch (event->window.event) {
|
||||||
case SDL_WINDOWEVENT_EXPOSED:
|
case SDL_WINDOWEVENT_EXPOSED:
|
||||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
|
||||||
screen_render(&screen);
|
screen_render(&screen);
|
||||||
break;
|
break;
|
||||||
|
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||||
|
screen_window_resized(&screen);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_TEXTINPUT:
|
case SDL_TEXTINPUT:
|
||||||
|
105
app/src/screen.c
105
app/src/screen.c
@ -134,16 +134,57 @@ 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
|
||||||
|
screen_get_sizes(struct screen *screen, struct screen_sizes *out) {
|
||||||
|
int ww, wh, dw, dh;
|
||||||
|
SDL_GetWindowSize(screen->window, &ww, &wh);
|
||||||
|
SDL_GL_GetDrawableSize(screen->window, &dw, &dh);
|
||||||
|
out->window.width = ww;
|
||||||
|
out->window.height = wh;
|
||||||
|
out->window.width = dw;
|
||||||
|
out->window.height = dh;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// This may be called more than once to work around SDL bugs
|
||||||
|
static bool
|
||||||
|
screen_init_renderer_and_texture(struct screen *screen) {
|
||||||
|
screen->renderer = SDL_CreateRenderer(screen->window, -1,
|
||||||
|
SDL_RENDERER_ACCELERATED);
|
||||||
|
if (!screen->renderer) {
|
||||||
|
LOGC("Could not create renderer: %s", SDL_GetError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SDL_RenderSetLogicalSize(screen->renderer, screen->frame_size.width,
|
||||||
|
screen->frame_size.height)) {
|
||||||
|
LOGE("Could not set renderer logical size: %s", SDL_GetError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
screen->texture = create_texture(screen->renderer, screen->frame_size);
|
||||||
|
if (!screen->texture) {
|
||||||
|
LOGC("Could not create texture: %s", SDL_GetError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HIDPI_WORKAROUND
|
||||||
|
screen_get_sizes(screen, &screen->sizes);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
screen_init_rendering(struct screen *screen, const char *window_title,
|
screen_init_rendering(struct screen *screen, const char *window_title,
|
||||||
struct size frame_size, bool always_on_top) {
|
struct size frame_size, bool always_on_top) {
|
||||||
screen->frame_size = frame_size;
|
screen->frame_size = frame_size;
|
||||||
|
|
||||||
struct size window_size = get_initial_optimal_size(frame_size);
|
struct size window_size = get_initial_optimal_size(frame_size);
|
||||||
uint32_t window_flags = SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE;
|
uint32_t window_flags = SDL_WINDOW_HIDDEN
|
||||||
#ifdef HIDPI_SUPPORT
|
| SDL_WINDOW_RESIZABLE
|
||||||
window_flags |= SDL_WINDOW_ALLOW_HIGHDPI;
|
| SDL_WINDOW_ALLOW_HIGHDPI;
|
||||||
#endif
|
|
||||||
if (always_on_top) {
|
if (always_on_top) {
|
||||||
#ifdef SCRCPY_SDL_HAS_WINDOW_ALWAYS_ON_TOP
|
#ifdef SCRCPY_SDL_HAS_WINDOW_ALWAYS_ON_TOP
|
||||||
window_flags |= SDL_WINDOW_ALWAYS_ON_TOP;
|
window_flags |= SDL_WINDOW_ALWAYS_ON_TOP;
|
||||||
@ -162,21 +203,6 @@ screen_init_rendering(struct screen *screen, const char *window_title,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
screen->renderer = SDL_CreateRenderer(screen->window, -1,
|
|
||||||
SDL_RENDERER_ACCELERATED);
|
|
||||||
if (!screen->renderer) {
|
|
||||||
LOGC("Could not create renderer: %s", SDL_GetError());
|
|
||||||
screen_destroy(screen);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SDL_RenderSetLogicalSize(screen->renderer, frame_size.width,
|
|
||||||
frame_size.height)) {
|
|
||||||
LOGE("Could not set renderer logical size: %s", SDL_GetError());
|
|
||||||
screen_destroy(screen);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Surface *icon = read_xpm(icon_xpm);
|
SDL_Surface *icon = read_xpm(icon_xpm);
|
||||||
if (icon) {
|
if (icon) {
|
||||||
SDL_SetWindowIcon(screen->window, icon);
|
SDL_SetWindowIcon(screen->window, icon);
|
||||||
@ -187,9 +213,7 @@ screen_init_rendering(struct screen *screen, const char *window_title,
|
|||||||
|
|
||||||
LOGI("Initial texture: %" PRIu16 "x%" PRIu16, frame_size.width,
|
LOGI("Initial texture: %" PRIu16 "x%" PRIu16, frame_size.width,
|
||||||
frame_size.height);
|
frame_size.height);
|
||||||
screen->texture = create_texture(screen->renderer, frame_size);
|
if (!screen_init_renderer_and_texture(screen)) {
|
||||||
if (!screen->texture) {
|
|
||||||
LOGC("Could not create texture: %s", SDL_GetError());
|
|
||||||
screen_destroy(screen);
|
screen_destroy(screen);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -278,6 +302,43 @@ 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>
|
||||||
|
static inline bool
|
||||||
|
screen_fix_hidpi(struct screen *screen) {
|
||||||
|
struct screen_sizes cur;
|
||||||
|
screen_get_sizes(screen, &cur);
|
||||||
|
|
||||||
|
struct screen_sizes *prev = &screen->sizes;
|
||||||
|
|
||||||
|
bool width_ratio_changed = cur.window.width * prev->drawable.width !=
|
||||||
|
cur.drawable.width * prev->window.width;
|
||||||
|
bool height_ratio_changed = cur.window.height * prev->drawable.height !=
|
||||||
|
cur.drawable.height * prev->window.height;
|
||||||
|
if (width_ratio_changed || height_ratio_changed) {
|
||||||
|
SDL_DestroyTexture(screen->texture);
|
||||||
|
SDL_DestroyRenderer(screen->renderer);
|
||||||
|
if (!screen_init_renderer_and_texture(screen)) {
|
||||||
|
screen->texture = NULL;
|
||||||
|
screen->renderer = NULL;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGI("Renderer reset after hidpi scaling changed");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void
|
||||||
|
screen_window_resized(struct screen *screen) {
|
||||||
|
#ifdef HIDPI_WORKAROUND
|
||||||
|
screen_fix_hidpi(screen);
|
||||||
|
#endif
|
||||||
|
screen_render(screen);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
screen_render(struct screen *screen) {
|
screen_render(struct screen *screen) {
|
||||||
SDL_RenderClear(screen->renderer);
|
SDL_RenderClear(screen->renderer);
|
||||||
|
@ -20,6 +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 size window;
|
||||||
|
struct size drawable;
|
||||||
|
} sizes;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SCREEN_INITIALIZER { \
|
#define SCREEN_INITIALIZER { \
|
||||||
@ -60,6 +66,10 @@ screen_destroy(struct screen *screen);
|
|||||||
bool
|
bool
|
||||||
screen_update_frame(struct screen *screen, struct video_buffer *vb);
|
screen_update_frame(struct screen *screen, struct video_buffer *vb);
|
||||||
|
|
||||||
|
// update content after window resizing
|
||||||
|
void
|
||||||
|
screen_window_resized(struct screen *screen);
|
||||||
|
|
||||||
// render the texture to the renderer
|
// render the texture to the renderer
|
||||||
void
|
void
|
||||||
screen_render(struct screen *screen);
|
screen_render(struct screen *screen);
|
||||||
|
@ -4,5 +4,5 @@ option('crossbuild_windows', type: 'boolean', value: false, description: 'Build
|
|||||||
option('windows_noconsole', type: 'boolean', value: false, description: 'Disable console on Windows (pass -mwindows flag)')
|
option('windows_noconsole', type: 'boolean', value: false, description: 'Disable console on Windows (pass -mwindows flag)')
|
||||||
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('hidpi_support', type: 'boolean', value: true, description: 'Enable High DPI support')
|
|
||||||
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')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user