diff --git a/skiko/src/jvmMain/cpp/linux/drawlayer.cc b/skiko/src/jvmMain/cpp/linux/drawlayer.cc index 22ce3f442..5e7116556 100755 --- a/skiko/src/jvmMain/cpp/linux/drawlayer.cc +++ b/skiko/src/jvmMain/cpp/linux/drawlayer.cc @@ -255,23 +255,43 @@ extern "C" return 1; } - double getDpiScale() + JNIEXPORT jfloat JNICALL Java_org_jetbrains_skiko_PlatformOperationsKt_linuxGetDpiScaleNative(JNIEnv *env, jobject properties, jobject component) { - Display *display = XOpenDisplay(nullptr); - if (display != nullptr) + JAWT awt; + JAWT_DrawingSurface *ds = NULL; + JAWT_DrawingSurfaceInfo *dsi = NULL; + + jboolean result = JNI_FALSE; + jint lock = 0; + JAWT_X11DrawingSurfaceInfo *dsi_x11; + + awt.version = (jint)JAWT_VERSION_9; + result = Skiko_GetAWT(env, &awt); + + if (result == JNI_FALSE) { - double result = getDpiScaleByDisplay(display); - XCloseDisplay(display); - return result; + fprintf(stderr, "JAWT_GetAWT failed! Result is JNI_FALSE\n"); + return -1; } - else + + if (jvm == NULL) { - return 1; + env->GetJavaVM(&jvm); } - } - JNIEXPORT jfloat JNICALL Java_org_jetbrains_skiko_PlatformOperationsKt_linuxGetDpiScaleNative(JNIEnv *env, jobject properties) - { - return (float)getDpiScale(); + ds = awt.GetDrawingSurface(env, component); + lock = ds->Lock(ds); + dsi = ds->GetDrawingSurfaceInfo(ds); + dsi_x11 = (JAWT_X11DrawingSurfaceInfo *)dsi->platformInfo; + + Display *display = dsi_x11->display; + + float dpi = (float)getDpiScaleByDisplay(display); + + ds->FreeDrawingSurfaceInfo(dsi); + ds->Unlock(ds); + awt.FreeDrawingSurface(ds); + + return dpi; } } // extern "C" \ No newline at end of file diff --git a/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/PlatformOperations.kt b/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/PlatformOperations.kt index f5d4d3eaa..902195f50 100644 --- a/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/PlatformOperations.kt +++ b/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/PlatformOperations.kt @@ -59,7 +59,7 @@ internal val platformOperations: PlatformOperations by lazy { } override fun getDpiScale(component: Component): Float { - return linuxGetDpiScaleNative() + return linuxGetDpiScaleNative(component) } } } @@ -71,4 +71,4 @@ external private fun osxIsFullscreenNative(component: Component): Boolean external private fun osxSetFullscreenNative(component: Component, value: Boolean) // Linux -external private fun linuxGetDpiScaleNative(): Float +external private fun linuxGetDpiScaleNative(component: Component): Float diff --git a/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkiaLayer.kt b/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkiaLayer.kt index a6b61405b..bd1a5cdad 100644 --- a/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkiaLayer.kt +++ b/skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkiaLayer.kt @@ -13,13 +13,7 @@ import org.jetbrains.skija.SurfaceOrigin import org.jetbrains.skija.ClipMode private class SkijaState { - val canvasBleach: () -> Unit - init { - when (hostOs) { - OS.MacOS -> canvasBleach = { canvas?.clear(0) } - else -> canvasBleach = { canvas?.clear(-1) } - } - } + val bleachConstant = if (hostOs == OS.MacOS) 0 else -1 var context: DirectContext? = null var renderTarget: BackendRenderTarget? = null var surface: Surface? = null @@ -71,7 +65,7 @@ open class SkiaLayer() : HardwareLayer() { } initSkija() skijaState.apply { - canvasBleach.invoke() + canvas!!.clear(bleachConstant) // cliping for (component in clipComponets) {