Unverified Commit 7ea3f41b authored by Pavel's avatar Pavel Committed by GitHub

Macos headerless window (#96)

* check that drawing surface lock is successful

* add disable title bar

* bump skija

* make window handle accessible after `window.pack()` but before `window.setVisible(true)`

* rollback changes in demo App

* fix warning and return value in `lockDrawingSurface`

* reduce code duplication
parent beeb6e52
kotlin.code.style=official kotlin.code.style=official
deploy.version=0.0.0 deploy.version=0.0.0
dependencies.skija.git.commit=adbb8c2926045af424a2ff93f5f0110f965bdbbb dependencies.skija.git.commit=a5d6dfd746b8a8ec2ef52ebea4baa53f299d080c
dependencies.skia.windows-x64=m89-109bfc9052/Skia-m89-109bfc9052-windows-Release-x64 dependencies.skia.windows-x64=m90-adbb69cd7f-2/Skia-m90-adbb69cd7f-2-windows-Release-x64
dependencies.skia.linux-x64=m89-109bfc9052/Skia-m89-109bfc9052-linux-Release-x64 dependencies.skia.linux-x64=m90-adbb69cd7f-2/Skia-m90-adbb69cd7f-2-linux-Release-x64
dependencies.skia.macos-x64=m89-109bfc9052/Skia-m89-109bfc9052-macos-Release-x64 dependencies.skia.macos-x64=m90-adbb69cd7f-2/Skia-m90-adbb69cd7f-2-macos-Release-x64
dependencies.skia.macos-arm64=m89-109bfc9052/Skia-m89-109bfc9052-macos-Release-arm64 dependencies.skia.macos-arm64=m90-adbb69cd7f-2/Skia-m90-adbb69cd7f-2-macos-Release-arm64
# signer=Apple Distribution: Nikolay Igotti (N462MKSJ7M) # signer=Apple Distribution: Nikolay Igotti (N462MKSJ7M)
...@@ -36,10 +36,10 @@ extern "C" ...@@ -36,10 +36,10 @@ extern "C"
awt->FreeDrawingSurface(ds); awt->FreeDrawingSurface(ds);
} }
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_AWTKt_lockDrawingSurface(JNIEnv *env, jobject obj, jlong drawingSurfacePtr) JNIEXPORT jint JNICALL Java_org_jetbrains_skiko_AWTKt_lockDrawingSurface(JNIEnv *env, jobject obj, jlong drawingSurfacePtr)
{ {
JAWT_DrawingSurface *ds = fromJavaPointer<JAWT_DrawingSurface *>(drawingSurfacePtr); JAWT_DrawingSurface *ds = fromJavaPointer<JAWT_DrawingSurface *>(drawingSurfacePtr);
ds->Lock(ds); return (ds->Lock(ds) & JAWT_LOCK_ERROR) != 0;
} }
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_AWTKt_unlockDrawingSurface(JNIEnv *env, jobject obj, jlong drawingSurfacePtr) JNIEXPORT void JNICALL Java_org_jetbrains_skiko_AWTKt_unlockDrawingSurface(JNIEnv *env, jobject obj, jlong drawingSurfacePtr)
......
...@@ -31,7 +31,7 @@ internal class DrawingSurface( ...@@ -31,7 +31,7 @@ internal class DrawingSurface(
} }
private set private set
fun lock() = lockDrawingSurface(ptr) fun lock() = lockDrawingSurface(ptr).also { check(it == 0) }
fun unlock() = unlockDrawingSurface(ptr) fun unlock() = unlockDrawingSurface(ptr)
...@@ -74,7 +74,7 @@ private external fun getAWT(): Long ...@@ -74,7 +74,7 @@ private external fun getAWT(): Long
private external fun getDrawingSurface(awt: Long, layer: Component): Long private external fun getDrawingSurface(awt: Long, layer: Component): Long
private external fun freeDrawingSurface(awt: Long, drawingSurface: Long) private external fun freeDrawingSurface(awt: Long, drawingSurface: Long)
private external fun lockDrawingSurface(drawingSurface: Long) private external fun lockDrawingSurface(drawingSurface: Long): Int
private external fun unlockDrawingSurface(drawingSurface: Long) private external fun unlockDrawingSurface(drawingSurface: Long)
private external fun getDrawingSurfaceInfo(drawingSurface: Long): Long private external fun getDrawingSurfaceInfo(drawingSurface: Long): Long
......
...@@ -14,6 +14,7 @@ import javax.swing.SwingUtilities ...@@ -14,6 +14,7 @@ import javax.swing.SwingUtilities
internal interface PlatformOperations { internal interface PlatformOperations {
fun isFullscreen(component: Component): Boolean fun isFullscreen(component: Component): Boolean
fun setFullscreen(component: Component, value: Boolean) fun setFullscreen(component: Component, value: Boolean)
fun disableTitleBar(platformInfo: Long)
fun getDpiScale(component: Component): Float fun getDpiScale(component: Component): Float
fun createRedrawer(layer: SkiaLayer, renderApi: GraphicsApi, properties: SkiaLayerProperties): Redrawer fun createRedrawer(layer: SkiaLayer, renderApi: GraphicsApi, properties: SkiaLayerProperties): Redrawer
} }
...@@ -33,6 +34,10 @@ internal val platformOperations: PlatformOperations by lazy { ...@@ -33,6 +34,10 @@ internal val platformOperations: PlatformOperations by lazy {
return component.graphicsConfiguration.defaultTransform.scaleX.toFloat() return component.graphicsConfiguration.defaultTransform.scaleX.toFloat()
} }
override fun disableTitleBar(platformInfo: Long) {
osxDisableTitleBar(platformInfo)
}
override fun createRedrawer( override fun createRedrawer(
layer: SkiaLayer, layer: SkiaLayer,
renderApi: GraphicsApi, renderApi: GraphicsApi,
...@@ -57,6 +62,9 @@ internal val platformOperations: PlatformOperations by lazy { ...@@ -57,6 +62,9 @@ internal val platformOperations: PlatformOperations by lazy {
device.setFullScreenWindow(if (value) window else null) device.setFullScreenWindow(if (value) window else null)
} }
override fun disableTitleBar(platformInfo: Long) {
}
override fun getDpiScale(component: Component): Float { override fun getDpiScale(component: Component): Float {
return component.graphicsConfiguration.defaultTransform.scaleX.toFloat() return component.graphicsConfiguration.defaultTransform.scaleX.toFloat()
} }
...@@ -86,6 +94,9 @@ internal val platformOperations: PlatformOperations by lazy { ...@@ -86,6 +94,9 @@ internal val platformOperations: PlatformOperations by lazy {
device.setFullScreenWindow(if (value) window else null) device.setFullScreenWindow(if (value) window else null)
} }
override fun disableTitleBar(platformInfo: Long) {
}
override fun getDpiScale(component: Component): Float { override fun getDpiScale(component: Component): Float {
return component.graphicsConfiguration.defaultTransform.scaleX.toFloat() return component.graphicsConfiguration.defaultTransform.scaleX.toFloat()
// TODO doesn't work well because java doesn't scale windows (content has offset with 200% scale) // TODO doesn't work well because java doesn't scale windows (content has offset with 200% scale)
...@@ -118,6 +129,7 @@ internal val platformOperations: PlatformOperations by lazy { ...@@ -118,6 +129,7 @@ internal val platformOperations: PlatformOperations by lazy {
// OSX // OSX
external private fun osxIsFullscreenNative(component: Component): Boolean external private fun osxIsFullscreenNative(component: Component): Boolean
external private fun osxSetFullscreenNative(component: Component, value: Boolean) external private fun osxSetFullscreenNative(component: Component, value: Boolean)
external private fun osxDisableTitleBar(platformInfo: Long)
// Linux // Linux
external private fun linuxGetDpiScaleNative(platformInfo: Long): Float external private fun linuxGetDpiScaleNative(platformInfo: Long): Float
...@@ -15,4 +15,10 @@ open class SkiaWindow( ...@@ -15,4 +15,10 @@ open class SkiaWindow(
layer.dispose() layer.dispose()
super.dispose() super.dispose()
} }
fun disableTitleBar() {
useDrawingSurfacePlatformInfo {
platformOperations.disableTitleBar(it)
}
}
} }
...@@ -104,6 +104,22 @@ NSWindow *findCALayerWindow(NSView *rootView, CALayer *layer) { ...@@ -104,6 +104,22 @@ NSWindow *findCALayerWindow(NSView *rootView, CALayer *layer) {
return recursiveWindowSearch(rootView, layer); return recursiveWindowSearch(rootView, layer);
} }
NSWindow *findWindow(jlong platformInfoPtr)
{
NSObject<JAWT_SurfaceLayers>* dsi_mac = (__bridge NSObject<JAWT_SurfaceLayers> *) platformInfoPtr;
CALayer* ca_layer = [dsi_mac windowLayer];
NSWindow* target_window = nil;
NSMutableArray<NSWindow *> *windows = [NSMutableArray arrayWithArray: [[NSApplication sharedApplication] windows]];
for (NSWindow* window in windows)
{
target_window = findCALayerWindow(window.contentView, ca_layer);
if (target_window != nil) break;
}
return target_window;
}
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_nativeInit(JNIEnv *env, jobject canvas, jlong platformInfoPtr) JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_nativeInit(JNIEnv *env, jobject canvas, jlong platformInfoPtr)
{ {
if (layerStorage == nil) if (layerStorage == nil)
...@@ -111,21 +127,12 @@ JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_nativeInit(JNIEnv ...@@ -111,21 +127,12 @@ JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_nativeInit(JNIEnv
layerStorage = [[NSMutableSet alloc] init]; layerStorage = [[NSMutableSet alloc] init];
} }
NSObject<JAWT_SurfaceLayers>* dsi_mac = (__bridge NSObject<JAWT_SurfaceLayers> *) platformInfoPtr;
LayerHandler *layersSet = [[LayerHandler alloc] init]; LayerHandler *layersSet = [[LayerHandler alloc] init];
NSObject<JAWT_SurfaceLayers>* dsi_mac = (__bridge NSObject<JAWT_SurfaceLayers> *) platformInfoPtr;
layersSet.container = [dsi_mac windowLayer]; layersSet.container = [dsi_mac windowLayer];
jobject canvasGlobalRef = env->NewGlobalRef(canvas); jobject canvasGlobalRef = env->NewGlobalRef(canvas);
[layersSet setCanvasGlobalRef: canvasGlobalRef]; [layersSet setCanvasGlobalRef: canvasGlobalRef];
layersSet.window = findWindow(platformInfoPtr);
NSMutableArray<NSWindow *> *windows = [NSMutableArray arrayWithArray: [[NSApplication sharedApplication] windows]];
for (NSWindow* window in windows) {
layersSet.window = findCALayerWindow(window.contentView, layersSet.container);
if (layersSet.window != nil) {
break;
}
}
[layerStorage addObject: layersSet]; [layerStorage addObject: layersSet];
} }
...@@ -141,16 +148,6 @@ JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_nativeDispose(JNIE ...@@ -141,16 +148,6 @@ JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_nativeDispose(JNIE
} }
} }
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_HardwareLayer_getWindowHandle(JNIEnv *env, jobject canvas)
{
LayerHandler *layer = findByObject(env, canvas);
if (layer != NULL)
{
return (jlong)[layer window];
}
return (jlong)kNullWindowHandle;
}
JNIEXPORT jboolean JNICALL Java_org_jetbrains_skiko_PlatformOperationsKt_osxIsFullscreenNative(JNIEnv *env, jobject properties, jobject component) JNIEXPORT jboolean JNICALL Java_org_jetbrains_skiko_PlatformOperationsKt_osxIsFullscreenNative(JNIEnv *env, jobject properties, jobject component)
{ {
LayerHandler *layer = findByObject(env, component); LayerHandler *layer = findByObject(env, component);
...@@ -170,6 +167,26 @@ JNIEXPORT void JNICALL Java_org_jetbrains_skiko_PlatformOperationsKt_osxSetFulls ...@@ -170,6 +167,26 @@ JNIEXPORT void JNICALL Java_org_jetbrains_skiko_PlatformOperationsKt_osxSetFulls
} }
} }
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_HardwareLayer_getWindowHandle(JNIEnv *env, jobject canvas, jlong platformInfoPtr)
{
NSWindow* window = findWindow(platformInfoPtr);
return (jlong)window;
}
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_PlatformOperationsKt_osxDisableTitleBar(JNIEnv *env, jobject properties, jlong platformInfoPtr)
{
NSWindow* window = findWindow(platformInfoPtr);
if (window == nil) return;
dispatch_async(dispatch_get_main_queue(), ^{
[window setTitlebarAppearsTransparent:YES];
[window setTitleVisibility:NSWindowTitleHidden];
[window setStyleMask:[window styleMask]|NSWindowStyleMaskFullSizeContentView];
// always show `fullscreen` green traffic light button instead of `maximize/zoom` button
[window setCollectionBehavior:[window collectionBehavior]|NSWindowCollectionBehaviorFullScreenPrimary];
[window setMovable:NO];
});
}
void getMetalDeviceAndQueue(void** device, void** queue) void getMetalDeviceAndQueue(void** device, void** queue)
{ {
id<MTLDevice> fDevice = MTLCreateSystemDefaultDevice(); id<MTLDevice> fDevice = MTLCreateSystemDefaultDevice();
......
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