Add animations to launcher and Files app

This commit is contained in:
James Babcock committed 2026-09-25 13:25:51 -07:00
1 parent 7ad9fe10ad
commit b0a98f5942
24 files changed
+1608 -738

No files matched your search

@@ -7,7 +7,9 @@ package com.faceclaw.app
/** Common draw-call header bits. */
const val DRAW_FLAG_RESOURCE_TARGET = 1
const val DRAW_FLAG_DEPTH = 2
const val DRAW_FLAGS_MASK = DRAW_FLAG_RESOURCE_TARGET or DRAW_FLAG_DEPTH
/** Revision 35: an x/y s16, w/h u16 clip rect follows the depth byte. */
const val DRAW_FLAG_CLIP = 4
const val DRAW_FLAGS_MASK = DRAW_FLAG_RESOURCE_TARGET or DRAW_FLAG_DEPTH or DRAW_FLAG_CLIP
/** Bounding-box payload flag: u16 coordinates/sizes instead of aligned compact units. */
const val DRAW_BBOX_FLAG_U16 = 1
@@ -1,6 +1,19 @@
package com.faceclaw.app
/** Revision 33 wire grammar, shared by scene planning and the local renderer. */
/**
* A draw call's clip rect (revision 35, DRAW_FLAG_CLIP), in the call's own
* coordinates: it moves with the call's depth, narrows any clip inherited
* from an enclosing play-list call, and is dropped by a target override.
*/
class DrawClip(val x: Int, val y: Int, val width: Int, val height: Int) {
init {
require(x in -32768..32767 && y in -32768..32767 && width in 0..65535 && height in 0..65535)
}
fun translated(dx: Int, dy: Int) = DrawClip(x + dx, y + dy, width, height)
}
/** Revision 35 wire grammar, shared by scene planning and the local renderer. */
object DrawProtocol {
/** Mirrors g2flash/patches/zlib_glue.c. */
const val DRAW = CFW_MSG_DRAW_CALLS
@@ -25,21 +38,29 @@ object DrawProtocol {
private fun encode(write: DrawWriter.() -> Unit): ByteArray = DrawWriter().apply(write).toByteArray()
fun call(op: Int, args: ByteArray, target: Int? = null, depth: Int? = null): ByteArray {
fun call(op: Int, args: ByteArray, target: Int? = null, depth: Int? = null, clip: DrawClip? = null): ByteArray {
require(depth == null || depth in -128..127)
val flags = (if (target == null) 0 else DRAW_FLAG_RESOURCE_TARGET) or
(if (depth == null) 0 else DRAW_FLAG_DEPTH)
(if (depth == null) 0 else DRAW_FLAG_DEPTH) or
(if (clip == null) 0 else DRAW_FLAG_CLIP)
return encode {
writeU8(op)
writeU8(flags)
if (target != null) writeU16(target)
if (depth != null) writeS8(depth)
if (clip != null) {
writeS16(clip.x)
writeS16(clip.y)
writeU16(clip.width)
writeU16(clip.height)
}
writeBytes(args)
}
}
private fun call(op: Int, target: Int? = null, depth: Int? = null, write: DrawWriter.() -> Unit): ByteArray =
call(op, encode(write), target, depth)
private fun call(op: Int, target: Int? = null, depth: Int? = null, clip: DrawClip? = null,
write: DrawWriter.() -> Unit): ByteArray =
call(op, encode(write), target, depth, clip)
fun depthOffset(depth: Int, right: Boolean): Int =
if (right) -floorHalf(depth + 1) else floorHalf(depth)
@@ -53,11 +74,11 @@ object DrawProtocol {
fun roundedRect(
x: DrawValue, y: DrawValue, width: Int, height: Int, radius: Int, background: Int,
border: Int = DRAW_ROUNDED_RECT_NO_BORDER, depth: Int? = null,
border: Int = DRAW_ROUNDED_RECT_NO_BORDER, depth: Int? = null, clip: DrawClip? = null,
): ByteArray {
require(width in 1..640 && height in 1..480 && radius in 0..65535)
require(background in 0..15 && border in 0..DRAW_ROUNDED_RECT_NO_BORDER)
return call(DRAW_OP_ROUNDED_RECT, depth = depth) {
return call(DRAW_OP_ROUNDED_RECT, depth = depth, clip = clip) {
writeExtended(x)
writeExtended(y)
writeU16(width)
@@ -86,11 +107,17 @@ object DrawProtocol {
fun image(
id: Int, x: Int, y: Int, options: Int = CFW_TEXTURE_OPT_BRIGHTNESS_MASK,
target: Int? = null, depth: Int? = null,
): ByteArray = call(DRAW_OP_IMAGE, target, depth) {
target: Int? = null, depth: Int? = null, clip: DrawClip? = null,
): ByteArray = image(id, DrawValue.Integer(x), DrawValue.Integer(y), options, target, depth, clip)
/** Revision 35: x and y are extended values and may be expressions. */
fun image(
id: Int, x: DrawValue, y: DrawValue, options: Int = CFW_TEXTURE_OPT_BRIGHTNESS_MASK,
target: Int? = null, depth: Int? = null, clip: DrawClip? = null,
): ByteArray = call(DRAW_OP_IMAGE, target, depth, clip) {
writeU16(id)
writeS16(x)
writeS16(y)
writeExtended(x)
writeExtended(y)
writeU8(options)
}
@@ -103,8 +130,8 @@ object DrawProtocol {
/** Revision 29: source and destination coordinates may be expressions; the source rect must stay in bounds. */
fun rectCopy(
source: Int, x: DrawValue, y: DrawValue, width: Int, height: Int, dx: DrawValue, dy: DrawValue,
target: Int? = null, depth: Int? = null,
): ByteArray = call(DRAW_OP_RECT_COPY, target, depth) {
target: Int? = null, depth: Int? = null, clip: DrawClip? = null,
): ByteArray = call(DRAW_OP_RECT_COPY, target, depth, clip) {
writeU16(source)
writeExtended(x)
writeExtended(y)
@@ -114,10 +141,13 @@ object DrawProtocol {
writeExtended(dy)
}
/** Fill the whole target, ignoring depth. */
fun clear(color: Int = 0, target: Int? = null): ByteArray {
/**
* Fill the whole target, ignoring depth; under a clip (revision 35), just
* the clipped part. Depth still moves the clip rect, like any call's.
*/
fun clear(color: Int = 0, target: Int? = null, clip: DrawClip? = null, depth: Int? = null): ByteArray {
require(color in 0..15)
return call(DRAW_OP_CLEAR, target) { writeU8(color) }
return call(DRAW_OP_CLEAR, target, depth, clip) { writeU8(color) }
}
/**
@@ -139,12 +169,17 @@ object DrawProtocol {
}
}
fun text(id: Int, x: Int, y: Int, options: Int, text: ByteArray): ByteArray {
fun text(id: Int, x: Int, y: Int, options: Int, text: ByteArray): ByteArray =
text(id, DrawValue.Integer(x), DrawValue.Integer(y), options, text)
/** Revision 35: x and y are extended values and may be expressions. */
fun text(id: Int, x: DrawValue, y: DrawValue, options: Int, text: ByteArray, depth: Int? = null,
clip: DrawClip? = null): ByteArray {
require(text.size <= 255)
return call(DRAW_OP_TEXT) {
return call(DRAW_OP_TEXT, depth = depth, clip = clip) {
writeU16(id)
writeS16(x)
writeS16(y)
writeExtended(x)
writeExtended(y)
writeU8(options)
writeU8(text.size)
writeBytes(text)
@@ -802,14 +802,14 @@ class TexturePlanner {
}
/** How many 1..31 control bytes are needed to move the cursor by delta. */
private fun adjustByteCount(delta: Int): Int {
internal fun adjustByteCount(delta: Int): Int {
if ((delta == 0)) {
return 0
}
return (if ((delta > 0)) ((delta + 19) / 20) else ((-delta + 9) / 10))
}
private fun emitAdjust(out: ByteSink, delta: Int): Unit {
internal fun emitAdjust(out: ByteSink, delta: Int): Unit {
var delta = delta
while ((delta != 0)) {
var step: Int = (if ((delta > 0)) minOf(delta, 20) else maxOf(delta, -10))
@@ -8,12 +8,18 @@ class DisplayListRenderer(
) {
class BuiltinGlyph(val image: ByteArray, val advance: Int, val x: Int = 0, val y: Int = 0)
/**
* [clip] (revision 35) is the writable [left, top, right, bottom) in
* shifted target pixels, or null for the whole target. Like the depth
* shift, it is inherited by nested lists and dropped by a target override.
*/
class Target(
val bytes: ByteArray,
val width: Int,
val height: Int,
val offset: Int = 0,
val shiftX: Int = 0,
val clip: IntArray? = null,
) {
val stride = (width + 1) / 2
@@ -26,11 +32,26 @@ class DisplayListRenderer(
return (bytes[offset + y * stride + x / 2].toInt() ushr shift) and 15
}
fun shifted(dx: Int) = Target(bytes, width, height, offset, shiftX + dx)
fun shifted(dx: Int) = Target(bytes, width, height, offset, shiftX + dx, clip)
/** Narrow the clip to a rect in (unshifted) call coordinates. */
fun clipped(x: Int, y: Int, w: Int, h: Int): Target {
val left = x + shiftX
val rect = intArrayOf(left, y, left + w, y + h)
if (clip != null) {
rect[0] = maxOf(rect[0], clip[0]); rect[1] = maxOf(rect[1], clip[1])
rect[2] = minOf(rect[2], clip[2]); rect[3] = minOf(rect[3], clip[3])
}
return Target(bytes, width, height, offset, shiftX, rect)
}
fun writable(x: Int, y: Int): Boolean =
x in 0 until width && y in 0 until height &&
(clip == null || (x >= clip[0] && y >= clip[1] && x < clip[2] && y < clip[3]))
fun put(localX: Int, y: Int, value: Int) {
val x = localX + shiftX
if (x !in 0 until width || y !in 0 until height) return
if (!writable(x, y)) return
val index = offset + y * stride + x / 2
val old = bytes[index].toInt()
bytes[index] = if (x % 2 == 0) {
@@ -220,6 +241,9 @@ class DisplayListRenderer(
if (flags and DRAW_FLAG_DEPTH != 0) {
target = target.shifted(DrawProtocol.depthOffset(reader.readS8(), rightLens))
}
if (flags and DRAW_FLAG_CLIP != 0) {
target = target.clipped(reader.readS16(), reader.readS16(), reader.readU16(), reader.readU16())
}
when (opcode) {
DRAW_OP_BOUNDING_BOX -> drawBoundingBox(reader, target, walk)
DRAW_OP_RECT_COPY -> drawRectCopy(reader, target, walk)
@@ -313,26 +337,31 @@ class DisplayListRenderer(
}
}
/** Mirrors the firmware: far-off image/text coordinates draw nothing (before the depth shift can overflow). */
private fun offTarget(x: Int, y: Int) = x !in -65536..65536 || y !in -65536..65536
private fun drawImage(reader: DrawReader, target: Target, walk: Walk) {
val id = reader.readU16()
val x = reader.readS16()
val y = reader.readS16()
val x = ExtendedVarint.evaluate(reader, walk.frame)
val y = ExtendedVarint.evaluate(reader, walk.frame)
val options = reader.readU8()
reader.requireDone()
walk.references.add(id)
draw(image(resource(id)), target, x, y, options, walk.apply)
val image = image(resource(id))
if (!offTarget(x, y)) draw(image, target, x, y, options, walk.apply)
}
private fun drawText(reader: DrawReader, target: Target, walk: Walk) {
val id = reader.readU16()
var x = reader.readS16()
val y = reader.readS16()
var x = ExtendedVarint.evaluate(reader, walk.frame)
val y = ExtendedVarint.evaluate(reader, walk.frame)
val options = reader.readU8()
val text = reader.readBytes(reader.readU8())
reader.requireDone()
walk.references.add(id)
val data = resource(id)
require(data.size >= 193 && data[0].toInt() == CFW_RESOURCE_TYPE_FONT)
val apply = walk.apply && !offTarget(x, y)
for (byte in text) {
val char = byte.toInt() and 255
if (char in 1..31) {
@@ -343,7 +372,7 @@ class DisplayListRenderer(
val offset = DrawProtocol.u16(data, 1 + (char - 32) * 2)
require(offset >= 193)
val glyph = image(data, offset)
draw(glyph, target, x, y, options, walk.apply)
draw(glyph, target, x, y, options, apply)
x += glyph.width
}
}
@@ -359,7 +388,7 @@ class DisplayListRenderer(
if (!walk.apply) return
for (yy in y until y + height) for (xx in x until x + width) {
val tx = xx + target.shiftX
if (tx !in 0 until target.width) continue
if (!target.writable(tx, yy)) continue
val value = target.get(tx, yy)
val shift = if (value % 2 == 0) 4 else 0
// The even-parity table comes first; parity is of the shifted target pixel.
@@ -371,7 +400,16 @@ class DisplayListRenderer(
val color = reader.readU8()
reader.requireDone()
require(color <= 15)
if (walk.apply) target.bytes.fill((color * 17).toByte(), target.offset, target.offset + target.stride * target.height)
if (!walk.apply) return
val clip = target.clip
if (clip == null) {
target.bytes.fill((color * 17).toByte(), target.offset, target.offset + target.stride * target.height)
} else {
// Revision 35: a clipped clear fills just the clip, which is in shifted pixels already.
for (y in maxOf(0, clip[1]) until minOf(target.height, clip[3])) {
for (x in maxOf(0, clip[0]) until minOf(target.width, clip[2])) target.put(x - target.shiftX, y, color)
}
}
}
private fun drawRoundedRect(reader: DrawReader, target: Target, walk: Walk) {
@@ -11,7 +11,17 @@ interface RetainedDrawing {
internal fun readRetainedDrawing(reader: ByteReader, kind: Int): RetainedDrawing =
if (kind == DrawRecordKind.DISPLAY_LIST) FrameDisplayList.read(reader) else MenuSelection.read(reader, kind)
/** Generic TS-authored calls. No menu or easing policy lives in this bridge. */
/**
* Generic TS-authored calls. No menu or easing policy lives in this bridge.
*
* Besides literal firmware calls, a record may carry a DRAWS call (bridge
* only): glyph and icon records in the frame draw-record format, whose atlas
* identities TS registered while painting. They compile to IMAGE calls on
* ImageAtlas resources, then TEXT runs on FontResourceAtlas fonts, all offset
* by the call's (possibly animated) x/y. When any record cannot be resolved,
* the whole list draws nothing: the frame's own pixels show instead, rather
* than content with a glyph missing.
*/
class FrameDisplayList private constructor(
private val x: Int, private val y: Int, private val depth: Int,
override val resources: List<CachedResource>, private val commands: List<Command>,
@@ -20,9 +30,11 @@ class FrameDisplayList private constructor(
override val fingerprint: String get() = "$x,$y,$depth,$identity"
override fun translated(dx: Int, dy: Int) = FrameDisplayList(x + dx, y + dy, depth, resources, commands, startedAt, identity)
/** Image/text [values] are resource, x offset, y offset, options; the offsets add to [x]/[y]. */
private class Command(val op: Int, val depth: Int, val values: IntArray,
val x: DrawValue = DrawValue.Integer(0), val y: DrawValue = DrawValue.Integer(0),
val dx: DrawValue = DrawValue.Integer(0), val dy: DrawValue = DrawValue.Integer(0))
val dx: DrawValue = DrawValue.Integer(0), val dy: DrawValue = DrawValue.Integer(0),
val clip: DrawClip? = null, val text: ByteArray? = null)
override fun calls(ids: IntArray, nowMs: Long): List<ByteArray> {
require(ids.size == resources.size)
@@ -30,14 +42,19 @@ class FrameDisplayList private constructor(
fun resource(index: Int) = if (index == DrawProtocol.SCREEN) index else ids[index]
return commands.map { c ->
val v = c.values
val clip = c.clip?.translated(x, y)
when (c.op) {
DRAW_OP_ROUNDED_RECT -> DrawProtocol.roundedRect(bind(c.x, elapsed, x), bind(c.y, elapsed, y),
v[0], v[1], v[2], v[3], v[4], depth + c.depth)
DRAW_OP_IMAGE -> DrawProtocol.image(resource(v[0]), x + v[1], y + v[2], v[3], depth = depth + c.depth)
v[0], v[1], v[2], v[3], v[4], depth + c.depth, clip)
DRAW_OP_IMAGE -> DrawProtocol.image(resource(v[0]), bind(c.x, elapsed, x + v[1]), bind(c.y, elapsed, y + v[2]),
v[3], depth = depth + c.depth, clip = clip)
DRAW_OP_TEXT -> DrawProtocol.text(resource(v[0]), bind(c.x, elapsed, x + v[1]), bind(c.y, elapsed, y + v[2]),
v[3], c.text!!, depth + c.depth, clip)
DRAW_OP_RECT_COPY -> DrawProtocol.rectCopy(resource(v[0]),
bind(c.x, elapsed, if (v[0] == DrawProtocol.SCREEN) x else 0),
bind(c.y, elapsed, if (v[0] == DrawProtocol.SCREEN) y else 0),
v[1], v[2], bind(c.dx, elapsed, x), bind(c.dy, elapsed, y), depth = depth + c.depth)
v[1], v[2], bind(c.dx, elapsed, x), bind(c.dy, elapsed, y), depth = depth + c.depth, clip = clip)
DRAW_OP_CLEAR -> DrawProtocol.clear(v[0], clip = clip, depth = if (clip == null) null else depth + c.depth)
else -> error("Unsupported frame display-list opcode")
}
}
@@ -47,6 +64,11 @@ class FrameDisplayList private constructor(
// Bridge-only constant binding, removed before a program reaches either renderer.
private const val ELAPSED = 128
private const val MAX_RECORD_BYTES = 4 * 1024 * 1024
/** Bridge-only: replay glyph/icon draw records (see the class comment). */
private const val DRAWS = 32
/** Bridge opcode bit: an x/y s16, w/h u16 clip rect follows the call's depth. */
private const val CLIPPED = 128
private const val IMAGE_OPTIONS = CFW_TEXTURE_OPT_BRIGHTNESS_MASK or CFW_TEXTURE_OPT_TRANSPARENT
private fun bind(value: DrawValue, elapsed: Int, offset: Int): DrawValue {
if (value is DrawValue.Integer) return DrawValue.Integer(value.value + offset)
@@ -68,6 +90,57 @@ class FrameDisplayList private constructor(
return DrawValue.Expression(program)
}
private class GlyphRecord(val fontId: Int, val encoding: Int, val penX: Int, val lineY: Int, val value: Int)
private class ImageRecord(val imageId: Int, val x: Int, val y: Int)
/**
* Compile one DRAWS call into [out], adding atlas resources through
* [resource]. False when a record has no atlas entry, or its font
* snapshot cannot hold every glyph this call needs.
*/
private fun compileDraws(glyphs: List<GlyphRecord>, images: List<ImageRecord>, x: DrawValue, y: DrawValue,
depth: Int, clip: DrawClip?, resource: (CachedResource) -> Int, out: MutableList<Command>): Boolean {
for (image in images) {
val entry = ImageAtlas.get(image.imageId) ?: return false
out.add(Command(DRAW_OP_IMAGE, depth, intArrayOf(resource(entry.resource), image.x, image.y, IMAGE_OPTIONS),
x, y, clip = clip))
}
for ((fontId, fontGlyphs) in glyphs.groupBy { it.fontId }) {
val encodings = fontGlyphs.map { it.encoding }.toSet()
val font = FontResourceAtlas.get(fontId, encodings)
if (!font.encodings.containsAll(encodings)) return false
val fontIndex = resource(font.resource)
// One run per line and color, like TexturePlanner's: control
// bytes move the pen to each glyph's exact left edge.
val lines = fontGlyphs.groupBy { it.lineY to BmpUtil.nibbleForGray(it.value) }
for ((line, members) in lines) {
val placed = members.map { glyph ->
val atlas = GlyphAtlas.get(fontId, glyph.encoding) ?: return false
Triple(glyph.penX + atlas.bbxX, atlas.width, glyph.encoding)
}.sortedBy { it.first }
var start = 0
while (start < placed.size) {
val text = ByteSink()
var cursor = placed[start].first
var end = start
while (end < placed.size) {
val (left, width, encoding) = placed[end]
if (text.size() + TexturePlanner.adjustByteCount(left - cursor) + 1 > 255) break
TexturePlanner.emitAdjust(text, left - cursor)
text.write(encoding)
cursor = left + width
end++
}
out.add(Command(DRAW_OP_TEXT, depth,
intArrayOf(fontIndex, placed[start].first, line.first, line.second or CFW_TEXTURE_OPT_TRANSPARENT),
x, y, clip = clip, text = text.toByteArray()))
start = end
}
}
}
return true
}
fun read(input: ByteReader, nowMs: Long = drawAnimationTimeMs()): FrameDisplayList {
val length = input.getInt()
require(length in 21..MAX_RECORD_BYTES && length <= input.remaining())
@@ -81,12 +154,15 @@ class FrameDisplayList private constructor(
val elapsed = r.readU16() or (r.readU16() shl 16)
require(elapsed >= 0)
val resourceCount = r.readU16(); require(resourceCount <= 256)
val resources = List(resourceCount) {
val local = List(resourceCount) {
val w = r.readU16(); val h = r.readU16()
require(w in 1..640 && h in 1..480 && 5 + (w + 1) / 2 * h <= 65536)
val gray = r.readBytes(w * h)
CachedResource(DrawProtocol.rawImage(w, h, BmpUtil.pack4bppFromGray8(gray, w, h)))
}
val resources = ArrayList(local)
val atlasIndices = HashMap<CachedResource, Int>()
fun atlasResource(cached: CachedResource): Int = atlasIndices.getOrPut(cached) { resources.add(cached); resources.size - 1 }
fun value(): DrawValue {
val first = r.readU8()
if (first != 255) return DrawValue.Integer(ExtendedVarint.read(r, true, first))
@@ -97,23 +173,27 @@ class FrameDisplayList private constructor(
bind(it, Int.MAX_VALUE, Int.MAX_VALUE)
}
}
fun resource(): Int = r.readU16().also { require(it == DrawProtocol.SCREEN || it in resources.indices) }
fun resource(): Int = r.readU16().also { require(it == DrawProtocol.SCREEN || it in local.indices) }
val count = r.readU16(); require(count <= 4096)
val calls = List(count) {
val op = r.readU8(); val d = r.readS16(); require(depth + d in -128..127)
val commands = ArrayList<Command>()
var replayable = true
repeat(count) {
val header = r.readU8(); val op = header and CLIPPED.inv()
val d = r.readS16(); require(depth + d in -128..127)
val clip = if (header and CLIPPED != 0) DrawClip(r.readS16(), r.readS16(), r.readU16(), r.readU16()) else null
when (op) {
DRAW_OP_ROUNDED_RECT -> {
val xx = value(); val yy = value()
val w = r.readU16(); val h = r.readU16(); val radius = r.readU16()
val background = r.readU8(); val border = r.readU8()
require(w in 1..640 && h in 1..480 && background in 0..15 && border in 0..16)
Command(op, d, intArrayOf(w, h, radius, background, border), xx, yy)
commands.add(Command(op, d, intArrayOf(w, h, radius, background, border), xx, yy, clip = clip))
}
DRAW_OP_IMAGE -> {
val id = resource(); require(id != DrawProtocol.SCREEN)
val xx = r.readS16(); val yy = r.readS16(); val options = r.readU8()
require(options == 15 || options == 31)
Command(op, d, intArrayOf(id, xx, yy, options))
commands.add(Command(op, d, intArrayOf(id, xx, yy, options), clip = clip))
}
DRAW_OP_RECT_COPY -> {
val id = resource(); val sx = value(); val sy = value()
@@ -121,7 +201,29 @@ class FrameDisplayList private constructor(
require(w in 1..640 && h in 1..480)
// Relative SCREEN sources may be negative until placement is added.
require(id == DrawProtocol.SCREEN || listOf(sx, sy).all { it !is DrawValue.Integer || it.value >= 0 })
Command(op, d, intArrayOf(id, w, h), sx, sy, dx, dy)
commands.add(Command(op, d, intArrayOf(id, w, h), sx, sy, dx, dy, clip = clip))
}
DRAW_OP_CLEAR -> {
val color = r.readU8(); require(color in 0..15)
commands.add(Command(op, d, intArrayOf(color), clip = clip))
}
DRAWS -> {
val xx = value(); val yy = value()
val glyphs = ArrayList<GlyphRecord>(); val images = ArrayList<ImageRecord>()
repeat(r.readU16()) {
when (r.readU8()) {
DrawRecordKind.GLYPH -> {
val fontId = r.readU16(); val encoding = r.readU16() or (r.readU16() shl 16)
glyphs.add(GlyphRecord(fontId, encoding, r.readS16(), r.readS16(), r.readU8()))
}
DrawRecordKind.TEXTURE_IMAGE -> {
val imageId = r.readU16() or (r.readU16() shl 16)
images.add(ImageRecord(imageId, r.readS16(), r.readS16()))
}
else -> error("Unsupported display-list draw record")
}
}
if (replayable) replayable = compileDraws(glyphs, images, xx, yy, d, clip, ::atlasResource, commands)
}
else -> error("Unsupported frame display-list opcode")
}
@@ -129,7 +231,11 @@ class FrameDisplayList private constructor(
r.requireDone()
// Elapsed changes while the same timeline is resubmitted; it is not content identity.
bytes.fill(0, 13, 17)
return FrameDisplayList(x, y, depth, resources, calls, nowMs - elapsed, CachedResource(bytes).hash.toString())
val identity = CachedResource(bytes).hash.toString()
if (!replayable || commands.size > 4096 || resources.size > 511) {
return FrameDisplayList(x, y, depth, emptyList(), emptyList(), nowMs - elapsed, identity)
}
return FrameDisplayList(x, y, depth, resources, commands, nowMs - elapsed, identity)
}
}
}