mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
fix(display): the frame limit lifts after picture-in-picture instead of holding the session at 30 fps (#3708)
Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
1 parent
eaa64597e0
commit
b37bc316bb
4 files changed
+34
-10
No files matched your search
@@ -1923,7 +1923,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
onBlackFrameInsertion = { on ->
|
||||
SessionPrefs.setBlackFrameInsertion(this@SessionActivity, on)
|
||||
blackFrameInsertion = on
|
||||
CompositorHost.setBlackFrameInsertion(on, refreshHz(), compositorFpsLimit())
|
||||
CompositorHost.setBlackFrameInsertion(on, refreshHz(), compositorFpsLimit(), outputFpsLimit())
|
||||
},
|
||||
hdr = hdrWanted,
|
||||
hdrAvailable = hdrAvailable,
|
||||
@@ -3194,7 +3194,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
CompositorHost.startOrAttach(
|
||||
this, holder.surface, runtimeDir.path,
|
||||
driverId?.let { turnip.driverPath(it) }, driverId?.let { turnip.libraryName(it) },
|
||||
applicationInfo.nativeLibraryDir, size.first, size.second, refreshHz(holder), compositorFpsLimit(),
|
||||
applicationInfo.nativeLibraryDir, size.first, size.second, refreshHz(holder), compositorFpsLimit(), outputFpsLimit(),
|
||||
)
|
||||
onOutputAttached(holder)
|
||||
if (SessionState.running && size != previous) {
|
||||
@@ -3469,7 +3469,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
)
|
||||
val hz = refreshHz()
|
||||
val changed = kotlin.math.abs(SessionState.refreshHz - hz) > 0.1f
|
||||
CompositorHost.updatePacing(hz, compositorFpsLimit())
|
||||
CompositorHost.updatePacing(hz, compositorFpsLimit(), outputFpsLimit())
|
||||
pushCardboard(activeCardboard)
|
||||
if (changed && ::surfaceView.isInitialized) applyFrameGen()
|
||||
}
|
||||
|
||||
@@ -1912,6 +1912,9 @@ object SessionPrefs {
|
||||
return if (pip && mirrorRefreshLimit <= 0 && (limit <= 0 || limit > PIP_FPS)) PIP_FPS else limit
|
||||
}
|
||||
|
||||
fun layerFrameRate(ownLimit: Int, refreshHz: Float, blackFrameInsertion: Boolean): Float =
|
||||
if (ownLimit > 0 && !blackFrameInsertion) ownLimit.toFloat() else refreshHz
|
||||
|
||||
/** The per-app rate Android holds this window to (Game Mode's FPS override), or 0 when the panel's rate applies. */
|
||||
fun hostFrameCap(overrideHz: Float, panelHz: Float): Int =
|
||||
if (overrideHz > 1f && panelHz - overrideHz > 1f) Math.round(overrideHz) else 0
|
||||
|
||||
@@ -67,13 +67,14 @@ object CompositorHost {
|
||||
outputHeight: Int,
|
||||
refreshHz: Float,
|
||||
fpsLimit: Int,
|
||||
layerFpsLimit: Int = fpsLimit,
|
||||
): Boolean {
|
||||
WaylandCompositor.nativeSetClockControl(java.io.File(context.filesDir, "${com.droiddeck.launcher.runtime.LinuxRuntime.DIR}/tmp/.dd-clock").path)
|
||||
ownVsyncThread = SessionPrefs.vsyncThread(context)
|
||||
WaylandCompositor.nativeSetRenderOnCommit(SessionPrefs.renderOnCommit(context))
|
||||
blackFrameInsertion = SessionPrefs.blackFrameInsertion(context)
|
||||
WaylandCompositor.nativeSetBlackFrameInsertion(blackFrameInsertion)
|
||||
pace(refreshHz, fpsLimit)
|
||||
pace(refreshHz, fpsLimit, layerFpsLimit)
|
||||
if (!SessionState.running) WaylandCompositor.nativeSetOutputSize(outputWidth, outputHeight)
|
||||
if (started) {
|
||||
attached = surface
|
||||
@@ -95,23 +96,23 @@ object CompositorHost {
|
||||
private var blackFrameInsertion = false
|
||||
private var pictureHolds = 0
|
||||
|
||||
private fun pace(refreshHz: Float, fpsLimit: Int) {
|
||||
private fun pace(refreshHz: Float, fpsLimit: Int, layerFpsLimit: Int) {
|
||||
WaylandCompositor.nativeSetFpsLimit(fpsLimit)
|
||||
WaylandCompositor.nativeSetLayerFrameRate(if (fpsLimit > 0 && !blackFrameInsertion) fpsLimit.toFloat() else refreshHz)
|
||||
WaylandCompositor.nativeSetLayerFrameRate(SessionPrefs.layerFrameRate(layerFpsLimit, refreshHz, blackFrameInsertion))
|
||||
WaylandCompositor.nativeSetOutputRefreshRate(refreshHz)
|
||||
SessionState.refreshHz = refreshHz
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun updatePacing(refreshHz: Float, fpsLimit: Int) {
|
||||
if (started) pace(refreshHz, fpsLimit)
|
||||
fun updatePacing(refreshHz: Float, fpsLimit: Int, layerFpsLimit: Int = fpsLimit) {
|
||||
if (started) pace(refreshHz, fpsLimit, layerFpsLimit)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun setBlackFrameInsertion(on: Boolean, refreshHz: Float, fpsLimit: Int) {
|
||||
fun setBlackFrameInsertion(on: Boolean, refreshHz: Float, fpsLimit: Int, layerFpsLimit: Int = fpsLimit) {
|
||||
blackFrameInsertion = on
|
||||
WaylandCompositor.nativeSetBlackFrameInsertion(on)
|
||||
if (started) pace(refreshHz, fpsLimit)
|
||||
if (started) pace(refreshHz, fpsLimit, layerFpsLimit)
|
||||
}
|
||||
|
||||
/** Presents only pictures until the matching release; false when nothing is strobing. */
|
||||
|
||||
@@ -42,4 +42,24 @@ class OutputPacingTest {
|
||||
assertEquals(45, SessionPrefs.compositorFpsLimit(0, 45, hostCap = 60))
|
||||
assertEquals(SessionPrefs.PIP_FPS, SessionPrefs.compositorFpsLimit(0, 0, pip = true, hostCap = 60))
|
||||
}
|
||||
|
||||
@Test fun afterPictureInPictureTheLayerStopsVotingThirtyWhileItsOwnOverrideIsStillReported() {
|
||||
val staleOverride = SessionPrefs.hostFrameCap(30f, 120f)
|
||||
assertEquals(SessionPrefs.PIP_FPS, staleOverride)
|
||||
val own = SessionPrefs.compositorFpsLimit(0, 0, pip = false)
|
||||
assertEquals(120f, SessionPrefs.layerFrameRate(own, 120f, false), 0f)
|
||||
assertEquals(staleOverride, SessionPrefs.compositorFpsLimit(0, 0, pip = false, hostCap = staleOverride))
|
||||
assertEquals(SessionPrefs.FPS_UNPACED, SessionPrefs.compositorFpsLimit(0, 0, pip = false, hostCap = SessionPrefs.hostFrameCap(120f, 120f)))
|
||||
}
|
||||
|
||||
@Test fun theLayerVotesOnlyTheSessionsOwnLimits() {
|
||||
assertEquals(SessionPrefs.PIP_FPS.toFloat(), SessionPrefs.layerFrameRate(SessionPrefs.compositorFpsLimit(0, pip = true), 120f, false), 0f)
|
||||
assertEquals(45f, SessionPrefs.layerFrameRate(SessionPrefs.compositorFpsLimit(0, 45), 120f, false), 0f)
|
||||
assertEquals(60f, SessionPrefs.layerFrameRate(SessionPrefs.compositorFpsLimit(60), 120f, false), 0f)
|
||||
assertEquals(120f, SessionPrefs.layerFrameRate(SessionPrefs.FPS_UNPACED, 120f, false), 0f)
|
||||
}
|
||||
|
||||
@Test fun blackFrameInsertionKeepsThePanelRate() {
|
||||
assertEquals(120f, SessionPrefs.layerFrameRate(45, 120f, true), 0f)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user