Animations are mainly on the typescript side, not kotlin

This commit is contained in:
James Babcock committed 2026-09-23 22:05:06 -07:00
1 parent 063d8a0b03
commit 440674b261
26 files changed
+783 -128

No files matched your search

@@ -72,48 +72,6 @@ class DrawExpressionTest {
assertEquals(110 to false, evaluate(continued.program, 250))
}
@Test fun animatedMenuBridgePreservesElapsedTimeAndTranslation() {
// Tag 6 record emitted by the TypeScript bridge: elapsed=200, delta=(-2,-4), duration=300.
val wire = hex("06030002000200020001001030020000fefffcffc8002a0000002c01ffffffff")
val input = ArrayByteReader(wire)
assertEquals(6, input.get().toInt())
val row = MenuSelection.read(input, DrawRecordKind.ANIMATED_MENU_SELECTION).translated(10, 10)
assertEquals(0, input.remaining())
val motion = assertNotNull(row.animation)
assertEquals(42, motion.token)
assertEquals(300, motion.durationMs)
assertEquals(-2, motion.dx)
assertEquals(-4, motion.dy)
val call = row.calls(7, motion.startedAt + 200).first()
for ((elapsed, expected) in listOf(0L to (12 to 10), 100L to (13 to 12))) {
val reader = DrawReader(call)
assertEquals(8, reader.readU8())
assertEquals(DRAW_FLAG_DEPTH, reader.readU8())
assertEquals(2, reader.readS8())
val frame = DrawEvaluation(elapsed)
assertEquals(expected.first, ExtendedVarint.evaluate(reader, frame))
assertEquals(expected.second, ExtendedVarint.evaluate(reader, frame))
assertEquals(elapsed < 100, frame.animationPending)
}
for (end in 1 until wire.size) assertFails {
MenuSelection.read(ArrayByteReader(wire.copyOf(end), 1), DrawRecordKind.ANIMATED_MENU_SELECTION)
}
}
@Test fun menuCoordinatesUseTheSuppliedDuration() {
val row = MenuSelection(0, 4, 2, 2, 0, 15, 16, 0, ByteArray(2),
animation = MenuSelection.Animation(0, -4, 1000, 42, 120))
val call = row.calls(7, 1000).first()
for ((elapsed, y) in listOf(0L to 0, 60L to 2, 120L to 4)) {
val reader = DrawReader(call)
reader.readBytes(3) // opcode, flags, depth
val frame = DrawEvaluation(elapsed)
assertEquals(0, ExtendedVarint.evaluate(reader, frame))
assertEquals(y, ExtendedVarint.evaluate(reader, frame))
assertEquals(elapsed < 120, frame.animationPending)
}
}
@Test fun playerSchedulesOnlyUnfinishedFramesAndCancelsStaleCallbacks() {
val call = DrawProtocol.roundedRect(DrawValue.Integer(0), DrawValue.animate(0, 4, 300), 2, 2, 0, 15)
val renderer = DisplayListRenderer(mapOf(1 to DrawProtocol.displayList(listOf(call))))
@@ -0,0 +1,90 @@
package com.faceclaw.app
import kotlin.test.*
class FrameDisplayListTest {
// Golden records emitted by display-list-authoring.test.cjs.
private val menu = "077e0000000300020002000200022a00000096000000010002000200ffffffff0200080000ff24017e30020000000001812c8001812c1611010017328001812c16103001812c3023414031ff24017c30020000000001812c8001812c1611010017328001812c16103001812c302341403102000200010001030400000000000000001f"
private val multi = "074c000000030002000400010002000000000000000002000200010000ff010001006003000400000000000000001f020000010000000000010001000200000002feffffffffff000001000100ffff0000"
private fun hex(s: String) = s.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
private fun read(bytes: ByteArray, now: Long = 1150): FrameDisplayList {
val reader = ArrayByteReader(bytes)
assertEquals(DrawRecordKind.DISPLAY_LIST, reader.get().toInt())
return FrameDisplayList.read(reader, now).also { assertEquals(0, reader.remaining()) }
}
@Test fun authoredExpressionsRebindOnPresentAndTranslateWithTheSurface() {
val row = read(hex(menu)).translated(10, 10)
assertEquals(1, row.resources.size)
fun coordinates(now: Long, elapsed: Long): Triple<Int, Int, Boolean> {
val call = DrawReader(row.calls(intArrayOf(7), now).first())
assertEquals(DRAW_OP_ROUNDED_RECT, call.readU8())
assertEquals(DRAW_FLAG_DEPTH, call.readU8())
assertEquals(2, call.readS8())
val frame = DrawEvaluation(elapsed)
val x = ExtendedVarint.evaluate(call, frame)
val y = ExtendedVarint.evaluate(call, frame)
return Triple(x, y, frame.animationPending)
}
assertEquals(Triple(12, 10, true), coordinates(1150, 0))
assertEquals(Triple(13, 12, false), coordinates(1150, 150))
assertEquals(coordinates(1150, 75), coordinates(1225, 0), "another PRESENT preserves progress")
assertEquals(Triple(13, 12, false), coordinates(1400, 0))
val later = hex(menu).also { it[18] = 200.toByte() } // envelope 5 + elapsed offset 13
assertEquals(read(hex(menu)).fingerprint, read(later).fingerprint)
val other = hex(menu).also { it[14] = 43 } // timeline token
assertNotEquals(read(hex(menu)).fingerprint, read(other).fingerprint)
}
@Test fun localResourceIdsAreResolvedAndScreenCopiesStayAtScreenDepth() {
val list = read(hex(multi)).translated(10, 10)
val calls = list.calls(intArrayOf(41, 42), 1150)
assertContentEquals(DrawProtocol.image(41, 13, 12, 31, depth = 2), calls[0])
assertContentEquals(DrawProtocol.rectCopy(42, 0, 0, 1, 1, 15, 12, depth = 2), calls[1])
assertContentEquals(DrawProtocol.rectCopy(DrawProtocol.SCREEN, 12, 12, 1, 1, 12, 12, depth = 0), calls[2])
val scene = ShellScene(emptyList(), listOf(read(hex(multi))))
assertEquals(2, scene.retainedResources.size)
for (right in listOf(false, true)) {
val pixels = scene.preview(ByteArray(64) { 32 }, 8, 8, right)
assertEquals(240, pixels[16 + if (right) 3 else 5].toInt() and 255)
assertEquals(96, pixels[16 + if (right) 4 else 6].toInt() and 255)
assertEquals(32, pixels[18].toInt() and 255)
}
val cache = ResourceCacheState()
val planner = ScenePlanner(cache)
val screen = ByteArray(32) { 0x22 }
planner.plan(screen, 8, 8, null, scene, 1)
val ids = scene.retainedResources.map { cache.resourceId(it) }
assertTrue(ids.all { it >= 0 }); assertNotEquals(ids[0], ids[1])
planner.plan(screen, 8, 8, null, scene, 1)
assertEquals(ids, scene.retainedResources.map { cache.resourceId(it) })
}
@Test fun frameAndShellSubmissionUseTheSameGenericDecoder() {
val c = SurfaceCompositor()
c.configureScreen(8, 8)
c.configureSurface("app", 0, 0, 8, 8, 0, 0)
c.submitSurface("app", ArrayByteReader(ByteArray(64) { 32 }), 0, 0, 8, 8, "list",
ArrayByteReader(hex(multi)))
val frame = c.composite()
assertEquals(2, frame.shellScene.retainedResources.size)
assertEquals(240, frame.gray[21].toInt() and 255)
assertTrue(frame.screenGray.all { it.toInt() == 32 })
// One opaque 1x1 shell layer, with one generic list after its pixels.
val layer = DrawProtocol.word(1) + DrawProtocol.word(1) + DrawProtocol.word(0) + DrawProtocol.word(0) +
DrawProtocol.word(1) + DrawProtocol.word(1) + DrawProtocol.word(256) + DrawProtocol.word(1) +
DrawProtocol.word(0) + byteArrayOf(32) + hex(multi)
val shell = ShellScene.decode(ArrayByteReader(layer))
assertEquals(2, shell.retainedResources.size)
assertEquals(240, shell.preview(ByteArray(64) { 32 }, 8, 8)[21].toInt() and 255)
}
@Test fun rejectsTruncationBadResourcesAndTrailingData() {
val bytes = hex(multi)
for (end in 1 until bytes.size) assertFails { read(bytes.copyOf(end)) }
assertFails { read(bytes.copyOf().also { it[40] = 9 }) } // first image's local resource
val trailing = bytes + byteArrayOf(0)
trailing[1] = (trailing[1] + 1).toByte()
assertFails { read(trailing) }
}
}