Clean up unused code

Mostly remnants of iOS porting, where some things were temporarily in
typescript but became shared kotlin
This commit is contained in:
James Babcock committed 2026-09-30 13:54:50 -07:00
1 parent 2c088378bd
commit 7d8f03ffe5
18 files changed
+66 -644

No files matched your search

-53
View File
@@ -1,53 +0,0 @@
/** Reader for the bundled Source Han Sans serialized LVGL font. Matches
* Android LvglFontFile's metrics/glyph byte format, without a Java dependency. */
export class LvglFont {
readonly metrics: Uint8Array
private readonly view: DataView
private readonly ids = new Map<number, number>()
private readonly bitmaps: number
private readonly descriptors: number
constructor(private readonly bytes: Uint8Array) {
this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)
if (bytes.length < 64 || bytes.slice(0, 4).some(v => v !== 90)) throw new Error('Missing LVGL font header')
const height = this.u16(0x38), baseline = height - this.u16(0x3a)
const descriptor = this.pointer(this.u32(0x34))
this.bitmaps = this.pointer(this.u32(descriptor)); this.descriptors = this.pointer(this.u32(descriptor + 4))
const cmaps = this.pointer(this.u32(descriptor + 8)), packed = this.u16(descriptor + 18), count = packed & 0x1ff
if (!height || baseline < 0 || !count || ((packed >>> 9) & 15) !== 4 || (packed >>> 14) !== 3) throw new Error('Unsupported LVGL font')
this.metrics = new Uint8Array([height, baseline])
for (let i = 0; i < count; i++) {
const at = cmaps + i * 20, start = this.u32(at), length = this.u16(at + 4), first = this.u16(at + 6)
const unicodePtr = this.u32(at + 8), offsetsPtr = this.u32(at + 12), listLength = this.u16(at + 16), type = this.u8(at + 18)
if (type === 2 || type === 0) {
const offsets = type === 0 ? this.pointer(offsetsPtr) : 0
for (let n = 0; n < length; n++) {
const offset = type === 0 ? this.u8(offsets + n) : n
if (n && !offset) continue
this.ids.set(start + n, first + offset)
}
} else if (type === 1 || type === 3) {
const unicode = this.pointer(unicodePtr), offsets = offsetsPtr ? this.pointer(offsetsPtr) : -1
for (let n = 0; n < listLength; n++) {
const offset = offsets < 0 ? n : type === 1 ? this.u16(offsets + n * 2) : this.u8(offsets + n)
if (n && !offset) continue
this.ids.set(start + this.u16(unicode + n * 2), first + offset)
}
} else throw new Error('Unsupported LVGL cmap')
}
}
glyph(codePoint: number): Uint8Array {
const id = this.ids.get(codePoint)
if (!id) return new Uint8Array()
const at = this.descriptors + id * 16, bitmap = this.bitmaps + this.u32(at)
const width = this.u16(at + 8), height = this.u16(at + 10), length = width && height ? (Math.floor(width / 2) + 1) * height : 0
this.check(bitmap, length)
const result = new Uint8Array(8 + length)
result.set(this.bytes.subarray(at + 8, at + 16)); result.set(this.bytes.subarray(bitmap, bitmap + length), 8)
return result
}
private check(at: number, size: number): void { if (at < 0 || at + size > this.bytes.length) throw new Error('Truncated LVGL font') }
private pointer(address: number): number { const at = address - 0x80100000; this.check(at, 1); return at }
private u8(at: number): number { this.check(at, 1); return this.bytes[at] }
private u16(at: number): number { return this.view.getUint16(at, true) }
private u32(at: number): number { return this.view.getUint32(at, true) }
}
+5 -2
View File
@@ -1,6 +1,9 @@
import { fromData, toData } from '../native/kotlin-data'
import type { SurfaceConfiguration, SurfaceRect } from './surface-compositor'
export type { SurfaceConfiguration, SurfaceRect } from './surface-compositor'
export type SurfaceRect = { x: number; y: number; width: number; height: number }
export type SurfaceConfiguration = SurfaceRect & {
zOrder: number
transparency: 'opaque' | 'color-key'
}
declare const FaceclawKitIosSurfaceCompositor: any
/** Retained pixels, clipping, layers and composition live in shared Kotlin. */
export class SurfaceCompositor {
-103
View File
@@ -1,103 +0,0 @@
import { presentationRecords, readPresentation, paintPresentation, type Selection } from "./presentation-wire"
/** Platform-independent 8bpp surface composition for the local display. */
export type SurfaceRect = { x: number; y: number; width: number; height: number }
export type SurfaceConfiguration = SurfaceRect & {
zOrder: number
transparency: 'opaque' | 'color-key'
}
type Surface = SurfaceConfiguration & { pixels: Uint8Array; visible: boolean; selections: Selection[] }
export class SurfaceCompositor {
private readonly surfaces = new Map<string, Surface>()
private shellScene: Uint8Array | null = null
private shellReceivedAt = 0
setShellScene(bytes: Uint8Array): void { this.shellScene = new Uint8Array(bytes); this.shellReceivedAt = Date.now() }
private dimBelow = 0
private dimFactor = 1
private blanked = false
constructor(readonly width: number, readonly height: number) {
if (!Number.isInteger(width) || !Number.isInteger(height) || width <= 0 || height <= 0) {
throw new Error('Invalid compositor size')
}
}
configureSurface(id: string, options: SurfaceConfiguration): void {
if (![options.x, options.y, options.width, options.height, options.zOrder].every(Number.isInteger)
|| options.width <= 0 || options.height <= 0) throw new Error('Invalid surface geometry')
const previous = this.surfaces.get(id)
const pixels = previous?.width === options.width && previous.height === options.height
? previous.pixels : new Uint8Array(options.width * options.height)
this.surfaces.set(id, { ...options, pixels, visible: previous?.visible ?? true, selections: previous?.selections ?? [] })
}
removeSurface(id: string): void { this.surfaces.delete(id) }
setSurfaceVisible(id: string, visible: boolean): void {
const surface = this.surfaces.get(id)
if (surface) surface.visible = visible
}
/** Stereo depth only shifts the lenses; this local composite shows the unshifted screen. */
setSurfaceDepth(_id: string, _depth: number): void {}
setUnderlayDim(belowZOrder: number, factor: number): void {
if (!Number.isFinite(factor)) throw new Error('Invalid dim factor')
this.dimBelow = belowZOrder
this.dimFactor = Math.max(0, Math.min(1, factor))
}
setScreenBlanked(blanked: boolean): void { this.blanked = blanked }
submitSurfaceFrame(id: string, pixels: Uint8Array, rect: SurfaceRect, _draws: ArrayBuffer | null = null): void {
const surface = this.surfaces.get(id)
if (!surface) throw new Error(`Unknown surface: ${id}`)
if (![rect.x, rect.y, rect.width, rect.height].every(Number.isInteger)
|| rect.width <= 0 || rect.height <= 0 || pixels.length !== rect.width * rect.height) {
throw new Error('Invalid frame buffer or rectangle')
}
surface.selections = presentationRecords(_draws)
const left = Math.max(0, rect.x), right = Math.min(surface.width, rect.x + rect.width)
const top = Math.max(0, rect.y), bottom = Math.min(surface.height, rect.y + rect.height)
for (let y = top; y < bottom; y++) {
if (right <= left) break
const source = (y - rect.y) * rect.width + left - rect.x
surface.pixels.set(pixels.subarray(source, source + right - left), y * surface.width + left)
}
}
composite(): Uint8Array {
const output = new Uint8Array(this.width * this.height)
if (this.blanked) return output
const surfaces = [...this.surfaces.values()].filter(s => s.visible && !(this.shellScene && s === this.surfaces.get('shell'))).sort((a, b) => a.zOrder - b.zOrder)
for (const surface of surfaces) {
const left = Math.max(0, surface.x), right = Math.min(this.width, surface.x + surface.width)
const top = Math.max(0, surface.y), bottom = Math.min(this.height, surface.y + surface.height)
const dim = !this.shellScene && surface.zOrder < this.dimBelow ? this.dimFactor : 1
for (let y = top; y < bottom; y++) {
let source = (y - surface.y) * surface.width + left - surface.x
let target = y * this.width + left
for (let x = left; x < right; x++, source++, target++) {
const value = surface.pixels[source]
// Test the original value: opaque near-black must still cover the
// window beneath, even when dimming rounds it down to black.
if (surface.transparency === 'color-key' && value === 0) continue
output[target] = Math.round(value * dim)
}
}
}
const screen = output.slice()
if (!surfaces.some(s => s.zOrder > 1) && (this.shellScene || surfaces.some(s => s.selections.length))) {
for(let i=0;i<output.length;i++) output[i]=Math.min(15,(output[i]!+8)>>4)*16
for(const surface of surfaces) for(const row of surface.selections) paintPresentation(output,screen,this.width,this.height,{...row,x:row.x+surface.x,y:row.y+surface.y,occlusions:row.occlusions.map(r=>({...r,x:r.x+surface.x,y:r.y+surface.y}))})
}
if (this.shellScene && !surfaces.some(s => s.zOrder > 1)) {
const quantize = (v: number) => Math.min(15, (v + 8) >> 4)
for (let i=0;i<output.length;i++) output[i]=quantize(output[i])*16
const bytes=this.shellScene, view=new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)
let p=2
for(let i=0;i<view.getUint16(0,true);i++) {
const x=view.getInt16(p+2,true), y=view.getInt16(p+4,true), w=view.getUint16(p+6,true), h=view.getUint16(p+8,true), dim=view.getUint16(p+10,true), selections=view.getUint16(p+12,true), shift=Math.floor(view.getInt16(p+14,true)/2)
p+=16
if(dim<256) for(let j=0;j<output.length;j++) output[j]=Math.floor((output[j]/16)*dim/256)*16
for(let yy=0;yy<h;yy++) for(let xx=0;xx<w;xx++) {
if(x+xx+shift>=0 && y+yy>=0 && x+xx+shift<this.width && y+yy<this.height) output[(y+yy)*this.width+x+xx+shift]=quantize(bytes[p+yy*w+xx])*16
}
p+=w*h
for(let j=0;j<selections;j++) { const record=readPresentation(bytes,p);p=record.end;if(record.selection.displayList?.timeline) record.selection.displayList = { ...record.selection.displayList, presentedAt: this.shellReceivedAt, timeline: { ...record.selection.displayList.timeline, startedAt: record.selection.displayList.timeline.startedAt - (Date.now()-this.shellReceivedAt) } };paintPresentation(output,screen,this.width,this.height,record.selection) }
}
}
return output
}
}