skiko/src/jsMain/kotlin/org/jetbrains/skia/impl/Native.js.kt [1:182]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @file:Suppress("UNCHECKED_CAST_TO_EXTERNAL_INTERFACE") package org.jetbrains.skia.impl internal actual class InteropScope actual constructor() { private val elements = mutableListOf() private var callbacksInitialized = false actual fun toInterop(string: String?): InteropPointer { return if (string != null) { toInterop(convertToZeroTerminatedString(string)) } else { 0 } } private fun toInterop(array: ByteArray?, copyArrayToWasm: Boolean): InteropPointer { return if (array != null && array.isNotEmpty()) { val data = _malloc(array.size) elements.add(data) if (copyArrayToWasm) toWasm(data, array) data } else { 0 } } actual fun toInterop(array: ByteArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = true) actual fun toInteropForResult(array: ByteArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = false) actual fun InteropPointer.fromInterop(result: ShortArray) { fromWasm(this@fromInterop, result) } private fun toInterop(array: ShortArray?, copyArrayToWasm: Boolean): InteropPointer { return if (array != null && array.isNotEmpty()) { val data = _malloc(array.size * 2) elements.add(data) if (copyArrayToWasm) toWasm(data, array) data } else { 0 } } actual fun toInterop(array: ShortArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = true) actual fun toInteropForResult(array: ShortArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = false) actual fun InteropPointer.fromInterop(result: IntArray) { fromWasm(this@fromInterop, result) } private fun toInterop(array: IntArray?, copyArrayToWasm: Boolean): InteropPointer { return if (array != null && array.isNotEmpty()) { val data = _malloc(array.size * 4) elements.add(data) if (copyArrayToWasm) toWasm(data, array) data } else { 0 } } actual fun toInterop(array: IntArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = true) actual fun toInteropForResult(array: IntArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = false) actual fun InteropPointer.fromInterop(result: LongArray) { TODO("implement wasm fromInterop(LongArray)") } actual fun toInterop(array: LongArray?): InteropPointer { TODO("implement wasm toInterop(LongArray)") } actual fun InteropPointer.fromInterop(result: FloatArray) { fromWasm(this@fromInterop, result) } private fun toInterop(array: FloatArray?, copyArrayToWasm: Boolean): InteropPointer { return if (array != null && array.isNotEmpty()) { val data = _malloc(array.size * 4) elements.add(data) if (copyArrayToWasm) toWasm(data, array) data } else { 0 } } actual fun toInterop(array: FloatArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = true) actual fun toInteropForResult(array: FloatArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = false) actual fun InteropPointer.fromInterop(result: DoubleArray) { fromWasm(this@fromInterop, result) } private fun toInterop(array: DoubleArray?, copyArrayToWasm: Boolean): InteropPointer { return if (array != null && array.isNotEmpty()) { val data = _malloc(array.size * 8) elements.add(data) if (copyArrayToWasm) toWasm(data, array) data } else { 0 } } actual fun toInterop(array: DoubleArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = true) actual fun toInteropForResult(array: DoubleArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = false) actual fun InteropPointer.fromInterop(result: ByteArray) { fromWasm(this@fromInterop, result) } private fun toInterop(array: NativePointerArray?, copyArrayToWasm: Boolean): InteropPointer { return if (array != null && array.size > 0) { val data = _malloc(array.size * 4) elements.add(data) if (copyArrayToWasm) toWasm(data, array.backing) data } else { 0 } } actual fun toInterop(array: NativePointerArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = true) actual fun toInteropForResult(array: NativePointerArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = false) actual fun InteropPointer.fromInterop(result: NativePointerArray) { return fromWasm(this@fromInterop, result.backing) } actual fun toInterop(stringArray: Array?): InteropPointer { return if (stringArray != null && stringArray.isNotEmpty()) { val ptrs = stringArray.map { toInterop(it) }.toIntArray() toInterop(ptrs) } else { 0 } } actual fun InteropPointer.fromInteropNativePointerArray(): NativePointerArray { TODO("implement wasm fromInteropNativePointerArray") } actual inline fun InteropPointer.fromInterop(decoder: ArrayInteropDecoder): Array { val size = decoder.getArraySize(this) val result = Array(size) { decoder.getArrayElement(this, it) } decoder.disposeArray(this) return result } actual fun toInteropForArraysOfPointers(interopPointers: Array): InteropPointer { return toInterop(interopPointers.toIntArray()) } actual fun booleanCallback(callback: (() -> Boolean)?): NativePointer { if (callback == null) { return 0 } initCallbacks() - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - skiko/src/wasmJsMain/kotlin/org/jetbrains/skia/impl/Native.wasm.kt [1:182]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @file:Suppress("UNCHECKED_CAST_TO_EXTERNAL_INTERFACE") package org.jetbrains.skia.impl internal actual class InteropScope actual constructor() { private val elements = mutableListOf() private var callbacksInitialized = false actual fun toInterop(string: String?): InteropPointer { return if (string != null) { toInterop(convertToZeroTerminatedString(string)) } else { 0 } } private fun toInterop(array: ByteArray?, copyArrayToWasm: Boolean): InteropPointer { return if (array != null && array.isNotEmpty()) { val data = _malloc(array.size) elements.add(data) if (copyArrayToWasm) toWasm(data, array) data } else { 0 } } actual fun toInterop(array: ByteArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = true) actual fun toInteropForResult(array: ByteArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = false) actual fun InteropPointer.fromInterop(result: ShortArray) { fromWasm(this@fromInterop, result) } private fun toInterop(array: ShortArray?, copyArrayToWasm: Boolean): InteropPointer { return if (array != null && array.isNotEmpty()) { val data = _malloc(array.size * 2) elements.add(data) if (copyArrayToWasm) toWasm(data, array) data } else { 0 } } actual fun toInterop(array: ShortArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = true) actual fun toInteropForResult(array: ShortArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = false) actual fun InteropPointer.fromInterop(result: IntArray) { fromWasm(this@fromInterop, result) } private fun toInterop(array: IntArray?, copyArrayToWasm: Boolean): InteropPointer { return if (array != null && array.isNotEmpty()) { val data = _malloc(array.size * 4) elements.add(data) if (copyArrayToWasm) toWasm(data, array) data } else { 0 } } actual fun toInterop(array: IntArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = true) actual fun toInteropForResult(array: IntArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = false) actual fun InteropPointer.fromInterop(result: LongArray) { TODO("implement wasm fromInterop(LongArray)") } actual fun toInterop(array: LongArray?): InteropPointer { TODO("implement wasm toInterop(LongArray)") } actual fun InteropPointer.fromInterop(result: FloatArray) { fromWasm(this@fromInterop, result) } private fun toInterop(array: FloatArray?, copyArrayToWasm: Boolean): InteropPointer { return if (array != null && array.isNotEmpty()) { val data = _malloc(array.size * 4) elements.add(data) if (copyArrayToWasm) toWasm(data, array) data } else { 0 } } actual fun toInterop(array: FloatArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = true) actual fun toInteropForResult(array: FloatArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = false) actual fun InteropPointer.fromInterop(result: DoubleArray) { fromWasm(this@fromInterop, result) } private fun toInterop(array: DoubleArray?, copyArrayToWasm: Boolean): InteropPointer { return if (array != null && array.isNotEmpty()) { val data = _malloc(array.size * 8) elements.add(data) if (copyArrayToWasm) toWasm(data, array) data } else { 0 } } actual fun toInterop(array: DoubleArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = true) actual fun toInteropForResult(array: DoubleArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = false) actual fun InteropPointer.fromInterop(result: ByteArray) { fromWasm(this@fromInterop, result) } private fun toInterop(array: NativePointerArray?, copyArrayToWasm: Boolean): InteropPointer { return if (array != null && array.size > 0) { val data = _malloc(array.size * 4) elements.add(data) if (copyArrayToWasm) toWasm(data, array.backing) data } else { 0 } } actual fun toInterop(array: NativePointerArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = true) actual fun toInteropForResult(array: NativePointerArray?): InteropPointer = toInterop(array = array, copyArrayToWasm = false) actual fun InteropPointer.fromInterop(result: NativePointerArray) { return fromWasm(this@fromInterop, result.backing) } actual fun toInterop(stringArray: Array?): InteropPointer { return if (stringArray != null && stringArray.isNotEmpty()) { val ptrs = stringArray.map { toInterop(it) }.toIntArray() toInterop(ptrs) } else { 0 } } actual fun InteropPointer.fromInteropNativePointerArray(): NativePointerArray { TODO("implement wasm fromInteropNativePointerArray") } actual inline fun InteropPointer.fromInterop(decoder: ArrayInteropDecoder): Array { val size = decoder.getArraySize(this) val result = Array(size) { decoder.getArrayElement(this, it) } decoder.disposeArray(this) return result } actual fun toInteropForArraysOfPointers(interopPointers: Array): InteropPointer { return toInterop(interopPointers.toIntArray()) } actual fun booleanCallback(callback: (() -> Boolean)?): NativePointer { if (callback == null) { return 0 } initCallbacks() - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -