Skip to content

Commit

Permalink
JBR-5321 Menu sometimes rendered as empty frame with Dsun.java2d.meta…
Browse files Browse the repository at this point in the history
…l.displaySync=true

(cherry picked from commit 2935bde)
  • Loading branch information
avu authored and vprovodin committed Feb 24, 2023
1 parent 9b20efd commit 1ad964a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ CVReturn mtlDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp*

- (void)startRedraw:(MTLLayer*)layer {
[_dlLock lock];
layer.redrawCount++;
J2dTraceLn2(J2D_TRACE_VERBOSE, "MTLContext_startRedraw: ctx=%p layer=%p", self, layer);
@try {
_displayLinkCount = KEEP_ALIVE_COUNT;
Expand All @@ -608,7 +609,10 @@ - (void)stopRedraw:(MTLLayer*) layer {
[_dlLock lock];
@try {
if (_displayLink != nil) {
[_layers removeObject:layer];
if (--layer.redrawCount <= 0) {
[_layers removeObject:layer];
layer.redrawCount = 0;
}
if (_layers.count == 0 && _displayLinkCount == 0) {
if (CVDisplayLinkIsRunning(_displayLink)) {
CVDisplayLinkStop(_displayLink);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
@property (readwrite, atomic) int nextDrawableCount;
@property (readwrite, assign) int topInset;
@property (readwrite, assign) int leftInset;
@property (readwrite, atomic) int redrawCount;

- (id) initWithJavaLayer:(jobject)layer;

Expand All @@ -52,7 +53,7 @@
- (void) display;
- (void) redraw;
- (void) startRedraw;
- (void) stopRedraw;
- (void) stopRedraw:(BOOL)force;
- (void) commitCommandBuffer:(MTLContext*)mtlc wait:(BOOL)waitUntilCompleted display:(BOOL)updateDisplay;
@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ - (id) initWithJavaLayer:(jobject)layer
self.nextDrawableCount = 0;
self.opaque = YES;
self.presentsWithTransaction = YES;
self.redrawCount = 0;
return self;
}

Expand All @@ -86,14 +87,14 @@ - (void) blitTexture {
J2dTraceLn4(J2D_TRACE_VERBOSE,
"MTLLayer.blitTexture: uninitialized (mtlc=%p, javaLayer=%p, buffer=%p, device=%p)", self.ctx,
self.javaLayer, self.buffer, self.ctx.device);
[self stopRedraw];
[self stopRedraw:YES];
return;
}

if (self.nextDrawableCount != 0) {
return;
}
[self stopRedraw];
[self stopRedraw:NO];

@autoreleasepool {
if (((*self.buffer).width == 0) || ((*self.buffer).height == 0)) {
Expand Down Expand Up @@ -184,7 +185,7 @@ - (void) dealloc {
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
(*env)->DeleteWeakGlobalRef(env, self.javaLayer);
self.javaLayer = nil;
[self stopRedraw];
[self stopRedraw:YES];
self.buffer = NULL;
[super dealloc];
}
Expand Down Expand Up @@ -227,8 +228,11 @@ - (void)startRedraw {
}
}

- (void)stopRedraw {
- (void)stopRedraw:(BOOL)force {
if (self.ctx != nil && isDisplaySyncEnabled()) {
if (force) {
self.redrawCount = 0;
}
[self.ctx stopRedraw:self];
}
}
Expand Down Expand Up @@ -320,7 +324,7 @@ - (void)commitCommandBuffer:(MTLContext*)mtlc wait:(BOOL)waitUntilCompleted disp
[layer startRedraw];
} else {
layer.ctx = NULL;
[layer stopRedraw];
[layer stopRedraw:YES];
}
}

Expand Down Expand Up @@ -359,7 +363,7 @@ - (void)commitCommandBuffer:(MTLContext*)mtlc wait:(BOOL)waitUntilCompleted disp
if (layer == nil || ctx == nil) {
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer_blit : Layer or Context is null");
if (layer != nil) {
[layer stopRedraw];
[layer stopRedraw:YES];
}
return;
}
Expand Down

0 comments on commit 1ad964a

Please sign in to comment.