Animate scrolling in menus

This commit is contained in:
James Babcock committed 2026-09-24 11:04:10 -07:00
1 parent 915f155819
commit c801bd5185
23 files changed
+514 -91

No files matched your search

@@ -90,9 +90,20 @@ class DisplayListTest {
}
@Test fun graphValidationPrecedesMutationAndCopyPreservesOverlap() {
val screen=hex("12345678"); val target=DisplayListRenderer.Target(screen,8,1)
val copy=DrawProtocol.call(DRAW_OP_RECT_COPY,hex("feff000000000600010002000000"))
val copy=DrawProtocol.call(DRAW_OP_RECT_COPY,hex("feff0000060001000200"))
DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(copy)),target)
assertContentEquals(hex("12123456"),screen)
// Revision 29: an animated source row scrolls a raw strip; source bounds are checked each frame.
val strip=mapOf(9 to DrawProtocol.rawImage(2,4,hex("11223344")))
val scroll=DrawProtocol.rectCopy(9,DrawValue.Integer(0),DrawValue.animate(0,2,100),2,2,DrawValue.Integer(0),DrawValue.Integer(0))
for ((elapsed,rows) in listOf(0L to "1122",100L to "3344",500L to "3344")) {
val window=DisplayListRenderer.Target(ByteArray(2),2,2)
val renderer=DisplayListRenderer(strip)
renderer.execute(DrawProtocol.sequence(listOf(scroll)),window,elapsedMs=elapsed)
assertContentEquals(hex(rows),window.bytes); assertEquals(elapsed<100,renderer.animationPending)
}
val past=DrawProtocol.rectCopy(9,0,3,2,2,0,0)
assertFails { DisplayListRenderer(strip).execute(DrawProtocol.sequence(listOf(past)),DisplayListRenderer.Target(ByteArray(2),2,2)) }
val valid=DrawProtocol.bbox(hex("ffffffff"),4,0,0,8,1)
assertFails { DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(valid,byteArrayOf(99,0))),target) }
assertContentEquals(hex("12123456"),screen)
@@ -5,13 +5,13 @@ import kotlin.test.*
class DrawWireTest {
private fun hex(value: String) = value.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
@Test fun encodersUseRevision28CoordinatesAndPreserveOtherWireBytes() {
@Test fun encodersUseRevision29CoordinatesAndPreserveOtherWireBytes() {
// Literal vectors pin the firmware grammar independently of the reader.
val calls = listOf(
DrawProtocol.image(0x1234, -32768, 32767, 0x1f, target = 511, depth = -128) to
"0403ff018034120080ff7f1f",
DrawProtocol.rectCopy(DrawProtocol.CURRENT, 1, 2, 3, 4, -5, -6) to
"0200feff0100020003000400fbfffaff",
"0200feff0102030004007b7a",
DrawProtocol.stockText(-1, 2, 15, hex("41c3a9")) to "0300ffff02000f0341c3a9",
DrawProtocol.text(511, -2, 3, 31, hex("01417f")) to "0500ff01feff03001f0301417f",
DrawProtocol.playList(511, depth = 127) to "07027fff01",
@@ -29,11 +29,11 @@ class DrawWireTest {
assertContentEquals(hex("1bffff"), DrawProtocol.root(DrawProtocol.SCREEN))
val flat = DrawProtocol.screenCopy(640, 352)
assertEquals(1, flat.size)
assertContentEquals(hex("0200ffff000000008002600100000000"), flat[0])
assertContentEquals(hex("0200ffff0000800260010000"), flat[0])
val shifted = DrawProtocol.screenCopy(640, 352, -32)
assertEquals(2, shifted.size)
assertContentEquals(hex("090000"), shifted[0])
assertContentEquals(hex("0202e0ffff000000008002600100000000"), shifted[1])
assertContentEquals(hex("0202e0ffff0000800260010000"), shifted[1])
}
@Test fun optimizerFieldsAreReencodedAndOpaqueBytesArePreserved() {
@@ -43,7 +43,7 @@ class DrawWireTest {
"0fffff02001f0341c3a9" to "0300ffff02001f0341c3a9",
"030001020134120f10" to "010000000102010f10",
"060f10" to "01000100000000080002000f10",
"090100020003000400fbfffaff" to "0200feff0100020003000400fbfffaff",
"090100020003000400fbfffaff" to "0200feff0102030004007b7a",
)
for ((record, expected) in records) {
val calls = DrawProtocol.fromOptimized(hex(record), 8, 2)
@@ -5,7 +5,8 @@ import kotlin.test.*
class FrameDisplayListTest {
// Golden records emitted by display-list-authoring.test.cjs.
private val menu = "077e0000000300020002000200022a00000096000000010002000200ffffffff0200080000ff24017e30020000000001812c8001812c1611010017328001812c16103001812c3023414031ff24017c30020000000001812c8001812c1611010017328001812c16103001812c302341403102000200010001030400000000000000001f"
private val multi = "074c000000030002000400010002000000000000000002000200010000ff010001006003000400000000000000001f020000010000000000010001000200000002feffffffffff000001000100ffff0000"
private val multi = "0744000000030002000400010002000000000000000002000200010000ff010001006003000400000000000000001f0200000100000001000100020002feffffff7f00010001007f00"
private val scroll = "0787000000030002000400020000070000009600000001000200040011223344556677880200020000000000ff220100300102300180f0800180f0161101001732800180f01610300180f0302341403102000200010008000000ff280101300100300180f0800180f0161101001732800180f01610300180f030234140310100170100160400020000000103"
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)
@@ -36,6 +37,25 @@ class FrameDisplayListTest {
assertNotEquals(read(hex(menu)).fingerprint, read(other).fingerprint)
}
@Test fun animatedCopySourcesRebindOnPresentAndDestinationsTranslate() {
// Emitted by menu-scroll-animation.test.cjs: a menu strip scrolling from row 0 to row 2.
val list = read(hex(scroll)).translated(10, 10)
fun copy(elapsed: Long): List<Int> {
val call = DrawReader(list.calls(intArrayOf(5), 1150).first())
assertEquals(DRAW_OP_RECT_COPY, call.readU8())
assertEquals(DRAW_FLAG_DEPTH, call.readU8())
assertEquals(0, call.readS8())
val frame = DrawEvaluation(elapsed)
val values = listOf(call.readU16(), ExtendedVarint.evaluate(call, frame), ExtendedVarint.evaluate(call, frame),
call.readU16(), call.readU16(), ExtendedVarint.evaluate(call, frame), ExtendedVarint.evaluate(call, frame))
call.requireDone()
return values + if (frame.animationPending) 1 else 0
}
// 150 of 240 ms elapsed before this PRESENT; the source row is not translated with the surface.
assertEquals(listOf(5, 0, 1, 2, 2, 14, 12, 1), copy(0))
assertEquals(listOf(5, 0, 2, 2, 2, 14, 12, 0), copy(90))
}
@Test fun localResourceIdsAreResolvedAndScreenCopiesStayAtScreenDepth() {
val list = read(hex(multi)).translated(10, 10)
val calls = list.calls(intArrayOf(41, 42), 1150)