Unverified Commit bc1adb8d authored by Ivan Matkov's avatar Ivan Matkov Committed by GitHub

Update Kotlin to 2.0.x (#1093)

Fixes [SKIKO-1039](https://youtrack.jetbrains.com/issue/SKIKO-1039)
Update Skiko project to K2

- Update Kotlin to 2.0.10
- Fix `InteropPointer` declaration
- Fix warnings
parent 7af1712f
build build
.gradle .gradle
.kotlin
.project .project
local.properties local.properties
.DS_Store .DS_Store
......
...@@ -6,6 +6,10 @@ import tasks.configuration.* ...@@ -6,6 +6,10 @@ import tasks.configuration.*
import kotlin.collections.HashMap import kotlin.collections.HashMap
import com.android.build.gradle.LibraryExtension import com.android.build.gradle.LibraryExtension
import com.android.build.gradle.LibraryPlugin import com.android.build.gradle.LibraryPlugin
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
plugins { plugins {
kotlin("multiplatform") kotlin("multiplatform")
...@@ -59,7 +63,9 @@ kotlin { ...@@ -59,7 +63,9 @@ kotlin {
if (supportAwt) { if (supportAwt) {
jvm("awt") { jvm("awt") {
compilations.all { compilations.all {
kotlinOptions.jvmTarget = "1.8" compileTaskProvider.configure {
compilerOptions.jvmTarget.set(JvmTarget.JVM_1_8)
}
} }
generateVersion(targetOs, targetArch, skiko) generateVersion(targetOs, targetArch, skiko)
} }
...@@ -70,7 +76,9 @@ kotlin { ...@@ -70,7 +76,9 @@ kotlin {
publishLibraryVariants("release") publishLibraryVariants("release")
compilations.all { compilations.all {
kotlinOptions.jvmTarget = "1.8" compileTaskProvider.configure {
compilerOptions.jvmTarget.set(JvmTarget.JVM_1_8)
}
} }
// Keep the previously defined attribute that was used to distinguish JVM and android variant // Keep the previously defined attribute that was used to distinguish JVM and android variant
...@@ -199,6 +207,7 @@ kotlin { ...@@ -199,6 +207,7 @@ kotlin {
} }
val jvmTest by creating { val jvmTest by creating {
dependsOn(commonTest)
dependencies { dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion")
implementation(kotlin("test-junit")) implementation(kotlin("test-junit"))
...@@ -629,10 +638,10 @@ tasks.withType<JavaCompile> { ...@@ -629,10 +638,10 @@ tasks.withType<JavaCompile> {
sourceCompatibility = "1.8" sourceCompatibility = "1.8"
} }
project.tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile>().configureEach { project.tasks.withType<KotlinJsCompile>().configureEach {
kotlinOptions.freeCompilerArgs += listOf( compilerOptions.freeCompilerArgs.addAll(listOf(
"-Xwasm-enable-array-range-checks", "-Xir-dce=true", "-Xskip-prerelease-check", "-Xwasm-enable-array-range-checks", "-Xir-dce=true", "-Xskip-prerelease-check",
) ))
} }
tasks.findByName("publishSkikoWasmRuntimePublicationToComposeRepoRepository") tasks.findByName("publishSkikoWasmRuntimePublicationToComposeRepoRepository")
...@@ -641,12 +650,12 @@ tasks.findByName("publishSkikoWasmRuntimePublicationToMavenLocal") ...@@ -641,12 +650,12 @@ tasks.findByName("publishSkikoWasmRuntimePublicationToMavenLocal")
?.dependsOn("publishWasmJsPublicationToMavenLocal") ?.dependsOn("publishWasmJsPublicationToMavenLocal")
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile>().configureEach { tasks.withType<KotlinNativeCompile>().configureEach {
// https://youtrack.jetbrains.com/issue/KT-56583 // https://youtrack.jetbrains.com/issue/KT-56583
compilerOptions.freeCompilerArgs.add("-XXLanguage:+ImplicitSignedToUnsignedIntegerConversion") compilerOptions.freeCompilerArgs.add("-XXLanguage:+ImplicitSignedToUnsignedIntegerConversion")
kotlinOptions.freeCompilerArgs += "-opt-in=kotlinx.cinterop.ExperimentalForeignApi" compilerOptions.freeCompilerArgs.add("-opt-in=kotlinx.cinterop.ExperimentalForeignApi")
} }
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>>().configureEach { tasks.withType<KotlinCompilationTask<*>>().configureEach {
kotlinOptions.freeCompilerArgs += "-Xexpect-actual-classes" compilerOptions.freeCompilerArgs.add("-Xexpect-actual-classes")
} }
kotlin.version=1.9.21 kotlin.version=2.0.10
...@@ -2,6 +2,7 @@ org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=512m ...@@ -2,6 +2,7 @@ org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=512m
kotlin.code.style=official kotlin.code.style=official
kotlin.mpp.applyDefaultHierarchyTemplate=false kotlin.mpp.applyDefaultHierarchyTemplate=false
kotlin.mpp.enableCInteropCommonization=true
deploy.version=0.0.0 deploy.version=0.0.0
......
...@@ -7,6 +7,7 @@ import org.jetbrains.kotlin.ir.expressions.IrConst ...@@ -7,6 +7,7 @@ import org.jetbrains.kotlin.ir.expressions.IrConst
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
import org.jetbrains.kotlin.ir.util.constructors import org.jetbrains.kotlin.ir.util.constructors
import org.jetbrains.kotlin.ir.util.defaultType import org.jetbrains.kotlin.ir.util.defaultType
import org.jetbrains.kotlin.ir.util.getAnnotation import org.jetbrains.kotlin.ir.util.getAnnotation
...@@ -26,6 +27,7 @@ internal class ImportGeneratorTransformer(private val pluginContext: IrPluginCon ...@@ -26,6 +27,7 @@ internal class ImportGeneratorTransformer(private val pluginContext: IrPluginCon
private fun IrConstructorCall.getStringValue(value: String): String = private fun IrConstructorCall.getStringValue(value: String): String =
(getValueArgument(Name.identifier(value)) as IrConst<String>).value (getValueArgument(Name.identifier(value)) as IrConst<String>).value
@OptIn(UnsafeDuringIrConstructionAPI::class)
private fun IrFunction.addWasmImportAnnotation(name: String) { private fun IrFunction.addWasmImportAnnotation(name: String) {
val annotationClass = pluginContext.referenceClass( val annotationClass = pluginContext.referenceClass(
ClassId.fromString("kotlin/wasm/WasmImport") // Replace with your fully qualified annotation name ClassId.fromString("kotlin/wasm/WasmImport") // Replace with your fully qualified annotation name
......
...@@ -33,7 +33,7 @@ internal actual fun makeDefaultRenderFactory(): RenderFactory = ...@@ -33,7 +33,7 @@ internal actual fun makeDefaultRenderFactory(): RenderFactory =
GraphicsApi.SOFTWARE_FAST -> LinuxSoftwareRedrawer(layer, analytics, properties) GraphicsApi.SOFTWARE_FAST -> LinuxSoftwareRedrawer(layer, analytics, properties)
else -> LinuxOpenGLRedrawer(layer, analytics, properties) else -> LinuxOpenGLRedrawer(layer, analytics, properties)
} }
OS.Android, OS.JS, OS.Ios, OS.Tvos, OS.Unknown -> throw UnsupportedOperationException("The awt target doesn't support $hostOs") else -> throw UnsupportedOperationException("AWT doesn't support $hostOs")
} }
} }
...@@ -44,11 +44,12 @@ internal actual fun URIHandler_openUri(uri: String) { ...@@ -44,11 +44,12 @@ internal actual fun URIHandler_openUri(uri: String) {
} else when (hostOs) { } else when (hostOs) {
OS.Linux -> { OS.Linux -> {
URI(uri) // Validate URI for exception behavior consistent with the Desktop.browse() case (throwing URISyntaxException) URI(uri) // Validate URI for exception behavior consistent with the Desktop.browse() case (throwing URISyntaxException)
Runtime.getRuntime().exec(arrayOf("xdg-open", URL(uri).toString())) Runtime.getRuntime().exec(arrayOf("xdg-open", URI(uri).toString()))
} }
OS.Android, OS.Windows, OS.MacOS, OS.Ios, OS.Tvos, OS.JS, OS.Unknown -> { OS.Windows, OS.MacOS -> {
throw UnsupportedOperationException("AWT does not support the BROWSE action on this platform") throw UnsupportedOperationException("AWT doesn't support the BROWSE action on $hostOs")
} }
else -> throw UnsupportedOperationException("AWT doesn't support $hostOs")
} }
} }
......
...@@ -124,10 +124,7 @@ internal val platformOperations: PlatformOperations by lazy { ...@@ -124,10 +124,7 @@ internal val platformOperations: PlatformOperations by lazy {
} }
} }
} }
OS.Android -> TODO() else -> throw UnsupportedOperationException()
OS.JS, OS.Ios, OS.Tvos, OS.Unknown -> {
TODO("Commonize me")
}
} }
} }
......
...@@ -107,6 +107,7 @@ actual open class SkiaLayer internal constructor( ...@@ -107,6 +107,7 @@ actual open class SkiaLayer internal constructor(
@Suppress("OVERRIDE_DEPRECATION") @Suppress("OVERRIDE_DEPRECATION")
override fun reshape(x: Int, y: Int, width: Int, height: Int) { override fun reshape(x: Int, y: Int, width: Int, height: Int) {
Logger.debug { "reshape(x=$x, y=$y, w=$width, h=$height) called on $this" } Logger.debug { "reshape(x=$x, y=$y, w=$width, h=$height) called on $this" }
@Suppress("DEPRECATION")
super.reshape(x, y, width, height) super.reshape(x, y, width, height)
redrawer?.syncBounds() redrawer?.syncBounds()
...@@ -382,6 +383,7 @@ actual open class SkiaLayer internal constructor( ...@@ -382,6 +383,7 @@ actual open class SkiaLayer internal constructor(
@Suppress("OVERRIDE_DEPRECATION") @Suppress("OVERRIDE_DEPRECATION")
override fun reshape(x: Int, y: Int, w: Int, h: Int) { override fun reshape(x: Int, y: Int, w: Int, h: Int) {
@Suppress("DEPRECATION")
super.reshape(x, y, w, h) super.reshape(x, y, w, h)
// Calling redrawImmediately as early as possible improves the situation with // Calling redrawImmediately as early as possible improves the situation with
......
...@@ -23,6 +23,7 @@ package org.jetbrains.skia ...@@ -23,6 +23,7 @@ package org.jetbrains.skia
*/ */
class CubicResampler(val b: Float, val c: Float) : SamplingMode { class CubicResampler(val b: Float, val c: Float) : SamplingMode {
@Suppress("OVERRIDE_DEPRECATION")
override fun _pack(): Long = (0x8L shl 60) or ((b.toBits().toULong() shl 32) or c.toBits().toULong()).toLong() override fun _pack(): Long = (0x8L shl 60) or ((b.toBits().toULong() shl 32) or c.toBits().toULong()).toLong()
override fun _packedInt1(): Int = b.toBits() or (0x8 shl 28) override fun _packedInt1(): Int = b.toBits() or (0x8 shl 28)
......
...@@ -5,6 +5,7 @@ class FilterMipmap constructor( ...@@ -5,6 +5,7 @@ class FilterMipmap constructor(
internal val mipmapMode: MipmapMode = MipmapMode.NONE internal val mipmapMode: MipmapMode = MipmapMode.NONE
) : SamplingMode { ) : SamplingMode {
@Suppress("OVERRIDE_DEPRECATION")
override fun _pack() = filterMode.ordinal.toLong() shl 32 or mipmapMode.ordinal.toLong() override fun _pack() = filterMode.ordinal.toLong() shl 32 or mipmapMode.ordinal.toLong()
override fun _packedInt1(): Int = filterMode.ordinal override fun _packedInt1(): Int = filterMode.ordinal
......
...@@ -162,6 +162,7 @@ class FontMetrics( ...@@ -162,6 +162,7 @@ class FontMetrics(
companion object companion object
} }
@Suppress("NOTHING_TO_INLINE")
private inline fun Float.asNumberOrNull(): Float? = if (isNaN()) null else this private inline fun Float.asNumberOrNull(): Float? = if (isNaN()) null else this
private fun FontMetrics.Companion.fromRawData(rawData: FloatArray) = FontMetrics( private fun FontMetrics.Companion.fromRawData(rawData: FloatArray) = FontMetrics(
......
...@@ -284,7 +284,7 @@ class ImageInfo(val colorInfo: ColorInfo, val width: Int, val height: Int) { ...@@ -284,7 +284,7 @@ class ImageInfo(val colorInfo: ColorInfo, val width: Int, val height: Int) {
return ImageInfo(ColorInfo(ColorType.UNKNOWN, ColorAlphaType.UNKNOWN, null), width, height) return ImageInfo(ColorInfo(ColorType.UNKNOWN, ColorAlphaType.UNKNOWN, null), width, height)
} }
fun createUsing( internal fun createUsing(
_ptr: NativePointer, _ptr: NativePointer,
_nGetImageInfo: (_ptr: NativePointer, intArrayPointer: InteropPointer, nativePointerArrayPtr: InteropPointer) -> Unit _nGetImageInfo: (_ptr: NativePointer, intArrayPointer: InteropPointer, nativePointerArrayPtr: InteropPointer) -> Unit
): ImageInfo { ): ImageInfo {
......
...@@ -4,7 +4,7 @@ import org.jetbrains.skia.ManagedString ...@@ -4,7 +4,7 @@ import org.jetbrains.skia.ManagedString
expect class NativePointer expect class NativePointer
expect class InteropPointer internal expect class InteropPointer
expect abstract class Native(ptr: NativePointer) { expect abstract class Native(ptr: NativePointer) {
internal var _ptr: NativePointer internal var _ptr: NativePointer
...@@ -157,6 +157,7 @@ internal inline fun withStringResult(block: () -> NativePointer): String { ...@@ -157,6 +157,7 @@ internal inline fun withStringResult(block: () -> NativePointer): String {
return ManagedString(block()).use { it.toString() } return ManagedString(block()).use { it.toString() }
} }
@Suppress("NOTHING_TO_INLINE")
internal inline fun withStringResult(pointer: NativePointer): String { internal inline fun withStringResult(pointer: NativePointer): String {
return ManagedString(pointer).use { it.toString() } return ManagedString(pointer).use { it.toString() }
} }
......
...@@ -219,6 +219,7 @@ class StrutStyle internal constructor(ptr: NativePointer) : Managed(ptr, _Finali ...@@ -219,6 +219,7 @@ class StrutStyle internal constructor(ptr: NativePointer) : Managed(ptr, _Finali
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) {
@Suppress("DEPRECATION")
setHalfLeading(value) setHalfLeading(value)
} }
......
...@@ -40,7 +40,7 @@ class TextBox(val rect: Rect, direction: Direction) { ...@@ -40,7 +40,7 @@ class TextBox(val rect: Rect, direction: Direction) {
_direction = direction _direction = direction
} }
companion object : ArrayInteropDecoder<TextBox> { internal companion object : ArrayInteropDecoder<TextBox> {
override fun getArrayElement(array: InteropPointer, index: Int): TextBox { override fun getArrayElement(array: InteropPointer, index: Int): TextBox {
val rect = FloatArray(4) val rect = FloatArray(4)
val direction = IntArray(1) val direction = IntArray(1)
......
...@@ -332,6 +332,7 @@ class TextStyle internal constructor(ptr: NativePointer) : Managed(ptr, _Finaliz ...@@ -332,6 +332,7 @@ class TextStyle internal constructor(ptr: NativePointer) : Managed(ptr, _Finaliz
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) {
@Suppress("DEPRECATION")
setHalfLeading(value) setHalfLeading(value)
} }
......
@file:Suppress("NESTED_EXTERNAL_DECLARATION")
package org.jetbrains.skia.shaper package org.jetbrains.skia.shaper
import org.jetbrains.skia.ExternalSymbolName import org.jetbrains.skia.ExternalSymbolName
......
@file:Suppress("NESTED_EXTERNAL_DECLARATION")
package org.jetbrains.skia.shaper package org.jetbrains.skia.shaper
import org.jetbrains.skia.ExternalSymbolName import org.jetbrains.skia.ExternalSymbolName
......
@file:Suppress("NESTED_EXTERNAL_DECLARATION")
package org.jetbrains.skia.shaper package org.jetbrains.skia.shaper
import org.jetbrains.skia.ExternalSymbolName import org.jetbrains.skia.ExternalSymbolName
......
@file:Suppress("NESTED_EXTERNAL_DECLARATION")
package org.jetbrains.skia.shaper package org.jetbrains.skia.shaper
import org.jetbrains.skia.ExternalSymbolName import org.jetbrains.skia.ExternalSymbolName
......
@file:Suppress("NESTED_EXTERNAL_DECLARATION")
package org.jetbrains.skia.shaper package org.jetbrains.skia.shaper
import org.jetbrains.skia.* import org.jetbrains.skia.*
......
@file:Suppress("NESTED_EXTERNAL_DECLARATION")
package org.jetbrains.skia.skottie package org.jetbrains.skia.skottie
import org.jetbrains.skia.impl.Library.Companion.staticLoad import org.jetbrains.skia.impl.Library.Companion.staticLoad
......
@file:Suppress("NESTED_EXTERNAL_DECLARATION")
package org.jetbrains.skia.skottie package org.jetbrains.skia.skottie
import org.jetbrains.skia.Data import org.jetbrains.skia.Data
......
@file:Suppress("NESTED_EXTERNAL_DECLARATION")
package org.jetbrains.skia.skottie package org.jetbrains.skia.skottie
import org.jetbrains.skia.ExternalSymbolName import org.jetbrains.skia.ExternalSymbolName
......
package org.jetbrains.skia package org.jetbrains.skia
import org.jetbrains.skia.impl.reachabilityBarrier
import org.jetbrains.skiko.OS import org.jetbrains.skiko.OS
import org.jetbrains.skiko.hostOs import org.jetbrains.skiko.hostOs
import org.jetbrains.skiko.tests.* import org.jetbrains.skiko.tests.*
......
...@@ -10,13 +10,13 @@ expect fun runTest(block: suspend () -> Unit): TestReturnType ...@@ -10,13 +10,13 @@ expect fun runTest(block: suspend () -> Unit): TestReturnType
internal expect fun InteropScope.allocateBytesForPixels(size: Int): NativePointer internal expect fun InteropScope.allocateBytesForPixels(size: Int): NativePointer
expect annotation class SkipNativeTarget expect annotation class SkipNativeTarget()
expect annotation class SkipJsTarget expect annotation class SkipJsTarget()
expect annotation class SkipWasmTarget expect annotation class SkipWasmTarget()
expect annotation class SkipJvmTarget expect annotation class SkipJvmTarget()
expect fun makeFromFileName(path: String?): Data expect fun makeFromFileName(path: String?): Data
......
...@@ -24,7 +24,7 @@ object SkikoDispatchers { ...@@ -24,7 +24,7 @@ object SkikoDispatchers {
) )
} }
@OptIn(InternalCoroutinesApi::class) @OptIn(InternalCoroutinesApi::class, ExperimentalCoroutinesApi::class)
internal class NsQueueDispatcher( internal class NsQueueDispatcher(
private val dispatchQueue: dispatch_queue_t private val dispatchQueue: dispatch_queue_t
) : CoroutineDispatcher(), Delay { ) : CoroutineDispatcher(), Delay {
...@@ -34,7 +34,6 @@ internal class NsQueueDispatcher( ...@@ -34,7 +34,6 @@ internal class NsQueueDispatcher(
} }
} }
@OptIn(InternalCoroutinesApi::class)
override fun scheduleResumeAfterDelay(timeMillis: Long, continuation: CancellableContinuation<Unit>) { override fun scheduleResumeAfterDelay(timeMillis: Long, continuation: CancellableContinuation<Unit>) {
val timer = Timer() val timer = Timer()
val timerBlock: TimerBlock = { val timerBlock: TimerBlock = {
...@@ -45,8 +44,6 @@ internal class NsQueueDispatcher( ...@@ -45,8 +44,6 @@ internal class NsQueueDispatcher(
continuation.disposeOnCancellation(timer) continuation.disposeOnCancellation(timer)
} }
@OptIn(InternalCoroutinesApi::class)
override fun invokeOnTimeout(timeMillis: Long, block: Runnable, context: CoroutineContext): DisposableHandle { override fun invokeOnTimeout(timeMillis: Long, block: Runnable, context: CoroutineContext): DisposableHandle {
val timer = Timer() val timer = Timer()
val timerBlock: TimerBlock = { val timerBlock: TimerBlock = {
...@@ -61,20 +58,15 @@ internal class NsQueueDispatcher( ...@@ -61,20 +58,15 @@ internal class NsQueueDispatcher(
internal typealias TimerBlock = (CFRunLoopTimerRef?) -> Unit internal typealias TimerBlock = (CFRunLoopTimerRef?) -> Unit
@SharedImmutable
private val TIMER_NEW = NativePtr.NULL private val TIMER_NEW = NativePtr.NULL
@SharedImmutable
private val TIMER_DISPOSED = NativePtr.NULL.plus(1) private val TIMER_DISPOSED = NativePtr.NULL.plus(1)
private class Timer : DisposableHandle { private class Timer : DisposableHandle {
private val ref = AtomicNativePtr(TIMER_NEW) private val ref = AtomicNativePtr(TIMER_NEW)
init { freeze() }
fun start(timeMillis: Long, timerBlock: TimerBlock) { fun start(timeMillis: Long, timerBlock: TimerBlock) {
val fireDate = CFAbsoluteTimeGetCurrent() + timeMillis / 1000.0 val fireDate = CFAbsoluteTimeGetCurrent() + timeMillis / 1000.0
@Suppress("EXPERIMENTAL_UNSIGNED_LITERALS")
val timer = CFRunLoopTimerCreateWithHandler(null, fireDate, 0.0, 0u, 0, timerBlock)!! val timer = CFRunLoopTimerCreateWithHandler(null, fireDate, 0.0, 0u, 0, timerBlock)!!
CFRunLoopAddTimer(CFRunLoopGetMain(), timer, kCFRunLoopCommonModes) CFRunLoopAddTimer(CFRunLoopGetMain(), timer, kCFRunLoopCommonModes)
if (!ref.compareAndSet(TIMER_NEW, timer.rawValue)) { if (!ref.compareAndSet(TIMER_NEW, timer.rawValue)) {
......
@file:Suppress("UNCHECKED_CAST_TO_EXTERNAL_INTERFACE")
package org.jetbrains.skia.impl package org.jetbrains.skia.impl
internal actual class InteropScope actual constructor() { internal actual class InteropScope actual constructor() {
...@@ -242,6 +244,7 @@ internal actual class InteropScope actual constructor() { ...@@ -242,6 +244,7 @@ internal actual class InteropScope actual constructor() {
releaseCallbacks() releaseCallbacks()
} }
@Suppress("NOTHING_TO_INLINE")
private inline fun initCallbacks() { private inline fun initCallbacks() {
if (!callbacksInitialized) { if (!callbacksInitialized) {
_createLocalCallbackScope() _createLocalCallbackScope()
...@@ -249,6 +252,7 @@ internal actual class InteropScope actual constructor() { ...@@ -249,6 +252,7 @@ internal actual class InteropScope actual constructor() {
} }
} }
@Suppress("NOTHING_TO_INLINE")
private inline fun releaseCallbacks() { private inline fun releaseCallbacks() {
if (callbacksInitialized) { if (callbacksInitialized) {
_releaseLocalCallbackScope() _releaseLocalCallbackScope()
......
...@@ -48,14 +48,14 @@ internal actual fun reachabilityBarrier(obj: Any?) { ...@@ -48,14 +48,14 @@ internal actual fun reachabilityBarrier(obj: Any?) {
actual typealias NativePointer = Long actual typealias NativePointer = Long
@Suppress("ACTUAL_TYPE_ALIAS_TO_NULLABLE_TYPE") internal actual typealias InteropPointer = java.lang.Object
actual typealias InteropPointer = Any?
internal object theScope: InteropScope() internal object theScope: InteropScope()
internal actual inline fun <T> interopScope(block: InteropScope.() -> T): T { internal actual inline fun <T> interopScope(block: InteropScope.() -> T): T {
return theScope.block() return theScope.block()
} }
@Suppress("RETURN_TYPE_MISMATCH") // Hack to pass nulls as InteropPointer
internal actual open class InteropScope actual constructor() { internal actual open class InteropScope actual constructor() {
actual fun toInterop(string: String?): InteropPointer = string actual fun toInterop(string: String?): InteropPointer = string
...@@ -93,11 +93,11 @@ internal actual open class InteropScope actual constructor() { ...@@ -93,11 +93,11 @@ internal actual open class InteropScope actual constructor() {
this@fromInterop as Array<T> this@fromInterop as Array<T>
actual fun toInteropForArraysOfPointers(interopPointers: Array<InteropPointer>): InteropPointer = interopPointers actual fun toInteropForArraysOfPointers(interopPointers: Array<InteropPointer>): InteropPointer = interopPointers
actual fun callback(callback: (() -> Unit)?) = callback as Any? actual fun callback(callback: (() -> Unit)?): InteropPointer = callback
actual fun intCallback(callback: (() -> Int)?) = callback as Any? actual fun intCallback(callback: (() -> Int)?): InteropPointer = callback
actual fun nativePointerCallback(callback: (() -> NativePointer)?) = callback as Any? actual fun nativePointerCallback(callback: (() -> NativePointer)?): InteropPointer = callback
actual fun interopPointerCallback(callback: (() -> InteropPointer)?) = callback as Any? actual fun interopPointerCallback(callback: (() -> InteropPointer)?): InteropPointer = callback
actual fun booleanCallback(callback: (() -> Boolean)?) = callback as Any? actual fun booleanCallback(callback: (() -> Boolean)?): InteropPointer = callback
actual fun virtual(method: () -> Unit) = callback(method) actual fun virtual(method: () -> Unit) = callback(method)
actual fun virtualInt(method: () -> Int) = intCallback(method) actual fun virtualInt(method: () -> Int) = intCallback(method)
......
...@@ -127,12 +127,12 @@ object SkikoProperties { ...@@ -127,12 +127,12 @@ object SkikoProperties {
} }
private fun bestRenderApiForCurrentOS(): GraphicsApi { private fun bestRenderApiForCurrentOS(): GraphicsApi {
when(hostOs) { return when(hostOs) {
OS.MacOS -> return GraphicsApi.METAL OS.MacOS -> GraphicsApi.METAL
OS.Linux -> return GraphicsApi.OPENGL OS.Linux -> GraphicsApi.OPENGL
OS.Windows -> return if (renderingAngleEnabled) GraphicsApi.ANGLE else GraphicsApi.DIRECT3D OS.Windows -> if (renderingAngleEnabled) GraphicsApi.ANGLE else GraphicsApi.DIRECT3D
OS.Android -> return GraphicsApi.OPENGL OS.Android -> GraphicsApi.OPENGL
OS.JS, OS.Ios, OS.Tvos, OS.Unknown -> TODO("commonize me") else -> GraphicsApi.UNKNOWN
} }
} }
...@@ -146,7 +146,7 @@ object SkikoProperties { ...@@ -146,7 +146,7 @@ object SkikoProperties {
else -> listOf(GraphicsApi.ANGLE, GraphicsApi.DIRECT3D, GraphicsApi.OPENGL, GraphicsApi.SOFTWARE_FAST, GraphicsApi.SOFTWARE_COMPAT) else -> listOf(GraphicsApi.ANGLE, GraphicsApi.DIRECT3D, GraphicsApi.OPENGL, GraphicsApi.SOFTWARE_FAST, GraphicsApi.SOFTWARE_COMPAT)
} }
OS.Android -> return listOf(GraphicsApi.OPENGL) OS.Android -> return listOf(GraphicsApi.OPENGL)
OS.JS, OS.Ios, OS.Tvos, OS.Unknown -> TODO("commonize me") else -> return listOf(GraphicsApi.UNKNOWN)
} }
val indexOfInitialApi = fallbackApis.indexOf(initialApi) val indexOfInitialApi = fallbackApis.indexOf(initialApi)
......
@file:OptIn(BetaInteropApi::class)
package org.jetbrains.skiko.redrawer package org.jetbrains.skiko.redrawer
import kotlinx.cinterop.BetaInteropApi
import kotlinx.cinterop.addressOf import kotlinx.cinterop.addressOf
import kotlinx.cinterop.autoreleasepool import kotlinx.cinterop.autoreleasepool
import kotlinx.cinterop.objcPtr import kotlinx.cinterop.objcPtr
......
@file:OptIn(BetaInteropApi::class)
package org.jetbrains.skiko.redrawer package org.jetbrains.skiko.redrawer
import kotlinx.cinterop.BetaInteropApi
import kotlinx.cinterop.CPointer import kotlinx.cinterop.CPointer
import kotlinx.cinterop.useContents import kotlinx.cinterop.useContents
import org.jetbrains.skiko.FrameDispatcher import org.jetbrains.skiko.FrameDispatcher
......
@file:Suppress("OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE") // https://youtrack.jetbrains.com/issue/KT-50727
package org.jetbrains.skia package org.jetbrains.skia
import org.jetbrains.skia.impl.InteropPointer import org.jetbrains.skia.impl.InteropPointer
......
...@@ -3,8 +3,9 @@ package org.jetbrains.skia.impl ...@@ -3,8 +3,9 @@ package org.jetbrains.skia.impl
import kotlinx.cinterop.nativeNullPtr import kotlinx.cinterop.nativeNullPtr
import org.jetbrains.skia.ExternalSymbolName import org.jetbrains.skia.ExternalSymbolName
import kotlin.concurrent.AtomicNativePtr import kotlin.concurrent.AtomicNativePtr
import kotlin.experimental.ExperimentalNativeApi
import kotlin.native.concurrent.freeze import kotlin.native.concurrent.freeze
import kotlin.native.internal.createCleaner import kotlin.native.ref.createCleaner
private class FinalizationThunk(private val finalizer: NativePointer, val className: String, obj: NativePointer) { private class FinalizationThunk(private val finalizer: NativePointer, val className: String, obj: NativePointer) {
private var obj = AtomicNativePtr(obj) private var obj = AtomicNativePtr(obj)
...@@ -29,10 +30,11 @@ actual abstract class Managed actual constructor( ...@@ -29,10 +30,11 @@ actual abstract class Managed actual constructor(
require(finalizer != NullPointer) { "Managed finalizer is nullptr" } require(finalizer != NullPointer) { "Managed finalizer is nullptr" }
val className = this::class.simpleName ?: "<kotlin>" val className = this::class.simpleName ?: "<kotlin>"
Stats.onAllocated(className) Stats.onAllocated(className)
FinalizationThunk(finalizer, className, ptr).freeze() FinalizationThunk(finalizer, className, ptr)
} else null } else null
@OptIn(ExperimentalStdlibApi::class) @Suppress("unused")
@OptIn(ExperimentalNativeApi::class)
private val cleaner = if (managed) { private val cleaner = if (managed) {
createCleaner(thunk) { createCleaner(thunk) {
it?.clean() it?.clean()
......
...@@ -48,7 +48,7 @@ actual abstract class Native actual constructor(ptr: NativePointer) { ...@@ -48,7 +48,7 @@ actual abstract class Native actual constructor(ptr: NativePointer) {
} }
actual typealias NativePointer = NativePtr actual typealias NativePointer = NativePtr
actual typealias InteropPointer = NativePtr internal actual typealias InteropPointer = NativePtr
internal actual fun reachabilityBarrier(obj: Any?) { internal actual fun reachabilityBarrier(obj: Any?) {
// TODO: implement native barrier // TODO: implement native barrier
......
package org.jetbrains.skiko package org.jetbrains.skiko
import kotlin.time.TimeSource
internal actual inline fun <R> maybeSynchronized(lock: Any, block: () -> R): R = internal actual inline fun <R> maybeSynchronized(lock: Any, block: () -> R): R =
block() block()
actual fun currentNanoTime(): Long = kotlin.system.getTimeNanos() private val markNow = TimeSource.Monotonic.markNow()
actual fun currentNanoTime(): Long = markNow.elapsedNow().inWholeNanoseconds
internal actual fun loadAngleLibrary() { internal actual fun loadAngleLibrary() {
// Nothing to do here // Nothing to do here
} }
\ No newline at end of file
@file:OptIn(BetaInteropApi::class)
package org.jetbrains.skiko package org.jetbrains.skiko
import kotlinx.cinterop.* import kotlinx.cinterop.*
...@@ -11,7 +13,6 @@ import kotlin.native.ref.* ...@@ -11,7 +13,6 @@ import kotlin.native.ref.*
internal expect fun UIView.skikoInitializeUIView(): Unit internal expect fun UIView.skikoInitializeUIView(): Unit
@Suppress("CONFLICTING_OVERLOADS")
@ExportObjCClass @ExportObjCClass
class SkikoUIView : UIView { class SkikoUIView : UIView {
companion object : UIViewMeta() { companion object : UIViewMeta() {
......
@file:OptIn(BetaInteropApi::class)
package org.jetbrains.skiko.redrawer package org.jetbrains.skiko.redrawer
import kotlinx.cinterop.* import kotlinx.cinterop.*
......
@file:Suppress("UNCHECKED_CAST_TO_EXTERNAL_INTERFACE")
package org.jetbrains.skia.impl package org.jetbrains.skia.impl
internal actual class InteropScope actual constructor() { internal actual class InteropScope actual constructor() {
......
...@@ -36,7 +36,7 @@ actual abstract class Native actual constructor(ptr: NativePointer) { ...@@ -36,7 +36,7 @@ actual abstract class Native actual constructor(ptr: NativePointer) {
internal actual fun reachabilityBarrier(obj: Any?) {} internal actual fun reachabilityBarrier(obj: Any?) {}
actual typealias NativePointer = Int actual typealias NativePointer = Int
actual typealias InteropPointer = Int internal actual typealias InteropPointer = Int
private val INTEROP_SCOPE = InteropScope() private val INTEROP_SCOPE = InteropScope()
private var interopScopeCounter = 0 private var interopScopeCounter = 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment