forked from Blendman974/faceclaw
Refactor a bunch of Java to Kotlin, making it usable in an iOS port
This commit is contained in:
1 parent
c0f8f7e9c2
commit
410fd5840b
162 files changed
+9650
-6224
No files matched your search
@@ -116,7 +116,7 @@ function prepareFwTextRun(placed: PlacedFwText): boolean {
|
||||
bytes.set(entry.data.nibbles, offset + 10);
|
||||
offset += 10 + entry.data.nibbles.length;
|
||||
}
|
||||
com.faceclaw.app.FwGlyphAtlas.register(buffer);
|
||||
com.faceclaw.app.FwGlyphAtlas.register(new com.faceclaw.app.AndroidByteReader(buffer));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -130,7 +130,7 @@ function imageId(placed: PlacedImage): number | null {
|
||||
let id: number | null = null;
|
||||
if (source.width > 0 && source.width <= 255 && source.height > 0 && source.height <= 255) {
|
||||
const key = `img:${source.width}x${source.height}:${source.contentHash32().toString(16)}`;
|
||||
id = com.faceclaw.app.ImageAtlas.ensure(key, source.width, source.height, source.pixels.buffer);
|
||||
id = com.faceclaw.app.ImageAtlas.ensure(key, source.width, source.height, new com.faceclaw.app.AndroidByteReader(source.pixels.buffer));
|
||||
if (!(typeof id === "number") || id <= 0) id = null;
|
||||
}
|
||||
imageIds.set(source, id);
|
||||
@@ -184,9 +184,9 @@ export function prepareFrameDraws(draws: readonly DeferredDraw[]): ArrayBuffer |
|
||||
}
|
||||
if (registration) {
|
||||
const plainBuffer = buildRegistrationBuffer(registration);
|
||||
if (plainBuffer) com.faceclaw.app.GlyphAtlas.register(plainBuffer);
|
||||
if (plainBuffer) com.faceclaw.app.GlyphAtlas.register(new com.faceclaw.app.AndroidByteReader(plainBuffer));
|
||||
const aaBuffer = buildAaRegistrationBuffer(registration);
|
||||
if (aaBuffer) com.faceclaw.app.GlyphAtlas.registerAa(aaBuffer);
|
||||
if (aaBuffer) com.faceclaw.app.GlyphAtlas.registerAa(new com.faceclaw.app.AndroidByteReader(aaBuffer));
|
||||
}
|
||||
if (bytes === 0) return null;
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { runKotlinProtocolSmokeTest } from './kotlin-protocol-smoke';
|
||||
import { isAndroid } from "@nativescript/core";
|
||||
|
||||
// Handwritten declarations for this small native surface. NativeScript builds
|
||||
@@ -18,6 +19,7 @@ export function runKotlinBridgeSmokeTest(): void {
|
||||
if (!isAndroid) return;
|
||||
|
||||
try {
|
||||
runKotlinProtocolSmokeTest();
|
||||
const bridge = new com.faceclaw.shared.KotlinBridge();
|
||||
const greeting = bridge.greet("Faceclaw");
|
||||
const message = "Faceclaw \u2194 Kotlin \ud83d\udc53";
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
declare const com: any
|
||||
|
||||
/** Development-only checks of NativeScript metadata and bulk ByteBuffer crossings. */
|
||||
export function runKotlinProtocolSmokeTest(): void {
|
||||
const native = com.faceclaw.app
|
||||
const hex = (data: any) => Array.from({ length: data.length }, (_, i) => (data[i] & 255).toString(16).padStart(2, '0')).join('')
|
||||
const assert = (condition: boolean, what: string) => { if (!condition) throw new Error(`Kotlin protocol bridge: ${what}`) }
|
||||
const auth = native.BleProtocol.buildAuthenticationRequest(101)
|
||||
assert(hex(auth) === '080410651a0408011004', 'authentication')
|
||||
const compositor = new native.SurfaceCompositor()
|
||||
compositor.configureScreen(3, 2)
|
||||
compositor.configureSurface('test', 0, 0, 3, 2, 0, 0)
|
||||
const pixels = new Uint8Array([0, 16, 255, 32, 48, 64])
|
||||
compositor.submitSurface('test', new native.AndroidByteReader(pixels.buffer), 0, 0, 3, 2, '1')
|
||||
assert(hex(compositor.composite().gray) === '0010ff203040', 'composition/ByteBuffer')
|
||||
assert(hex(native.BmpUtil.pack4bppFromGray8(compositor.composite().gray, 3, 2)) === '01f02340', 'packing')
|
||||
const id = native.ImageAtlas.ensure('kotlin-smoke', 3, 2, new native.AndroidByteReader(pixels.buffer))
|
||||
assert(id > 0 && native.ImageAtlas.get(id).width === 3, 'image atlas/reused buffer')
|
||||
console.log('FACECLAW_KOTLIN_PROTOCOL_PASS Android')
|
||||
}
|
||||
Reference in new issue
Block a user