Align the virtual display size

When the virtual display size is not aligned, a resize filter may be
inserted to compensate for small dimension mismatches, increasing
processing and resulting in a blurry image.

PR #6771 <https://github.com/Genymobile/scrcpy/pull/6771>
This commit is contained in:
Romain Vimont 2026-04-16 19:16:30 +02:00
parent 965d0e6856
commit 266e2eaf14
2 changed files with 16 additions and 1 deletions

View file

@ -84,6 +84,15 @@ public final class Size {
return new Size(w, h);
}
public Size align(int alignment) {
int w = width / alignment * alignment;
int h = height / alignment * alignment;
if (w == width && h == height) {
return this;
}
return new Size(w, h);
}
private static int round(int value, int alignment) {
return (value + (alignment / 2)) / alignment * alignment;
}

View file

@ -108,6 +108,10 @@ public class NewDisplayCapture extends SurfaceCapture {
if (!newDisplay.hasExplicitSize()) {
displaySize = mainDisplaySize;
}
// Align the physical display size to avoid unnecessary mismatches with the output size
displaySize = displaySize.align(getVideoConstraints().getAlignment());
if (!newDisplay.hasExplicitDpi()) {
dpi = scaleDpi(mainDisplaySize, mainDisplayDpi, displaySize);
}
@ -117,9 +121,11 @@ public class NewDisplayCapture extends SurfaceCapture {
displayMonitor.setSessionDisplayProperties(new DisplayProperties(displaySize, displayRotation));
} else {
DisplayInfo displayInfo = ServiceManager.getDisplayManager().getDisplayInfo(virtualDisplay.getDisplay().getDisplayId());
displaySize = displayInfo.getSize();
dpi = displayInfo.getDpi();
displayRotation = displayInfo.getRotation();
// Align the physical display size to avoid unnecessary mismatches with the output size
displaySize = displayInfo.getSize().align(getVideoConstraints().getAlignment());
}
VideoFilter filter = new VideoFilter(displaySize);