From 11218f0b24c1135b50546afba9f5f2c476353328 Mon Sep 17 00:00:00 2001 From: KeegantheVeganat0r <58369898+KeegantheVeganat0r@users.noreply.github.com> Date: Sat, 7 Nov 2026 20:41:46 +0000 Subject: [PATCH] perf(hud): reduce Strip rendering cost with bitmap graph and logo (#2235) perf(hud): rasterize Strip graph and logo separately Replace PR2194's whole-View software layer with a hardware-accelerated Strip that rasterizes its graph and logo into small reusable bitmaps. Keep the 66 ms graph invalidation cap, clear stale graph pixels, and refresh cached logo colours when the theme changes. Include the comparison method and six sanitized benchmark samples. With matched Steam navigation, the hybrid averaged 12.2% less UI-thread CPU and 34.0% lower draw p95 than the PR2194 software path. App-process CPU averaged 5.9% lower in this run; whole-device and battery savings are not established. Current-build physical flicker confirmation is recorded separately from timing validation. Validation: all 12 DroidDeckHudPanelTest checks passed; comparison APK built and six alternating device samples completed with matched input counts, no focus loss, thermal status 0, and no frame metric report drops. --- .../launcher/hud/DroidDeckHudView.kt | 47 +++++++- .../launcher/hud/DroidDeckHudPanelTest.kt | 37 ++++++ docs/testing/hud-strip-hybrid-2026-11-07.json | 110 ++++++++++++++++++ docs/testing/hud-strip-hybrid-2026-11-07.md | 85 ++++++++++++++ 4 files changed, 274 insertions(+), 5 deletions(-) create mode 100644 docs/testing/hud-strip-hybrid-2026-11-07.json create mode 100644 docs/testing/hud-strip-hybrid-2026-11-07.md diff --git a/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudView.kt b/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudView.kt index b5dbb54ef3..a353a6d201 100644 --- a/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudView.kt +++ b/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudView.kt @@ -534,9 +534,6 @@ class DroidDeckHudView(context: Context) : View(context) { private val inkRect = android.graphics.Rect() private fun rebuild() { - val renderingLayer = if (size == DroidDeckHudSize.STRIP && dock == DroidDeckHudDock.NONE) - LAYER_TYPE_SOFTWARE else LAYER_TYPE_NONE - if (layerType != renderingLayer) setLayerType(renderingLayer, null) glyphs.clear(); tileRects.clear(); graphRect = null headerMark = null; headerWordmark = null; chipRect = null; dPanel = null; dDividerTop = -1f; tabRect = null; stripRect = null val s = snap @@ -1353,10 +1350,15 @@ class DroidDeckHudView(context: Context) : View(context) { canvas.drawText(g.text, g.x, g.baseline, paint) if (g.glow) paint.clearShadowLayer() } - headerMark?.let { DroidDeckMark.draw(canvas, it.left, it.top, it.height(), blend(colValue), accent) } + headerMark?.let { + if (stripRect != null && layerType != LAYER_TYPE_SOFTWARE) drawCachedMark(canvas, it) + else DroidDeckMark.draw(canvas, it.left, it.top, it.height(), blend(colValue), accent) + } headerWordmark?.let { WordmarkArt.draw(canvas, it.left, it.top, it.height(), blend(colValue), accent) } - graphRect?.let { drawGraph(canvas, it) } + graphRect?.let { + if (stripRect != null && layerType != LAYER_TYPE_SOFTWARE) drawCachedGraph(canvas, it) else drawGraph(canvas, it) + } lockController.drawBadge(canvas) } @@ -1381,6 +1383,41 @@ class DroidDeckHudView(context: Context) : View(context) { canvas.drawPath(graphPath, graphPaint) } + private var cachedGraphBitmap: Bitmap? = null + private var cachedGraphCanvas: Canvas? = null + private val cachedGraphRect = RectF() + private var cachedMarkBitmap: Bitmap? = null + private var cachedMarkKey = "" + + private fun drawCachedGraph(canvas: Canvas, rect: RectF) { + val w = rect.width().roundToInt().coerceAtLeast(1) + val h = rect.height().roundToInt().coerceAtLeast(1) + var bitmap = cachedGraphBitmap + if (bitmap == null || bitmap.width != w || bitmap.height != h) { + bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888) + cachedGraphBitmap = bitmap + cachedGraphCanvas = Canvas(bitmap) + cachedGraphRect.set(0f, 0f, w.toFloat(), h.toFloat()) + } + bitmap.eraseColor(Color.TRANSPARENT) + drawGraph(cachedGraphCanvas!!, cachedGraphRect) + canvas.drawBitmap(bitmap, rect.left, rect.top, null) + } + + private fun drawCachedMark(canvas: Canvas, rect: RectF) { + val w = rect.width().roundToInt().coerceAtLeast(1) + val h = rect.height().roundToInt().coerceAtLeast(1) + val key = "$w,$h,${blend(colValue)},$accent" + var bitmap = cachedMarkBitmap + if (bitmap == null || key != cachedMarkKey) { + bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888) + DroidDeckMark.draw(Canvas(bitmap), 0f, 0f, h.toFloat(), blend(colValue), accent) + cachedMarkBitmap = bitmap + cachedMarkKey = key + } + canvas.drawBitmap(bitmap, rect.left, rect.top, null) + } + private fun drawStrip(canvas: Canvas, rect: RectF) { val p = parent as? View val atBottom = p != null && p.height > 0 && y + height / 2f > p.height / 2f diff --git a/app/src/test/java/com/droiddeck/launcher/hud/DroidDeckHudPanelTest.kt b/app/src/test/java/com/droiddeck/launcher/hud/DroidDeckHudPanelTest.kt index 05c6d2e679..a439e703b9 100644 --- a/app/src/test/java/com/droiddeck/launcher/hud/DroidDeckHudPanelTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/hud/DroidDeckHudPanelTest.kt @@ -2,12 +2,15 @@ package com.droiddeck.launcher.hud import android.graphics.Bitmap import android.graphics.Canvas +import android.graphics.RectF import android.os.Looper import android.os.SystemClock import android.view.MotionEvent import android.view.View import android.view.ViewConfiguration import android.widget.FrameLayout +import com.droiddeck.launcher.session.SessionPrefs +import com.droiddeck.launcher.ui.Themes import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue @@ -169,6 +172,40 @@ class DroidDeckHudPanelTest { after.getPixel(x, graph.top.toInt() + 2), after.getPixel(x, y)) } + @Test fun stripMarkUpdatesAfterThemeChangesWithoutChangingSize() { + val app = RuntimeEnvironment.getApplication() + val oldTheme = SessionPrefs.theme(app) + val parent = FrameLayout(app) + val view = DroidDeckHudView(app) + parent.addView(view) + parent.layout(0, 0, 2400, 1080) + fun render(theme: String): Bitmap { + SessionPrefs.setTheme(app, theme) + view.applyConfig(DroidDeckHudConfig.encode(DroidDeckHudConfig.DEFAULTS + ("hudSize" to "strip"))) + view.showForTest(SNAPSHOT, "DXVK", 0L) + val unspecified = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED) + view.measure(unspecified, unspecified) + view.layout(0, 0, view.measuredWidth, view.measuredHeight) + return Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888).also { view.draw(Canvas(it)) } + } + try { + val first = render(Themes.GRAPHITE) + val mark = DroidDeckHudView::class.java.getDeclaredField("headerMark").let { + it.isAccessible = true + RectF(it.get(view) as RectF) + } + val second = render(Themes.ELECTRIC) + val x = (mark.left + mark.width() / 2f).toInt() + val y = mark.centerY().toInt() + assertEquals(first.width, second.width) + assertEquals(first.height, second.height) + assertTrue("the mark orb follows the current theme", first.getPixel(x, y) != second.getPixel(x, y)) + assertEquals(View.LAYER_TYPE_NONE, view.layerType) + } finally { + SessionPrefs.setTheme(app, oldTheme) + } + } + @Test fun stripFollowsTheHudScaleInHeightAndKeepsTheFullWidth() { val app = RuntimeEnvironment.getApplication() val parent = FrameLayout(app) diff --git a/docs/testing/hud-strip-hybrid-2026-11-07.json b/docs/testing/hud-strip-hybrid-2026-11-07.json new file mode 100644 index 0000000000..b3c978d7d1 --- /dev/null +++ b/docs/testing/hud-strip-hybrid-2026-11-07.json @@ -0,0 +1,110 @@ +{ + "cpuUnits": "100 percent equals one occupied CPU core", + "sampleSeconds": 25, + "warmupSeconds": 5, + "navigationIntervalSeconds": 0.125, + "measurements": [ + { + "run": 1, + "mode": "software15", + "cpuPercentOneCore": 31.663757784918452, + "mainCpuPercentOneCore": 7.044499908393501, + "drawP95Ms": 2.094739, + "frameP95Ms": 5.356661, + "gpuP95Ms": 1.383803, + "navigationInputs": 244, + "layerType": 1, + "canvasHardware": false, + "windowFrames": 401, + "focusLostSamples": 0, + "droppedMetricReports": 0, + "thermalStart": 0, + "thermalEnd": 0 + }, + { + "run": 2, + "mode": "hardware15", + "cpuPercentOneCore": 31.57198290945421, + "mainCpuPercentOneCore": 6.232491898227486, + "drawP95Ms": 1.394844, + "frameP95Ms": 4.569843, + "gpuP95Ms": 1.37625, + "navigationInputs": 244, + "layerType": 0, + "canvasHardware": true, + "windowFrames": 397, + "focusLostSamples": 0, + "droppedMetricReports": 0, + "thermalStart": 0, + "thermalEnd": 0 + }, + { + "run": 3, + "mode": "hardware15", + "cpuPercentOneCore": 31.61184616790523, + "mainCpuPercentOneCore": 6.104517009710966, + "drawP95Ms": 1.327395, + "frameP95Ms": 4.548805, + "gpuP95Ms": 1.360052, + "navigationInputs": 244, + "layerType": 0, + "canvasHardware": true, + "windowFrames": 395, + "focusLostSamples": 0, + "droppedMetricReports": 0, + "thermalStart": 0, + "thermalEnd": 0 + }, + { + "run": 4, + "mode": "software15", + "cpuPercentOneCore": 33.22786890143692, + "mainCpuPercentOneCore": 6.873449737216468, + "drawP95Ms": 2.024947, + "frameP95Ms": 5.430132, + "gpuP95Ms": 1.425989, + "navigationInputs": 244, + "layerType": 1, + "canvasHardware": false, + "windowFrames": 397, + "focusLostSamples": 0, + "droppedMetricReports": 0, + "thermalStart": 0, + "thermalEnd": 0 + }, + { + "run": 5, + "mode": "software15", + "cpuPercentOneCore": 33.472465000822694, + "mainCpuPercentOneCore": 6.952114615054318, + "drawP95Ms": 2.045417, + "frameP95Ms": 5.403243, + "gpuP95Ms": 1.356354, + "navigationInputs": 244, + "layerType": 1, + "canvasHardware": false, + "windowFrames": 402, + "focusLostSamples": 0, + "droppedMetricReports": 0, + "thermalStart": 0, + "thermalEnd": 0 + }, + { + "run": 6, + "mode": "hardware15", + "cpuPercentOneCore": 29.40371307271493, + "mainCpuPercentOneCore": 5.991546211883758, + "drawP95Ms": 1.347709, + "frameP95Ms": 4.509034, + "gpuP95Ms": 1.302135, + "navigationInputs": 244, + "layerType": 0, + "canvasHardware": true, + "windowFrames": 401, + "focusLostSamples": 0, + "droppedMetricReports": 0, + "thermalStart": 0, + "thermalEnd": 0 + } + ] +} diff --git a/docs/testing/hud-strip-hybrid-2026-11-07.md b/docs/testing/hud-strip-hybrid-2026-11-07.md new file mode 100644 index 0000000000..b5b8646da1 --- /dev/null +++ b/docs/testing/hud-strip-hybrid-2026-11-07.md @@ -0,0 +1,85 @@ +# Strip hybrid rendering versus PR2194 + +PR2194 avoids the observed Strip flicker by rendering the entire Strip in a +software View layer. This follow-up keeps the View hardware accelerated and +rasterizes only its graph and logo into small bitmaps. The graph bitmap is +reused and cleared before each trace; the logo bitmap updates when its size +or colours change. Text and the rest of the HUD use the normal hardware path. +The 66 ms graph invalidation cap from PR2194 is retained. + +This reduces the amount of HUD drawing that needs a software layer while +retaining bitmap rendering for the vector content used by the previously +working hybrid approach. It preserves Strip's layout and settings. + +## Device comparison + +On 2026-11-07, six samples were captured on a HONOR BKQ-N49 with Adreno 840 +and Android 17. Both renderers were selected in the same comparison APK, +based on upstream `e5434117f`, using the same cached published-preview runtime +components. The later native presentation and producer-wait experiments were +excluded. The local build reused those components with source-provenance +warnings; this was a matched HUD comparison, not validation of newly built +runtime components from upstream main. + +The debug harness selected either `LAYER_TYPE_SOFTWARE` with direct graph/logo +Paths, matching PR2194, or `LAYER_TYPE_NONE` with the hybrid bitmap graph/logo. +The software baseline therefore did not pay for the hybrid bitmap rendering +as well as its software View layer. + +Each sample had a five-second warm-up and a 25-second measurement. Real +DPAD Right/Left inputs alternated at a target interval of 0.125 seconds, +keeping Steam navigation active. Each run delivered 244 inputs over its +30.5-second navigation window, including warm-up. The order was software, +hybrid, hybrid, software, software, hybrid. The same full-width Strip layout +and settings were used throughout. Display settings were temporarily held at +60 Hz and the original adaptive settings were restored and read back afterward. +No screen recording ran during measurement. + +Values below are means of the three per-run measurements. CPU percentages +use 100% for one occupied CPU core. Draw and frame values are means of the +individual runs' p95 values, not pooled percentiles. + +| Metric | PR2194 software | Hybrid | Relative change | +| --- | ---: | ---: | ---: | +| UI-thread CPU | 6.957% | 6.110% | -12.2% | +| App-process CPU | 32.788% | 30.863% | -5.9% | +| App-window draw p95 | 2.055 ms | 1.357 ms | -34.0% | +| App-window frame p95 | 5.397 ms | 4.543 ms | -15.8% | +| Reported GPU p95 | 1.389 ms | 1.346 ms | -3.1% | + +| Run | Renderer | UI-thread CPU | App-process CPU | Draw p95 | Frame p95 | +| --- | --- | ---: | ---: | ---: | ---: | +| 1 | Software | 7.044% | 31.664% | 2.095 ms | 5.357 ms | +| 2 | Hybrid | 6.232% | 31.572% | 1.395 ms | 4.570 ms | +| 3 | Hybrid | 6.105% | 31.612% | 1.327 ms | 4.549 ms | +| 4 | Software | 6.873% | 33.228% | 2.025 ms | 5.430 ms | +| 5 | Software | 6.952% | 33.472% | 2.045 ms | 5.403 ms | +| 6 | Hybrid | 5.992% | 29.404% | 1.348 ms | 4.509 ms | + +All three pairs favoured hybrid rendering for UI-thread CPU and draw p95. +All runs retained Steam focus, reported thermal status 0, and lost no frame +metric reports. Layer type and Canvas hardware acceleration were checked +for each mode. The per-run measurements are in +[the accompanying JSON](hud-strip-hybrid-2026-11-07.json). + +## Validation and limits + +The 12 HUD regression checks passed, including graph trace clearing, scaling, +and a new check that a cached Strip logo updates its colours after a theme +change without resizing. The comparison APK built successfully. + +An earlier saved APK using this hybrid approach was physically confirmed +flicker-free by the tester. Physical confirmation of the rebuilt comparison +APK is separate from the automated measurements and remains pending. +Frame metrics cannot establish absence of visible corruption. + +These short samples on one device show a reduction in measured HUD rendering +cost. App-process CPU excludes other guest processes and is not whole-device +CPU usage. Sustained game performance, battery life, and temperature savings +were not established. This change targets Strip; it does not address the +separately observed flicker while moving a docked FPS tab or shrinking other +HUD modes. + +Comparison APK SHA256: +`8df2d75216c40f24353a22a7c830341cb62a5ce6423ad2207477a0d769e22ae2`. +Temporary benchmark controls were excluded from the proposed production patch.