Skip to content

Commit

Permalink
Getting dpi scale by Display in Linux.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rsedaikin committed Dec 15, 2020
1 parent b0dc2e0 commit 4e00455
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
44 changes: 32 additions & 12 deletions skiko/src/jvmMain/cpp/linux/drawlayer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal val platformOperations: PlatformOperations by lazy {
}

override fun getDpiScale(component: Component): Float {
return linuxGetDpiScaleNative()
return linuxGetDpiScaleNative(component)
}
}
}
Expand All @@ -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
10 changes: 2 additions & 8 deletions skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkiaLayer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -71,7 +65,7 @@ open class SkiaLayer() : HardwareLayer() {
}
initSkija()
skijaState.apply {
canvasBleach.invoke()
canvas!!.clear(bleachConstant)

// cliping
for (component in clipComponets) {
Expand Down

0 comments on commit 4e00455

Please sign in to comment.