Commit 4e00455a authored by Roman Sedaikin's avatar Roman Sedaikin

Getting dpi scale by Display in Linux.

parent b0dc2e01
......@@ -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
......@@ -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
......@@ -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) {
......
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