Skip to content

Commit cbf3345

Browse files
authored
1 parent 79f1d43 commit cbf3345

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

skiko/src/awtMain/objectiveC/macos/DisplayLinkThrottler.mm

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,25 @@ - (instancetype)initWithWindow:(NSWindow *)window {
8888
[weakSelf onScreenDidChange];
8989
}];
9090

91-
[self onScreenDidChange];
91+
if (NSThread.currentThread.isMainThread) {
92+
[self onScreenDidChange];
93+
} else {
94+
// In case of OpenJDK, EDT thread != NSThread main thread
95+
// 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:
96+
//
97+
// ```
98+
// create window
99+
// (10x) schedule render -> render
100+
// onScreenDidChange
101+
// schedule render -> wait vsync -> render
102+
// ```
103+
//
104+
// 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.
105+
__weak DisplayLinkThrottler *weakSelf = self;
106+
dispatch_async(dispatch_get_main_queue(), ^{
107+
[weakSelf onScreenDidChange];
108+
});
109+
}
92110
}
93111

94112
return self;

skiko/src/awtMain/objectiveC/macos/MetalRedrawer.mm

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,26 @@ static jmethodID getOnOcclusionStateChangedMethodID(JNIEnv *env, jobject redrawe
115115
return onOcclusionStateChanged;
116116
}
117117

118+
119+
static void setWindowPropertiesUnsafe(NSWindow* window, jboolean transparency) {
120+
if (window == NULL) return;
121+
if (transparency) {
122+
window.hasShadow = NO;
123+
}
124+
}
125+
126+
static void setWindowProperties(NSWindow* window, jboolean transparency) {
127+
if (NSThread.currentThread.isMainThread) {
128+
setWindowPropertiesUnsafe(window, transparency);
129+
} else {
130+
// In case of OpenJDK, EDT thread != NSThread main thread
131+
__weak NSWindow *weakWindow = window;
132+
dispatch_async(dispatch_get_main_queue(), ^{
133+
setWindowPropertiesUnsafe(weakWindow, transparency);
134+
});
135+
}
136+
}
137+
118138
extern "C"
119139
{
120140

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

163183
NSWindow* window = (__bridge NSWindow*) (void *) windowPtr;
164-
165-
if (transparency) {
166-
window.hasShadow = NO;
167-
}
184+
setWindowProperties(window, transparency);
168185

169186
jmethodID onOcclusionStateChanged = getOnOcclusionStateChangedMethodID(env, redrawer);
170187
device.occlusionObserver =

0 commit comments

Comments
 (0)