Skip to content

Commit 18c64af

Browse files
committed
Refactor virtual display properties initialization
Following the changes from the previous commit, the behavior is now identical when mirroring the main display or using the SurfaceControl API. Factorize the code to perform the initialization in a single location. Refs #5605 <#5605>
1 parent 2d4a6c6 commit 18c64af

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

server/src/main/java/com/genymobile/scrcpy/video/ScreenCapture.java

+12-18
Original file line numberDiff line numberDiff line change
@@ -124,35 +124,17 @@ public void start(Surface surface) throws IOException {
124124
inputSize = videoSize;
125125
}
126126

127-
int virtualDisplayId;
128-
PositionMapper positionMapper;
129127
try {
130128
virtualDisplay = ServiceManager.getDisplayManager()
131129
.createVirtualDisplay("scrcpy", inputSize.getWidth(), inputSize.getHeight(), displayId, surface);
132-
133-
134-
if (displayId == 0) {
135-
// Main display: send all events to the original display, relative to the device size
136-
Size deviceSize = displayInfo.getSize();
137-
positionMapper = PositionMapper.create(videoSize, transform, deviceSize);
138-
virtualDisplayId = 0;
139-
} else {
140-
// The positions are relative to the virtual display, not the original display (so use inputSize, not deviceSize!)
141-
positionMapper = PositionMapper.create(videoSize, transform, inputSize);
142-
virtualDisplayId = virtualDisplay.getDisplay().getDisplayId();
143-
}
144130
Ln.d("Display: using DisplayManager API");
145131
} catch (Exception displayManagerException) {
146132
try {
147133
display = createDisplay();
148134

149135
Size deviceSize = displayInfo.getSize();
150136
int layerStack = displayInfo.getLayerStack();
151-
152137
setDisplaySurface(display, surface, deviceSize.toRect(), inputSize.toRect(), layerStack);
153-
virtualDisplayId = displayId;
154-
155-
positionMapper = PositionMapper.create(videoSize, transform, deviceSize);
156138
Ln.d("Display: using SurfaceControl API");
157139
} catch (Exception surfaceControlException) {
158140
Ln.e("Could not create display using DisplayManager", displayManagerException);
@@ -162,6 +144,18 @@ public void start(Surface surface) throws IOException {
162144
}
163145

164146
if (vdListener != null) {
147+
int virtualDisplayId;
148+
PositionMapper positionMapper;
149+
if (virtualDisplay == null || displayId == 0) {
150+
// Surface control or main display: send all events to the original display, relative to the device size
151+
Size deviceSize = displayInfo.getSize();
152+
positionMapper = PositionMapper.create(videoSize, transform, deviceSize);
153+
virtualDisplayId = displayId;
154+
} else {
155+
// The positions are relative to the virtual display, not the original display (so use inputSize, not deviceSize!)
156+
positionMapper = PositionMapper.create(videoSize, transform, inputSize);
157+
virtualDisplayId = virtualDisplay.getDisplay().getDisplayId();
158+
}
165159
vdListener.onNewVirtualDisplay(virtualDisplayId, positionMapper);
166160
}
167161
}

0 commit comments

Comments
 (0)