forked from Blendman974/faceclaw
Depth effects
This commit is contained in:
1 parent
4320021222
commit
392554dd37
26 files changed
+623
-136
No files matched your search
@@ -156,7 +156,7 @@ test('the background registers once and uses a nine-byte image reference on late
|
||||
return 1;
|
||||
} } } } },
|
||||
});
|
||||
const { prepareFrameDraws } = load('app/graphics/glyph-wire.ts', { '../native/texture-atlas': atlas });
|
||||
const { prepareFrameDraws } = load('app/graphics/glyph-wire.ts', { '../native/texture-atlas': atlas, './presentation-wire': load('app/graphics/presentation-wire.ts') });
|
||||
const background = compass.createCompassBackground(576, 260, 256, 193.25, 98, 140, 1);
|
||||
for (const heading of [0, 1, 2, 45, 90]) {
|
||||
const image = background.clone();
|
||||
|
||||
@@ -34,7 +34,86 @@ class DisplayListTest {
|
||||
2 to DrawProtocol.displayList(listOf(DrawProtocol.call(7,DrawProtocol.word(1)))))
|
||||
assertFails { DisplayListRenderer(cyclic).render(1,target,target) }
|
||||
}
|
||||
private class Glasses {
|
||||
@Test fun roundedRectsAndNestedOddNegativeDepthMatchFirmwareOnBothLenses() {
|
||||
val resources = mapOf(
|
||||
40 to hex("0404000200f00f0ff0"),
|
||||
41 to hex("0202000f00080202010001000c0008000300040a0a000402022800050004001f"),
|
||||
42 to hex("02010005000702fd2900"))
|
||||
val screen = hex("012345601234560112345601234560122345601234560123345601234560123445601234560123455601234f60123456601234560123456001234560123456011234560123456012234560123456012334560123456012344560123456012345")
|
||||
val expected = listOf("01234560123456011aaaaaaaaaa56012aa45644444aa0123a4564444456a1234a564f44f564a2345a6444fff644a3456a4444456444a4560aa44456444aa56011aaaaaaaaaa56012234560123456012334560123456012344560123456012345", "012345601234560112aaaaaaaaaa60122aa56444445aa1233a5644444564a2344a644f44f644a3455a4444ff6444a4566a4444564444a5600aa44564444aa60112aaaaaaaaaa6012234560123456012334560123456012344560123456012345")
|
||||
for (right in listOf(false, true)) {
|
||||
val output = ByteArray(screen.size)
|
||||
DisplayListRenderer(resources, rightLens = right).render(42, DisplayListRenderer.Target(screen,16,12), DisplayListRenderer.Target(output,16,12))
|
||||
assertContentEquals(hex(expected[if(right) 1 else 0]), output)
|
||||
}
|
||||
for (depth in -128..127) {
|
||||
assertEquals(kotlin.math.floor(depth / 2.0).toInt(), DrawProtocol.depthOffset(depth, false))
|
||||
assertEquals(-kotlin.math.floor((depth + 1) / 2.0).toInt(), DrawProtocol.depthOffset(depth, true))
|
||||
}
|
||||
}
|
||||
@Test fun roundedFillPreservesBrighterTextAndDepthClipsWithoutNibbleDamage() {
|
||||
val pixels = ByteArray(32) { 0x11 }; pixels[13] = 0xf1.toByte()
|
||||
val target = DisplayListRenderer.Target(pixels,8,8)
|
||||
val fill = DrawProtocol.roundedRect(-1,0,8,8,2,6,16,2)
|
||||
DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(fill)),target)
|
||||
assertEquals(15,target.get(2,3)); assertEquals(6,target.get(3,3)); assertEquals(1,target.get(0,0))
|
||||
val bbox = DrawProtocol.call(1,hex("00000002010f10"),depth=-1)
|
||||
DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(bbox)),target)
|
||||
assertEquals(15,target.get(0,0));assertEquals(1,target.get(7,0))
|
||||
val before=pixels.copyOf()
|
||||
assertFails { DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(byteArrayOf(8,2))),target) }
|
||||
assertContentEquals(before,pixels)
|
||||
}
|
||||
@Test fun selectedMenuResourcesStayOutOfScreenAndReplayAtDepthTwo() {
|
||||
val planner=ScenePlanner(ResourceCacheState()); val left=Glasses(); val right=Glasses(true)
|
||||
val app=ByteArray(640*480/2) { 0x11 }
|
||||
fun row(x:Int) = MenuSelection(x,8,8,4,1,4,9,2,hex("00ff0000000000000000000000000000"))
|
||||
val scene=ShellScene(emptyList(),listOf(row(10)))
|
||||
val first=planner.plan(app,640,480,null,scene,1);left.apply(first.commands);right.apply(first.commands)
|
||||
assertContentEquals(app,left.screen);assertContentEquals(app,right.screen)
|
||||
val l=DisplayListRenderer.Target(left.composition,640,480);val r=DisplayListRenderer.Target(right.composition,640,480)
|
||||
assertEquals(15,l.get(13,8));assertEquals(15,r.get(11,8));assertEquals(1,l.get(9,8))
|
||||
val moved=planner.plan(app,640,480,null,ShellScene(emptyList(),listOf(row(20))),1)
|
||||
assertFalse(moved.commands.any { it[0].toInt()==26 || it[0].toInt()==29 })
|
||||
left.apply(moved.commands);assertContentEquals(app,left.screen)
|
||||
left.apply(planner.plan(app,640,480,null,ShellScene.EMPTY,1).commands)
|
||||
assertContentEquals(app,left.composition)
|
||||
}
|
||||
@Test fun contextMenusAndSidebarDepthReplayOnBothLensesWithoutBakedCopies() {
|
||||
fun record(kind: Int, x: Int, y: Int, w: Int, h: Int, depth: Int, gray: ByteArray): MenuSelection {
|
||||
val bytes = DrawProtocol.word(x) + DrawProtocol.word(y) + DrawProtocol.word(w) + DrawProtocol.word(h) +
|
||||
DrawProtocol.word(0) + byteArrayOf(16, 48, depth.toByte()) + DrawProtocol.word(0) + gray
|
||||
return MenuSelection.read(ArrayByteReader(bytes), kind)
|
||||
}
|
||||
val menu = record(5, 10, 10, 8, 8, 4, ByteArray(64) { if (it == 0) 0 else 1 })
|
||||
val selected = record(3, 12, 12, 4, 2, 6, ByteArray(8) { -1 })
|
||||
val icon = record(4, 30, 10, 2, 2, -2, ByteArray(4) { -1 })
|
||||
val app = ByteArray(640 * 480 / 2) { 0x66 }
|
||||
val planner = ScenePlanner(ResourceCacheState())
|
||||
val scene = ShellScene(emptyList(), listOf(menu, selected, icon))
|
||||
val plan = planner.plan(app, 640, 480, null, scene, 1)
|
||||
for (right in listOf(false, true)) {
|
||||
val glasses = Glasses(right); glasses.apply(plan.commands)
|
||||
assertContentEquals(app, glasses.screen)
|
||||
val output = DisplayListRenderer.Target(glasses.composition,640,480)
|
||||
val shift = if (right) -2 else 2
|
||||
assertEquals(6, output.get(10 + shift,10)) // transparent corner
|
||||
assertEquals(0, output.get(11 + shift,10)) // opaque black stays opaque
|
||||
assertEquals(15, output.get(12 + (if (right) -3 else 3),12))
|
||||
assertEquals(15, output.get(30 + (if (right) 1 else -1),10))
|
||||
assertEquals(6, output.get(if (right) 30 else 31,10)) // no unshifted icon
|
||||
val preview = scene.preview(ByteArray(640*480) { 96 },640,480,right)
|
||||
assertContentEquals(glasses.composition, BmpUtil.pack4bppFromGray8(preview,640,480))
|
||||
}
|
||||
// The shell uses an independently owned surface with its own depth.
|
||||
val shell = ShellScene(listOf(ShellScene.Layer(1,10,10,8,8,256,ByteArray(32),listOf(selected),4)))
|
||||
val left = shell.preview(ByteArray(640*480) { 96 },640,480)
|
||||
val right = shell.preview(ByteArray(640*480) { 96 },640,480,true)
|
||||
assertEquals(0,left[10*640+12].toInt()); assertEquals(96,left[10*640+10].toInt())
|
||||
assertEquals(0,right[10*640+8].toInt()); assertEquals(96,right[10*640+16].toInt())
|
||||
}
|
||||
|
||||
private class Glasses(val right: Boolean = false) {
|
||||
val resources=mutableMapOf<Int,ByteArray>(); val screen=ByteArray(640*480/2);val composition=ByteArray(screen.size)
|
||||
var root=65535
|
||||
fun apply(commands: List<ByteArray>) {
|
||||
@@ -46,9 +125,9 @@ class DisplayListTest {
|
||||
} }
|
||||
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))
|
||||
26 -> DisplayListRenderer(resources, rightLens = right).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))
|
||||
28 -> DisplayListRenderer(resources, rightLens = right).render(root,DisplayListRenderer.Target(screen,640,480),DisplayListRenderer.Target(composition,640,480))
|
||||
else -> error("legacy command ${b[0]}")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
const test=require('node:test');
|
||||
const assert=require('node:assert/strict');
|
||||
const fs=require('node:fs');
|
||||
const vm=require('node:vm');
|
||||
const ts=require('typescript');
|
||||
const graphics=require('../.test-build/app/graphics/image.js');
|
||||
const planes=require('../.test-build/app/graphics/plane.js');
|
||||
const wire=require('../.test-build/app/graphics/presentation-wire.js');
|
||||
const {encodeShellScene}=require('../.test-build/app/graphics/shell-scene.js');
|
||||
const {SurfaceCompositor}=require('../.test-build/app/graphics/surface-compositor.js');
|
||||
function load(file,modules) {
|
||||
const context={exports:{},require:name=>{assert.ok(name in modules, name);return modules[name];}};
|
||||
vm.runInNewContext(ts.transpileModule(fs.readFileSync(file,'utf8'),{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2020}}).outputText,context);
|
||||
return context.exports;
|
||||
}
|
||||
const font={lineHeight:12,ascent:10,descent:2,measureText:text=>text.length*4,
|
||||
drawText:(image,x,y,text,value)=>{for(let i=0;i<text.length;i++) image.fillRect(x+i*4,y+2,2,6,value);}};
|
||||
const {MenuLayer}=load('app/ui/menu.ts',{
|
||||
'../graphics/image':graphics,'../graphics/textwrap':{},'../graphics/ui-fonts':{getDefaultSmallFont:()=>font},
|
||||
'../util/numeric-util':{clamp:(n,a,b)=>Math.max(a,Math.min(b,n))},'./gestures':{},
|
||||
'./metrics':require('../.test-build/app/ui/metrics.js'),
|
||||
});
|
||||
const {prepareFrameDraws}=load('app/graphics/glyph-wire.ts',{'./presentation-wire':wire,'../native/texture-atlas':{textureAtlasAvailable:()=>false}});
|
||||
function menu() {
|
||||
const layer=new MenuLayer(null,[{label:'FIRST',onSelect(){}},{label:'SECOND',onSelect(){}}],{x:0,y:0,width:80,minHeight:70,maxHeight:80,squareCorners:true});
|
||||
const context={stack:{getBaseSize:()=>({width:80,height:80}),isFocused:()=>true}};
|
||||
return {layer,paint:()=>layer.paint(context,()=>new graphics.GrayImage(80,80)),context};
|
||||
}
|
||||
test('menu retains the selected text and rounded highlight at depth +2',async()=>{
|
||||
const m=menu(),image=m.paint(),row=image.draws.find(d=>d.presentation);
|
||||
assert.equal(row.presentation.depth,2);assert.equal(row.presentation.radius,8);
|
||||
assert.ok(row.source.pixels.some(v=>v===255));assert.ok(!image.withDrawsBaked(false).pixels.some(v=>v===255));
|
||||
const flat=planes.flattenPlanesWithDraws([{image,x:0,y:0}]);
|
||||
const records=wire.presentationRecords(prepareFrameDraws(flat.draws));assert.equal(records.length,1);
|
||||
const c=new SurfaceCompositor(80,80);c.configureSurface('app',{x:0,y:0,width:80,height:80,zOrder:0,transparency:'opaque'});
|
||||
c.submitSurfaceFrame('app',flat.image.pixels,{x:0,y:0,width:80,height:80},prepareFrameDraws(flat.draws));
|
||||
const screen=flat.image.pixels.slice(),preview=c.composite();
|
||||
assert.ok(preview.some(v=>v===240));assert.deepEqual(flat.image.pixels,screen);
|
||||
await m.layer.handleInput({type:'scroll-down'},m.context);
|
||||
const next=m.paint().draws.find(d=>d.presentation);assert.ok(next.y>row.y);assert.equal(next.presentation.depth,2);
|
||||
});
|
||||
test('shell menu selection survives serialization and is not baked into its surface',()=>{
|
||||
const image=menu().paint(),bytes=encodeShellScene([{image,x:0,y:0,shellKey:7}]);
|
||||
assert.equal(new DataView(bytes.buffer).getUint16(14,true),1);
|
||||
const c=new SurfaceCompositor(80,80);c.setShellScene(bytes);assert.ok(c.composite().some(v=>v===240));
|
||||
});
|
||||
test('later opaque planes occlude a replayed selection without erasing its visible part',()=>{
|
||||
const image=menu().paint(),row=image.draws.find(d=>d.presentation),cover=new graphics.GrayImage(10,8,1);
|
||||
const flat=planes.flattenPlanesWithDraws([{image,x:0,y:0},{image:cover,x:row.x+10,y:row.y+2}]);
|
||||
const records=wire.presentationRecords(prepareFrameDraws(flat.draws));assert.ok(records[0].occlusions.length);
|
||||
const c=new SurfaceCompositor(80,80);c.configureSurface('app',{x:0,y:0,width:80,height:80,zOrder:0,transparency:'opaque'});
|
||||
c.submitSurfaceFrame('app',flat.image.pixels,{x:0,y:0,width:80,height:80},prepareFrameDraws(flat.draws));
|
||||
const preview=c.composite();
|
||||
for(let y=row.y+2;y<row.y+10;y++) for(let x=row.x+10;x<row.x+20;x++) assert.equal(preview[y*80+x],0);
|
||||
assert.ok(preview.some(v=>v===240));
|
||||
});
|
||||
|
||||
const {LayerStack,noopLayerActions}=load('app/ui/layers.ts',{
|
||||
'../graphics/image':graphics,'../graphics/plane':planes,'../native/frame-timings':{spanCurrent:(_name,fn)=>fn()},'./gestures':{},
|
||||
});
|
||||
test('context menu surface uses +4 and selected row +6 without changing the app screen',()=>{
|
||||
const base=new graphics.GrayImage(100,90,96);
|
||||
const stack=new LayerStack({paint:()=>base},noopLayerActions,{width:100,height:90});
|
||||
stack.push(new MenuLayer(null,[{label:'FIRST',onSelect(){}}],{x:10,y:8,width:80,minHeight:70,maxHeight:70,depth:4}));
|
||||
const frame=planes.flattenPlanesWithDraws(stack.paint());
|
||||
assert.deepEqual(frame.image.pixels,base.pixels);
|
||||
const records=wire.presentationRecords(prepareFrameDraws(frame.draws));
|
||||
assert.deepEqual(records.map(r=>r.depth),[4,6]);assert.equal(records[0].mode,'masked-image');
|
||||
const c=new SurfaceCompositor(100,90);c.configureSurface('app',{x:0,y:0,width:100,height:90,zOrder:0,transparency:'opaque'});
|
||||
c.submitSurfaceFrame('app',frame.image.pixels,{x:0,y:0,width:100,height:90},prepareFrameDraws(frame.draws));
|
||||
const preview=c.composite();
|
||||
assert.equal(preview[45*100+10],96); // old left edge has no baked menu
|
||||
assert.equal(preview[45*100+13],0); // shifted opaque black interior
|
||||
assert.equal(preview[8*100+12],96); // transparent rounded corner
|
||||
assert.ok(preview.some(v=>v===240));
|
||||
stack.pop();const closed=planes.flattenPlanesWithDraws(stack.paint());
|
||||
c.submitSurfaceFrame('app',closed.image.pixels,{x:0,y:0,width:100,height:90},prepareFrameDraws(closed.draws));
|
||||
assert.deepEqual(c.composite(),base.pixels);
|
||||
});
|
||||
test('system menu bridge shifts its surface +4 and selected row +6',()=>{
|
||||
const image=menu().paint(),bytes=encodeShellScene([{image,x:8,y:0,shellKey:7,depth:4}]);
|
||||
const view=new DataView(bytes.buffer),w=view.getUint16(8,true),h=view.getUint16(10,true);
|
||||
assert.equal(view.getInt16(16,true),4);
|
||||
assert.equal(wire.readPresentation(bytes,18+w*h).selection.depth,6);
|
||||
const c=new SurfaceCompositor(100,80);c.setShellScene(bytes);const preview=c.composite();
|
||||
assert.equal(preview[40*100+8],0);assert.equal(preview[40*100+10],80);
|
||||
});
|
||||
test('unselected sidebar icons retain -2 depth through shell cropping, including attention badges',()=>{
|
||||
const shellScene=require('../.test-build/app/graphics/shell-scene.js');
|
||||
const {ShellChromeLayer}=load('app/ui/shell/chrome-layer.ts',{
|
||||
'../../graphics/shell-scene':shellScene,'../../graphics/image':graphics,
|
||||
'../../graphics/ui-fonts':{getDefaultSmallFont:()=>font,getDefaultMediumFont:()=>font},
|
||||
'../../graphics/textwrap':{},'./ambient-cards':{},'../../graphics/battery':{},
|
||||
'../../native/notification-icons':{},'../../native/phone-battery':{},'../../util/render-freshness':{},
|
||||
'../../graphics/icons':{},'../dashboard-settings':{},'../clock-format':{},'../../graphics/bdffont':{},
|
||||
'../layers':{LayerStack},'../menu':{scrollToKeepSelectionVisible:()=>0},'../metrics':{},
|
||||
'./geometry':{MIN_WINDOW_HEIGHT:280,minWindowTop:()=>0,windowTop:()=>0,SHELL_OPAQUE_BLACK:1,SIDEBAR_WIDTH:64,TOP_BAR_HEIGHT:24},
|
||||
});
|
||||
const state={selectedIndex:0,focus:'sidebar',windows:[0,1,2].map(n=>({attention:n===1,drawIcon:(image,x,y)=>image.fillRect(x,y,4,4,240)}))};
|
||||
const chrome=new ShellChromeLayer(()=>state),image=new graphics.GrayImage(640,480);
|
||||
chrome.drawSidebar(image,state);
|
||||
assert.deepEqual(Array.from(image.draws.filter(d=>d.presentation),d=>d.presentation.depth),[-2,-2]);
|
||||
const crop=shellScene.shellCrop(image,0,0,64,280,1),bytes=encodeShellScene([crop]);
|
||||
const c=new SurfaceCompositor(640,480);c.setShellScene(bytes);const preview=c.composite();
|
||||
assert.equal(preview[34*640+30],240); // selected icon stays at its original x
|
||||
assert.equal(preview[74*640+29],240); // unselected icon moves left by one
|
||||
assert.equal(preview[74*640+33],0); // no baked copy at the original right edge
|
||||
state.selectedIndex=1;const next=new graphics.GrayImage(640,480);chrome.drawSidebar(next,state);
|
||||
assert.equal(next.draws.filter(d=>d.presentation).length,2);
|
||||
});
|
||||
@@ -142,6 +142,10 @@ test('Music settings keeps toggles and selection when a new app arrives and supp
|
||||
const font = BdfFont.parse(source('app/fonts/terminus/ter-u20n.bdf'));
|
||||
class RecordingImage extends graphics.GrayImage {
|
||||
texts = [];
|
||||
drawMenuSelection(source, x, y, ...args) {
|
||||
this.texts.push(...source.texts.map(t => ({ ...t, x: t.x + x, y: t.y + y })));
|
||||
super.drawMenuSelection(source, x, y, ...args);
|
||||
}
|
||||
drawText(font, x, y, text, value) { this.texts.push({ x, y, text }); super.drawText(font, x, y, text, value); }
|
||||
}
|
||||
const deps = {
|
||||
|
||||
@@ -58,6 +58,10 @@ function ui(fontSize = 12) {
|
||||
const font = BdfFont.parse(source(`app/fonts/terminus/ter-u${fontSize}n.bdf`));
|
||||
class RecordingImage extends graphics.GrayImage {
|
||||
texts = [];
|
||||
drawMenuSelection(source, x, y, ...args) {
|
||||
this.texts.push(...source.texts.map(t => ({ ...t, x: t.x + x, y: t.y + y })));
|
||||
super.drawMenuSelection(source, x, y, ...args);
|
||||
}
|
||||
drawText(font, x, y, text, value) {
|
||||
this.texts.push({ x, y, text });
|
||||
super.drawText(font, x, y, text, value);
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
"../app/g2/flash-prompt-protocol.ts",
|
||||
"../app/graphics/surface-compositor.ts",
|
||||
"../app/graphics/image.ts",
|
||||
"../app/graphics/plane.ts",
|
||||
"../app/graphics/shell-scene.ts",
|
||||
"../app/ui/metrics.ts",
|
||||
"../app/phone-ui/phone-gestures.ts",
|
||||
"../app/g2/firmware-compat.ts",
|
||||
"../app/g2/glasses-hardware-identity.ts",
|
||||
|
||||
Reference in new issue
Block a user