Skip to content

Display and control your Android device

Add hacky workaround to fix Meta Quest flickering

Romain Vimontd3ffab9d7489
diff --git a/server/src/main/java/com/genymobile/scrcpy/video/ScreenCapture.java b/server/src/main/java/com/genymobile/scrcpy/video/ScreenCapture.java
index 2278beec..afe93457 100644
--- a/server/src/main/java/com/genymobile/scrcpy/video/ScreenCapture.java
+++ b/server/src/main/java/com/genymobile/scrcpy/video/ScreenCapture.java
@@ -133,17 +133,26 @@ public class ScreenCapture extends SurfaceCapture {
.createVirtualDisplay("scrcpy", inputSize.getWidth(), inputSize.getHeight(), displayId, surface);
Ln.d("Display: using DisplayManager API");
} catch (Exception displayManagerException) {
- try {
- display = createDisplay();
-
- Size deviceSize = displayInfo.getSize();
- int layerStack = displayInfo.getLayerStack();
- setDisplaySurface(display, surface, deviceSize.toRect(), inputSize.toRect(), layerStack);
- Ln.d("Display: using SurfaceControl API");
- } catch (Exception surfaceControlException) {
- Ln.e("Could not create display using DisplayManager", displayManagerException);
- Ln.e("Could not create display using SurfaceControl", surfaceControlException);
- throw new AssertionError("Could not create display");
+ if (Build.BRAND.equalsIgnoreCase("oculus") && Build.MODEL.toLowerCase().startsWith("quest")) {
+ // Workaround for buggy createVirtualDisplay on Quest
+ try {
+ virtualDisplay = (VirtualDisplay) VirtualDisplay.class.getDeclaredConstructors()[0].newInstance(null, null, null, surface);
+ } catch (ReflectiveOperationException e) {
+ Ln.e("Could not create VirtualDisplay", e);
+ }
+ } else {
+ try {
+ display = createDisplay();
+
+ Size deviceSize = displayInfo.getSize();
+ int layerStack = displayInfo.getLayerStack();
+ setDisplaySurface(display, surface, deviceSize.toRect(), inputSize.toRect(), layerStack);
+ Ln.d("Display: using SurfaceControl API");
+ } catch (Exception surfaceControlException) {
+ Ln.e("Could not create display using DisplayManager", displayManagerException);
+ Ln.e("Could not create display using SurfaceControl", surfaceControlException);
+ throw new AssertionError("Could not create display");
+ }
}
}