mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
fix: stop switching between display modes with the same refresh rate (S26 lag and heat since 0.6.7) (#2192)
fix: stop switching between display modes with the same refresh rate
This commit is contained in:
1 parent
542bbf89c3
commit
250f80fbb5
2 files changed
+28
-1
No files matched your search
@@ -21,7 +21,7 @@ object PerfMode {
|
||||
val cur = display.mode
|
||||
val cap = minOf(peakRefreshCap(a), refreshLimit.takeIf { it > 0 }?.toFloat() ?: Float.POSITIVE_INFINITY)
|
||||
val best = selectMode(display.supportedModes, cur, fpsLimit, cap)
|
||||
if (best != null && a.window.attributes.preferredDisplayModeId != best.modeId) {
|
||||
if (best != null && needsChange(display.supportedModes, a.window.attributes.preferredDisplayModeId, best)) {
|
||||
a.window.attributes = a.window.attributes.apply { preferredDisplayModeId = best.modeId }
|
||||
"display ${cur.refreshRate.toInt()} → ${best.refreshRate.toInt()} Hz (mode ${best.modeId})"
|
||||
} else "display ${cur.refreshRate.toInt()} Hz"
|
||||
@@ -64,6 +64,11 @@ object PerfMode {
|
||||
?: sameSize.minByOrNull { it.refreshRate }
|
||||
}
|
||||
|
||||
internal fun needsChange(modes: Array<Display.Mode>, preferredId: Int, best: Display.Mode): Boolean {
|
||||
val preferred = modes.firstOrNull { preferredId != 0 && it.modeId == preferredId } ?: return true
|
||||
return Math.abs(preferred.refreshRate - best.refreshRate) > 0.5f
|
||||
}
|
||||
|
||||
fun cadenceFits(hz: Float, fpsLimit: Int): Boolean {
|
||||
if (fpsLimit <= 0) return true
|
||||
val ratio = hz / fpsLimit
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.droiddeck.launcher.session
|
||||
|
||||
import android.view.Display
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
@@ -34,4 +36,24 @@ class PerfModeTest {
|
||||
val otherResolution = mode(3, 60f, 720)
|
||||
assertEquals(low, PerfMode.selectMode(arrayOf(low, high, otherResolution), high, 60, 60f))
|
||||
}
|
||||
|
||||
@Test fun anotherModeWithTheRequestedRefreshRateKeepsTheRequestInsteadOfSwitchingBackAndForth() {
|
||||
val sixty = mode(2, 60f)
|
||||
val requested = mode(1, 120f)
|
||||
val reported = mode(255, 120f, 1440)
|
||||
val modes = arrayOf(sixty, requested, reported)
|
||||
assertEquals(reported, PerfMode.selectMode(modes, reported, 0, Float.POSITIVE_INFINITY))
|
||||
assertFalse(PerfMode.needsChange(modes, requested.modeId, reported))
|
||||
assertFalse(PerfMode.needsChange(modes, reported.modeId, requested))
|
||||
}
|
||||
|
||||
@Test fun aDifferentRefreshRateNoRequestOrAMissingModeStillChangesTheMode() {
|
||||
val sixty = mode(2, 60f)
|
||||
val oneTwenty = mode(1, 120f)
|
||||
val modes = arrayOf(sixty, oneTwenty)
|
||||
assertTrue(PerfMode.needsChange(modes, sixty.modeId, oneTwenty))
|
||||
assertTrue(PerfMode.needsChange(modes, oneTwenty.modeId, sixty))
|
||||
assertTrue(PerfMode.needsChange(modes, 0, oneTwenty))
|
||||
assertTrue(PerfMode.needsChange(modes, 99, oneTwenty))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user