1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
30
30
#import " MTLSurfaceData.h"
31
31
#import " JNIUtilities.h"
32
32
#define KEEP_ALIVE_INC 4
33
+ #define CV_DISPLAYLINK_FAIL_DELAY 1.0
34
+ #define MAX_DISPLAYLINK_FAIL_COUNT 5
33
35
34
36
@implementation MTLLayer
35
37
@@ -44,11 +46,27 @@ @implementation MTLLayer
44
46
@synthesize nextDrawableCount;
45
47
@synthesize displayLink;
46
48
@synthesize displayLinkCount;
49
+ @synthesize displayLinkFailCount;
47
50
48
51
- (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
+ }
52
70
}
53
71
54
72
- (id ) initWithJavaLayer : (jobject)layer
0 commit comments