Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix macOS transparent windows on OpenJDK #1008

Merged
merged 4 commits into from
Jan 13, 2025
Merged
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
20 changes: 19 additions & 1 deletion skiko/src/awtMain/objectiveC/macos/DisplayLinkThrottler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,25 @@ - (instancetype)initWithWindow:(NSWindow *)window {
[weakSelf onScreenDidChange];
}];

[self onScreenDidChange];
if (NSThread.currentThread.isMainThread) {
[self onScreenDidChange];
} else {
// In case of OpenJDK, EDT thread != NSThread main thread
MatkovIvan marked this conversation as resolved.
Show resolved Hide resolved
// There is one thing we should keep in mind. Postponing creation of vsync throttler will cause that for sometime there won't be any waiting:
//
// ```
// create window
// (10x) schedule render -> render
// onScreenDidChange
// schedule render -> wait vsync -> render
// ```
//
// It is probably okay, but possible alternative would be to wait for throttler creation. It is difficult, so we can just keep the current code.
__weak DisplayLinkThrottler *weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf onScreenDidChange];
});
}
}

return self;
Expand Down
25 changes: 21 additions & 4 deletions skiko/src/awtMain/objectiveC/macos/MetalRedrawer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,26 @@ static jmethodID getOnOcclusionStateChangedMethodID(JNIEnv *env, jobject redrawe
return onOcclusionStateChanged;
}


static void setWindowPropertiesUnsafe(NSWindow* window, jboolean transparency) {
if (window == NULL) return;
if (transparency) {
window.hasShadow = NO;
igordmn marked this conversation as resolved.
Show resolved Hide resolved
}
}

static void setWindowProperties(NSWindow* window, jboolean transparency) {
if (NSThread.currentThread.isMainThread) {
setWindowPropertiesUnsafe(window, transparency);
} else {
// In case of OpenJDK, EDT thread != NSThread main thread
__weak NSWindow *weakWindow = window;
dispatch_async(dispatch_get_main_queue(), ^{
setWindowPropertiesUnsafe(weakWindow, transparency);
});
}
}

extern "C"
{

Expand Down Expand Up @@ -161,10 +181,7 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_redrawer_MetalRedrawer_createMe
device.inflightSemaphore = dispatch_semaphore_create(device.layer.maximumDrawableCount);

NSWindow* window = (__bridge NSWindow*) (void *) windowPtr;

if (transparency) {
window.hasShadow = NO;
}
setWindowProperties(window, transparency);

jmethodID onOcclusionStateChanged = getOnOcclusionStateChangedMethodID(env, redrawer);
device.occlusionObserver =
Expand Down
Loading