forked from Blendman974/faceclaw
Display lists
This commit is contained in:
1 parent
a7af84e231
commit
4320021222
44 files changed
+823
-284
No files matched your search
@@ -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())
|
||||
|
||||
Reference in new issue
Block a user