Expand description
Kotlin JNI Bridge for Blinc
Provides JNI functions for embedding Blinc rendering into Kotlin/Java Android applications. This allows developers to use Blinc as a rendering engine within existing Android apps.
§Usage from Kotlin
package com.blinc
import android.view.Surface
object BlincBridge {
init {
System.loadLibrary("blinc_platform_android")
}
external fun nativeInit(surface: Surface, width: Int, height: Int, density: Float): Long
external fun nativeRenderFrame(handle: Long)
external fun nativeOnTouch(handle: Long, action: Int, x: Float, y: Float): Boolean
external fun nativeResize(handle: Long, width: Int, height: Int)
external fun nativeDestroy(handle: Long)
}§Example Usage
class BlincSurfaceView(context: Context) : SurfaceView(context), SurfaceHolder.Callback {
private var blincHandle: Long = 0
init {
holder.addCallback(this)
}
override fun surfaceCreated(holder: SurfaceHolder) {
val metrics = resources.displayMetrics
blincHandle = BlincBridge.nativeInit(
holder.surface,
holder.surfaceFrame.width(),
holder.surfaceFrame.height(),
metrics.density
)
}
override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
if (blincHandle != 0L) {
BlincBridge.nativeResize(blincHandle, width, height)
}
}
override fun surfaceDestroyed(holder: SurfaceHolder) {
if (blincHandle != 0L) {
BlincBridge.nativeDestroy(blincHandle)
blincHandle = 0
}
}
fun render() {
if (blincHandle != 0L) {
BlincBridge.nativeRenderFrame(blincHandle)
}
}
}