mirror of
https://github.com/Genymobile/scrcpy
synced 2025-08-31 14:25:56 +00:00
Stabilize auto-resize
The window dimensions are integers, so resizing to fit the content may not be exact. When computing the optimal size, it could cause to reduce alternatively the width and height by few pixels, making the "optimal size" unstable. To avoid this problem, check if the optimal size is already correct either by keeping the width or the height.
This commit is contained in:
@@ -113,6 +113,13 @@ get_optimal_size(struct size current_size, struct size content_size) {
|
||||
h = MIN(current_size.height, display_size.height);
|
||||
}
|
||||
|
||||
if (h == w * content_size.height / content_size.width
|
||||
|| w == h * content_size.width / content_size.height) {
|
||||
// The size is already optimal, if we ignore rounding errors due to
|
||||
// integer window dimensions
|
||||
return (struct size) {w, h};
|
||||
}
|
||||
|
||||
bool keep_width = content_size.width * h > content_size.height * w;
|
||||
if (keep_width) {
|
||||
// remove black borders on top and bottom
|
||||
|
Reference in New Issue
Block a user