Commit 875ff2dd authored by Nikolay Igotti's avatar Nikolay Igotti

Make proper lazy loading.

parent 3a01ba64
skija
build build
.gradle .gradle
local.properties local.properties
......
...@@ -9,7 +9,6 @@ import javax.swing.JFrame ...@@ -9,7 +9,6 @@ import javax.swing.JFrame
import javax.swing.JButton import javax.swing.JButton
import javax.swing.event.MouseInputAdapter import javax.swing.event.MouseInputAdapter
import javax.swing.WindowConstants import javax.swing.WindowConstants
import org.jetbrains.skiko.Library
import org.jetbrains.skiko.SkiaLayer import org.jetbrains.skiko.SkiaLayer
fun Button(text: String): JButton { fun Button(text: String): JButton {
...@@ -19,7 +18,6 @@ fun Button(text: String): JButton { ...@@ -19,7 +18,6 @@ fun Button(text: String): JButton {
} }
fun SwingSkia() { fun SwingSkia() {
Library.load("/", "skiko")
val window = JFrame() val window = JFrame()
window.defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE window.defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE
......
kotlin.code.style=official kotlin.code.style=official
deploy.version=0.1 deploy.version=0.1
dependencies.skija.git.commit=8fc45764727610bd4b3d228198432f6f327a34ad dependencies.skija.git.commit=6652e622a76604278c0156dc8acf40b66b05c0e9
dependencies.skia.windows-x64=m88-59bafeeaa7/Skia-m88-59bafeeaa7-windows-Release-x64 dependencies.skia.windows-x64=m88-59bafeeaa7/Skia-m88-59bafeeaa7-windows-Release-x64
dependencies.skia.linux-x64=m88-59bafeeaa7/Skia-m88-59bafeeaa7-linux-Release-x64 dependencies.skia.linux-x64=m88-59bafeeaa7/Skia-m88-59bafeeaa7-linux-Release-x64
dependencies.skia.macos-x64=m88-59bafeeaa7/Skia-m88-59bafeeaa7-macos-Release-x64 dependencies.skia.macos-x64=m88-59bafeeaa7/Skia-m88-59bafeeaa7-macos-Release-x64
......
package org.jetbrains.skija
class CustomLoader : Runnable {
override fun run() {
org.jetbrains.skiko.Library.run()
}
}
\ No newline at end of file
...@@ -7,7 +7,7 @@ import java.nio.file.Files ...@@ -7,7 +7,7 @@ import java.nio.file.Files
import java.nio.file.StandardCopyOption import java.nio.file.StandardCopyOption
import javax.swing.UIManager import javax.swing.UIManager
object Library { object Library : Runnable {
private var loaded = false private var loaded = false
private val cacheRoot = "${System.getProperty("user.home")}/.skiko/" private val cacheRoot = "${System.getProperty("user.home")}/.skiko/"
...@@ -31,10 +31,11 @@ object Library { ...@@ -31,10 +31,11 @@ object Library {
// in Skiko's home, and if not - unpacks it. Also, it could load additional // in Skiko's home, and if not - unpacks it. Also, it could load additional
// localization resource on platforms wher it is needed. // localization resource on platforms wher it is needed.
@Synchronized @Synchronized
fun load(resourcePath: String = "/", name: String = "skiko") { private fun load() {
// TODO: remove arguments.
if (loaded) return if (loaded) return
val resourcePath = "/"
val name = "skiko"
val platformName = System.mapLibraryName(name) val platformName = System.mapLibraryName(name)
val hash = Library::class.java.getResourceAsStream("$resourcePath$platformName.sha256").use { val hash = Library::class.java.getResourceAsStream("$resourcePath$platformName.sha256").use {
...@@ -73,4 +74,8 @@ object Library { ...@@ -73,4 +74,8 @@ object Library {
// Not all platforms allow this. // Not all platforms allow this.
} }
} }
override fun run() {
load()
}
} }
package org.jetbrains.skiko
import org.jetbrains.skija.Surface
fun main() {
println(SkiaLibraryTester().nativeMethod(41))
val surface = Surface.makeRasterN32Premul(100, 100)
println(surface)
}
private class SkiaLibraryTester {
companion object {
init {
Library.load()
}
}
external fun nativeMethod(param: Long): Long
}
\ No newline at end of file
...@@ -123,12 +123,6 @@ open class SkiaLayer() : HardwareLayer() { ...@@ -123,12 +123,6 @@ open class SkiaLayer() : HardwareLayer() {
} }
open class SkiaWindow : JFrame() { open class SkiaWindow : JFrame() {
companion object {
init {
Library.load()
}
}
val layer: SkiaLayer = SkiaLayer() val layer: SkiaLayer = SkiaLayer()
init { init {
......
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