Display lists

This commit is contained in:
James Babcock committed 2026-09-22 00:25:40 -07:00
1 parent a7af84e231
commit 4320021222
44 files changed
+823 -284

No files matched your search

+1
View File
@@ -248,6 +248,7 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
const settings = { wakeWordActionSetting: { get: () => wakeAction }, brightnessSetting: { get: () => 'auto' },
assistantSkipConfirmationSetting: { get: () => skipConfirmation } };
const { shell, rawInputEventToInputEvent } = load('app/ui/shell/shell.ts', {
'../../graphics/shell-scene': { encodeShellScene: () => new Uint8Array([0, 0]) },
'../../graphics/image': images, '../../graphics/plane': {}, '../../graphics/ui-fonts': {}, '../../g2/events': load('app/g2/events.ts', {}),
'../gestures': gestures, '../layers': layers, '../menu': { MenuLayer: Menu },
'../input-monitor': load('app/ui/input-monitor.ts', {}),
+16 -1
View File
@@ -2,7 +2,22 @@ const assert = require('node:assert/strict');
// Independent firmware-format decoder for reconstruction tests (not app code).
function applyDisplayPayload(base, payload, width = 640, height = 480) {
const mode = payload[0]; assert.ok(mode === 3 || mode === 6);
const mode = payload[0];
if (mode === 28) return base;
if (mode === 26) {
const word = i => payload[i] | payload[i+1] << 8;
let pos=3, out=base;
for(let n=0;n<word(1);n++) {
const length=word(pos);pos+=2;const call=payload.subarray(pos,pos+length);pos+=length;
assert.equal(call[0],1);assert.equal(call[1],0);
let legacy;
if(call[2]===0) legacy=Uint8Array.from([3,...call.subarray(3,7),0,0,...call.subarray(7)]);
else { assert.deepEqual([...call.subarray(3,11)],[0,0,0,0,width&255,width>>8,height&255,height>>8]);legacy=Uint8Array.from([6,...call.subarray(11)]); }
out=applyDisplayPayload(out,legacy,width,height);
}
assert.equal(pos,payload.length);return out;
}
assert.ok(mode === 3 || mode === 6);
const [left, top, w, h] = mode === 3
? [payload[1] * 4, payload[2] * 2, payload[3] * 4, payload[4] * 2] : [0, 0, width, height];
assert.ok(w > 0 && h > 0 && left + w <= width && top + h <= height);
+2 -2
View File
@@ -212,7 +212,7 @@ test('background glasses input still composites frames; phone resume preserves t
setScreenOn: on => screenStates.push(on), requestRender() {} };
const shell = { configure() {}, registerWindow() {}, wake() {}, focusWindow() {},
getWindows: () => [window], foregroundWindow: () => window, isScreenOn: () => true,
setBatteryLevels() {}, paintSurface() {}, underlayDim: () => 0, getFocus: () => 'app',
setBatteryLevels() {}, paintScene() { return new Uint8Array([0,0]); }, paintSurface() {}, underlayDim: () => 0, getFocus: () => 'app',
receiveInput: async input => { inputs.push(input); } };
class Session {
state = { phase: 'disconnected' };
@@ -247,7 +247,7 @@ test('background glasses input still composites frames; phone resume preserves t
'../apps/all-apps': { ALL_APPS: [] }, '../ui/dashboard-settings': settings,
'../native/phone-battery': { readPhoneBatteryState: () => ({ battery: 80, charging: false }) },
'../graphics/surface-compositor': { SurfaceCompositor: class {
configureSurface() {} setSurfaceVisible() {} submitSurfaceFrame() {} setUnderlayDim() {} setScreenBlanked() {}
setShellScene() {} configureSurface() {} setSurfaceVisible() {} submitSurfaceFrame() {} setUnderlayDim() {} setScreenBlanked() {}
compositeFrame() { return { pixels: new Uint8Array([1, 2]) }; }
} },
'../graphics/plane': { flattenPlanesWithDraws: () => ({ image: { pixels: new Uint8Array([1, 2]), width: 2, height: 1 }, draws: [] }) },
+47 -67
View File
@@ -178,9 +178,9 @@ test('session authenticates both arms, checks firmware and sends acknowledged di
assert.equal(h.session.state.charging, false);
assert.deepEqual(h.transport.sent.filter(s => s.message.sid === 128).map(s => s.id).sort(), ['L', 'R']);
h.session.setFrame(new Uint8Array(640 * 480)); await until(() => h.session.state.frames === 1);
const image = h.transport.sent.find(s => s.message.sid === p.SID.cfw && s.message.payload[0] === 6);
const image = h.transport.sent.find(s => s.message.sid === p.SID.cfw && s.message.payload[0] === 26);
assert.equal(image.id, 'L');
assert.equal(image.message.payload[0], 6);
assert.equal(image.message.payload[0], 26);
const layout = h.transport.sent.find(s => s.message.sid === p.SID.hub && s.message.command === 0);
assert.equal(p.readBytes(p.readBytes(layout.message.payload, 3), 4), undefined);
await h.session.stop();
@@ -399,14 +399,15 @@ test('CFW ACK identity and both-lens completion gate display metrics', async t =
const write = h.transport.write.bind(h.transport);
h.transport.write = async (...args) => { written += args[2].length; await write(...args); };
h.session.setFrame(new Uint8Array(640 * 480));
await until(() => imageMessages(h.transport).length === 1);
const sent = imageMessages(h.transport)[0];
await until(() => imageMessages(h.transport).length === 2);
const [draw, sent] = imageMessages(h.transport);
ack(h.transport,draw);
for (const wrong of [{ identifier: 'R' }, { size: 99 }, { checksum: 0 }, { ordinal: 1 }, { magic: sent.message.magic + 1 }]) ack(h.transport, sent, wrong);
ack(h.transport, sent, { lenses: [1] }); await tick();
assert.equal(h.session.state.frames, 0);
ack(h.transport, sent, { lenses: [2] }); await until(() => h.session.state.frames === 1);
assert.equal(iosBleTraffic.sample().bytes - before.bytes, written);
assert.equal(iosBleTraffic.sample().messages - before.messages, 1);
assert.equal(iosBleTraffic.sample().messages - before.messages, 2);
assert.equal(iosBleTraffic.sample().frames - before.frames, 1);
ack(h.transport, sent); await tick(); assert.equal(h.session.state.frames, 1);
});
@@ -421,7 +422,7 @@ test('large frames use bounded RLE bands and ordered three-message pipelining',
assert.equal(imageMessages(h.transport).length, 3); assert.equal(h.session.state.frames, 0);
ack(h.transport, first[0]); await until(() => imageMessages(h.transport).length === 6);
for (const sent of imageMessages(h.transport).slice(3)) ack(h.transport, sent);
await until(() => imageMessages(h.transport).length === 8);
await until(() => imageMessages(h.transport).length === 9);
assert.equal(h.session.state.frames, 0);
for (const sent of imageMessages(h.transport).slice(6)) ack(h.transport, sent);
await until(() => h.session.state.frames === 1);
@@ -433,19 +434,21 @@ test('large frames use bounded RLE bands and ordered three-message pipelining',
assert.deepEqual(shadow, p.packGray4(gray, 640, 480));
});
test('display pipelines A-B-A and coalesces newer waiting frames', async t => {
const h = harness(t); await h.session.start(addresses); h.transport.hold = true;
const submit = async value => { h.session.setFrame(new Uint8Array(640 * 480).fill(value)); await h.session.pump(); await tick(); };
await submit(0); await submit(0); assert.equal(imageMessages(h.transport).length, 1);
await submit(255); await submit(0); await until(() => imageMessages(h.transport).length === 3);
await submit(80); await submit(160);
const sent = imageMessages(h.transport);
ack(h.transport, sent[2]); ack(h.transport, sent[1]); await tick();
assert.equal(h.session.state.frames, 0); assert.equal(imageMessages(h.transport).length, 3);
ack(h.transport, sent[0]); await until(() => imageMessages(h.transport).length === 4);
assert.equal(h.session.state.frames, 3);
assert.deepEqual(imageBody(imageMessages(h.transport)[3]), p.concat(new Uint8Array([6]), p.rle4(p.packGray4(new Uint8Array(640 * 480).fill(160), 640, 480))));
ack(h.transport, imageMessages(h.transport)[3]); await until(() => h.session.state.frames === 4);
test('draw/present pairs pipeline and coalesce waiting frames', async t => {
const h=harness(t);await h.session.start(addresses);h.transport.hold=true;
const submit=async v=>{h.session.setFrame(new Uint8Array(640*480).fill(v));await h.session.pump();await tick();};
await submit(0);await submit(0);assert.equal(imageMessages(h.transport).length,2);
await submit(255);await until(()=>imageMessages(h.transport).length===3);
await submit(80);await submit(160);
const first=imageMessages(h.transport);ack(h.transport,first[2]);ack(h.transport,first[1]);await tick();
assert.equal(h.session.state.frames,0);assert.equal(imageMessages(h.transport).length,3);
ack(h.transport,first[0]);await until(()=>imageMessages(h.transport).length===6);
for(const message of imageMessages(h.transport).slice(3)) ack(h.transport,message);
await until(()=>h.session.state.frames===3);
const {applyDisplayPayload}=require('./helpers/display-payload.cjs');let screen=new Uint8Array(320*480);
for(const {message} of imageMessages(h.transport)) screen=applyDisplayPayload(screen,message.payload);
assert.deepEqual(screen,p.packGray4(new Uint8Array(640*480).fill(160),640,480));
assert.deepEqual(imageMessages(h.transport).map(s=>s.message.payload[0]),[26,28,26,28,26,28]);
});
test('NACK replays the unresolved window with fresh IDs and reset compression; stale ACKs are ignored', async t => {
@@ -459,6 +462,8 @@ test('NACK replays the unresolved window with fresh IDs and reset compression; s
for (const sent of old) ack(h.transport, sent);
await tick(); assert.equal(h.session.state.frames, 0);
replay.forEach((sent, i) => { assert.notEqual(sent.message.magic, old[i].message.magic); assert.ok(sent.message.flags & 8); assert.deepEqual(sent.message.payload, old[i].message.payload); ack(h.transport, sent); });
await until(() => imageMessages(h.transport).length === 9);
imageMessages(h.transport).slice(6).forEach(sent=>ack(h.transport,sent));
await until(() => h.session.state.frames === 3);
});
@@ -470,10 +475,10 @@ test('timeout starts after writes; missing ACK retries are bounded and invalidat
h.session.setFrame(new Uint8Array(640 * 480)); await h.session.pump();
await new Promise(resolve => setTimeout(resolve, 550));
assert.equal(h.session.state.phase, 'connected'); assert.equal(imageMessages(h.transport).length, 0);
release(); await until(() => imageMessages(h.transport).length === 1); await tick();
release(); await until(() => imageMessages(h.transport).length === 2); await tick();
for (let i = 1; i <= 4; i++) {
h.session.cfwPending.forEach(p => p.deadline = 1); h.session.recoverCfw();
if (i < 4) await until(() => imageMessages(h.transport).length === i + 1);
if (i < 4) await until(() => imageMessages(h.transport).length === 2 * (i + 1));
}
assert.equal(h.session.state.phase, 'retrying'); assert.match(h.session.state.status, /retry limit/);
assert.equal(h.session.lastEnqueued, null); assert.equal(h.session.cfwPending.length, 0);
@@ -509,55 +514,30 @@ test('full display window still services input and microphone control', async t
assert.deepEqual(audio, ['010203']); assert.equal(h.session.displayInFlight, 3);
});
test('pipelined bounding boxes reconstruct moving and erased content against the last queued frame', async t => {
const { applyDisplayPayload } = require('./helpers/display-payload.cjs');
const h = harness(t); await h.session.start(addresses); h.transport.hold = true;
const base = new Uint8Array(640 * 480), a = base.slice(), b = base.slice();
a[11 * 640 + 13] = 255; b[11 * 640 + 101] = 160;
const frames = [base, a, b];
for (let i = 0; i < frames.length; i++) {
h.session.setFrame(frames[i]); await h.session.pump();
await until(() => imageMessages(h.transport).length === i + 1);
test('draw updates reconstruct moving and erased pixels while present gates frame completion', async t => {
const {applyDisplayPayload}=require('./helpers/display-payload.cjs');
const h=harness(t);await h.session.start(addresses);h.transport.hold=true;
const base=new Uint8Array(640*480),a=base.slice(),b=base.slice();a[11*640+13]=255;b[11*640+101]=160;
let screen=new Uint8Array(320*480);
for(const [i,frame] of [base,a,b,base].entries()) {
h.session.setFrame(frame);await h.session.pump();await until(()=>imageMessages(h.transport).length===(i+1)*2);
const [draw,present]=imageMessages(h.transport).slice(i*2);
assert.equal(draw.message.payload[0],26);assert.equal(present.message.payload[0],28);
screen=applyDisplayPayload(screen,draw.message.payload);assert.deepEqual(screen,p.packGray4(frame,640,480));
ack(h.transport,draw);await tick();assert.equal(h.session.state.frames,i);
ack(h.transport,present);await until(()=>h.session.state.frames===i+1);
}
const messages = imageMessages(h.transport), payloads = messages.map(m => imageBody(m));
assert.deepEqual(payloads.map(b => b[0]), [6, 3, 3]);
assert.deepEqual(payloads.slice(1).map(b => b[5] | (b[6] << 8)), [1, 2]);
assert.equal(h.session.state.frames, 0); // All three updates precede any ACK.
let shadow = new Uint8Array(320 * 480);
for (let i = 0; i < payloads.length; i++) {
shadow = applyDisplayPayload(shadow, payloads[i]);
assert.deepEqual(shadow, p.packGray4(frames[i], 640, 480));
}
// A late ACK for the old full frame must not replace the delta comparison base.
ack(h.transport, messages[0]); await until(() => h.session.state.frames === 1);
h.session.setFrame(base); await h.session.pump();
await until(() => imageMessages(h.transport).length === 4);
const clear = imageBody(imageMessages(h.transport)[3]);
assert.equal(clear[0], 3); assert.equal(clear[1], 25); // Only B's dot needs clearing.
assert.deepEqual(applyDisplayPayload(shadow, clear), p.packGray4(base, 640, 480));
for (const message of imageMessages(h.transport).slice(1)) ack(h.transport, message);
await until(() => h.session.state.frames === 4);
assert.equal(imageMessages(h.transport)[2].message.payload[7],0); // compact bbox
});
test('delta ids skip reserved values and advance only on emitted deltas; reconnect reseeds with a full frame', async t => {
const h = harness(t); await h.session.start(addresses);
const submit = async gray => {
const before = h.session.state.frames; h.session.setFrame(gray);
await until(() => h.session.state.frames === before + 1);
return imageBody(imageMessages(h.transport).at(-1));
};
const base = new Uint8Array(640 * 480), next = base.slice(); next[1234] = 255;
assert.equal((await submit(base))[0], 6);
h.session.nextImageFrameId = 0xfffe;
const delta = await submit(next); assert.equal(delta[5] | (delta[6] << 8), 0xfffe);
h.session.setFrame(next); await h.session.pump(); await tick();
assert.equal(h.session.nextImageFrameId, 1);
const full = await submit(new Uint8Array(640 * 480).fill(255)); assert.equal(full[0], 6);
assert.equal(h.session.nextImageFrameId, 1);
const clear = await submit(next); assert.equal(clear[0], 6); // Whole-screen bounding box.
const wrapped = await submit(base); assert.equal(wrapped[5] | (wrapped[6] << 8), 1);
await h.session.stop(); await h.session.start(addresses);
assert.equal((await submit(base))[0], 6); // Even the same pixels need a trusted full base.
test('reconnect reseeds the screen and unified draw calls carry no legacy frame id', async t => {
const h=harness(t);await h.session.start(addresses);
const submit=async gray=>{const before=h.session.state.frames;h.session.setFrame(gray);await until(()=>h.session.state.frames===before+1);return imageBody(imageMessages(h.transport).at(-2));};
const base=new Uint8Array(640*480),next=base.slice();next[1234]=255;
assert.equal((await submit(base))[7],1); // wide full-screen bounds
const delta=await submit(next);assert.equal(delta[7],0); // compact bbox, immediately followed by RLE
const count=imageMessages(h.transport).length;h.session.setFrame(next);await h.session.pump();await tick();assert.equal(imageMessages(h.transport).length,count);
await h.session.stop();await h.session.start(addresses);assert.equal((await submit(next))[7],1);
});
const compassMessages = transport => transport.sent.filter(s => s.message.sid === p.SID.cfw && s.message.payload[0] === 10);
+6 -6
View File
@@ -48,7 +48,7 @@ function fixture() {
isScreenOn: () => screenOn, getWindows: () => [window], foregroundWindow: () => window,
setBatteryLevels() {}, underlayDim: () => 1, getFocus: () => 'app', hasOverlay: () => false,
describeInputTarget: () => 'test app',
paintSurface: () => [{ image: new images.GrayImage(640, 480, 0), x: 0, y: 0 }],
paintScene: () => new Uint8Array([0, 0]), paintSurface: () => [{ image: new images.GrayImage(640, 480, 0), x: 0, y: 0 }],
receiveInput: async input => {
received.push(input);
if (input.type === 'display-wake' || !screenOn && input.type === 'double-click') shell.wake();
@@ -179,17 +179,17 @@ test('double-tap and other shell wakes replace Glanceboard without waking it aga
const f = fixture(); await f.controller.connect(); f.shell.sleep();
await f.hardware(9); await f.hardware(3);
assert.equal(f.shell.isScreenOn(), true); assert.equal(f.controller.glance.isVisible(), false);
assert.equal(f.sent.at(-1)[0], 75); assert.equal(f.boardStats.stops, 1);
assert.equal(f.sent.at(-1)[0], 80); assert.equal(f.boardStats.stops, 1);
f.shell.sleep(); await f.hardware(0); f.shell.wake(); await f.render();
assert.equal(f.controller.glance.isVisible(), false); assert.equal(f.sent.at(-1)[0], 75);
await f.advance(5000); await f.render(); assert.equal(f.sent.at(-1)[0], 75);
assert.equal(f.controller.glance.isVisible(), false); assert.equal(f.sent.at(-1)[0], 80);
await f.advance(5000); await f.render(); assert.equal(f.sent.at(-1)[0], 80);
});
test('head tilt uses Glanceboard when enabled and otherwise wakes the regular UI', async () => {
const f = fixture(); await f.controller.connect(); f.shell.sleep();
await f.hardware(12, 1); assertBoard(f.sent.at(-1)); assert.equal(f.shell.isScreenOn(), false);
await f.hardware(3); f.shell.sleep(); f.settings.tilt = false;
await f.hardware(12, 1); assert.equal(f.shell.isScreenOn(), true); assert.equal(f.sent.at(-1)[0], 75);
await f.hardware(12, 1); assert.equal(f.shell.isScreenOn(), true); assert.equal(f.sent.at(-1)[0], 80);
});
test('disabled triggers and scrolls do not show the board; awake taps still reach the shell', async () => {
@@ -234,7 +234,7 @@ test('iOS lock hides apps and Glanceboard, blocks input, and stays locked when p
await f.hardware(12, 1); assert.ok(f.sent.at(-1).every(p => p === 123));
f.observers.get('unlock')(); await f.render();
assert.equal(f.controller.glassesLocked, false);
assert.equal(f.sent.at(-1)[0], 75);
assert.equal(f.sent.at(-1)[0], 80);
await f.hardware(0); assert.equal(f.received.length, 1);
});
@@ -0,0 +1,83 @@
package com.faceclaw.app
import kotlin.test.*
class DisplayListTest {
private fun hex(s: String) = s.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
@Test fun oddPixelsRawRleClippingFontsNestedListsAndLut() {
val raw = DrawProtocol.rawImage(3, 3, hex("123045607890"))
val font = ByteArray(197); font[0]=1; font[67]=193.toByte(); hex("0801011f").copyInto(font,193)
val resources = mutableMapOf(10 to raw, 11 to hex("0802024f"), 12 to font)
val nested = listOf(DrawProtocol.image(11, -1, 0), DrawProtocol.bbox(hex("0c000000"), 2, 1, 0, 1, 1, 10))
resources[20]=DrawProtocol.displayList(nested)
val calls = listOf(DrawProtocol.call(7,DrawProtocol.word(20)), DrawProtocol.image(10,3,1),
DrawProtocol.call(5,hex("0c00070003000f0141")), DrawProtocol.lut(8,4,128))
resources[21]=DrawProtocol.displayList(calls)
val screen=hex("123456789abcdef0123456789abcdef0"); val output=ByteArray(16)
val renderer=DisplayListRenderer(resources)
assertEquals(setOf(10,11,12,20,21),renderer.render(21,DisplayListRenderer.Target(screen,8,4),DisplayListRenderer.Target(output,8,4)))
// Shared with the C sanitizer harness: signed clipping, resource target override, font and LUT.
assertContentEquals(hex("71122334755061700112233445534477"),output)
val first=output.copyOf(); renderer.render(21,DisplayListRenderer.Target(screen,8,4),DisplayListRenderer.Target(output,8,4))
assertContentEquals(first,output)
assertContentEquals(hex("123456789abcdef0123456789abcdef0"),screen)
}
@Test fun graphValidationPrecedesMutationAndCopyPreservesOverlap() {
val screen=hex("12345678"); val target=DisplayListRenderer.Target(screen,8,1)
val copy=DrawProtocol.call(2,hex("feff000000000600010002000000"))
DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(copy)),target)
assertContentEquals(hex("12123456"),screen)
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)
val cyclic=mapOf(1 to DrawProtocol.displayList(listOf(DrawProtocol.call(7,DrawProtocol.word(2)))),
2 to DrawProtocol.displayList(listOf(DrawProtocol.call(7,DrawProtocol.word(1)))))
assertFails { DisplayListRenderer(cyclic).render(1,target,target) }
}
private class Glasses {
val resources=mutableMapOf<Int,ByteArray>(); val screen=ByteArray(640*480/2);val composition=ByteArray(screen.size)
var root=65535
fun apply(commands: List<ByteArray>) {
for(b in commands) when(b[0].toInt()) {
21 -> { var p=3;repeat(DrawProtocol.u16(b,1)) {
val id=DrawProtocol.u16(b,p); val total=DrawProtocol.u16(b,p+2) or (DrawProtocol.u16(b,p+4) shl 16)
val offset=DrawProtocol.u16(b,p+6);val n=DrawProtocol.u16(b,p+8)
b.copyInto(resources.getOrPut(id){ByteArray(total)},offset,p+10,p+10+n);p+=10+n
} }
22 -> repeat(DrawProtocol.u16(b,1)) { resources.remove(DrawProtocol.u16(b,3+it*2)) }
29 -> repeat(DrawProtocol.u16(b,1)) { val p=3+it*6;resources.getOrPut(DrawProtocol.u16(b,p)) { DrawProtocol.rawImage(DrawProtocol.u16(b,p+2),DrawProtocol.u16(b,p+4)) } }
26 -> DisplayListRenderer(resources).execute(b.copyOfRange(1,b.size),DisplayListRenderer.Target(screen,640,480))
27 -> root=DrawProtocol.u16(b,1)
28 -> DisplayListRenderer(resources).render(root,DisplayListRenderer.Target(screen,640,480),DisplayListRenderer.Target(composition,640,480))
else -> error("legacy command ${b[0]}")
}
}
}
@Test fun persistentShellUpdatesDoNotPolluteScreenAndClosingRevealsCurrentApp() {
val cache=ResourceCacheState();val planner=ScenePlanner(cache);val glasses=Glasses()
val app=ByteArray(640*480/2){0x99.toByte()}
val overlay=ShellScene(listOf(ShellScene.Layer(1,0,0,3,3,128,hex("fff0fff0fff0"))))
val first=planner.plan(app,640,480,null,overlay,1);glasses.apply(first.commands)
assertContentEquals(app,glasses.screen);assertEquals(255,glasses.composition[0].toInt() and 255)
assertEquals(0x44,glasses.composition[100].toInt() and 255)
val changed=ShellScene(listOf(ShellScene.Layer(1,0,0,3,3,128,hex("111011101110"))))
val repaint=planner.plan(app,640,480,null,changed,1)
assertFalse(repaint.commands.any { it[0].toInt() in listOf(21,22,29) })
glasses.apply(repaint.commands);assertContentEquals(app,glasses.screen)
val newer=app.copyOf();newer[0]=0x22
glasses.apply(planner.plan(newer,640,480,null,changed,1).commands)
glasses.apply(planner.plan(newer,640,480,null,ShellScene.EMPTY,1).commands)
assertContentEquals(newer,glasses.composition)
cache.reset();val reconnect=planner.plan(newer,640,480,null,changed,1)
assertTrue(reconnect.commands.any { it[0].toInt()==29 });glasses.apply(reconnect.commands)
assertContentEquals(newer,glasses.screen)
}
@Test fun noisyFramesRemainBoundedAndResourceBudgetIs192KiB() {
val cache=ResourceCacheState();val planner=ScenePlanner(cache);val glasses=Glasses()
val app=ByteArray(640*480/2){(it*37).toByte()}
val plan=planner.plan(app,640,480,null,ShellScene.EMPTY,1)
assertTrue(plan.commands.all { it.size<=65535 });glasses.apply(plan.commands)
assertContentEquals(app,glasses.screen);assertContentEquals(app,glasses.composition)
assertEquals(196608,ResourceCacheState.CACHE_SIZE)
}
}
@@ -64,7 +64,7 @@ class ResourceCacheTest {
@Test fun lruEvictsByBytesAndProtectsAllCurrentFrameHits() {
val cache = ResourceCacheState()
val a = resource(65536, 1); val b = resource(65536, 2); val c = resource(65536, 3); val d = resource(65536, 4)
val a = resource(60000, 1); val b = resource(60000, 2); val c = resource(60000, 3); val d = resource(60000, 4)
assertContentEquals(intArrayOf(0, 1, 2), cache.prepare(listOf(a, b, c)))
cache.drainCommands(3600)
cache.prepare(listOf(a)); cache.drainCommands(3600) // b is oldest now.
@@ -142,12 +142,12 @@ class ResourceCacheTest {
@Test fun fontTablesUseRelativeU16OffsetsAndGrowOnDemand() {
val id = registerFont("resource-font-relative", listOf(65, 66))
val first = FontResourceAtlas.get(id, setOf(65))
assertEquals(192, u16(first.resource.bytes, (65 - 32) * 2))
assertEquals(0, u16(first.resource.bytes, (66 - 32) * 2))
assertEquals(193, u16(first.resource.bytes, 1 + (65 - 32) * 2))
assertEquals(0, u16(first.resource.bytes, 1 + (66 - 32) * 2))
assertSame(first, FontResourceAtlas.get(id, setOf(65)))
val second = FontResourceAtlas.get(id, setOf(66))
assertTrue(second.encodings.containsAll(setOf(65, 66)))
assertEquals(192 + GlyphAtlas.get(id, 65)!!.cachedBytes.size, u16(second.resource.bytes, (66 - 32) * 2))
assertEquals(193 + GlyphAtlas.get(id, 65)!!.cachedBytes.size, u16(second.resource.bytes, 1 + (66 - 32) * 2))
val cache = ResourceCacheState()
cache.prepare(listOf(second.resource)); val commands = cache.drainCommands(3600)
assertContentEquals(second.resource.bytes, uploaded(commands).getValue(0))
@@ -160,7 +160,7 @@ class ResourceCacheTest {
val b = FontResourceAtlas.get(id, setOf(66))
assertEquals(setOf(66), b.encodings)
assertTrue(b.resource.bytes.size <= 65536)
assertEquals(0, u16(b.resource.bytes, (65 - 32) * 2))
assertEquals(192, u16(b.resource.bytes, (66 - 32) * 2))
assertEquals(0, u16(b.resource.bytes, 1 + (65 - 32) * 2))
assertEquals(193, u16(b.resource.bytes, 1 + (66 - 32) * 2))
}
}
@@ -24,9 +24,9 @@ class IosTextureApiTest {
val next = IosProtocol().pack(frame.pixels, 8, 4)
val planner = IosTexturePlanner()
val cold = assertNotNull(planner.plan(null, next, frame, 1))
assertEquals(22, cold.resourceCommands.first().byteArray()[0].toInt())
assertEquals(27, cold.resourceCommands.first().byteArray()[0].toInt())
assertTrue(cold.resourceCommands.any { it.byteArray()[0].toInt() == 21 })
assertEquals(8, cold.payload.byteArray()[0].toInt())
assertEquals(28, cold.payload.byteArray()[0].toInt())
val warm = assertNotNull(planner.plan(null, next, frame, 1))
assertTrue(warm.resourceCommands.isEmpty())
assertContentEquals(cold.payload.byteArray(), warm.payload.byteArray())
@@ -52,10 +52,11 @@ class IosTextureApiTest {
val frame = compositor.compositeFrame()
val plan = assertNotNull(IosTexturePlanner().plan(null, IosProtocol().pack(frame.pixels, 4, 2), frame, 1))
assertTrue(plan.usedBytes > 2048 + 192)
val payload = plan.payload.byteArray()
// The last mode-8 submessage is the shared mode-20 cached glyph run.
assertEquals(20, payload[payload.size - 10].toInt())
assertEquals(65, payload.last().toInt())
assertEquals(28, plan.payload.byteArray()[0].toInt())
assertTrue(plan.resourceCommands.any { command ->
val bytes = command.byteArray()
bytes[0].toInt() == 26 && bytes.last().toInt() == 65
})
}
@Test
@@ -76,7 +77,9 @@ class IosTextureApiTest {
compositor.submitDraws("noise", gray.data(), 0, 0, 640, 480, imageDraw(id).data())
val frame = compositor.compositeFrame()
val planner = IosTexturePlanner()
assertNull(planner.plan(null, IosProtocol().pack(frame.pixels, 640, 480), frame, 1))
val noisy = assertNotNull(planner.plan(null, IosProtocol().pack(frame.pixels, 640, 480), frame, 1))
assertTrue(noisy.resourceCommands.all { it.length <= 65535uL })
planner.reset()
val small = IosSurfaceCompositor(4, 2)
small.configure("icon", 0, 0, 2, 2, 0, false)
small.submitDraws("icon", white, 0, 0, 2, 2, imageDraw(id).data())