package org.jetbrains.skiko

import org.jetbrains.skia.ColorType
import platform.ArkTS.ArkTS_Napi_NativeModule.napi_env
import kotlin.concurrent.Volatile

object ArkTsContext {
    @Volatile
    private var napiEnv: napi_env? = null
    val NapiEnv: napi_env get() = napiEnv ?: error("napiEnv is null")
    fun initEnv(env: napi_env) {
        napiEnv = env;
        // Fusion-renderer only: align the platform-native 32-bit color order with OHRender's C++ side.
        // OHRender is built with SK_R32_SHIFT defaulting to 0, so its native kN32 is RGBA_8888 (its
        // image decoders and MakeRasterN32Premul all produce RGBA). skiko's commonMain default is
        // ColorType.N32 = BGRA_8888, leaving the Kotlin side disagreeing with native: a BGRA dst (e.g.
        // AnimatedImagePainter.readFrameToImage's makeN32Premul) reaches an RGBA codec and used to hit
        // kInvalidConversion. Setting N32 = RGBA here makes the Kotlin side match native everywhere.
        // The self-render (skia) source set has no ArkTsContext, so it keeps the BGRA default untouched.
        ColorType.N32 = ColorType.RGBA_8888
    }
    private var ratio: Float = 1.0F
    val Ratio: Float get() = ratio
    fun initRatio(rat: Float) {
        ratio = rat
    }
}
