mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
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.
This commit is contained in:
1 parent
d9bf6d8a17
commit
11218f0b24
4 files changed
+274
-5
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user