mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-04-20 03:25:03 +00:00
Turn scale factor into float for better precision
This commit is contained in:
parent
8313e60ee2
commit
a5e690d2a0
2 changed files with 9 additions and 9 deletions
|
@ -65,23 +65,23 @@ static void set_window_size(struct screen *screen, struct size new_size) {
|
|||
}
|
||||
}
|
||||
|
||||
void get_window_scale(SDL_Window *window, int *scale_x, int *scale_y) {
|
||||
void get_window_scale(SDL_Window *window, float *scale_x, float *scale_y) {
|
||||
int win_w, win_h;
|
||||
SDL_GetWindowSize(window, &win_w, &win_h);
|
||||
int output_w, output_h;
|
||||
SDL_GL_GetDrawableSize(window, &output_w, &output_h);
|
||||
*scale_x = output_w / win_w;
|
||||
*scale_y = output_h / win_h;
|
||||
*scale_x = (float)output_w / win_w;
|
||||
*scale_y = (float)output_h / win_h;
|
||||
}
|
||||
|
||||
SDL_bool screen_update_logical_size_if_needed(struct screen *screen) {
|
||||
int scale_x, scale_y;
|
||||
float scale_x, scale_y;
|
||||
get_window_scale(screen->window, &scale_x, &scale_y);
|
||||
if (scale_x != screen->scale_x || scale_y != screen->scale_y) {
|
||||
int logical_width, logical_height;
|
||||
SDL_RenderGetLogicalSize(screen->renderer, &logical_width, &logical_height);
|
||||
logical_width *= (float)scale_x / screen->scale_x;
|
||||
logical_height *= (float)scale_y / screen->scale_y;
|
||||
logical_width *= scale_x / screen->scale_x;
|
||||
logical_height *= scale_y / screen->scale_y;
|
||||
screen->scale_x = scale_x;
|
||||
screen->scale_y = scale_y;
|
||||
if (SDL_RenderSetLogicalSize(screen->renderer, logical_width, logical_height)) {
|
||||
|
|
|
@ -12,8 +12,8 @@ struct screen {
|
|||
SDL_Renderer *renderer;
|
||||
SDL_Texture *texture;
|
||||
struct size frame_size;
|
||||
int scale_x;
|
||||
int scale_y;
|
||||
float scale_x;
|
||||
float scale_y;
|
||||
//used only in fullscreen mode to know the windowed window size
|
||||
struct size windowed_window_size;
|
||||
SDL_bool has_frame;
|
||||
|
@ -68,7 +68,7 @@ void screen_resize_to_fit(struct screen *screen);
|
|||
// resize window to 1:1 (pixel-perfect)
|
||||
void screen_resize_to_pixel_perfect(struct screen *screen);
|
||||
|
||||
void get_window_scale(SDL_Window *window, int *scale_x, int *scale_y);
|
||||
void get_window_scale(SDL_Window *window, float *scale_x, float *scale_y);
|
||||
|
||||
SDL_bool screen_update_logical_size_if_needed(struct screen *screen);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue