forked from Blendman974/faceclaw
Add an option to move the app switcher to the right or bottom, and adjust screen depth if bottom
This commit is contained in:
1 parent
46fded856a
commit
8f99779f98
21 files changed
+827
-286
No files matched your search
+21
@@ -62,6 +62,27 @@ object DrawProtocol {
|
||||
write: DrawWriter.() -> Unit): ByteArray =
|
||||
call(op, encode(write), target, depth, clip)
|
||||
|
||||
/**
|
||||
* [call] moved [extra] depth units further, as if played from a list called at that depth:
|
||||
* adds to its depth field, or inserts one (after any target override) when it has none. The
|
||||
* sum saturates at the field's range rather than failing the whole presentation.
|
||||
*/
|
||||
fun withAddedDepth(call: ByteArray, extra: Int): ByteArray {
|
||||
if (extra == 0) return call
|
||||
val flags = call[1].toInt() and 255
|
||||
val at = if (flags and DRAW_FLAG_RESOURCE_TARGET != 0) 4 else 2
|
||||
val result = if (flags and DRAW_FLAG_DEPTH != 0) {
|
||||
call.copyOf().also { it[at] = addDepth(call[at].toInt(), extra).toByte() }
|
||||
} else {
|
||||
call.copyOfRange(0, at) + byteArrayOf(addDepth(0, extra).toByte()) + call.copyOfRange(at, call.size)
|
||||
}
|
||||
result[1] = (flags or DRAW_FLAG_DEPTH).toByte()
|
||||
return result
|
||||
}
|
||||
|
||||
/** Two depths combined, saturated to the s8 depth field. */
|
||||
fun addDepth(depth: Int, extra: Int): Int = (depth + extra).coerceIn(-128, 127)
|
||||
|
||||
fun depthOffset(depth: Int, right: Boolean): Int =
|
||||
if (right) -floorHalf(depth + 1) else floorHalf(depth)
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.faceclaw.app
|
||||
|
||||
/** Immutable shell snapshot. Keys identify writable surfaces across repaints, not their pixels. */
|
||||
/**
|
||||
* Immutable shell snapshot. Keys identify writable surfaces across repaints, not their pixels.
|
||||
* [screenDepth] is the stereo depth of the whole presentation: the screen copy and everything
|
||||
* drawn over it shift together per lens (see [calls]).
|
||||
*/
|
||||
class ShellScene(val layers: List<Layer>, val selections: List<RetainedDrawing> = emptyList(), val screenDepth: Int = 0) {
|
||||
class Layer(val key: Int, val x: Int, val y: Int, val width: Int, val height: Int, val dim: Int, val packed: ByteArray, val selections: List<RetainedDrawing> = emptyList(), val depth: Int = 0) {
|
||||
// Layers are reused by every composite until the shell repaints, and hashing packed
|
||||
@@ -13,22 +17,32 @@ class ShellScene(val layers: List<Layer>, val selections: List<RetainedDrawing>
|
||||
val retainedResources = allSelections.flatMap { it.resources }
|
||||
init { require(retainedResources.size + layers.size < 511 && screenDepth in -128..127) }
|
||||
val fingerprint: String = layers.joinToString(";") { it.fingerprint } + selections.joinToString { it.fingerprint } + "|depth:$screenDepth"
|
||||
/**
|
||||
* The root list. A nonzero [screenDepth] adds to every positional call's own depth, so the
|
||||
* scene moves as one; depths are even (see uiDepthSetting) so the per-lens halves add
|
||||
* exactly. Dim LUTs stay put: they cover the whole target, and a shifted one would leave an
|
||||
* undimmed strip at one edge.
|
||||
*/
|
||||
fun calls(width: Int, height: Int, surfaces: IntArray, selected: IntArray): List<ByteArray> {
|
||||
val calls = ArrayList<ByteArray>(); var rowId = 0
|
||||
val now = drawAnimationTimeMs()
|
||||
fun shifted(call: ByteArray) = DrawProtocol.withAddedDepth(call, screenDepth)
|
||||
calls.addAll(DrawProtocol.screenCopy(width, height, screenDepth))
|
||||
fun add(row: RetainedDrawing) {
|
||||
calls.addAll(row.calls(selected.copyOfRange(rowId, rowId + row.resources.size), now))
|
||||
for (call in row.calls(selected.copyOfRange(rowId, rowId + row.resources.size), now)) calls.add(shifted(call))
|
||||
rowId += row.resources.size
|
||||
}
|
||||
for (row in selections) add(row)
|
||||
for ((index, layer) in layers.withIndex()) {
|
||||
if (layer.dim < 256) calls.add(DrawProtocol.lut(width, height, layer.dim))
|
||||
calls.add(DrawProtocol.image(surfaces[index], layer.x, layer.y, depth = layer.depth))
|
||||
calls.add(DrawProtocol.image(surfaces[index], layer.x, layer.y, depth = DrawProtocol.addDepth(layer.depth, screenDepth)))
|
||||
for (row in layer.selections) add(row)
|
||||
}
|
||||
return calls
|
||||
}
|
||||
/** This scene without its whole-presentation shift: the phone mirror's view (see SurfaceCompositor.previewScene). */
|
||||
fun unshifted(): ShellScene = if (screenDepth == 0) this else ShellScene(layers, selections, 0)
|
||||
|
||||
fun preview(screenGray: ByteArray, width: Int, height: Int, rightLens: Boolean = false): ByteArray {
|
||||
val screen = BmpUtil.pack4bppFromGray8(screenGray, width, height)
|
||||
val output = ByteArray(screen.size); val resources = HashMap<Int, ByteArray>()
|
||||
@@ -89,10 +103,11 @@ class ShellScene(val layers: List<Layer>, val selections: List<RetainedDrawing>
|
||||
val selections = List(selectionCount) { readRetainedDrawing(reader, reader.get().toInt()) }
|
||||
layers.add(Layer(key, x, y, w, h, dim, BmpUtil.pack4bppFromGray8(gray, w, h), selections, depth))
|
||||
}
|
||||
require(reader.remaining() == 0)
|
||||
require(reader.remaining() == 2)
|
||||
val screenDepth = reader.getShort().toInt()
|
||||
require(layers.sumOf { layer -> layer.selections.sumOf { it.resources.size } } + layers.size < 511)
|
||||
require(layers.map { it.key }.toSet().size == layers.size)
|
||||
return ShellScene(layers)
|
||||
return ShellScene(layers, screenDepth = screenDepth)
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
-4
@@ -316,10 +316,14 @@ class SurfaceCompositor @JvmOverloads constructor(private val includePreviewInFr
|
||||
private var lastScene: ShellScene? = null
|
||||
private var previewKey: String? = null
|
||||
|
||||
/**
|
||||
* The phone mirror's view of [scene]: without the whole-screen stereo shift, which would move
|
||||
* it off centre by half the depth and put mirror touches that far from what they land on.
|
||||
*/
|
||||
private fun previewScene(scene: ShellScene, gray: ByteArray, key: String): ByteArray {
|
||||
if (previewKey != key) {
|
||||
animatedPreview?.player?.stop()
|
||||
animatedPreview = scene.animatedPreview(gray, screenWidth, screenHeight,
|
||||
animatedPreview = scene.unshifted().animatedPreview(gray, screenWidth, screenHeight,
|
||||
schedule = { delay, action -> scheduleDrawRedraw(delay) { lock.withLock(action) } })
|
||||
previewKey = key
|
||||
}
|
||||
@@ -480,12 +484,16 @@ class SurfaceCompositor @JvmOverloads constructor(private val includePreviewInFr
|
||||
}
|
||||
}
|
||||
|
||||
/** The screen's stereo depth: see setSurfaceDepth. */
|
||||
/**
|
||||
* The screen's stereo depth: a covering surface's own (see setSurfaceDepth), else the shell
|
||||
* scene's depth for the whole display (the regular UI's Depth setting).
|
||||
*/
|
||||
private fun screenDepthLocked(ordered: List<Surface>): Int {
|
||||
val top = ordered.lastOrNull { it.visible } ?: return 0
|
||||
val uiDepth = shellScene?.screenDepth ?: 0
|
||||
val top = ordered.lastOrNull { it.visible } ?: return uiDepth
|
||||
val covers = top.transparency == TRANSPARENCY_OPAQUE && top.x <= 0 && top.y <= 0 &&
|
||||
top.x + top.width >= screenWidth && top.y + top.height >= screenHeight
|
||||
return if (covers) top.depth else 0
|
||||
return if (covers) top.depth else uiDepth
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user