forked from Blendman974/faceclaw
Add animations to launcher and Files app
This commit is contained in:
1 parent
7ad9fe10ad
commit
b0a98f5942
24 files changed
+1608
-738
No files matched your search
@@ -85,3 +85,45 @@ test('frame submission supports resource-free lists and plain PRESENT-relative t
|
||||
paintDisplayList(output,screen,8,8,placed,false,1002);
|
||||
assert.equal(output[2],240); assert.equal(output[0],0);
|
||||
});
|
||||
|
||||
// Also consumed by FrameDisplayListTest.kt, with 0xbeef / 0xcafebabe replaced by
|
||||
// the font and image ids it registers: a clipped clear, a clipped rounded rect,
|
||||
// and replayed glyph + icon draws clipped while sliding up. REPLAY_PIXELS is
|
||||
// what the list paints over a nibble-1 screen, 16x8 at 4 bits per pixel.
|
||||
const REPLAY = '0780000000020003000800040000070000006400000000000300890000000000000600040002880000010001000200020000000400030000000510a00000000000000600040000ff2502000080c002000000000180c8800180c8161101001732800180c81610300180c830234031020000efbe4100000000000000ff01bebafeca04000100';
|
||||
const REPLAY_PIXELS = '11111111111111111111111111111111111111111111111111fff28f111111111125522211111111112552221111111111222222111111111111111111111111';
|
||||
|
||||
function replayList() {
|
||||
// 'A' is 3x2 ink one row below a 4px line top; the icon is 2x2.
|
||||
const font = { fingerprintId: 9001, atlasKey: 'stub-font', ascent: 3, lineHeight: 4 };
|
||||
const glyph = { encoding: 65, bbxWidth: 3, bbxHeight: 2, bbxX: 0, bbxY: 0, bitmapRows: [0xa0, 0xe0] };
|
||||
const icon = new GrayImage(2, 2); icon.pixels.set([255, 0, 128, 255]);
|
||||
const source = new GrayImage(8, 4);
|
||||
source.drawGlyph(font, glyph, 0, 0, 255);
|
||||
source.drawImage(icon, 4, 1);
|
||||
const records = Uint8Array.from([0, 0xef, 0xbe, 65, 0, 0, 0, 0, 0, 0, 0, 255, 1, 0xbe, 0xba, 0xfe, 0xca, 4, 0, 1, 0]);
|
||||
const clip = { x: 0, y: 0, width: 6, height: 4 };
|
||||
return { x: 2, y: 3, width: 8, height: 4, depth: 0, displayList: { resources: [], timeline: { token: 7, startedAt: 1000 }, calls: [
|
||||
{ op: DrawOp.CLEAR, color: 2, clip },
|
||||
{ op: DrawOp.ROUNDED_RECT, x: 0, y: 0, width: 4, height: 3, radius: 0, background: 5, border: 16, clip: { x: 1, y: 1, width: 2, height: 2 } },
|
||||
{ op: DrawOp.DRAWS, x: 0, y: E.progress(200).lerp(E.f32(-4), E.f32(0)).toInt(), records, count: 2, source, clip },
|
||||
] } };
|
||||
}
|
||||
|
||||
test('clipped clears, rects and replayed draws encode, decode and paint', () => {
|
||||
const placed = replayList();
|
||||
const hex = Buffer.from(encodeDisplayList(placed, 1100)).toString('hex');
|
||||
const output = new Uint8Array(16 * 8).fill(16);
|
||||
paintDisplayList(output, output.slice(), 16, 8, placed, false, 1100);
|
||||
const nibbles = Array.from(output, (v) => (Math.min(15, (v + 8) >> 4)).toString(16)).join('');
|
||||
assert.equal(hex, REPLAY);
|
||||
assert.equal(nibbles, REPLAY_PIXELS);
|
||||
const decoded = readDisplayList(Buffer.from(REPLAY, 'hex'), 0, 1100).placed;
|
||||
const [clear, rect, draws] = decoded.displayList.calls;
|
||||
assert.deepEqual([clear.op, clear.color, clear.clip], [DrawOp.CLEAR, 2, { x: 0, y: 0, width: 6, height: 4 }]);
|
||||
assert.deepEqual(rect.clip, { x: 1, y: 1, width: 2, height: 2 });
|
||||
assert.equal(draws.count, 2);
|
||||
assert.deepEqual(Array.from(draws.records), Array.from(placed.displayList.calls[2].records));
|
||||
assert.equal(draws.source, undefined, 'decoded draws have no software source');
|
||||
assert.throws(() => readDisplayList(Buffer.from(REPLAY.replace('01bebafeca', '05bebafeca'), 'hex'), 0, 1100), /draw record/);
|
||||
});
|
||||
@@ -0,0 +1,300 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const vm = require('node:vm');
|
||||
const ts = require('typescript');
|
||||
const build = (name) => require(`../.test-build/app/${name}.js`);
|
||||
const metrics = build('ui/metrics');
|
||||
const { GrayImage } = build('graphics/image');
|
||||
const { DrawOp } = build('graphics/display-list');
|
||||
const { MENU_HIGHLIGHT_DURATION_MS } = build('ui/menu-highlight-motion');
|
||||
const { MENU_BOUNCE_DURATION_MS } = build('ui/menu-scroll-motion');
|
||||
|
||||
const LINE_HEIGHT = 21;
|
||||
// icon 44 + label gap 2 + line 21 + 8 breathing room.
|
||||
const ROW_H = 75;
|
||||
|
||||
/** A font whose every glyph is a 4x6 block, drawn as deferred glyph draws like a real atlas font. */
|
||||
function stubFont() {
|
||||
const glyphs = new Map();
|
||||
const glyph = (cp) => {
|
||||
if (!glyphs.has(cp)) glyphs.set(cp, { encoding: cp, bbxWidth: 4, bbxHeight: 6, bbxX: 0, bbxY: 0, bitmapRows: Array(6).fill(0xf0) });
|
||||
return glyphs.get(cp);
|
||||
};
|
||||
const font = {
|
||||
fingerprintId: 77, atlasKey: 'stub', ascent: 15, descent: 6, lineHeight: LINE_HEIGHT,
|
||||
measureText: (text) => text.length * 6,
|
||||
getGlyph: glyph,
|
||||
hasGlyph: () => true,
|
||||
drawText(image, x, y, text, value) {
|
||||
let pen = x;
|
||||
for (const ch of text) { image.drawGlyph(font, glyph(ch.codePointAt(0)), pen, y, value); pen += 6; }
|
||||
},
|
||||
};
|
||||
return font;
|
||||
}
|
||||
|
||||
/** Transpile one module with its imports resolved from `deps`. */
|
||||
function load(file, deps) {
|
||||
const exports = {};
|
||||
const source = fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
|
||||
vm.runInNewContext(ts.transpileModule(source, {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
||||
}).outputText, { exports, console, Date, require(name) {
|
||||
assert.ok(name in deps, `Unexpected import ${name} in ${file}`);
|
||||
return deps[name];
|
||||
} });
|
||||
return exports;
|
||||
}
|
||||
|
||||
function loadIconGrid({ lastInputWasWatch = false } = {}) {
|
||||
const font = stubFont();
|
||||
const state = { replayable: true };
|
||||
const common = {
|
||||
'../graphics/image': build('graphics/image'),
|
||||
'../graphics/textwrap': build('graphics/textwrap'),
|
||||
'../graphics/ui-fonts': { getDefaultSmallFont: () => font },
|
||||
'../util/numeric-util': build('util/numeric-util'),
|
||||
'./gestures': build('ui/gestures'),
|
||||
'./menu-core': build('ui/menu-core'),
|
||||
'./metrics': metrics,
|
||||
};
|
||||
const menu = load('app/ui/menu.ts', { ...common, './layers': {} });
|
||||
const grid = load('app/ui/icon-grid.ts', {
|
||||
...common,
|
||||
'../graphics/draw-expression': build('graphics/draw-expression'),
|
||||
'../graphics/display-list': build('graphics/display-list'),
|
||||
// Registration is native; any draws are replayable unless a test says not.
|
||||
'../graphics/glyph-wire': { encodeReplayDraws: (draws) => state.replayable ? { records: new Uint8Array(0), count: draws.length } : null },
|
||||
'../graphics/menu-scroll-list': build('graphics/menu-scroll-list'),
|
||||
'./menu': menu,
|
||||
'./menu-highlight-motion': build('ui/menu-highlight-motion'),
|
||||
'./menu-scroll-motion': build('ui/menu-scroll-motion'),
|
||||
'./shell/shell': { shell: { lastInputWasWatch: () => lastInputWasWatch } },
|
||||
'./layers': {},
|
||||
});
|
||||
return { ...grid, state };
|
||||
}
|
||||
|
||||
const ICON = new GrayImage(44, 44);
|
||||
ICON.fillRect(10, 10, 24, 24, 200);
|
||||
const ring = (type) => ({ type });
|
||||
const watch = (type) => ({ type, source: 'watch' });
|
||||
const BOX = { x: 0, y: 10, width: 500, height: 180 };
|
||||
|
||||
function makeGrid({ items = Array.from({ length: 12 }, (_, i) => `item${i}`), isWide, onActivate, onBack, watchLast } = {}) {
|
||||
const { IconGrid, state } = loadIconGrid({ lastInputWasWatch: watchLast });
|
||||
const log = { activated: [], backs: 0 };
|
||||
const data = { items };
|
||||
const grid = new IconGrid({
|
||||
items: () => data.items,
|
||||
isWide,
|
||||
describe: (item) => ({ label: item, icon: ICON }),
|
||||
onActivate: onActivate ?? ((item, index) => { log.activated.push({ item, index }); }),
|
||||
onBack: onBack ?? (() => { log.backs++; return false; }),
|
||||
});
|
||||
return { grid, log, data, state };
|
||||
}
|
||||
|
||||
function withClock(now, fn) {
|
||||
const original = Date.now;
|
||||
Date.now = () => now;
|
||||
try { return fn(); } finally { Date.now = original; }
|
||||
}
|
||||
|
||||
function paint(grid, now, box = BOX) {
|
||||
return withClock(now, () => {
|
||||
const image = new GrayImage(500, 200);
|
||||
grid.paint(image, box, true);
|
||||
return image;
|
||||
});
|
||||
}
|
||||
|
||||
const animation = (image) => image.draws.find((draw) => draw.presentation?.displayList)?.presentation.displayList;
|
||||
|
||||
/** What the glasses show at `at`, as 4-bit values. */
|
||||
function shown(image, at) {
|
||||
return withClock(at, () => Array.from(image.withDrawsBaked().pixels, (v) => Math.min(15, (v + 8) >> 4)));
|
||||
}
|
||||
|
||||
test('rows keep their content height instead of stretching, and the next row peeks clipped', () => {
|
||||
assert.equal(metrics.iconGridMinRowHeight({ lineHeight: LINE_HEIGHT }, 44, 2), ROW_H);
|
||||
const { grid } = makeGrid({ items: Array.from({ length: 15 }, (_, i) => `item${i}`) });
|
||||
const image = paint(grid, 1000);
|
||||
const iconYs = [...new Set(image.draws.filter((d) => d.kind === 'image' && !d.presentation).map((d) => d.y))];
|
||||
assert.deepEqual(iconYs, [14, 14 + ROW_H], 'full rows are deferred draws at the natural pitch');
|
||||
const glyphYs = [...new Set(image.draws.filter((d) => d.kind === 'glyph').map((d) => d.y))];
|
||||
assert.deepEqual(glyphYs, [60, 60 + ROW_H], 'labels of full rows only');
|
||||
// The third row's top is baked into the raster, cut off at the box bottom (y 190).
|
||||
const peekTop = 14 + 2 * ROW_H;
|
||||
assert.ok(image.pixels[(peekTop + 15) * 500 + 60] > 0, 'the peeking icon shows');
|
||||
for (let y = 190; y < 200; y++) for (let x = 0; x < 500; x++) assert.equal(image.pixels[y * 500 + x], 0, `nothing below the box at (${x}, ${y})`);
|
||||
assert.equal(animation(image), undefined, 'a first paint does not animate');
|
||||
});
|
||||
|
||||
test('the pitch only changes with the font, not with how many rows fit', () => {
|
||||
const { grid } = makeGrid();
|
||||
for (const height of [150, 180, 224]) {
|
||||
const image = paint(grid, 1000, { x: 0, y: 0, width: 500, height });
|
||||
const ys = [...new Set(image.draws.filter((d) => d.kind === 'image').map((d) => d.y))];
|
||||
for (let i = 1; i < ys.length; i++) assert.equal(ys[i] - ys[i - 1], ROW_H, `height ${height}`);
|
||||
}
|
||||
});
|
||||
|
||||
test('scrolling rows into view animates from the old paint to the new one', async () => {
|
||||
const { grid } = makeGrid({ items: Array.from({ length: 15 }, (_, i) => `item${i}`) });
|
||||
paint(grid, 500);
|
||||
await grid.handleInput(ring('scroll-down'), null);
|
||||
const before = paint(grid, 1000);
|
||||
assert.equal(animation(before) !== undefined, true, 'moving the band animates its slide');
|
||||
const settledBefore = paint(grid, 2000);
|
||||
await grid.handleInput(ring('scroll-down'), null);
|
||||
const moving = paint(grid, 3000);
|
||||
const list = animation(moving);
|
||||
assert.ok(list, 'the scroll is retained as a display list');
|
||||
assert.deepEqual(Array.from(list.calls, (c) => c.op), [DrawOp.CLEAR, DrawOp.ROUNDED_RECT, DrawOp.DRAWS]);
|
||||
assert.ok(list.calls.every((c) => c.clip && c.clip.width === 500 && c.clip.height === 180), 'every call is clipped to the box');
|
||||
// First and last frames match the static paints on either side.
|
||||
assert.deepEqual(shown(moving, 3000), shown(settledBefore, 2000));
|
||||
const end = 3000 + MENU_HIGHLIGHT_DURATION_MS;
|
||||
const settled = paint(grid, end);
|
||||
assert.equal(animation(settled), undefined, 'the static paint takes over once the animation ends');
|
||||
assert.deepEqual(shown(moving, end), shown(settled, end));
|
||||
const middle = shown(moving, 3000 + MENU_HIGHLIGHT_DURATION_MS / 2);
|
||||
assert.notDeepEqual(middle, shown(settled, end));
|
||||
assert.notDeepEqual(middle, shown(settledBefore, 2000));
|
||||
});
|
||||
|
||||
test('item selection slides the highlight between cells without redrawing past the scrollbar gutter', async () => {
|
||||
const { IconGrid } = loadIconGrid();
|
||||
const grid = new IconGrid({
|
||||
items: () => Array.from({ length: 30 }, (_, i) => `item${i}`),
|
||||
describe: (item) => ({ label: item, icon: ICON }), onActivate: () => {}, onBack: () => false, scrollbar: true,
|
||||
});
|
||||
paint(grid, 500);
|
||||
await grid.handleInput(ring('click'), null);
|
||||
const before = paint(grid, 1000);
|
||||
assert.equal(animation(before), undefined, 'entering item mode snaps');
|
||||
await grid.handleInput(ring('scroll-down'), null);
|
||||
const moving = paint(grid, 2000);
|
||||
const list = animation(moving);
|
||||
assert.ok(list);
|
||||
assert.equal(list.calls[0].clip.width, 495, 'the scrollbar gutter is left to the static paint');
|
||||
const rect = list.calls[1];
|
||||
const { evaluate } = build('graphics/draw-expression');
|
||||
assert.equal(evaluate(rect.x, 0).value, 200 + 6, 'starts on the middle cell');
|
||||
assert.equal(evaluate(rect.x, MENU_HIGHLIGHT_DURATION_MS).value, 300 + 6, 'rests on the next cell');
|
||||
assert.deepEqual(shown(moving, 2000), shown(before, 1000));
|
||||
const end = 2000 + MENU_HIGHLIGHT_DURATION_MS;
|
||||
assert.deepEqual(shown(moving, end), shown(paint(grid, end), end));
|
||||
});
|
||||
|
||||
test('navigating past an end bounces and comes back', async () => {
|
||||
const { grid } = makeGrid();
|
||||
const rest = paint(grid, 1000);
|
||||
await grid.handleInput(ring('scroll-up'), null);
|
||||
const bouncing = paint(grid, 2000);
|
||||
const list = animation(bouncing);
|
||||
assert.ok(list, 'a bounce at the top is animated');
|
||||
assert.deepEqual(shown(bouncing, 2000), shown(rest, 1000));
|
||||
const peak = shown(bouncing, 2000 + Math.round(MENU_BOUNCE_DURATION_MS * 0.35));
|
||||
assert.notDeepEqual(peak, shown(rest, 1000), 'the rows move down past the top');
|
||||
// The first icon row moved 24px down (0.4 of a row, capped); the highlight moved with it.
|
||||
// Column 0's icon ink spans x 38..61 at 4-bit level 13.
|
||||
const iconTop = (image) => { for (let y = 10; y < 200; y++) if (image[y * 500 + 50] === 13) return y; };
|
||||
assert.equal(iconTop(peak) - iconTop(shown(rest, 1000)), 24);
|
||||
assert.deepEqual(shown(bouncing, 2000 + MENU_BOUNCE_DURATION_MS), shown(rest, 1000));
|
||||
});
|
||||
|
||||
test('unreplayable rows, host navigation and taps snap', async () => {
|
||||
const { grid, state } = makeGrid({ onBack: () => { grid.resetSelection(); return false; } });
|
||||
paint(grid, 1000);
|
||||
state.replayable = false;
|
||||
await grid.handleInput(ring('scroll-down'), null);
|
||||
assert.equal(animation(paint(grid, 2000)), undefined, 'rows that cannot be replayed snap');
|
||||
state.replayable = true;
|
||||
assert.equal(animation(paint(grid, 2100)), undefined, 'the cancelled motion does not resume');
|
||||
await grid.handleInput(ring('double-click'), null);
|
||||
assert.equal(animation(paint(grid, 3000)), undefined, 'a host reset is not navigation');
|
||||
await grid.hitTest(250, 20 + ROW_H, null);
|
||||
assert.equal(animation(paint(grid, 4000)), undefined, 'a tap selects without sliding');
|
||||
});
|
||||
|
||||
test('ring: row mode, then item mode at the middle column, linear traversal, back out', async () => {
|
||||
const { grid, log } = makeGrid();
|
||||
assert.equal(grid.selectedItem, null, 'row mode pins no item');
|
||||
await grid.handleInput(ring('click'), null);
|
||||
assert.equal(grid.selectedItem, 'item2', 'click enters item mode at the middle column');
|
||||
await grid.handleInput(ring('scroll-down'), null);
|
||||
await grid.handleInput(ring('scroll-down'), null);
|
||||
await grid.handleInput(ring('scroll-down'), null);
|
||||
assert.equal(grid.selectedItem, 'item5', 'item scrolling continues onto the next row');
|
||||
await grid.handleInput(ring('scroll-up'), null);
|
||||
assert.equal(grid.selectedItem, 'item4', 'and back onto the previous row at its end');
|
||||
await grid.handleInput(ring('click'), null);
|
||||
assert.deepEqual(log.activated, [{ item: 'item4', index: 4 }]);
|
||||
await grid.handleInput(ring('double-click'), null);
|
||||
assert.equal(grid.selectedItem, null, 'double-click drops to row mode');
|
||||
assert.equal(log.backs, 0);
|
||||
await grid.handleInput(ring('double-click'), null);
|
||||
assert.equal(log.backs, 1, 'double-click in row mode backs out');
|
||||
});
|
||||
|
||||
test('watch: four-way cells, left from the first column backs out and stays in item mode', async () => {
|
||||
const { grid, log, data } = makeGrid({
|
||||
onBack: () => { log.backs++; grid.resetSelection(); return false; },
|
||||
});
|
||||
await grid.handleInput(watch('swipe-down'), null);
|
||||
await grid.handleInput(watch('swipe-right'), null);
|
||||
assert.equal(grid.selectedItem, 'item6', 'row 1, column 1');
|
||||
await grid.handleInput(watch('swipe-down'), null);
|
||||
assert.equal(grid.selectedItem, 'item11', 'a shorter row clamps the column');
|
||||
await grid.handleInput(watch('swipe-left'), null);
|
||||
assert.equal(grid.selectedItem, 'item10');
|
||||
assert.equal(log.backs, 0);
|
||||
await grid.handleInput(watch('swipe-left'), null);
|
||||
assert.equal(log.backs, 1);
|
||||
assert.equal(grid.selectedItem, 'item0', 'the host reset the selection, and the watch keeps a cell selected');
|
||||
data.items = ['only'];
|
||||
await grid.handleInput(watch('click'), null);
|
||||
assert.deepEqual(log.activated, [{ item: 'only', index: 0 }]);
|
||||
});
|
||||
|
||||
test('activating or backing out of the grid returns it to row mode', async () => {
|
||||
const { grid } = makeGrid({ onActivate: async () => true, onBack: () => true });
|
||||
await grid.handleInput(watch('swipe-right'), null);
|
||||
await grid.handleInput(watch('click'), null);
|
||||
assert.equal(grid.selectedItem, null, 'a launch leaves row mode behind');
|
||||
await grid.handleInput(ring('click'), null);
|
||||
assert.notEqual(grid.selectedItem, null);
|
||||
await grid.handleInput(watch('double-click'), null);
|
||||
assert.equal(grid.selectedItem, null, 'leaving via the watch restores row mode too');
|
||||
});
|
||||
|
||||
test('wide items take their own row and count as one item', async () => {
|
||||
const items = ['notice', 'a', 'b', 'c', 'd', 'e', 'f'];
|
||||
const { grid, log } = makeGrid({ items, isWide: (item) => item === 'notice' });
|
||||
assert.equal(grid.selectedItem, 'notice', 'a wide row is selected as a whole even in row mode');
|
||||
await grid.handleInput(ring('click'), null);
|
||||
assert.deepEqual(log.activated, [{ item: 'notice', index: 0 }], 'one click opens a wide row');
|
||||
grid.selectIndex(6);
|
||||
assert.equal(grid.cursorIndex, 6);
|
||||
assert.equal(grid.selectedItem, null, 'selectIndex keeps row mode');
|
||||
await grid.handleInput(ring('click'), null);
|
||||
assert.equal(grid.selectedItem, 'f', 'the one-item row clamps the middle column');
|
||||
await grid.handleInput(ring('scroll-up'), null);
|
||||
assert.equal(grid.selectedItem, 'e', 'item traversal walks back through the full row');
|
||||
for (let i = 0; i < 5; i++) await grid.handleInput(ring('scroll-up'), null);
|
||||
assert.equal(grid.selectedItem, 'notice');
|
||||
});
|
||||
|
||||
test('hitTest opens the cell under the touch, including the peeking row', async () => {
|
||||
const { grid, log } = makeGrid();
|
||||
paint(grid, 1000);
|
||||
assert.equal(await grid.hitTest(50, 10 + 2 * ROW_H + 5, null), true);
|
||||
assert.deepEqual(log.activated, [{ item: 'item10', index: 10 }]);
|
||||
assert.equal(grid.selectedItem, 'item10', 'the touched cell becomes the selection');
|
||||
assert.equal(await grid.hitTest(250, 5, null), false, 'above the box');
|
||||
assert.equal(await grid.hitTest(250, 10 + 2 * ROW_H + 5, null), false, 'past the last cell of a short row');
|
||||
});
|
||||
@@ -49,7 +49,7 @@ class DisplayListTest {
|
||||
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(DRAW_OP_DISPLAY_LIST,DrawProtocol.word(20)), DrawProtocol.image(10,3,1),
|
||||
DrawProtocol.call(DRAW_OP_TEXT,hex("0c00070003000f0141")), DrawProtocol.lut(8,4,128))
|
||||
DrawProtocol.call(DRAW_OP_TEXT,hex("0c0007030f0141")), DrawProtocol.lut(8,4,128))
|
||||
resources[21]=DrawProtocol.displayList(calls)
|
||||
// Like the C harness, seed composition with the screen: this list has no screen copy.
|
||||
val screen=hex("123456789abcdef0123456789abcdef0"); val output=screen.copyOf()
|
||||
@@ -114,7 +114,7 @@ class DisplayListTest {
|
||||
@Test fun roundedRectsAndNestedOddNegativeDepthMatchFirmwareOnBothLenses() {
|
||||
val resources = mapOf(
|
||||
40 to hex("0404000200f00f0ff0"),
|
||||
41 to hex("0202000d0008020201010c0008000300040a0a000402022800050004001f"),
|
||||
41 to hex("0202000d0008020201010c0008000300040a0800040202280005041f"),
|
||||
42 to hex("02010005000702fd2900"))
|
||||
val screen = hex("012345601234560112345601234560122345601234560123345601234560123445601234560123455601234f60123456601234560123456001234560123456011234560123456012234560123456012334560123456012344560123456012345")
|
||||
val expected = listOf("01234560123456011aaaaaaaaaa56012aa45644444aa0123a4564444456a1234a564f44f564a2345a6444fff644a3456a4444456444a4560aa44456444aa56011aaaaaaaaaa56012234560123456012334560123456012344560123456012345", "012345601234560112aaaaaaaaaa60122aa56444445aa1233a5644444564a2344a644f44f644a3455a4444ff6444a4566a4444564444a5600aa44564444aa60112aaaaaaaaaa6012234560123456012334560123456012344560123456012345")
|
||||
@@ -267,4 +267,38 @@ class DisplayListTest {
|
||||
assertContentEquals(app,glasses.screen);assertContentEquals(app,glasses.composition)
|
||||
assertEquals(196608,ResourceCacheState.CACHE_SIZE)
|
||||
}
|
||||
/** Revision 35. Same calls and expectations as ClipTest in g2flash/tests/test_display_list.py. */
|
||||
@Test fun clipRectsNarrowEveryOpNestThroughListsAndMoveWithDepth() {
|
||||
val font = ByteArray(198); font[0] = 1; font[1 + 33 * 2] = 193.toByte(); hex("000202ffff").copyInto(font, 193)
|
||||
val resources = mutableMapOf(1 to hex("000404ffffffffffffffff"), 3 to font,
|
||||
5 to hex("0202000700" + "0400010000000f" + "0f00" + "04040900000002000200010008000f"),
|
||||
6 to hex("00040200000000"), 7 to hex("0201000e00080106000000040002000000" + "0f10"))
|
||||
fun draw(call: String, right: Boolean = false): DisplayListRenderer.Target {
|
||||
val target = DisplayListRenderer.Target(ByteArray(64) { 0x11 }, 16, 8)
|
||||
DisplayListRenderer(resources, rightLens = right).execute(DrawProtocol.sequence(listOf(hex(call))), target)
|
||||
return target
|
||||
}
|
||||
fun expect(target: DisplayListRenderer.Target, color: Int, inside: (Int, Int) -> Boolean) {
|
||||
for (y in 0 until 8) for (x in 0 until 16) assertEquals(if (inside(x, y)) color else 1, target.get(x, y), "($x, $y)")
|
||||
}
|
||||
expect(draw("040403000200" + "0a000a00" + "0100" + "0201" + "0f"), 15) { x, y -> x in 3..5 && y in 2..4 }
|
||||
expect(draw("0400" + "0100" + "ff020105" + "00" + "0f"), 15) { x, y -> x in 5..8 && y < 4 }
|
||||
expect(draw("0504" + "0100000002000100" + "0300" + "0000" + "0f" + "02" + "4141"), 15) { x, y -> y == 0 && x in 1..2 }
|
||||
expect(draw("0804" + "0400040004000200" + "0000" + "1000" + "0800" + "0000" + "0f10"), 15) { x, y -> x in 4..7 && y in 4..5 }
|
||||
expect(draw("0904" + "fefffeff04000400" + "09"), 9) { x, y -> x < 2 && y < 2 }
|
||||
expect(draw("0904" + "0300050003000100" + "09"), 9) { x, y -> y == 5 && x in 3..5 }
|
||||
expect(draw("0604" + "0100010001000600" + "0000000010000800" + "77".repeat(16)), 7) { x, y -> x == 1 && y in 1..6 }
|
||||
expect(draw("0204" + "0200020001000100" + "0100" + "0000" + "04000400" + "0000"), 15) { x, y -> x == 2 && y == 2 }
|
||||
expect(draw("0104" + "0100010002000100" + "00" + "000001" + "01" + "8f"), 15) { x, y -> y == 1 && x in 1..2 }
|
||||
expect(draw("0704" + "000000000a000300" + "0500"), 15) { x, y -> (x < 4 && y < 3) || (x == 9 && y < 2) }
|
||||
val deep = "0806" + "02" + "0000000004000400" + "0000" + "1000" + "0800" + "0000" + "0f10"
|
||||
expect(draw(deep), 15) { x, y -> x in 1..4 && y < 4 }
|
||||
expect(draw(deep, right = true), 15) { x, y -> x < 3 && y < 4 }
|
||||
// A target override starts unclipped: the whole resource fills, the screen stays.
|
||||
expect(draw("0704" + "0000000001000100" + "0700"), 15) { _, _ -> false }
|
||||
assertContentEquals(hex("000402ffffffff"), resources.getValue(6))
|
||||
expect(draw("0804" + "0400040000000000" + "0000" + "1000" + "0800" + "0000" + "0f10"), 15) { _, _ -> false }
|
||||
// Unknown flag bits, a truncated clip header, and the old s16 image layout all reject.
|
||||
for (bad in listOf("090800", "0904000000000100", "04000100020001000f")) assertFails(bad) { draw(bad) }
|
||||
}
|
||||
}
|
||||
@@ -5,15 +5,15 @@ import kotlin.test.*
|
||||
class DrawWireTest {
|
||||
private fun hex(value: String) = value.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
|
||||
|
||||
@Test fun encodersUseRevision29CoordinatesAndPreserveOtherWireBytes() {
|
||||
@Test fun encodersUseRevision35CoordinatesAndPreserveOtherWireBytes() {
|
||||
// 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",
|
||||
"0403ff01803412df8000c07fff1f",
|
||||
DrawProtocol.rectCopy(DrawProtocol.CURRENT, 1, 2, 3, 4, -5, -6) to
|
||||
"0200feff0102030004007b7a",
|
||||
DrawProtocol.stockText(-1, 2, 15, hex("41c3a9")) to "0300ffff02000f0341c3a9",
|
||||
DrawProtocol.text(511, -2, 3, 31, hex("01417f")) to "0500ff01feff03001f0301417f",
|
||||
DrawProtocol.text(511, -2, 3, 31, hex("01417f")) to "0500ff017e031f0301417f",
|
||||
DrawProtocol.playList(511, depth = 127) to "07027fff01",
|
||||
DrawProtocol.roundedRect(-1, 2, 640, 480, 65535, 15, 16) to
|
||||
"08007f028002e001ffff0f10",
|
||||
@@ -21,6 +21,9 @@ class DrawWireTest {
|
||||
DrawProtocol.bbox(hex("ffffffffffffffff"), 4, 0, 0, 8, 2) to "010000000002010f10",
|
||||
DrawProtocol.bbox(hex("0f"), 1, 1, 0, 1, 1) to "01000101000000010001001f",
|
||||
DrawProtocol.clear(15, target = 511) to "0901ff010f",
|
||||
// Revision 35: the clip rect follows target and depth.
|
||||
DrawProtocol.clear(3, target = 511, clip = DrawClip(-1, 2, 3, 4)) to "0905ff01ffff02000300040003",
|
||||
DrawProtocol.image(7, 1, 2, depth = 2, clip = DrawClip(0, 0, 640, 480)) to "040602000000008002e001070001020f",
|
||||
)
|
||||
for ((call, expected) in calls) assertContentEquals(hex(expected), call)
|
||||
assertContentEquals(hex("0100050007027fff01"), DrawProtocol.sequence(listOf(calls[4].first)))
|
||||
@@ -38,8 +41,8 @@ class DrawWireTest {
|
||||
|
||||
@Test fun optimizerFieldsAreReencodedAndOpaqueBytesArePreserved() {
|
||||
val records = listOf(
|
||||
"1300020080ff7f1f" to "040000020080ff7f1f",
|
||||
"14ff01ffff02000f0341017f" to "0500ff01ffff02000f0341017f",
|
||||
"1300020080ff7f1f" to "04000002df8000c07fff1f",
|
||||
"14ff01ffff02000f0341017f" to "0500ff017f020f0341017f",
|
||||
"0fffff02001f0341c3a9" to "0300ffff02001f0341c3a9",
|
||||
"030001020134120f10" to "010000000102010f10",
|
||||
"060f10" to "01000100000000080002000f10",
|
||||
|
||||
@@ -7,6 +7,11 @@ class FrameDisplayListTest {
|
||||
private val menu = "077e0000000300020002000200022a00000096000000010002000200ffffffff0200080000ff24017e30020000000001812c8001812c1611010017328001812c16103001812c3023414031ff24017c30020000000001812c8001812c1611010017328001812c16103001812c302341403102000200010001030400000000000000001f"
|
||||
private val multi = "0744000000030002000400010002000000000000000002000200010000ff010001006003000400000000000000001f0200000100000001000100020002feffffff7f00010001007f00"
|
||||
private val scroll = "078a000000030002000400020000070000009600000001000200040011223344556677880200020000000000ff250100300102300180f0800180f0161101001732800180f01610300180f0302341403101001102000200010008000000ff280101300100300180f0800180f0161101001732800180f01610300180f030234140310100170100160400020000000103"
|
||||
// Clipped clear, clipped rounded rect, and replayed glyph + icon records with
|
||||
// placeholder atlas ids 0xbeef / 0xcafebabe, plus what they paint over a
|
||||
// nibble-1 16x8 screen (display-list-authoring.test.cjs).
|
||||
private val replay = "0780000000020003000800040000070000006400000000000300890000000000000600040002880000010001000200020000000400030000000510a00000000000000600040000ff2502000080c002000000000180c8800180c8161101001732800180c81610300180c830234031020000efbe4100000000000000ff01bebafeca04000100"
|
||||
private val replayPixels = "11111111111111111111111111111111111111111111111111fff28f111111111125522211111111112552221111111111222222111111111111111111111111"
|
||||
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)
|
||||
@@ -107,4 +112,38 @@ class FrameDisplayListTest {
|
||||
trailing[1] = (trailing[1] + 1).toByte()
|
||||
assertFails { read(trailing) }
|
||||
}
|
||||
|
||||
/** The TS golden's placeholder ids, replaced by ids registered in this process. */
|
||||
private fun registeredReplay(imageKnown: Boolean = true): ByteArray {
|
||||
val key = "stub-font".encodeToByteArray()
|
||||
val glyph = byteArrayOf(key.size.toByte()) + key + byteArrayOf(4, 1, 0, 65, 0, 0, 0, 0, 1, 3, 2) +
|
||||
byteArrayOf(0xa0.toByte(), 0, 0, 0, 0xe0.toByte(), 0, 0, 0)
|
||||
GlyphAtlas.register(ArrayByteReader(glyph))
|
||||
val fontId = GlyphAtlas.fontId("stub-font")
|
||||
val imageId = if (imageKnown) ImageAtlas.ensure("stub-replay-icon", 2, 2,
|
||||
ArrayByteReader(byteArrayOf(255.toByte(), 0, 128.toByte(), 255.toByte()))) else 0x7fffffff
|
||||
fun le(value: Int, bytes: Int) = (0 until bytes).joinToString("") { ((value ushr (8 * it)) and 255).toString(16).padStart(2, '0') }
|
||||
return hex(replay.replace("efbe", le(fontId, 2)).replace("bebafeca", le(imageId, 4)))
|
||||
}
|
||||
|
||||
@Test fun replayedDrawsCompileToClippedImageAndTextCallsThatPaintLikeTheSoftwareRenderer() {
|
||||
val list = read(registeredReplay(), 1100)
|
||||
assertEquals(2, list.resources.size, "the icon and a font snapshot")
|
||||
val ids = intArrayOf(1, 2)
|
||||
val calls = list.calls(ids, 1100)
|
||||
assertEquals(listOf(DRAW_OP_CLEAR, DRAW_OP_ROUNDED_RECT, DRAW_OP_IMAGE, DRAW_OP_TEXT), calls.map { it[0].toInt() })
|
||||
assertTrue(calls.all { it[1].toInt() and DRAW_FLAG_CLIP != 0 })
|
||||
val resources = list.resources.withIndex().associate { (i, resource) -> ids[i] to resource.bytes }
|
||||
val screen = ByteArray(64) { 0x11 }
|
||||
val target = DisplayListRenderer.Target(screen, 16, 8)
|
||||
DisplayListRenderer(resources).execute(DrawProtocol.sequence(calls), target)
|
||||
val nibbles = (0 until 128).joinToString("") { target.get(it % 16, it / 16).toString(16) }
|
||||
assertEquals(replayPixels, nibbles)
|
||||
}
|
||||
|
||||
@Test fun replayWithAnUnknownRecordDrawsNothing() {
|
||||
val list = read(registeredReplay(imageKnown = false), 1100)
|
||||
assertTrue(list.resources.isEmpty())
|
||||
assertTrue(list.calls(IntArray(0), 1100).isEmpty())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user