Skip to content

Commit a50d3be

Browse files
committed
8312198: [macos] metal pipeline - window rendering stops after display sleep
Reviewed-by: serb, avu, prr
1 parent aac287e commit a50d3be

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -56,6 +56,7 @@
5656
@property (readwrite, assign) int leftInset;
5757
@property (readwrite, assign) CVDisplayLinkRef displayLink;
5858
@property (readwrite, atomic) int displayLinkCount;
59+
@property (readwrite, atomic) int displayLinkFailCount;
5960

6061
- (id) initWithJavaLayer:(jobject)layer;
6162

src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.m

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,6 +30,8 @@
3030
#import "MTLSurfaceData.h"
3131
#import "JNIUtilities.h"
3232
#define KEEP_ALIVE_INC 4
33+
#define CV_DISPLAYLINK_FAIL_DELAY 1.0
34+
#define MAX_DISPLAYLINK_FAIL_COUNT 5
3335

3436
@implementation MTLLayer
3537

@@ -44,11 +46,27 @@ @implementation MTLLayer
4446
@synthesize nextDrawableCount;
4547
@synthesize displayLink;
4648
@synthesize displayLinkCount;
49+
@synthesize displayLinkFailCount;
4750

4851
- (void) createDisplayLink {
49-
CVDisplayLinkCreateWithActiveCGDisplays(&displayLink);
50-
CVDisplayLinkSetOutputCallback(displayLink, &displayLinkCallback, (__bridge void*)self);
51-
self.displayLinkCount = 0;
52+
CVReturn r = CVDisplayLinkCreateWithActiveCGDisplays(&displayLink);
53+
if (r != kCVReturnSuccess) {
54+
if (self.displayLinkFailCount >= MAX_DISPLAYLINK_FAIL_COUNT) {
55+
J2dTraceLn(J2D_TRACE_ERROR,
56+
"MTLLayer.createDisplayLink --- unable to create CVDisplayLink.");
57+
self.displayLinkFailCount = 0;
58+
return;
59+
}
60+
self.displayLinkFailCount++;
61+
[self performSelector:@selector(createDisplayLink)
62+
withObject:nil
63+
afterDelay:CV_DISPLAYLINK_FAIL_DELAY];
64+
return;
65+
} else {
66+
CVDisplayLinkSetOutputCallback(displayLink, &displayLinkCallback, (__bridge void*)self);
67+
self.displayLinkCount = 0;
68+
self.displayLinkFailCount = 0;
69+
}
5270
}
5371

5472
- (id) initWithJavaLayer:(jobject)layer

0 commit comments

Comments
 (0)