mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
feat: FusionHUD replaces the session HUD, with MangoHud's readings (#1743)
The session HUD is FusionHUD (Bannerlator's HUD) with every reading taken from the same source, and worked out the same way, as the MangoHud build that runs Steam's performance overlay in a DroidDeck session. - gamescope patch 0125 (gamescope-3.16.29-p19) shares the frame times that mangoapp reads (one per signalled commit of connector 0) in a ring named by DROIDDECK_HUD_FRAMES; the app reads it once per display frame and counts the compositor's frames when gamescope sends none. - MangoHud's rules: FPS over periods of at least 500 ms, frame time = 1000/FPS, 200-frame graph on a fixed 0-50 ms scale; CPU, GPU, temperatures, RAM, swap, VRAM and battery from MangoHud's sources. Zones 22/26/28 are typed as GPU and DDR sensors, so Steam's overlay CPU temperature no longer includes them. - Five sizes in a panel shaped like the DroidDeck mark, with a centred header, one left edge, neon outline and FPS; Minimal is the default size. Settings on a new "Performance HUD" drawer page, with Bannerlator's options. - The HUD reads sensors and polls frames only while it is drawn (not while hidden, in picture-in-picture or behind another app), keeps its place after picture-in-picture, and the diagnostics export has its own reader. Device-tested on the AYANEO Pocket FIT: same readings as Steam's overlay side by side in Dead Cells; the HUD updates in a game, hides in picture-in-picture and comes back in place, no crashes.
This commit is contained in:
1 parent
e871557bf2
commit
110cfc28f8
70 files changed
+7269
-320
No files matched your search
@@ -0,0 +1,138 @@
|
||||
package com.droiddeck.launcher.hud
|
||||
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import kotlin.random.Random
|
||||
|
||||
class FrameStatsTest {
|
||||
/** MangoHud's update_hud_info_with_frametime and fps()/frame_timing(), line by line (overlay.cpp). */
|
||||
private class Mango {
|
||||
val frametimeData = ArrayList<Float>(List(200) { 0f })
|
||||
var lastPresentTime = 0L
|
||||
var lastFpsUpdate = 0L
|
||||
var framesSinceUpdate = 0L
|
||||
var fps = 0.0
|
||||
|
||||
fun update(frametimeNs: Long, now: Long) {
|
||||
val elapsed = now - lastFpsUpdate
|
||||
if (lastPresentTime != 0L) {
|
||||
frametimeData.add(frametimeNs / 1000000f)
|
||||
frametimeData.removeAt(0)
|
||||
}
|
||||
if (elapsed >= 500000000L) {
|
||||
fps = 1000000000.0 * framesSinceUpdate / elapsed
|
||||
framesSinceUpdate = 0
|
||||
lastFpsUpdate = now
|
||||
}
|
||||
lastPresentTime = now
|
||||
framesSinceUpdate++
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun readingsMatchMangoHudFrameByFrame() {
|
||||
val random = Random(7)
|
||||
val stats = FrameStats()
|
||||
val mango = Mango()
|
||||
var now = 5_000_000_000L
|
||||
val graph = FloatArray(FrameStats.GRAPH_FRAMES)
|
||||
repeat(20_000) { i ->
|
||||
val frametime = when {
|
||||
i % 977 == 0 -> 100_000_000L
|
||||
i % 131 == 0 -> 33_000_000L
|
||||
else -> 2_700_000L + random.nextLong(-400_000L, 400_000L)
|
||||
}
|
||||
now += frametime
|
||||
stats.add(frametime, now)
|
||||
mango.update(frametime, now)
|
||||
assertEquals("fps at frame $i", mango.fps.toFloat(), stats.fps, 0.0001f)
|
||||
assertEquals(1000f / maxOf(mango.fps.toFloat(), 1f), stats.frametimeMs(), 0.0001f)
|
||||
if (i % 499 == 0 || i < 210) {
|
||||
stats.graph(graph)
|
||||
assertArrayEquals("graph at frame $i", mango.frametimeData.toFloatArray(), graph, 0f)
|
||||
assertEquals(mango.frametimeData.min(), stats.graphMinMs(), 0f)
|
||||
assertEquals(mango.frametimeData.max(), stats.graphMaxMs(), 0f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun compositorFramesWakeTheHudWhenGamescopeSharesNone() {
|
||||
val feed = GameFrameFeed(java.io.File("/nonexistent/droiddeck-hud/frames"))
|
||||
var now = 1_000_000_000L
|
||||
assertFalse(feed.poll(now))
|
||||
feed.onCompositorFrame(now)
|
||||
now += 16_666_667L
|
||||
feed.onCompositorFrame(now)
|
||||
assertTrue(feed.poll(now))
|
||||
assertFalse(feed.poll(now + 1))
|
||||
}
|
||||
|
||||
@Test fun aCompletedPeriodIsCountedWhenMangoHudWouldRedraw() {
|
||||
val stats = FrameStats()
|
||||
var now = 1_000_000_000L
|
||||
stats.add(10_000_000L, now)
|
||||
assertEquals(1L, stats.fpsUpdates)
|
||||
repeat(49) { now += 10_000_000L; stats.add(10_000_000L, now) }
|
||||
assertEquals(1L, stats.fpsUpdates)
|
||||
now += 10_000_000L; stats.add(10_000_000L, now)
|
||||
assertEquals(2L, stats.fpsUpdates)
|
||||
assertEquals(100f, stats.fps, 0.01f)
|
||||
}
|
||||
|
||||
@Test fun aSteadyRateReadsExactlyWithoutMillisecondRounding() {
|
||||
val stats = FrameStats()
|
||||
var now = 1_000_000_000L
|
||||
val frametime = 16_666_667L
|
||||
repeat(600) { now += frametime; stats.add(frametime, now) }
|
||||
assertEquals(60f, stats.fps, 0.01f)
|
||||
val lows = stats.lows(now)
|
||||
assertEquals(60f, lows.low1Fps, 0.01f)
|
||||
assertEquals(60f, lows.low01Fps, 0.01f)
|
||||
assertEquals(60f, stats.averageFps(), 0.01f)
|
||||
}
|
||||
|
||||
@Test fun stuttersShowInTheGraphAndTheLows() {
|
||||
val stats = FrameStats()
|
||||
var now = 1_000_000_000L
|
||||
repeat(1000) { i ->
|
||||
val frametime = if (i % 100 == 50) 100_000_000L else 2_700_000L
|
||||
now += frametime
|
||||
stats.add(frametime, now)
|
||||
}
|
||||
assertEquals(100f, stats.graphMaxMs(), 0.001f)
|
||||
assertEquals(2.7f, stats.graphMinMs(), 0.001f)
|
||||
assertEquals(10f, stats.lows(now).low01Fps, 0.01f)
|
||||
assertEquals(370.37f, stats.lows(now).low1Fps, 0.01f)
|
||||
}
|
||||
|
||||
@Test fun pausesStayOutOfTheAverageAndLowsButNotTheGraph() {
|
||||
val stats = FrameStats()
|
||||
var now = 1_000_000_000L
|
||||
repeat(300) { now += 10_000_000L; stats.add(10_000_000L, now) }
|
||||
now += 3_000_000_000L
|
||||
stats.add(3_000_000_000L, now)
|
||||
assertEquals(100f, stats.lows(now).low01Fps, 0.01f)
|
||||
assertEquals(3000f, stats.graphMaxMs(), 0.01f)
|
||||
}
|
||||
|
||||
@Test fun resetStartsOver() {
|
||||
val stats = FrameStats()
|
||||
var now = 1_000_000_000L
|
||||
repeat(300) { now += 10_000_000L; stats.add(10_000_000L, now) }
|
||||
stats.reset()
|
||||
assertEquals(0f, stats.fps, 0f)
|
||||
assertEquals(0f, stats.graphMaxMs(), 0f)
|
||||
assertEquals(FrameStats.Lows.EMPTY, stats.lows(now))
|
||||
}
|
||||
|
||||
@Test fun engineNamesFollowMangoHud() {
|
||||
assertEquals("DXVK", GameFrameFeed.engineLabel("DXVK"))
|
||||
assertEquals("VKD3D", GameFrameFeed.engineLabel("vkd3d"))
|
||||
assertEquals("ZINK", GameFrameFeed.engineLabel("mesa zink"))
|
||||
assertEquals("GAMESCOPE", GameFrameFeed.engineLabel("gamescope"))
|
||||
assertEquals("GAMESCOPE", GameFrameFeed.engineLabel(""))
|
||||
assertEquals("VULKAN", GameFrameFeed.engineLabel("UnityEngine"))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.droiddeck.launcher.hud
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.view.View
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.GraphicsMode
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.util.Base64
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.math.sqrt
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33], qualifiers = "xhdpi")
|
||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
class FusionHudPanelTest {
|
||||
@Test fun minimalIsTheSizeTheHudStartsWith() {
|
||||
assertEquals(FusionSize.MINIMAL, FusionSize.from(FusionHudConfig.DEFAULTS["hudSize"]))
|
||||
}
|
||||
|
||||
@Test fun everySizeDrawsTheDPanelWithEverythingInsideIt() {
|
||||
val stats = FrameStats()
|
||||
var now = 1_000_000_000L
|
||||
repeat(2_000) { i ->
|
||||
val frametime = if (i == 1_700) 25_600_000L else 2_850_000L
|
||||
now += frametime
|
||||
stats.add(frametime, now)
|
||||
}
|
||||
val snapshot = HudMetrics.Snapshot(64, 52, 3302, 1050, 89, 79, 10_800_000_000L, 16_000_000_000L, 67f,
|
||||
1_800_000_000L, HudMetrics.Battery(16f, false, 79, 34, null),
|
||||
intArrayOf(91, 91, 48, 50, 48, 19, 17, 73), intArrayOf(2265, 2265, 3148, 3148, 3148, 2956, 2956, 3302),
|
||||
2_700_000_000L, 6_400_000_000L, 31_000L, 9_000L)
|
||||
|
||||
for (size in FusionSize.values()) {
|
||||
val view = FusionHudView(RuntimeEnvironment.getApplication())
|
||||
view.applyConfig(FusionHudConfig.encode(FusionHudConfig.DEFAULTS + ("hudSize" to size.token)))
|
||||
view.setFrameStats(stats)
|
||||
view.showForTest(snapshot, "DXVK", now)
|
||||
val unspecified = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
|
||||
view.measure(unspecified, unspecified)
|
||||
view.layout(0, 0, view.measuredWidth, view.measuredHeight)
|
||||
val bitmap = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888)
|
||||
view.draw(Canvas(bitmap))
|
||||
|
||||
val png = ByteArrayOutputStream().also { bitmap.compress(Bitmap.CompressFormat.PNG, 100, it) }
|
||||
println("FUSIONHUD-${size.token.uppercase()}-PNG ${Base64.getEncoder().encodeToString(png.toByteArray())}")
|
||||
|
||||
val panel = view.panelForTest()!!
|
||||
assertTrue("$size panel inside the view",
|
||||
panel.left > 0f && panel.top > 0f && panel.right < view.width && panel.bottom < view.height)
|
||||
view.graphForTest()?.let { graph ->
|
||||
val r = view.panelRadiusForTest()
|
||||
val d = maxOf(panel.top + r - graph.top, graph.bottom - (panel.bottom - r), 0f)
|
||||
val edge = panel.right - r + sqrt(r * r - d * d)
|
||||
assertTrue("$size graph clears the round side", graph.right <= edge)
|
||||
}
|
||||
val orb = bitmap.getPixel(panel.left.roundToInt() + 1, panel.centerY().roundToInt())
|
||||
assertTrue("$size orb on the left side", Color.blue(orb) > 200 && Color.alpha(orb) > 200)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.droiddeck.launcher.hud
|
||||
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import java.io.File
|
||||
|
||||
class MangoReadingsTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
private fun readings() = MangoReadings(tmp.root, tmp.root)
|
||||
|
||||
@Test fun cpuLoadFollowsMangoHudsFormulaAndTruncates() {
|
||||
val stat = File(tmp.root, "stat")
|
||||
val m = readings()
|
||||
// user nice system idle iowait irq softirq steal guest guest_nice
|
||||
stat.writeText("cpu 1000 100 500 8000 400 50 50 0 200 0\ncpu0 500 50 250 4000 200 25 25 0 100 0\ncpu1 500 50 250 4000 200 25 25 0 100 0\nintr 0\n")
|
||||
m.cpu(stat)
|
||||
stat.writeText("cpu 1500 100 700 8600 500 60 70 10 300 0\ncpu0 900 50 400 4100 250 30 35 10 200 0\ncpu1 600 50 300 4500 250 30 35 0 100 0\nintr 0\n")
|
||||
val cpu = m.cpu(stat)!!
|
||||
// busy = user-guest 400 + nice 0 + system+irq+softirq 230 + steal 10 + guest 100 = 740 of 1440 (idle+iowait 700)
|
||||
assertEquals((740 * 100f / 1440).toInt(), cpu.percent)
|
||||
assertEquals(51, cpu.percent)
|
||||
assertArrayEquals(intArrayOf(((300 + 165 + 10 + 100) * 100f / (300 + 165 + 10 + 100 + 150)).toInt(), ((100 + 65) * 100f / (100 + 65 + 550)).toInt()), cpu.perCore)
|
||||
}
|
||||
|
||||
@Test fun anUnchangedCounterKeepsTheLastLoad() {
|
||||
val stat = File(tmp.root, "stat")
|
||||
val m = readings()
|
||||
stat.writeText("cpu 100 0 0 100 0 0 0 0 0 0\n")
|
||||
m.cpu(stat)
|
||||
stat.writeText("cpu 200 0 0 100 0 0 0 0 0 0\n")
|
||||
assertEquals(100, m.cpu(stat)!!.percent)
|
||||
assertEquals(100, m.cpu(stat)!!.percent)
|
||||
}
|
||||
|
||||
private fun battery(status: String, chargeNow: Long, chargeFull: Long, powerUw: Long) {
|
||||
val dir = File(tmp.root, "sys/power_supply/BAT1").apply { mkdirs() }
|
||||
File(dir, "status").writeText("$status\n")
|
||||
File(dir, "charge_now").writeText("$chargeNow\n")
|
||||
File(dir, "charge_full").writeText("$chargeFull\n")
|
||||
File(dir, "power_now").writeText("$powerUw\n")
|
||||
}
|
||||
|
||||
@Test fun batteryHidesWattsWhileChargingAsMangoHudDoes() {
|
||||
battery("Discharging", 3_622_942, 3_854_193, 8_760_000)
|
||||
val discharging = readings().battery()!!
|
||||
assertEquals(94, discharging.percent)
|
||||
assertEquals(8.76f, discharging.watts, 0.001f)
|
||||
assertFalse(discharging.charging)
|
||||
battery("Charging", 3_622_942, 3_854_193, 8_760_000)
|
||||
val charging = readings().battery()!!
|
||||
assertEquals(0f, charging.watts, 0f)
|
||||
assertTrue(charging.charging)
|
||||
}
|
||||
|
||||
@Test fun noBatteryFolderMeansNoReading() {
|
||||
assertNull(readings().battery())
|
||||
}
|
||||
|
||||
@Test fun gpuLoadIsTheLeadingNumber() {
|
||||
val f = File(tmp.root, "perf_now").apply { writeText(" 6 %\n") }
|
||||
assertEquals(6.0, MangoReadings.leadingNumber(f)!!, 0.0)
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class PerfHudGraphTest {
|
||||
@Test fun theGraphShowsOnlyFramesFromThisHudRun() {
|
||||
val samples = floatArrayOf(9f, 9f, 9f, 9f, 9f, 16.7f, 33.4f, 16.6f)
|
||||
assertArrayEquals(floatArrayOf(16.7f, 33.4f, 16.6f), PerfHud.recent(samples, 105, 102), 0f)
|
||||
assertEquals(0, PerfHud.recent(samples, 103, 102).size)
|
||||
}
|
||||
|
||||
@Test fun anEarlySessionShowsWhatWasShownSoFar() {
|
||||
val samples = floatArrayOf(16.6f, 16.7f, 120f, 0f, 0f, 0f)
|
||||
assertArrayEquals(floatArrayOf(16.6f, 16.7f, 50f), PerfHud.recent(samples, 3, 0), 0f)
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,8 @@ class SettingsResetTest {
|
||||
SessionPrefs.setHudShowGraph(app, false)
|
||||
SessionPrefs.setHudColor(app, "amber")
|
||||
SessionPrefs.setHudOpacity(app, 40)
|
||||
SessionPrefs.setFusionHudConfig(app, "hudSize=mega,showFPSGraph=0")
|
||||
SessionPrefs.setFusionHudPosition(app, 120f, 40f)
|
||||
ControllerPrefs.setOpacity(app, 40)
|
||||
AppUiPrefs.setScale(app, 150)
|
||||
FrameGen.set(app, FrameGen.Mode(FrameGen.ENGINE_DDFG, 3))
|
||||
@@ -64,8 +66,8 @@ class SettingsResetTest {
|
||||
assertTrue(SessionPrefs.hudShowGraph(app))
|
||||
assertEquals(SessionPrefs.HUD_COLOR_MINT, SessionPrefs.hudColor(app))
|
||||
assertEquals(SessionPrefs.HUD_OPACITY_DEFAULT, SessionPrefs.hudOpacity(app))
|
||||
assertEquals("32.4°C", PerfHud.batteryCelsius(324))
|
||||
assertNull(PerfHud.batteryCelsius(0))
|
||||
assertNull(SessionPrefs.fusionHudConfig(app))
|
||||
assertNull(SessionPrefs.fusionHudPosition(app))
|
||||
assertEquals(100, ControllerPrefs.read(app).opacity)
|
||||
assertEquals(AppUiPrefs.DEFAULT_SCALE, AppUiPrefs.scale(app))
|
||||
assertEquals(FrameGen.Mode.OFF.engine, FrameGen.engine(app))
|
||||
|
||||
@@ -19,7 +19,8 @@ class SessionDrawerPageTest {
|
||||
assertEquals(SessionDrawerPage.DISPLAY, connected.step(SessionDrawerPage.SECOND_SCREEN, 1))
|
||||
assertEquals(sessionDrawerPages(false), connected.filter { it != SessionDrawerPage.SECOND_SCREEN })
|
||||
for (pages in listOf(connected, sessionDrawerPages(false))) {
|
||||
assertEquals(SessionDrawerPage.EFFECTS, pages.step(SessionDrawerPage.DISPLAY, 1))
|
||||
assertEquals(SessionDrawerPage.HUD, pages.step(SessionDrawerPage.DISPLAY, 1))
|
||||
assertEquals(SessionDrawerPage.EFFECTS, pages.step(SessionDrawerPage.HUD, 1))
|
||||
assertEquals(SessionDrawerPage.VR, pages.step(SessionDrawerPage.EFFECTS, 1))
|
||||
assertEquals(SessionDrawerPage.GAMES, pages.step(SessionDrawerPage.VR, 1))
|
||||
assertEquals(SessionDrawerPage.SESSION, pages.step(SessionDrawerPage.GAMES, 1))
|
||||
|
||||
Reference in new issue
Block a user