forked from Blendman974/faceclaw
Add Glanceboard depth setting
This commit is contained in:
1 parent
71c1971992
commit
915f155819
29 files changed
+262
-50
No files matched your search
@@ -9,3 +9,4 @@ const val DRAW_OP_TEXT = 5
|
||||
const val DRAW_OP_REMAP_COLORS = 6
|
||||
const val DRAW_OP_DISPLAY_LIST = 7
|
||||
const val DRAW_OP_ROUNDED_RECT = 8
|
||||
const val DRAW_OP_CLEAR = 9
|
||||
+15
-1
@@ -1,6 +1,6 @@
|
||||
package com.faceclaw.app
|
||||
|
||||
/** Revision 27 wire grammar, shared by scene planning and the local renderer. */
|
||||
/** Revision 28 wire grammar, shared by scene planning and the local renderer. */
|
||||
object DrawProtocol {
|
||||
/** Mirrors g2flash/patches/zlib_glue.c. */
|
||||
const val DRAW = CFW_MSG_DRAW_CALLS
|
||||
@@ -107,6 +107,20 @@ object DrawProtocol {
|
||||
writeS16(dy)
|
||||
}
|
||||
|
||||
/** Fill the whole target, ignoring depth. */
|
||||
fun clear(color: Int = 0, target: Int? = null): ByteArray {
|
||||
require(color in 0..15)
|
||||
return call(DRAW_OP_CLEAR, target) { writeU8(color) }
|
||||
}
|
||||
|
||||
/**
|
||||
* The copy that starts every root list: firmware presents only what the root
|
||||
* draws. A shifted copy clears first so its uncovered edge is not stale.
|
||||
*/
|
||||
fun screenCopy(width: Int, height: Int, depth: Int = 0): List<ByteArray> =
|
||||
if (depth == 0) listOf(rectCopy(SCREEN, 0, 0, width, height, 0, 0))
|
||||
else listOf(clear(), rectCopy(SCREEN, 0, 0, width, height, 0, 0, depth = depth))
|
||||
|
||||
fun stockText(x: Int, y: Int, options: Int, text: ByteArray): ByteArray {
|
||||
require(text.size <= 255)
|
||||
return call(DRAW_OP_STOCK_FONT_STRING) {
|
||||
|
||||
+3
@@ -930,6 +930,9 @@ class GlassesSessionCore(
|
||||
* actually appear — otherwise a static window (e.g. the terminal hub) whose
|
||||
* frame landed while briefly hidden would stay blank until its next repaint.
|
||||
*/
|
||||
/** Stereo depth for a full-screen surface; applies from its next frame. */
|
||||
fun setSurfaceDepth(id: String, depth: Int) = compositor.setSurfaceDepth(id, depth)
|
||||
|
||||
fun setSurfaceVisible(id: String, visible: Boolean) {
|
||||
// Its own frame: this recomposite is a real screen update with real
|
||||
// latency, and without one it would show up in other frames' logs only
|
||||
|
||||
+11
-1
@@ -164,9 +164,11 @@ class DisplayListRenderer(
|
||||
val frame = DrawEvaluation(elapsedMs)
|
||||
val references = mutableSetOf<Int>()
|
||||
for (apply in listOf(false, true)) {
|
||||
if (apply) copyScreen(screen, composition)
|
||||
// A root list composes the whole frame, including its screen copy.
|
||||
if (root != DrawProtocol.SCREEN) {
|
||||
executeList(root, composition, Walk(screen, apply, references, frame))
|
||||
} else if (apply) {
|
||||
copyScreen(screen, composition)
|
||||
}
|
||||
}
|
||||
animationPending = frame.animationPending
|
||||
@@ -226,6 +228,7 @@ class DisplayListRenderer(
|
||||
DRAW_OP_TEXT -> drawText(reader, target, walk)
|
||||
DRAW_OP_REMAP_COLORS -> remapColors(reader, target, walk)
|
||||
DRAW_OP_ROUNDED_RECT -> drawRoundedRect(reader, target, walk)
|
||||
DRAW_OP_CLEAR -> clear(reader, target, walk)
|
||||
DRAW_OP_DISPLAY_LIST -> {
|
||||
val id = reader.readU16()
|
||||
reader.requireDone()
|
||||
@@ -360,6 +363,13 @@ class DisplayListRenderer(
|
||||
}
|
||||
}
|
||||
|
||||
private fun clear(reader: DrawReader, target: Target, walk: Walk) {
|
||||
val color = reader.readU8()
|
||||
reader.requireDone()
|
||||
require(color <= 15)
|
||||
if (walk.apply) target.bytes.fill((color * 17).toByte(), target.offset, target.offset + target.stride * target.height)
|
||||
}
|
||||
|
||||
private fun drawRoundedRect(reader: DrawReader, target: Target, walk: Walk) {
|
||||
val x = ExtendedVarint.evaluate(reader, walk.frame)
|
||||
val y = ExtendedVarint.evaluate(reader, walk.frame)
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package com.faceclaw.app
|
||||
|
||||
/** Immutable shell snapshot. Keys identify writable surfaces across repaints, not their pixels. */
|
||||
class ShellScene(val layers: List<Layer>, val selections: List<RetainedDrawing> = emptyList()) {
|
||||
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)
|
||||
val allSelections = selections + layers.flatMap { it.selections }
|
||||
val retainedResources = allSelections.flatMap { it.resources }
|
||||
init { require(retainedResources.size + layers.size < 511) }
|
||||
val fingerprint: String = layers.joinToString(";") { "${it.key},${it.x},${it.y},${it.width},${it.height},${it.dim},${it.depth},${CachedResource(it.packed).hash},${it.selections.joinToString { row -> row.fingerprint }}" } + selections.joinToString { it.fingerprint }
|
||||
init { require(retainedResources.size + layers.size < 511 && screenDepth in -128..127) }
|
||||
val fingerprint: String = layers.joinToString(";") { "${it.key},${it.x},${it.y},${it.width},${it.height},${it.dim},${it.depth},${CachedResource(it.packed).hash},${it.selections.joinToString { row -> row.fingerprint }}" } + selections.joinToString { it.fingerprint } + "|depth:$screenDepth"
|
||||
fun calls(width: Int, height: Int, surfaces: IntArray, selected: IntArray): List<ByteArray> {
|
||||
val calls = ArrayList<ByteArray>(); var rowId = 0
|
||||
val now = drawAnimationTimeMs()
|
||||
calls.addAll(DrawProtocol.screenCopy(width, height, screenDepth))
|
||||
fun add(row: RetainedDrawing) {
|
||||
calls.addAll(row.calls(selected.copyOfRange(rowId, rowId + row.resources.size), now))
|
||||
rowId += row.resources.size
|
||||
|
||||
+27
-1
@@ -274,6 +274,9 @@ class SurfaceCompositor @JvmOverloads constructor(private val includePreviewInFr
|
||||
|
||||
@JvmField var visible: Boolean = true
|
||||
|
||||
/** Stereo depth; see setSurfaceDepth. */
|
||||
@JvmField var depth: Int = 0
|
||||
|
||||
@JvmField var pixels: ByteArray = ByteArray(0)
|
||||
|
||||
@JvmField var fingerprint: String = ""
|
||||
@@ -419,6 +422,27 @@ class SurfaceCompositor @JvmOverloads constructor(private val includePreviewInFr
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stereo depth (DrawProtocol.depthOffset) for a surface. It applies while the surface is the
|
||||
* topmost visible one and opaquely covers the screen: the glasses then copy the whole screen
|
||||
* into the frame shifted per lens. Takes effect when the next frame composites.
|
||||
*/
|
||||
fun setSurfaceDepth(id: String, depth: Int): Unit {
|
||||
require(depth in -128..127) { "bad depth $depth for $id" }
|
||||
lock.withLock {
|
||||
val surface = surfaces.get(id) ?: throw IllegalArgumentException(("unknown surface " + id))
|
||||
surface.depth = depth
|
||||
}
|
||||
}
|
||||
|
||||
/** The screen's stereo depth: see setSurfaceDepth. */
|
||||
private fun screenDepthLocked(ordered: List<Surface>): Int {
|
||||
val top = ordered.lastOrNull { it.visible } ?: return 0
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
* While blanked (screen off), composites are all-zero regardless of surface content; retained
|
||||
* state is untouched, so unblanking restores the screen without asking sources to repaint.
|
||||
@@ -681,7 +705,9 @@ class SurfaceCompositor @JvmOverloads constructor(private val includePreviewInFr
|
||||
fingerprint.append(":dim").append(dim)
|
||||
}
|
||||
}
|
||||
val scene = if (surfaces.values.any { it.visible && it.zOrder > 1 }) ShellScene.EMPTY else ShellScene(shellScene?.layers ?: emptyList(), selections)
|
||||
val screenDepth = screenDepthLocked(ordered)
|
||||
val scene = if (surfaces.values.any { it.visible && it.zOrder > 1 }) ShellScene(emptyList(), screenDepth = screenDepth)
|
||||
else ShellScene(shellScene?.layers ?: emptyList(), selections, screenDepth)
|
||||
val sceneKey = fingerprint.append("|shell:").append(scene.fingerprint).toString()
|
||||
val preview = if (includePreview && (shellScene != null || selections.isNotEmpty())) {
|
||||
previewScene(scene, gray, sceneKey)
|
||||
|
||||
@@ -223,6 +223,8 @@ class IosSurfaceCompositor(width: Int, height: Int) {
|
||||
|
||||
fun visible(id: String, visible: Boolean) = compositor.setSurfaceVisible(id, visible)
|
||||
|
||||
fun depth(id: String, depth: Int) = compositor.setSurfaceDepth(id, depth)
|
||||
|
||||
fun dim(below: Int, factor: Double) {
|
||||
require(factor.isFinite())
|
||||
compositor.setUnderlayDim(below, (factor.coerceIn(0.0, 1.0) * 256).toInt())
|
||||
|
||||
@@ -207,6 +207,8 @@ class IosGlassesSession internal constructor(
|
||||
|
||||
fun setSurfaceVisible(id: String, visible: Boolean) = core.setSurfaceVisible(id, visible)
|
||||
|
||||
fun setSurfaceDepth(id: String, depth: Int) = core.setSurfaceDepth(id, depth)
|
||||
|
||||
fun setScreenBlanked(blanked: Boolean) = core.setScreenBlanked(blanked)
|
||||
|
||||
fun configureSurface(id: String, x: Int, y: Int, width: Int, height: Int, zOrder: Int, transparency: Int) =
|
||||
|
||||
Reference in new issue
Block a user