Skip to content

Commit

Permalink
8304825: MacOS metal pipeline - window isn't painted if created durin…
Browse files Browse the repository at this point in the history
…g display sleep

Reviewed-by: kcr, avu, prr
  • Loading branch information
aghaisas committed Apr 10, 2023
1 parent 9727685 commit 969a6b9
Showing 1 changed file with 38 additions and 3 deletions.
Expand Up @@ -45,6 +45,12 @@ @implementation MTLLayer
@synthesize displayLink;
@synthesize displayLinkCount;

- (void) createDisplayLink {
CVDisplayLinkCreateWithActiveCGDisplays(&displayLink);
CVDisplayLinkSetOutputCallback(displayLink, &displayLinkCallback, (__bridge void*)self);
self.displayLinkCount = 0;
}

- (id) initWithJavaLayer:(jobject)layer
{
AWT_ASSERT_APPKIT_THREAD;
Expand Down Expand Up @@ -74,12 +80,38 @@ - (id) initWithJavaLayer:(jobject)layer
self.framebufferOnly = NO;
self.nextDrawableCount = 0;
self.opaque = YES;
CVDisplayLinkCreateWithActiveCGDisplays(&displayLink);
CVDisplayLinkSetOutputCallback(displayLink, &displayLinkCallback, (__bridge void*)self);
self.displayLinkCount = 0;
[self createDisplayLink];

[[[NSWorkspace sharedWorkspace] notificationCenter]
addObserver : self
selector : @selector(onScreenSleep)
name : NSWorkspaceScreensDidSleepNotification object: NULL];

[[[NSWorkspace sharedWorkspace] notificationCenter]
addObserver : self
selector : @selector(onScreenWakeup)
name : NSWorkspaceScreensDidWakeNotification object: NULL];

return self;
}

- (void) onScreenSleep {
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer.onScreenSleep --- received screen sleep notification.");

[self stopDisplayLink];
}

- (void) onScreenWakeup {
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer.onScreenWakeup --- received screen wakeup notification.");
[self stopDisplayLink];
CVDisplayLinkRelease(self.displayLink);
self.displayLink = nil;

[self createDisplayLink];

[self startDisplayLink];
}

- (void) blitTexture {
if (self.ctx == NULL || self.javaLayer == NULL || self.buffer == nil || self.ctx.device == nil) {
J2dTraceLn4(J2D_TRACE_VERBOSE,
Expand Down Expand Up @@ -148,6 +180,9 @@ - (void) blitTexture {
}

- (void) dealloc {

[[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];

JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
(*env)->DeleteWeakGlobalRef(env, self.javaLayer);
self.javaLayer = nil;
Expand Down

1 comment on commit 969a6b9

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.