Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions extended/native-image/hello-awtfree/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// A Compose desktop application with no AWT in it: no ComposeWindow, no java.awt. The window
// is core-extended's extended/window WindowPlatform (graalvm-macos or graalvm-linux, chosen by
// the operating system this is built on), the scene is hosted by the window scene module,
// and Skia draws into the window's surface, Metal on macOS and GL on Linux.
//
// The window modules come from the local Maven repository: core-extended publishes them with
// `./kotlin publish mavenLocal` in extended/window.
plugins {
kotlin("jvm") version "2.2.20"
kotlin("plugin.compose") version "2.2.20"
id("org.jetbrains.compose") version "1.11.1-extended-dev"
}

val windowing = "org.thisisthepy.compose.window"
val windowVersion = "0.1.0"
val mac = org.gradle.internal.os.OperatingSystem.current().isMacOsX

sourceSets.main {
// The one file that names the platform layer and its graphics API.
kotlin.srcDir(if (mac) "src/mac/kotlin" else "src/linux/kotlin")
}

dependencies {
implementation(compose.desktop.currentOs)
implementation(compose.foundation)
implementation("$windowing:common:$windowVersion")
implementation("$windowing:scene:$windowVersion")
implementation("$windowing:${if (mac) "graalvm-macos" else "graalvm-linux"}:$windowVersion")
}

compose.desktop.application {
mainClass = "hello.MainKt"
nativeImage {
providers.environmentVariable("SKIKO_STATIC").orNull?.let { skikoStaticDirectory.set(file(it)) }
}
}

// The classpath the application runs with, for probes that call native-image directly.
tasks.register("writeRuntimeClasspath") {
val classpath = sourceSets.main.get().runtimeClasspath
val out = layout.buildDirectory.file("runtime-classpath.txt")
inputs.files(classpath)
outputs.file(out)
doLast { out.get().asFile.writeText(classpath.files.joinToString(File.pathSeparator)) }
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.0-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
249 changes: 249 additions & 0 deletions extended/native-image/hello-awtfree/gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions extended/native-image/hello-awtfree/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
mavenCentral()
google()
}
}
dependencyResolutionManagement {
repositories {
mavenLocal()
mavenCentral()
google()
}
}
rootProject.name = "native-image-hello-awtfree"
56 changes: 56 additions & 0 deletions extended/native-image/hello-awtfree/src/linux/kotlin/Platform.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package hello

import org.jetbrains.skia.BackendRenderTarget
import org.jetbrains.skia.ColorSpace
import org.jetbrains.skia.DirectContext
import org.jetbrains.skia.PixelGeometry
import org.jetbrains.skia.Surface
import org.jetbrains.skia.SurfaceColorFormat
import org.jetbrains.skia.SurfaceOrigin
import org.jetbrains.skia.SurfaceProps
import org.thisisthepy.compose.window.WindowPlatform
import org.thisisthepy.compose.window.graalvm.linux.X11Upcalls
import org.thisisthepy.compose.window.graalvm.linux.X11Window
import org.thisisthepy.compose.window.scene.FrameTarget
import org.thisisthepy.compose.window.scene.WindowSurface

private const val GL_RGBA8 = 0x8058

internal fun newPlatform(): WindowPlatform = X11Window()

internal fun newSurface(platform: WindowPlatform): WindowSurface? = GlWindowSurface(platform as X11Window)

/** Skia over the window's GLX framebuffer, which the window makes current when it opens. */
private class GlWindowSurface(private val window: X11Window) : WindowSurface {
private val context = DirectContext.makeGL()

override fun begin(width: Int, height: Int): FrameTarget? {
if (!window.beginFrame()) return null
val target = BackendRenderTarget.makeGL(width, height, 0, 0, 0, GL_RGBA8)
val surface = Surface.makeFromBackendRenderTarget(
context,
target,
SurfaceOrigin.BOTTOM_LEFT,
SurfaceColorFormat.RGBA_8888,
ColorSpace.sRGB,
SurfaceProps(PixelGeometry.RGB_H),
)
if (surface == null) {
target.close()
return null
}
return object : FrameTarget {
override val surface: Surface = surface
override fun close() {
surface.close()
target.close()
}
}
}

override fun setResizePainter(paint: (() -> Boolean)?) {
if (paint == null) X11Upcalls.clearFramePainter() else X11Upcalls.setFramePainter(paint)
}

override fun close() = context.close()
}
Loading
Loading