Optimize on-glasses animation

This commit is contained in:
James Babcock committed 2026-09-23 02:58:29 -07:00
1 parent c8d835176f
commit 08f1b9a2a2
8 files changed
+94 -46

No files matched your search

+8 -8
View File
@@ -19,7 +19,7 @@ export type FirmwarePatchSet = {
export const CFW_PATCH_SET: FirmwarePatchSet = {
"base": "g2_2.3.0.24.bin",
"baseSha256": "187ccf2bcc5c17a212106e8a376745511e8289c4232b634a7ea94b9bf25a0979",
"outputSha256": "2d9f4200b3980156d65732e1d5fe4ba673768baf06683427710ff9a818cfb7ae",
"outputSha256": "62ed330a71d6be45a4482e6007b00fc7f029a01d238f358f69ba992f83769590",
"patches": [
{
"offset": 1045797,
@@ -210,43 +210,43 @@ export const CFW_PATCH_SET: FirmwarePatchSet = {
{
"offset": 4537963,
"old": "",
"new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf2de9f04fc5b04ff64c484ef66c6b4ff29c591446cff6ff78ccf2ff0bc2f229094ff6ff75002701260d93cde90e0106e048f2a351c0f24501bff32f8f8847d9f800a0bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f04bfc002800f01a81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001f5145abd1bff35f8f49e8000121b159e8001f5145f8d0a1e70f99012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847d9f80070bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f0e5fb002800f0b480414600bf42180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb942abd1bff35f8f49e8000121b159e8001fb942f8d0a1e7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f023810f9800285fd00e980778a7f11700022859d80f980c2840f00c810e9e7078b178084300f00681f0780138022800f20181b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f06f83172f40f08483002a40f0e880fe2800f07485812800f06685002840f07b8551ea030040f0db8000f0fabe04460020b047d8b104f51d7151e800afbaf1000f0bd1bff35f8f00bf41e80002002a7bd051e800afbaf1000ff6d00021bff32f8f0029bff35f8f6bd0824694e74ff0ff37bfe047f6df40c0f24f008047002701261197adf8487006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594549d04ff46d7006f003fb002842d0414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142add1bff35f8f49e8000159b159e8001fa142f8d0a3e706f5a971884726e7012189e700200e9999b10f9a8ab1097801f07f02b2f10b0418bf0124b2f11c0618bf01268a2924dc0b2926d01c2924d03fe00d9010a804f0c7f84ff0ff3701269df84900002810a818bf4ff0ff3704f08bf9054646b99df8480028b94af21f30c0f247004c3080470d98002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010746884797f8641119b997f80413384669b14ff0ff3742f6f760c0f2440000f5807150468847384645b0bde8f08f0d9010a8264004f086f80e98007800f07f041d2c00f07e0018bf1a2811d1d9f800100322cff680720a40b2f1005fbff35f8f0ad10a685a4504bf002281f8812303e0a4f115010129e9d90f2c0adc092c00f3cc80052c00f07882072c40f0f282002769e0142c00f37781102c00f07582112c40f0e7820f98022840f00b840e990878112840f006844878002840f0028445f64d50c0f24600804701284ff000077ff475af40f20830c0f210003590ff208df8d00044f25220c0f20100339040f2c960c0f248003446cde93677804798b148f27e30c2f2070000880122c1b264298df8cf2008d80721b0f5807f38bf03218df8cf108df8d00040f2d260adf8d800052035ae8df8da00f01d33a90522fff78afc4ff22507c0f247070120092132460c23b8470746264631e748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f04e844ff46d7006f0b4f9002800f04684414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d10121c0f800b081728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142aad1bff35f8f49e80001002900f00c8459e8001fa142f6d09ee70a2c00f0b9810b2c40f02682d9f800500320cff680702840b0f1005fbff35f8f41f059802868002758457ff4baaed5f870030c9642f68d46c0f244060028a5f8807318bfb0470021a5f8b013c5f8ac13c5f8681185f8661185f86411d5f86c01c5f8601185f86511c5f86c11c5f80013a5f86c1320b148f2a351c0f245018847d5f87802002818bf04f02df90024c5f87842d5f8680320b148f2a351c0f245018847c5f86843a5f86c43286ca5f8444040b1b047286c06f166018847002804bf002028644bf63940c0f251008047d9f800400320cff680702040b0f1005fbff35f8f2ad12068584527d194f877010027c4f8807188b149f25962c0f25902002044f2436184f8777190474ef6e378c0f25a08c04708f1bc008047d4f8840184f8707150b1b047d4f8840106f166018847002804bf0020c4f88401d9f800000321cff680710140b1f1005fbff35f8f40f00a860168594540f0068690f8a811002900f0fb8506f0c9fb00f0fdbd152c00f06b81162c40f070810f9801380228c0f093820e994ff0ff374878897840ea0120b0f5007f3ff605ae03210f9a01eb400191427ff4fead002700288df8d4708df8d5708df8d6708df8d7708df8d8708df8d9708df8da708df8db708df8dc708df8dd708df8de708df8df708df8e0708df8e1708df8e2708df8e3708df8e4708df8e5708df8e6708Line truncated
"new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf2de9f04fc5b04ff64c484ef66c6b4ff29c591446cff6ff78ccf2ff0bc2f229094ff6ff75002701260d93cde90e0106e048f2a351c0f24501bff32f8f8847d9f800a0bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f04bfc002800f01a81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001f5145abd1bff35f8f49e8000121b159e8001f5145f8d0a1e70f99012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847d9f80070bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f0e5fb002800f0b480414600bf42180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb942abd1bff35f8f49e8000121b159e8001fb942f8d0a1e7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f023810f9800285fd00e980778a7f11700022859d80f980c2840f00c810e9e7078b178084300f00681f0780138022800f20181b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f06f83172f40f08483002a40f0e880fe2800f07485812800f06685002840f07b8551ea030040f0db8000f0fabe04460020b047d8b104f51d7151e800afbaf1000f0bd1bff35f8f00bf41e80002002a7bd051e800afbaf1000ff6d00021bff32f8f0029bff35f8f6bd0824694e74ff0ff37bfe047f6df40c0f24f008047002701261197adf8487006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594549d04ff46d7006f003fb002842d0414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142add1bff35f8f49e8000159b159e8001fa142f8d0a3e706f5a971884726e7012189e700200e9999b10f9a8ab1097801f07f02b2f10b0418bf0124b2f11c0618bf01268a2924dc0b2926d01c2924d03fe00d9010a804f0c7f84ff0ff3701269df84900002810a818bf4ff0ff3704f08bf9054646b99df8480028b94af21f30c0f247004c3080470d98002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010746884797f8641119b997f80413384669b14ff0ff3742f6f760c0f2440000f5807150468847384645b0bde8f08f0d9010a8264004f086f80e98007800f07f041d2c00f07e0018bf1a2811d1d9f800100322cff680720a40b2f1005fbff35f8f0ad10a685a4504bf002281f8812303e0a4f115010129e9d90f2c0adc092c00f3cc80052c00f07882072c40f0f282002769e0142c00f37781102c00f07582112c40f0e7820f98022840f00b840e990878112840f006844878002840f0028445f64d50c0f24600804701284ff000077ff475af40f20830c0f210003590ff208df8d00044f25220c0f20100339040f2c960c0f248003446cde93677804798b148f27e30c2f2070000880122c1b264298df8cf2008d80721b0f5807f38bf03218df8cf108df8d00040f2d260adf8d800052035ae8df8da00f01d33a90522fff78afc4ff22507c0f247070120092132460c23b8470746264631e748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f04e844ff46d7006f0b4f9002800f04684414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d10121c0f800b081728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142aad1bff35f8f49e80001002900f00c8459e8001fa142f6d09ee70a2c00f0b9810b2c40f02682d9f800500320cff680702840b0f1005fbff35f8f41f059802868002758457ff4baaed5f870030c9642f68d46c0f244060028a5f8807318bfb0470021a5f8b013c5f8ac13c5f8681185f8661185f86411d5f86c01c5f8601185f86511c5f86c11c5f80013a5f86c1320b148f2a351c0f245018847d5f87802002818bf04f02df90024c5f87842d5f8680320b148f2a351c0f245018847c5f86843a5f86c43286ca5f8444040b1b047286c06f166018847002804bf002028644bf63940c0f251008047d9f800400320cff680702040b0f1005fbff35f8f2ad12068584527d194f877010027c4f8807188b149f25962c0f25902002044f2436184f8777190474ef6e378c0f25a08c04708f1bc008047d4f8840184f8707150b1b047d4f8840106f166018847002804bf0020c4f88401d9f800000321cff680710140b1f1005fbff35f8f40f00a860168594540f0068690f8a811002900f0fb8506f0c9fb00f0fdbd152c00f06b81162c40f070810f9801380228c0f093820e994ff0ff374878897840ea0120b0f5007f3ff605ae03210f9a01eb400191427ff4fead002700288df8d4708df8d5708df8d6708df8d7708df8d8708df8d9708df8da708df8db708df8dc708df8dd708df8de708df8df708df8e0708df8e1708df8e2708df8e3708df8e4708df8e5708df8e6708Line truncated
"desc": "append injected blobs to main-app payload"
},
{
"offset": 779123,
"old": "805a3900",
"new": "1c483a00",
"new": "e84d3a00",
"desc": "main-app subheader payload size (ps)"
},
{
"offset": 152,
"old": "005b3900",
"new": "9c483a00",
"new": "684e3a00",
"desc": "main-app TOC entry size (ps + 128)"
},
{
"offset": 779243,
"old": "805a3904",
"new": "1c483a04",
"new": "e84d3a04",
"desc": "main-app preamble length (low 24 bits)"
},
{
"offset": 779247,
"old": "effdbcea",
"new": "b66f5542",
"new": "e5d1780a",
"desc": "[5] ota/s200_firmware_ota.bin preamble crc32"
},
{
"offset": 156,
"old": "c0c6322a",
"new": "d0697cd9",
"new": "e2593a34",
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (TOC)"
},
{
"offset": 779127,
"old": "c0c6322a",
"new": "d0697cd9",
"new": "e2593a34",
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (subheader)"
}
]
+1 -1
View File
@@ -395,7 +395,7 @@ export class GrayImage {
hash = mixInt(hash, placed.source.width);
hash = mixInt(hash, placed.source.height);
hash = mixInt(hash, placed.source.sourceContentHash32());
if (placed.presentation) { const p = placed.presentation; for (const value of [p.radius, p.background, p.border, p.depth, p.mode === "image" ? 1 : p.mode === "masked-image" ? 2 : 0, p.animation?.token ?? 0, p.animation?.dx ?? 0, p.animation?.dy ?? 0]) hash = mixInt(hash, value); }
if (placed.presentation) { const p = placed.presentation; for (const value of [p.radius, p.background, p.border, p.depth, p.mode === "image" ? 1 : p.mode === "masked-image" ? 2 : 0, p.animation?.token ?? 0, p.animation?.dx ?? 0, p.animation?.dy ?? 0, p.animation?.durationMs ?? 0]) hash = mixInt(hash, value); }
} else {
hash = mixInt(hash, 0xf17e);
hash = mixInt(hash, placed.font.atlasTag);
+14 -7
View File
@@ -1,4 +1,5 @@
import type { PlacedImage } from './image'
import type { MenuHighlightAnimation } from '../ui/menu-highlight-motion'
/** Bridge record: tag 3 (selection), 4 (image), 5 (gray8-masked image), 6 (animated selection), signed xy, u16 wh/radius, gray fill/stroke, signed depth, restore-count, gray pixels, restore rectangles. */
export function encodePresentation(draw: PlacedImage): Uint8Array {
@@ -8,7 +9,8 @@ export function encodePresentation(draw: PlacedImage): Uint8Array {
if (!Number.isInteger(p.depth) || p.depth < -128 || p.depth > 127) throw new Error('Invalid menu depth')
if ((p.occlusions?.length ?? 0) > 2048) throw new Error('Too many menu occlusion rectangles')
const animation = p.animation;
const header = animation ? 26 : 16;
if (animation && (!Number.isInteger(animation.durationMs) || animation.durationMs < 1 || animation.durationMs > 65535)) throw new Error('Invalid menu animation duration')
const header = animation ? 28 : 16;
const bytes = new Uint8Array(header + width * height + (p.occlusions?.length ?? 0) * 8), view = new DataView(bytes.buffer)
bytes[0] = animation ? 6 : p.mode === "image" ? 4 : p.mode === "masked-image" ? 5 : 3
view.setInt16(1, draw.x, true); view.setInt16(3, draw.y, true)
@@ -17,8 +19,9 @@ export function encodePresentation(draw: PlacedImage): Uint8Array {
view.setUint16(14, p.occlusions?.length ?? 0, true)
if (animation) {
view.setInt16(16, animation.dx, true); view.setInt16(18, animation.dy, true);
view.setUint16(20, Math.max(0, Math.min(500, Date.now() - animation.startedAt)), true);
view.setUint16(20, Math.max(0, Math.min(animation.durationMs, Date.now() - animation.startedAt)), true);
view.setUint32(22, animation.token, true);
view.setUint16(26, animation.durationMs, true);
}
bytes.set(pixels, header)
let offset = header + pixels.length
@@ -29,15 +32,19 @@ export function encodePresentation(draw: PlacedImage): Uint8Array {
return bytes
}
export type Selection = { animation?: { dx: number; dy: number; startedAt: number; token: number }; mode?: "image" | "masked-image"; x: number; y: number; width: number; height: number; radius: number; background: number; border: number; depth: number; pixels: Uint8Array; occlusions: { x: number; y: number; width: number; height: number }[] }
export type Selection = { animation?: MenuHighlightAnimation; mode?: "image" | "masked-image"; x: number; y: number; width: number; height: number; radius: number; background: number; border: number; depth: number; pixels: Uint8Array; occlusions: { x: number; y: number; width: number; height: number }[] }
export function readPresentation(bytes: Uint8Array, offset: number): { selection: Selection; end: number } {
const v = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength), w = v.getUint16(offset + 5, true), h = v.getUint16(offset + 7, true)
const header = bytes[offset] === 6 ? 26 : 16
const header = bytes[offset] === 6 ? 28 : 16
const selection: Selection = { mode: bytes[offset] === 4 ? "image" : bytes[offset] === 5 ? "masked-image" : undefined, x: v.getInt16(offset+1,true), y: v.getInt16(offset+3,true), width:w, height:h,
radius:v.getUint16(offset+9,true), background:bytes[offset+11]!, border:bytes[offset+12]!, depth:v.getInt8(offset+13),
pixels:bytes.slice(offset+header,offset+header+w*h), occlusions:[] }
if (header === 26) selection.animation = { dx:v.getInt16(offset+16,true), dy:v.getInt16(offset+18,true),
startedAt:Date.now()-v.getUint16(offset+20,true), token:v.getUint32(offset+22,true) }
if (header === 28) {
const durationMs = v.getUint16(offset+26,true), elapsed = v.getUint16(offset+20,true)
if (!durationMs || elapsed > durationMs) throw new Error('Invalid menu animation timing')
selection.animation = { dx:v.getInt16(offset+16,true), dy:v.getInt16(offset+18,true),
startedAt:Date.now()-elapsed, token:v.getUint32(offset+22,true), durationMs }
}
let end=offset+header+w*h
for(let i=0;i<v.getUint16(offset+14,true);i++) { selection.occlusions.push({x:v.getUint16(end,true),y:v.getUint16(end+2,true),width:v.getUint16(end+4,true),height:v.getUint16(end+6,true)});end+=8 }
return {selection,end}
@@ -62,7 +69,7 @@ export function paintPresentation(output: Uint8Array, screen: Uint8Array, width:
const dx=Math.max(0,2*r-(2*Math.min(x,w-1-x)+1)),dy=Math.max(0,2*r-(2*Math.min(y,h-1-y)+1))
return dx*dx+dy*dy<=4*r*r
}
const t = row.animation ? Math.max(0, Math.min(1, (Date.now() - row.animation.startedAt) / 500)) : 1
const t = row.animation ? Math.max(0, Math.min(1, (Date.now() - row.animation.startedAt) / row.animation.durationMs)) : 1
const remaining = 1 - t * t * (3 - 2 * t)
const highlightX = Math.trunc(row.x + (row.animation?.dx ?? 0) * remaining)
const highlightY = Math.trunc(row.y + (row.animation?.dy ?? 0) * remaining)
+5 -4
View File
@@ -1,4 +1,5 @@
export type MenuHighlightAnimation = { dx: number; dy: number; startedAt: number; token: number };
export const MENU_HIGHLIGHT_DURATION_MS = 300;
export type MenuHighlightAnimation = { dx: number; dy: number; startedAt: number; token: number; durationMs: number };
let nextToken = 1;
@@ -18,17 +19,17 @@ export class MenuHighlightMotion {
previous.x !== x || previous.y !== y || previous.width !== width || previous.height !== height) {
let fromX = previous?.x ?? x, fromY = previous?.y ?? y;
if (previous && this.animation) {
const t = Math.max(0, Math.min(1, (now - this.animation.startedAt) / 500));
const t = Math.max(0, Math.min(1, (now - this.animation.startedAt) / this.animation.durationMs));
const remaining = 1 - t * t * (3 - 2 * t);
fromX += this.animation.dx * remaining;
fromY += this.animation.dy * remaining;
}
const eligible = previous && previous.index !== index && this.fromIndex === previous.index &&
previous.scroll === scroll && previous.width === width && previous.height === height;
this.animation = eligible ? { dx: Math.round(fromX - x), dy: Math.round(fromY - y), startedAt: now, token: nextToken++ } : undefined;
this.animation = eligible ? { dx: Math.round(fromX - x), dy: Math.round(fromY - y), startedAt: now, token: nextToken++, durationMs: MENU_HIGHLIGHT_DURATION_MS } : undefined;
this.fromIndex = null;
this.previous = { index, scroll, x, y, width, height };
}
return this.animation && now - this.animation.startedAt < 500 ? this.animation : undefined;
return this.animation && now - this.animation.startedAt < this.animation.durationMs ? this.animation : undefined;
}
}
@@ -7,7 +7,7 @@ sealed class DrawValue {
companion object {
/** Smoothstep interpolation; time is measured from the next PRESENT. */
fun animate(from: Int, to: Int, durationMs: Int = 500, elapsedMs: Int = 0): DrawValue {
fun animate(from: Int, to: Int, durationMs: Int, elapsedMs: Int = 0): DrawValue {
require(durationMs > 0 && elapsedMs >= 0)
if (from == to || elapsedMs >= durationMs) return Integer(to)
val code = ByteSink()
@@ -3,14 +3,14 @@ package com.faceclaw.app
/** A retained selection or image, replayed at stereo depth over the screen and shell surfaces. */
class MenuSelection(val x: Int, val y: Int, val width: Int, val height: Int, val radius: Int,
val background: Int, val border: Int, val depth: Int, val packed: ByteArray, val occlusions: List<IntArray> = emptyList(), val kind: Int = 3, val mask: List<IntArray> = emptyList(), val animation: Animation? = null) {
class Animation(val dx: Int, val dy: Int, val startedAt: Long, val token: Int)
class Animation(val dx: Int, val dy: Int, val startedAt: Long, val token: Int, val durationMs: Int)
val resource = CachedResource(DrawProtocol.rawImage(width, height, packed))
val fingerprint = "${animation?.token},${animation?.dx},${animation?.dy},$kind,${mask.joinToString { it.joinToString() }},$x,$y,$width,$height,$radius,$background,$border,$depth,${resource.hash},${occlusions.joinToString { it.joinToString() }}"
val fingerprint = "${animation?.token},${animation?.dx},${animation?.dy},${animation?.durationMs},$kind,${mask.joinToString { it.joinToString() }},$x,$y,$width,$height,$radius,$background,$border,$depth,${resource.hash},${occlusions.joinToString { it.joinToString() }}"
fun translated(dx: Int, dy: Int) = MenuSelection(x + dx, y + dy, width, height, radius, background, border, depth, packed, occlusions.map { intArrayOf(it[0] + dx, it[1] + dy, it[2], it[3]) }, kind, mask, animation)
fun calls(id: Int, nowMs: Long = drawAnimationTimeMs()): List<ByteArray> {
val elapsed = animation?.let { (nowMs - it.startedAt).coerceIn(0, 500).toInt() } ?: 500
val highlightX = animation?.let { DrawValue.animate(x + it.dx, x, 500, elapsed) } ?: DrawValue.Integer(x)
val highlightY = animation?.let { DrawValue.animate(y + it.dy, y, 500, elapsed) } ?: DrawValue.Integer(y)
val elapsed = animation?.let { (nowMs - it.startedAt).coerceIn(0, it.durationMs.toLong()).toInt() } ?: 0
val highlightX = animation?.let { DrawValue.animate(x + it.dx, x, it.durationMs, elapsed) } ?: DrawValue.Integer(x)
val highlightY = animation?.let { DrawValue.animate(y + it.dy, y, it.durationMs, elapsed) } ?: DrawValue.Integer(y)
val image = when (kind) {
3 -> listOf(DrawProtocol.roundedRect(highlightX, highlightY, width, height, radius, background, border, depth),
DrawProtocol.image(id, x, y, CFW_TEXTURE_OPT_BRIGHTNESS_MASK or CFW_TEXTURE_OPT_TRANSPARENT, depth = depth))
@@ -43,12 +43,14 @@ class MenuSelection(val x: Int, val y: Int, val width: Int, val height: Int, val
require(count <= 2048)
require(w in 1..640 && h in 1..480 && 5 + (w + 1) / 2 * h <= 65536 && reader.remaining() >= w * h)
val animation = if (kind == 6) {
require(reader.remaining() >= 10)
require(reader.remaining() >= 12)
val dx = reader.getShort().toInt()
val dy = reader.getShort().toInt()
val elapsed = reader.getShort().toInt() and 65535
require(elapsed <= 500)
Animation(dx, dy, drawAnimationTimeMs() - elapsed, reader.getInt())
val token = reader.getInt()
val duration = reader.getShort().toInt() and 65535
require(duration > 0 && elapsed <= duration)
Animation(dx, dy, drawAnimationTimeMs() - elapsed, token, duration)
} else null
val gray = ByteArray(w * h); reader.get(gray)
require(reader.remaining() >= count * 8)
@@ -61,30 +61,31 @@ class DrawExpressionTest {
}
@Test fun smoothstepCoordinatesMatchFirmwareAndSurvivePresentTimeReset() {
val value = DrawValue.animate(10, 110) as DrawValue.Expression
val value = DrawValue.animate(10, 110, 500) as DrawValue.Expression
val code = "010a3001806e300181f432010010300181f43023414031"
assertContentEquals(hex(code), value.program)
for ((time, expected) in listOf(0L to 10, 125L to 25, 250L to 60, 375L to 94, 500L to 110, 900L to 110)) {
assertEquals(expected to (time < 500), evaluate(value.program, time))
}
val continued = DrawValue.animate(10, 110, elapsedMs = 250) as DrawValue.Expression
val continued = DrawValue.animate(10, 110, 500, elapsedMs = 250) as DrawValue.Expression
assertEquals(60 to true, evaluate(continued.program, 0))
assertEquals(110 to false, evaluate(continued.program, 250))
}
@Test fun animatedMenuBridgePreservesElapsedTimeAndTranslation() {
// Tag 6 record emitted by the TypeScript bridge: elapsed=200, delta=(-2,-4).
val wire = hex("06030002000200020001001030020000fefffcffc8002a000000ffffffff")
// 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, 6).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 (11 to 9), 300L to (13 to 12))) {
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())
@@ -92,15 +93,29 @@ class DrawExpressionTest {
val frame = DrawEvaluation(elapsed)
assertEquals(expected.first, ExtendedVarint.evaluate(reader, frame))
assertEquals(expected.second, ExtendedVarint.evaluate(reader, frame))
assertEquals(elapsed < 300, frame.animationPending)
assertEquals(elapsed < 100, frame.animationPending)
}
for (end in 1 until wire.size) assertFails {
MenuSelection.read(ArrayByteReader(wire.copyOf(end), 1), 6)
}
}
@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), 2, 2, 0, 15)
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))))
val screen = DisplayListRenderer.Target(ByteArray(16), 4, 8)
val output = DisplayListRenderer.Target(ByteArray(16), 4, 8)
@@ -116,7 +131,7 @@ class DrawExpressionTest {
player.present(1)
assertEquals(15, output.get(0, 0))
val first = queued.removeAt(0)
now += 250
now += 150
first()
assertEquals(15, output.get(0, 2))
assertEquals(0, output.get(0, 0))
@@ -125,7 +140,7 @@ class DrawExpressionTest {
assertEquals(15, output.get(0, 0))
stale()
assertEquals(3, displayed)
now += 500
now += 300
queued.removeAt(0)()
assertEquals(15, output.get(0, 4))
assertFalse(renderer.animationPending)
+31 -8
View File
@@ -1,8 +1,8 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { MenuHighlightMotion } = require('../.test-build/app/ui/menu-highlight-motion.js');
const { MenuHighlightMotion, MENU_HIGHLIGHT_DURATION_MS } = require('../.test-build/app/ui/menu-highlight-motion.js');
const { GrayImage } = require('../.test-build/app/graphics/image.js');
const { encodePresentation, readPresentation } = require('../.test-build/app/graphics/presentation-wire.js');
const { encodePresentation, readPresentation, paintPresentation } = require('../.test-build/app/graphics/presentation-wire.js');
test('highlight animates only navigation that preserves the scroll window', () => {
const motion = new MenuHighlightMotion();
@@ -11,9 +11,10 @@ test('highlight animates only navigation that preserves the scroll window', () =
const moved = motion.paint(1, 0, 10, 40, 100, 20, 100);
assert.equal(moved.dx, 0);
assert.equal(moved.dy, -20);
assert.equal(motion.paint(1, 0, 10, 40, 100, 20, 350).token, moved.token);
assert.equal(moved.durationMs, 300);
assert.equal(motion.paint(1, 0, 10, 40, 100, 20, 250).token, moved.token);
motion.navigate(1, false);
const next = motion.paint(2, 0, 10, 60, 100, 20, 350);
const next = motion.paint(2, 0, 10, 60, 100, 20, 250);
assert.equal(next.dy, -30, 'continue from the halfway position');
motion.navigate(2, false);
assert.equal(motion.paint(3, 1, 10, 60, 100, 20, 400), undefined, 'scroll snaps');
@@ -21,23 +22,45 @@ test('highlight animates only navigation that preserves the scroll window', () =
assert.equal(motion.paint(0, 0, 10, 20, 100, 20, 500), undefined, 'wrap snaps');
motion.navigate(0, false);
motion.paint(1, 0, 10, 40, 100, 20, 600);
assert.equal(motion.paint(1, 0, 10, 40, 100, 20, 1100), undefined, 'finished after 500 ms');
assert.ok(motion.paint(1, 0, 10, 40, 100, 20, 899));
assert.equal(motion.paint(1, 0, 10, 40, 100, 20, 900), undefined, 'finished after 300 ms');
assert.equal(motion.paint(2, 0, 10, 60, 100, 20, 1200), undefined, 'programmatic changes snap');
});
test('bridge and fallback preview use the supplied animation duration', () => {
const now = Date.now;
Date.now = () => 1050;
try {
const image = new GrayImage(8, 2);
image.drawMenuSelection(new GrayImage(2, 2), 5, 0, 0, 255, 0, 0,
{ dx: -4, dy: 0, startedAt: 1000, token: 1, durationMs: 100 });
const record = readPresentation(encodePresentation(image.draws[0]), 0);
assert.equal(record.selection.animation.durationMs, 100);
const screen = new Uint8Array(16), output = new Uint8Array(16);
paintPresentation(output, screen, 8, 2, record.selection);
assert.equal(output[3], 240, 'halfway at 50 ms');
assert.equal(output[1], 0);
Date.now = () => 1100;
output.fill(0);
paintPresentation(output, screen, 8, 2, record.selection);
assert.equal(output[5], 240, 'complete at 100 ms');
assert.equal(output[3], 0);
} finally { Date.now = now; }
});
test('animated selection bridge carries relative start, elapsed time and stable token', () => {
const now = Date.now;
Date.now = () => 1200;
try {
const image = new GrayImage(8, 4);
image.drawMenuSelection(new GrayImage(2, 2, 255), 3, 2, 16, 48, 1, 2,
{ dx: -2, dy: -4, startedAt: 1000, token: 42 });
{ dx: -2, dy: -4, startedAt: 1000, token: 42, durationMs: MENU_HIGHLIGHT_DURATION_MS });
const bytes = encodePresentation(image.draws[0]);
assert.equal(bytes[0], 6);
assert.equal(bytes.length, 30);
assert.equal(bytes.length, 32);
const record = readPresentation(bytes, 0);
assert.equal(record.end, bytes.length);
assert.deepEqual(record.selection.animation, { dx: -2, dy: -4, startedAt: 1000, token: 42 });
assert.deepEqual(record.selection.animation, { dx: -2, dy: -4, startedAt: 1000, token: 42, durationMs: MENU_HIGHLIGHT_DURATION_MS });
assert.equal(record.selection.x, 3);
assert.equal(record.selection.y, 2);
} finally { Date.now = now; }