From bccb17a47610b17ee5e297d3665b4fc0625da9e1 Mon Sep 17 00:00:00 2001 From: jakub-senohrabek-jb <45628978+jakub-senohrabek-jb@users.noreply.github.com> Date: Mon, 9 Dec 2024 16:50:55 +0100 Subject: [PATCH] Allow setting skiko properties using skiko.properties file inside jar (#994) In order to use two different versions of skiko in one app (using multiple classloaders), it is required to use the unpacking strategy, as the skiko.library.path is a system property, which is same for all classloaders. This change will allow to use presigned natives shipped together with the app, while still being able to use multiple versions as the property skiko.library.path will be loaded from current classloader resources, with fallback to system property. Co-authored-by: Jakub Senohrabek --- .../kotlin/org/jetbrains/skiko/SkikoProperties.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkikoProperties.kt b/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkikoProperties.kt index 1b4ee47fa..4b912d1b6 100644 --- a/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkikoProperties.kt +++ b/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkikoProperties.kt @@ -1,6 +1,6 @@ package org.jetbrains.skiko -import java.lang.System.getProperty +import java.util.* // TODO maybe we can get rid of global properties, and pass SkiaLayerProperties to Window -> ComposeWindow -> SkiaLayer @Suppress("SameParameterValue") @@ -89,6 +89,19 @@ object SkikoProperties { val macOsOpenGLEnabled: Boolean get() = getProperty("skiko.macos.opengl.enabled")?.toBoolean() ?: false + private val properties = run { + val resourcePropertiesEnabled = System.getProperty("skiko.resource.properties.enabled")?.toBoolean() ?: false + val resources = if (resourcePropertiesEnabled) { + SkikoProperties::class.java.classLoader.getResourceAsStream("skiko.properties") + } else { + null + } + val systemProps = System.getProperties() + if (resources == null) systemProps else Properties(systemProps).apply { load(resources) } + } + + private fun getProperty(key: String): String? = properties.getProperty(key) + internal fun parseRenderApi(text: String?): GraphicsApi { when(text) { "SOFTWARE_COMPAT" -> return GraphicsApi.SOFTWARE_COMPAT