From a50d3bee12cd2f528067bc15b404cf2289977af5 Mon Sep 17 00:00:00 2001 From: Jayathirth D V Date: Mon, 26 May 2025 06:03:28 +0000 Subject: [PATCH] 8312198: [macos] metal pipeline - window rendering stops after display sleep Reviewed-by: serb, avu, prr --- .../libawt_lwawt/java2d/metal/MTLLayer.h | 3 ++- .../libawt_lwawt/java2d/metal/MTLLayer.m | 26 ++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.h b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.h index 83e868b37b7..ec477323f98 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.h +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -56,6 +56,7 @@ @property (readwrite, assign) int leftInset; @property (readwrite, assign) CVDisplayLinkRef displayLink; @property (readwrite, atomic) int displayLinkCount; +@property (readwrite, atomic) int displayLinkFailCount; - (id) initWithJavaLayer:(jobject)layer; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.m index d7d75f16966..9f3ab974feb 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,6 +30,8 @@ #import "MTLSurfaceData.h" #import "JNIUtilities.h" #define KEEP_ALIVE_INC 4 +#define CV_DISPLAYLINK_FAIL_DELAY 1.0 +#define MAX_DISPLAYLINK_FAIL_COUNT 5 @implementation MTLLayer @@ -44,11 +46,27 @@ @synthesize nextDrawableCount; @synthesize displayLink; @synthesize displayLinkCount; +@synthesize displayLinkFailCount; - (void) createDisplayLink { - CVDisplayLinkCreateWithActiveCGDisplays(&displayLink); - CVDisplayLinkSetOutputCallback(displayLink, &displayLinkCallback, (__bridge void*)self); - self.displayLinkCount = 0; + CVReturn r = CVDisplayLinkCreateWithActiveCGDisplays(&displayLink); + if (r != kCVReturnSuccess) { + if (self.displayLinkFailCount >= MAX_DISPLAYLINK_FAIL_COUNT) { + J2dTraceLn(J2D_TRACE_ERROR, + "MTLLayer.createDisplayLink --- unable to create CVDisplayLink."); + self.displayLinkFailCount = 0; + return; + } + self.displayLinkFailCount++; + [self performSelector:@selector(createDisplayLink) + withObject:nil + afterDelay:CV_DISPLAYLINK_FAIL_DELAY]; + return; + } else { + CVDisplayLinkSetOutputCallback(displayLink, &displayLinkCallback, (__bridge void*)self); + self.displayLinkCount = 0; + self.displayLinkFailCount = 0; + } } - (id) initWithJavaLayer:(jobject)layer