mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
fix(hud): isolate strip rendering in a software layer (#2194)
* fix(hud): skip relayout when size is unchanged and cap graph redraws * fix(hud): limit the redraw and relayout changes to the strip * fix(hud): draw the strip background from a cached bitmap like the panels * fix(hud): drop the strip-only redraw cap and relayout skip * fix(hud): the strip graph redraws at most 15 times a second * fix(hud): isolate strip rendering in a software layer --------- Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
1 parent
066834d17d
commit
a552f1e293
2 files changed
+67
-10
No files matched your search
@@ -141,6 +141,8 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
private var dDividerTop = -1f
|
||||
private var dFrame: Bitmap? = null
|
||||
private var dFrameKey = ""
|
||||
private var sFrame: Bitmap? = null
|
||||
private var sFrameKey = ""
|
||||
private val glowPaint = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
|
||||
private val colGpu = 0xFF5EE08A.toInt()
|
||||
@@ -274,9 +276,17 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
seenFpsUpdates = updates
|
||||
periodDone.trySend(Unit)
|
||||
}
|
||||
if (graphRect != null) invalidate()
|
||||
if (graphRect == null) return
|
||||
if (stripRect != null) {
|
||||
val now = SystemClock.uptimeMillis()
|
||||
if (now - lastGraphDrawMs < STRIP_GRAPH_REDRAW_MS) return
|
||||
lastGraphDrawMs = now
|
||||
}
|
||||
invalidate()
|
||||
}
|
||||
|
||||
private var lastGraphDrawMs = 0L
|
||||
|
||||
private fun cycleSize() {
|
||||
size = size.next()
|
||||
onSizeCycledListener?.accept(size.token)
|
||||
@@ -524,6 +534,9 @@ 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
|
||||
@@ -1369,17 +1382,30 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
}
|
||||
|
||||
private fun drawStrip(canvas: Canvas, rect: RectF) {
|
||||
headerPaint.shader = null
|
||||
headerPaint.color = panelColor()
|
||||
canvas.drawRect(rect, headerPaint)
|
||||
val stroke = outlineWidth()
|
||||
if (stroke <= 0f) return
|
||||
val line = max(stroke / 2f, density)
|
||||
val p = parent as? View
|
||||
val atBottom = p != null && p.height > 0 && y + height / 2f > p.height / 2f
|
||||
headerPaint.color = withAlpha(outlineColor(), (110 + 145 * outlineIntensity).roundToInt().coerceAtMost(255))
|
||||
if (atBottom) canvas.drawRect(rect.left, rect.top, rect.right, rect.top + line, headerPaint)
|
||||
else canvas.drawRect(rect.left, rect.bottom - line, rect.right, rect.bottom, headerPaint)
|
||||
stripFrame(rect, atBottom)?.let { canvas.drawBitmap(it, 0f, 0f, null) }
|
||||
}
|
||||
|
||||
private fun stripFrame(rect: RectF, atBottom: Boolean): Bitmap? {
|
||||
val w = rect.width().roundToInt(); val h = rect.height().roundToInt()
|
||||
if (w <= 0 || h <= 0) return null
|
||||
val stroke = outlineWidth()
|
||||
val key = "$w,$h,$stroke,$atBottom,$surfaceRgb,$bgOpacity,$outlineIntensity,${outlineColor()}"
|
||||
if (key == sFrameKey) sFrame?.let { return it }
|
||||
val bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888)
|
||||
val c = Canvas(bmp)
|
||||
headerPaint.shader = null
|
||||
headerPaint.color = panelColor()
|
||||
c.drawRect(rect, headerPaint)
|
||||
if (stroke > 0f) {
|
||||
val line = max(stroke / 2f, density)
|
||||
headerPaint.color = withAlpha(outlineColor(), (110 + 145 * outlineIntensity).roundToInt().coerceAtMost(255))
|
||||
if (atBottom) c.drawRect(rect.left, rect.top, rect.right, rect.top + line, headerPaint)
|
||||
else c.drawRect(rect.left, rect.bottom - line, rect.right, rect.bottom, headerPaint)
|
||||
}
|
||||
sFrame = bmp; sFrameKey = key
|
||||
return bmp
|
||||
}
|
||||
|
||||
private fun outlineWidth(): Float = if (outlineIntensity > 0f) outlineIntensity * sp(3.5f) else 0f
|
||||
@@ -1499,6 +1525,7 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
const val TAB_PAD_X_SP = 7f
|
||||
const val TAB_PAD_Y_SP = 5.5f
|
||||
const val REFRESH_MS = 500L
|
||||
const val STRIP_GRAPH_REDRAW_MS = 66L
|
||||
private const val HUE_IDLE_MS = 500L
|
||||
const val MIN_SCALE = 0.5f
|
||||
const val MAX_SCALE = 2f
|
||||
|
||||
Reference in new issue
Block a user