Make PositionMapper use affine transforms
This will allow to apply transformations performed by video filters.
This commit is contained in:
parent
18be0b5e28
commit
4ed958def8
@ -3,15 +3,16 @@ package com.genymobile.scrcpy.control;
|
||||
import com.genymobile.scrcpy.device.Point;
|
||||
import com.genymobile.scrcpy.device.Position;
|
||||
import com.genymobile.scrcpy.device.Size;
|
||||
import com.genymobile.scrcpy.util.AffineMatrix;
|
||||
|
||||
public final class PositionMapper {
|
||||
|
||||
private final Size sourceSize;
|
||||
private final Size videoSize;
|
||||
private final AffineMatrix videoToDeviceMatrix;
|
||||
|
||||
public PositionMapper(Size sourceSize, Size videoSize) {
|
||||
this.sourceSize = sourceSize;
|
||||
public PositionMapper(Size videoSize, AffineMatrix videoToDeviceMatrix) {
|
||||
this.videoSize = videoSize;
|
||||
this.videoToDeviceMatrix = videoToDeviceMatrix;
|
||||
}
|
||||
|
||||
public Point map(Position position) {
|
||||
@ -23,8 +24,9 @@ public final class PositionMapper {
|
||||
}
|
||||
|
||||
Point point = position.getPoint();
|
||||
int convertedX = point.getX() * sourceSize.getWidth() / videoSize.getWidth();
|
||||
int convertedY = point.getY() * sourceSize.getHeight() / videoSize.getHeight();
|
||||
return new Point(convertedX, convertedY);
|
||||
if (videoToDeviceMatrix != null) {
|
||||
point = videoToDeviceMatrix.apply(point);
|
||||
}
|
||||
return point;
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ public class NewDisplayCapture extends SurfaceCapture {
|
||||
}
|
||||
|
||||
if (vdListener != null) {
|
||||
PositionMapper positionMapper = new PositionMapper(size, size);
|
||||
PositionMapper positionMapper = new PositionMapper(size, null);
|
||||
vdListener.onNewVirtualDisplay(virtualDisplayId, positionMapper);
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import com.genymobile.scrcpy.device.ConfigurationException;
|
||||
import com.genymobile.scrcpy.device.Device;
|
||||
import com.genymobile.scrcpy.device.DisplayInfo;
|
||||
import com.genymobile.scrcpy.device.Size;
|
||||
import com.genymobile.scrcpy.util.AffineMatrix;
|
||||
import com.genymobile.scrcpy.util.Ln;
|
||||
import com.genymobile.scrcpy.util.LogUtils;
|
||||
import com.genymobile.scrcpy.wrappers.DisplayManager;
|
||||
@ -145,7 +146,7 @@ public class ScreenCapture extends SurfaceCapture {
|
||||
.createVirtualDisplay("scrcpy", videoSize.getWidth(), videoSize.getHeight(), displayId, surface);
|
||||
virtualDisplayId = virtualDisplay.getDisplay().getDisplayId();
|
||||
// The position are relative to the virtual display, not the original display
|
||||
positionMapper = new PositionMapper(videoSize, videoSize);
|
||||
positionMapper = new PositionMapper(videoSize, null);
|
||||
Ln.d("Display: using DisplayManager API");
|
||||
} catch (Exception displayManagerException) {
|
||||
try {
|
||||
@ -156,7 +157,9 @@ public class ScreenCapture extends SurfaceCapture {
|
||||
|
||||
setDisplaySurface(display, surface, deviceSize.toRect(), videoSize.toRect(), layerStack);
|
||||
virtualDisplayId = displayId;
|
||||
positionMapper = new PositionMapper(deviceSize, videoSize);
|
||||
|
||||
AffineMatrix videoToDeviceMatrix = videoSize.equals(deviceSize) ? null : AffineMatrix.scale(videoSize, deviceSize);
|
||||
positionMapper = new PositionMapper(videoSize, videoToDeviceMatrix);
|
||||
Ln.d("Display: using SurfaceControl API");
|
||||
} catch (Exception surfaceControlException) {
|
||||
Ln.e("Could not create display using DisplayManager", displayManagerException);
|
||||
|
Loading…
x
Reference in New Issue
Block a user