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
.gradle
.kotlin
.project
local.properties
.DS_Store
......
......@@ -6,6 +6,10 @@ import tasks.configuration.*
import kotlin.collections.HashMap
import com.android.build.gradle.LibraryExtension
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 {
kotlin("multiplatform")
......@@ -59,7 +63,9 @@ kotlin {
if (supportAwt) {
jvm("awt") {
compilations.all {
kotlinOptions.jvmTarget = "1.8"
compileTaskProvider.configure {
compilerOptions.jvmTarget.set(JvmTarget.JVM_1_8)
}
}
generateVersion(targetOs, targetArch, skiko)
}
......@@ -70,7 +76,9 @@ kotlin {
publishLibraryVariants("release")
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
......@@ -199,6 +207,7 @@ kotlin {
}
val jvmTest by creating {
dependsOn(commonTest)
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion")
implementation(kotlin("test-junit"))
......@@ -629,10 +638,10 @@ tasks.withType<JavaCompile> {
sourceCompatibility = "1.8"
}
project.tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile>().configureEach {
kotlinOptions.freeCompilerArgs += listOf(
project.tasks.withType<KotlinJsCompile>().configureEach {
compilerOptions.freeCompilerArgs.addAll(listOf(
"-Xwasm-enable-array-range-checks", "-Xir-dce=true", "-Xskip-prerelease-check",
)
))
}
tasks.findByName("publishSkikoWasmRuntimePublicationToComposeRepoRepository")
......@@ -641,12 +650,12 @@ tasks.findByName("publishSkikoWasmRuntimePublicationToMavenLocal")
?.dependsOn("publishWasmJsPublicationToMavenLocal")
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile>().configureEach {
tasks.withType<KotlinNativeCompile>().configureEach {
// https://youtrack.jetbrains.com/issue/KT-56583
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 {
kotlinOptions.freeCompilerArgs += "-Xexpect-actual-classes"
tasks.withType<KotlinCompilationTask<*>>().configureEach {
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
kotlin.code.style=official
kotlin.mpp.applyDefaultHierarchyTemplate=false
kotlin.mpp.enableCInteropCommonization=true
deploy.version=0.0.0
......
......@@ -7,6 +7,7 @@ import org.jetbrains.kotlin.ir.expressions.IrConst
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
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.defaultType
import org.jetbrains.kotlin.ir.util.getAnnotation
......@@ -26,6 +27,7 @@ internal class ImportGeneratorTransformer(private val pluginContext: IrPluginCon
private fun IrConstructorCall.getStringValue(value: String): String =
(getValueArgument(Name.identifier(value)) as IrConst<String>).value
@OptIn(UnsafeDuringIrConstructionAPI::class)
private fun IrFunction.addWasmImportAnnotation(name: String) {
val annotationClass = pluginContext.referenceClass(
ClassId.fromString("kotlin/wasm/WasmImport") // Replace with your fully qualified annotation name
......
......@@ -33,7 +33,7 @@ internal actual fun makeDefaultRenderFactory(): RenderFactory =
GraphicsApi.SOFTWARE_FAST -> LinuxSoftwareRedrawer(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) {
} else when (hostOs) {
OS.Linux -> {
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 -> {
throw UnsupportedOperationException("AWT does not support the BROWSE action on this platform")
OS.Windows, OS.MacOS -> {
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 {
}
}
}
OS.Android -> TODO()
OS.JS, OS.Ios, OS.Tvos, OS.Unknown -> {
TODO("Commonize me")
}
else -> throw UnsupportedOperationException()
}
}
......
......@@ -107,6 +107,7 @@ actual open class SkiaLayer internal constructor(
@Suppress("OVERRIDE_DEPRECATION")
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" }
@Suppress("DEPRECATION")
super.reshape(x, y, width, height)
redrawer?.syncBounds()
......@@ -382,6 +383,7 @@ actual open class SkiaLayer internal constructor(
@Suppress("OVERRIDE_DEPRECATION")
override fun reshape(x: Int, y: Int, w: Int, h: Int) {
@Suppress("DEPRECATION")
super.reshape(x, y, w, h)
// Calling redrawImmediately as early as possible improves the situation with
......
......@@ -23,6 +23,7 @@ package org.jetbrains.skia
*/
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 _packedInt1(): Int = b.toBits() or (0x8 shl 28)
......
......@@ -5,6 +5,7 @@ class FilterMipmap constructor(
internal val mipmapMode: MipmapMode = MipmapMode.NONE
) : SamplingMode {
@Suppress("OVERRIDE_DEPRECATION")
override fun _pack() = filterMode.ordinal.toLong() shl 32 or mipmapMode.ordinal.toLong()
override fun _packedInt1(): Int = filterMode.ordinal
......
......@@ -162,6 +162,7 @@ class FontMetrics(
companion object
}
@Suppress("NOTHING_TO_INLINE")
private inline fun Float.asNumberOrNull(): Float? = if (isNaN()) null else this
private fun FontMetrics.Companion.fromRawData(rawData: FloatArray) = FontMetrics(
......
......@@ -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)
}
fun createUsing(
internal fun createUsing(
_ptr: NativePointer,
_nGetImageInfo: (_ptr: NativePointer, intArrayPointer: InteropPointer, nativePointerArrayPtr: InteropPointer) -> Unit
): ImageInfo {
......
......@@ -4,7 +4,7 @@ import org.jetbrains.skia.ManagedString
expect class NativePointer
expect class InteropPointer
internal expect class InteropPointer
expect abstract class Native(ptr: NativePointer) {
internal var _ptr: NativePointer
......@@ -157,6 +157,7 @@ internal inline fun withStringResult(block: () -> NativePointer): String {
return ManagedString(block()).use { it.toString() }
}
@Suppress("NOTHING_TO_INLINE")
internal inline fun withStringResult(pointer: NativePointer): String {
return ManagedString(pointer).use { it.toString() }
}
......
......@@ -219,6 +219,7 @@ class StrutStyle internal constructor(ptr: NativePointer) : Managed(ptr, _Finali
reachabilityBarrier(this)
}
set(value) {
@Suppress("DEPRECATION")
setHalfLeading(value)
}
......
......@@ -40,7 +40,7 @@ class TextBox(val rect: Rect, direction: Direction) {
_direction = direction
}
companion object : ArrayInteropDecoder<TextBox> {
internal companion object : ArrayInteropDecoder<TextBox> {
override fun getArrayElement(array: InteropPointer, index: Int): TextBox {
val rect = FloatArray(4)
val direction = IntArray(1)
......
......@@ -332,6 +332,7 @@ class TextStyle internal constructor(ptr: NativePointer) : Managed(ptr, _Finaliz
reachabilityBarrier(this)
}
set(value) {
@Suppress("DEPRECATION")
setHalfLeading(value)
}
......
@file:Suppress("NESTED_EXTERNAL_DECLARATION")
package org.jetbrains.skia.shaper
import org.jetbrains.skia.ExternalSymbolName
......
@file:Suppress("NESTED_EXTERNAL_DECLARATION")
package org.jetbrains.skia.shaper
import org.jetbrains.skia.ExternalSymbolName
......
@file:Suppress("NESTED_EXTERNAL_DECLARATION")
package org.jetbrains.skia.shaper
import org.jetbrains.skia.ExternalSymbolName
......
@file:Suppress("NESTED_EXTERNAL_DECLARATION")
package org.jetbrains.skia.shaper
import org.jetbrains.skia.ExternalSymbolName
......
@file:Suppress("NESTED_EXTERNAL_DECLARATION")
package org.jetbrains.skia.shaper
import org.jetbrains.skia.*
......
@file:Suppress("NESTED_EXTERNAL_DECLARATION")
package org.jetbrains.skia.skottie
import org.jetbrains.skia.impl.Library.Companion.staticLoad
......
@file:Suppress("NESTED_EXTERNAL_DECLARATION")
package org.jetbrains.skia.skottie
import org.jetbrains.skia.Data
......
@file:Suppress("NESTED_EXTERNAL_DECLARATION")
package org.jetbrains.skia.skottie
import org.jetbrains.skia.ExternalSymbolName
......
package org.jetbrains.skia
import org.jetbrains.skia.impl.reachabilityBarrier
import org.jetbrains.skiko.OS
import org.jetbrains.skiko.hostOs
import org.jetbrains.skiko.tests.*
......
......@@ -10,13 +10,13 @@ expect fun runTest(block: suspend () -> Unit): TestReturnType
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
......
......@@ -24,7 +24,7 @@ object SkikoDispatchers {
)
}
@OptIn(InternalCoroutinesApi::class)
@OptIn(InternalCoroutinesApi::class, ExperimentalCoroutinesApi::class)
internal class NsQueueDispatcher(
private val dispatchQueue: dispatch_queue_t
) : CoroutineDispatcher(), Delay {
......@@ -34,7 +34,6 @@ internal class NsQueueDispatcher(
}
}
@OptIn(InternalCoroutinesApi::class)
override fun scheduleResumeAfterDelay(timeMillis: Long, continuation: CancellableContinuation<Unit>) {
val timer = Timer()
val timerBlock: TimerBlock = {
......@@ -45,8 +44,6 @@ internal class NsQueueDispatcher(
continuation.disposeOnCancellation(timer)
}
@OptIn(InternalCoroutinesApi::class)
override fun invokeOnTimeout(timeMillis: Long, block: Runnable, context: CoroutineContext): DisposableHandle {
val timer = Timer()
val timerBlock: TimerBlock = {
......@@ -61,20 +58,15 @@ internal class NsQueueDispatcher(
internal typealias TimerBlock = (CFRunLoopTimerRef?) -> Unit
@SharedImmutable
private val TIMER_NEW = NativePtr.NULL
@SharedImmutable
private val TIMER_DISPOSED = NativePtr.NULL.plus(1)
private class Timer : DisposableHandle {
private val ref = AtomicNativePtr(TIMER_NEW)
init { freeze() }
fun start(timeMillis: Long, timerBlock: TimerBlock) {
val fireDate = CFAbsoluteTimeGetCurrent() + timeMillis / 1000.0
@Suppress("EXPERIMENTAL_UNSIGNED_LITERALS")
val timer = CFRunLoopTimerCreateWithHandler(null, fireDate, 0.0, 0u, 0, timerBlock)!!
CFRunLoopAddTimer(CFRunLoopGetMain(), timer, kCFRunLoopCommonModes)
if (!ref.compareAndSet(TIMER_NEW, timer.rawValue)) {
......
@file:Suppress("UNCHECKED_CAST_TO_EXTERNAL_INTERFACE")
package org.jetbrains.skia.impl
internal actual class InteropScope actual constructor() {
......@@ -242,6 +244,7 @@ internal actual class InteropScope actual constructor() {
releaseCallbacks()
}
@Suppress("NOTHING_TO_INLINE")
private inline fun initCallbacks() {
if (!callbacksInitialized) {
_createLocalCallbackScope()
......@@ -249,6 +252,7 @@ internal actual class InteropScope actual constructor() {
}
}
@Suppress("NOTHING_TO_INLINE")
private inline fun releaseCallbacks() {
if (callbacksInitialized) {
_releaseLocalCallbackScope()
......
......@@ -48,14 +48,14 @@ internal actual fun reachabilityBarrier(obj: Any?) {
actual typealias NativePointer = Long
@Suppress("ACTUAL_TYPE_ALIAS_TO_NULLABLE_TYPE")
actual typealias InteropPointer = Any?
internal actual typealias InteropPointer = java.lang.Object
internal object theScope: InteropScope()
internal actual inline fun <T> interopScope(block: InteropScope.() -> T): T {
return theScope.block()
}
@Suppress("RETURN_TYPE_MISMATCH") // Hack to pass nulls as InteropPointer
internal actual open class InteropScope actual constructor() {
actual fun toInterop(string: String?): InteropPointer = string
......@@ -93,11 +93,11 @@ internal actual open class InteropScope actual constructor() {
this@fromInterop as Array<T>
actual fun toInteropForArraysOfPointers(interopPointers: Array<InteropPointer>): InteropPointer = interopPointers
actual fun callback(callback: (() -> Unit)?) = callback as Any?
actual fun intCallback(callback: (() -> Int)?) = callback as Any?
actual fun nativePointerCallback(callback: (() -> NativePointer)?) = callback as Any?
actual fun interopPointerCallback(callback: (() -> InteropPointer)?) = callback as Any?
actual fun booleanCallback(callback: (() -> Boolean)?) = callback as Any?
actual fun callback(callback: (() -> Unit)?): InteropPointer = callback
actual fun intCallback(callback: (() -> Int)?): InteropPointer = callback
actual fun nativePointerCallback(callback: (() -> NativePointer)?): InteropPointer = callback
actual fun interopPointerCallback(callback: (() -> InteropPointer)?): InteropPointer = callback
actual fun booleanCallback(callback: (() -> Boolean)?): InteropPointer = callback
actual fun virtual(method: () -> Unit) = callback(method)
actual fun virtualInt(method: () -> Int) = intCallback(method)
......
......@@ -127,12 +127,12 @@ object SkikoProperties {
}
private fun bestRenderApiForCurrentOS(): GraphicsApi {
when(hostOs) {
OS.MacOS -> return GraphicsApi.METAL
OS.Linux -> return GraphicsApi.OPENGL
OS.Windows -> return if (renderingAngleEnabled) GraphicsApi.ANGLE else GraphicsApi.DIRECT3D
OS.Android -> return GraphicsApi.OPENGL
OS.JS, OS.Ios, OS.Tvos, OS.Unknown -> TODO("commonize me")
return when(hostOs) {
OS.MacOS -> GraphicsApi.METAL
OS.Linux -> GraphicsApi.OPENGL
OS.Windows -> if (renderingAngleEnabled) GraphicsApi.ANGLE else GraphicsApi.DIRECT3D
OS.Android -> GraphicsApi.OPENGL
else -> GraphicsApi.UNKNOWN
}
}
......@@ -146,7 +146,7 @@ object SkikoProperties {
else -> listOf(GraphicsApi.ANGLE, GraphicsApi.DIRECT3D, GraphicsApi.OPENGL, GraphicsApi.SOFTWARE_FAST, GraphicsApi.SOFTWARE_COMPAT)
}
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)
......
@file:OptIn(BetaInteropApi::class)
package org.jetbrains.skiko.redrawer
import kotlinx.cinterop.BetaInteropApi
import kotlinx.cinterop.addressOf
import kotlinx.cinterop.autoreleasepool
import kotlinx.cinterop.objcPtr
......
@file:OptIn(BetaInteropApi::class)
package org.jetbrains.skiko.redrawer
import kotlinx.cinterop.BetaInteropApi
import kotlinx.cinterop.CPointer
import kotlinx.cinterop.useContents
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
import org.jetbrains.skia.impl.InteropPointer
......
......@@ -3,8 +3,9 @@ package org.jetbrains.skia.impl
import kotlinx.cinterop.nativeNullPtr
import org.jetbrains.skia.ExternalSymbolName
import kotlin.concurrent.AtomicNativePtr
import kotlin.experimental.ExperimentalNativeApi
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 var obj = AtomicNativePtr(obj)
......@@ -29,10 +30,11 @@ actual abstract class Managed actual constructor(
require(finalizer != NullPointer) { "Managed finalizer is nullptr" }
val className = this::class.simpleName ?: "<kotlin>"
Stats.onAllocated(className)
FinalizationThunk(finalizer, className, ptr).freeze()
FinalizationThunk(finalizer, className, ptr)
} else null
@OptIn(ExperimentalStdlibApi::class)
@Suppress("unused")
@OptIn(ExperimentalNativeApi::class)
private val cleaner = if (managed) {
createCleaner(thunk) {
it?.clean()
......
......@@ -48,7 +48,7 @@ actual abstract class Native actual constructor(ptr: NativePointer) {
}
actual typealias NativePointer = NativePtr
actual typealias InteropPointer = NativePtr
internal actual typealias InteropPointer = NativePtr
internal actual fun reachabilityBarrier(obj: Any?) {
// TODO: implement native barrier
......
package org.jetbrains.skiko
import kotlin.time.TimeSource
internal actual inline fun <R> maybeSynchronized(lock: Any, block: () -> R): R =
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() {
// Nothing to do here
......
@file:OptIn(BetaInteropApi::class)
package org.jetbrains.skiko
import kotlinx.cinterop.*
......@@ -11,7 +13,6 @@ import kotlin.native.ref.*
internal expect fun UIView.skikoInitializeUIView(): Unit
@Suppress("CONFLICTING_OVERLOADS")
@ExportObjCClass
class SkikoUIView : UIView {
companion object : UIViewMeta() {
......
@file:OptIn(BetaInteropApi::class)
package org.jetbrains.skiko.redrawer
import kotlinx.cinterop.*
......
@file:Suppress("UNCHECKED_CAST_TO_EXTERNAL_INTERFACE")
package org.jetbrains.skia.impl
internal actual class InteropScope actual constructor() {
......
......@@ -36,7 +36,7 @@ actual abstract class Native actual constructor(ptr: NativePointer) {
internal actual fun reachabilityBarrier(obj: Any?) {}
actual typealias NativePointer = Int
actual typealias InteropPointer = Int
internal actual typealias InteropPointer = Int
private val INTEROP_SCOPE = InteropScope()
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