mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 13:26:02 +00:00
feat(display): black frame insertion on 100 Hz and faster screens (#2653)
* feat(display): black frame insertion on 100 Hz and faster screens * feat(display): black frame insertion lives in Screen effects * test(compositor): cover black frame insertion in the render-on-commit harness * fix(display): keep HDR and pacing intact around black frame insertion * fix(display): gate black frame insertion on the panel's refresh, not the tick rate BFI checked the 100 Hz minimum against g_refresh_ns, an average of the time between handled vsync ticks. BFI presents on every tick, so under load the ticks run late, the average fell to 95-100 Hz on a 120 Hz panel, and BFI switched off and on again many times a second (3793 times in one session on a Retroid Pocket Duo). That showed as uneven flicker. Use the display mode's refresh (g_output_refresh_mhz) instead, which only changes when the mode does. * fix(display): offer black frame insertion for the bottom screen and while it is on * fix(display): capture a picture, not a black refresh, while black frame insertion strobes * fix(display): hold black frame insertion off until the last capture ends * fix(display): keep the game composed while a capture holds black frame insertion * test(display): a picture hold presents only pictures while black frame insertion runs
This commit is contained in:
1 parent
f65e7a3d43
commit
758e7983fa
46 files changed
+343
-29
No files matched your search
@@ -500,6 +500,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
private var drawerGameProfileId by mutableStateOf<Long?>(null)
|
||||
private var drawerGameProfileSelectionMade = false
|
||||
private var fpsLimit by mutableStateOf(SessionState.fpsLimit)
|
||||
private var blackFrameInsertion by mutableStateOf(false)
|
||||
|
||||
private fun noSteamSession(): Boolean = (SessionState.mode == SessionService.MODE_RUN &&
|
||||
SessionState.program in setOf(
|
||||
@@ -1588,6 +1589,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
fpsLimit = fps
|
||||
applyOutputPacing()
|
||||
},
|
||||
blackFrameInsertion = blackFrameInsertion,
|
||||
blackFrameInsertionAvailable = blackFrameInsertion || blackFrameInsertionAvailable(),
|
||||
onBlackFrameInsertion = { on ->
|
||||
SessionPrefs.setBlackFrameInsertion(this@SessionActivity, on)
|
||||
blackFrameInsertion = on
|
||||
CompositorHost.setBlackFrameInsertion(on, refreshHz(), outputFpsLimit())
|
||||
},
|
||||
onFrameGenPick = { mode ->
|
||||
val appId = frameGenTargetGameId()
|
||||
|
||||
@@ -2402,6 +2410,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
picturePosition = SessionPrefs.picturePosition(this)
|
||||
integerScaling = SessionPrefs.integerScaling(this)
|
||||
hudOn = SessionPrefs.hudEnabled(this)
|
||||
blackFrameInsertion = SessionPrefs.blackFrameInsertion(this)
|
||||
hudConfig = DroidDeckHudConfig.load(this)
|
||||
hudColor = SessionPrefs.hudColor(this)
|
||||
hudOpacity = SessionPrefs.hudOpacity(this)
|
||||
@@ -2871,6 +2880,17 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
return if (capped > 1f) capped else 60f
|
||||
}
|
||||
|
||||
private fun blackFrameInsertionAvailable(): Boolean {
|
||||
// Glasses that present the game run at their own rate, uncapped, as refreshHz() reads them.
|
||||
glassesScreen?.display?.let { glasses ->
|
||||
return (glasses.supportedModes?.maxOfOrNull { it.refreshRate } ?: 0f) >= PerfMode.BFI_MIN_REFRESH_HZ
|
||||
}
|
||||
val display = bottomGame?.takeIf { bottomOutputActive }?.display
|
||||
?: if (Build.VERSION.SDK_INT >= 30) display else @Suppress("DEPRECATION") windowManager.defaultDisplay
|
||||
val peak = display?.supportedModes?.maxOfOrNull { it.refreshRate } ?: 0f
|
||||
return minOf(peak, PerfMode.peakRefreshCap(this)) >= PerfMode.BFI_MIN_REFRESH_HZ
|
||||
}
|
||||
|
||||
private fun mirrorRefreshLimit(): Int =
|
||||
GlassesRendering.mirrorRefreshLimit(glassesSettings, glasses, glassesScreen != null)
|
||||
|
||||
@@ -4194,19 +4214,35 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
onFrame(null)
|
||||
return
|
||||
}
|
||||
try {
|
||||
android.view.PixelCopy.request(source, bitmap, { result ->
|
||||
if (result != android.view.PixelCopy.SUCCESS) {
|
||||
bitmap.recycle()
|
||||
onFrame(null)
|
||||
} else onFrame(bitmap)
|
||||
}, uiHandler)
|
||||
} catch (_: IllegalArgumentException) {
|
||||
bitmap.recycle()
|
||||
onFrame(null)
|
||||
withPictureFrame { done ->
|
||||
try {
|
||||
android.view.PixelCopy.request(source, bitmap, { result ->
|
||||
done()
|
||||
if (result != android.view.PixelCopy.SUCCESS) {
|
||||
bitmap.recycle()
|
||||
onFrame(null)
|
||||
} else onFrame(bitmap)
|
||||
}, uiHandler)
|
||||
} catch (_: IllegalArgumentException) {
|
||||
done()
|
||||
bitmap.recycle()
|
||||
onFrame(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** PixelCopy reads the last queued buffer, which black frame insertion makes black every other refresh. */
|
||||
private fun withPictureFrame(copy: (done: () -> Unit) -> Unit) {
|
||||
if (!CompositorHost.holdPicture()) return copy {}
|
||||
uiHandler.postDelayed({
|
||||
var released = false
|
||||
copy {
|
||||
if (!released) CompositorHost.releasePicture()
|
||||
released = true
|
||||
}
|
||||
}, BFI_PICTURE_SETTLE_MS)
|
||||
}
|
||||
|
||||
private fun tapSteamButton() {
|
||||
if (SessionState.mode == SessionService.MODE_STEAM) padBridge?.triggerSteamMenu()
|
||||
}
|
||||
@@ -5311,17 +5347,21 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
val left = surfaceAt[0] - overlayAt[0]
|
||||
val top = surfaceAt[1] - overlayAt[1]
|
||||
val bounds = android.graphics.Rect(left, top, left + width, top + height)
|
||||
try {
|
||||
android.view.PixelCopy.request(surfaceView, bitmap, { result ->
|
||||
if (result == android.view.PixelCopy.SUCCESS && !isDestroyed) {
|
||||
pausedFrame = com.droiddeck.launcher.ui.PausedFrame(bitmap.asImageBitmap(), bounds)
|
||||
pausedFrameWanted = false
|
||||
} else {
|
||||
bitmap.recycle()
|
||||
}
|
||||
}, uiHandler)
|
||||
} catch (_: IllegalArgumentException) {
|
||||
bitmap.recycle()
|
||||
withPictureFrame { done ->
|
||||
try {
|
||||
android.view.PixelCopy.request(surfaceView, bitmap, { result ->
|
||||
done()
|
||||
if (result == android.view.PixelCopy.SUCCESS && !isDestroyed) {
|
||||
pausedFrame = com.droiddeck.launcher.ui.PausedFrame(bitmap.asImageBitmap(), bounds)
|
||||
pausedFrameWanted = false
|
||||
} else {
|
||||
bitmap.recycle()
|
||||
}
|
||||
}, uiHandler)
|
||||
} catch (_: IllegalArgumentException) {
|
||||
done()
|
||||
bitmap.recycle()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6323,6 +6363,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
private const val LEAVE_TIMEOUT_MS = 1_500L
|
||||
private const val TEXT_FIELD_TAP_MS = 1_000L
|
||||
private const val PAUSED_FRAME_MAX_EDGE = 1920f
|
||||
private const val BFI_PICTURE_SETTLE_MS = 50L
|
||||
private const val PAUSED_FRAME_REDRAW_MS = 150L
|
||||
private const val BOTTOM_RECOVERY_MS = 1_000L
|
||||
private const val BOTTOM_RECOVERY_TRIES = 3
|
||||
|
||||
Reference in new issue
Block a user