8290344: Start/stop displaysync affects performance in metal rendering pipeline
Reviewed-by: aghaisas, jdv
This commit is contained in:
parent
afa5d4ced3
commit
f766d92755
@ -55,6 +55,7 @@
|
||||
@property (readwrite, assign) int topInset;
|
||||
@property (readwrite, assign) int leftInset;
|
||||
@property (readwrite, assign) CVDisplayLinkRef displayLink;
|
||||
@property (readwrite, atomic) int displayLinkCount;
|
||||
|
||||
- (id) initWithJavaLayer:(jobject)layer;
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
#import "LWCToolkit.h"
|
||||
#import "MTLSurfaceData.h"
|
||||
#import "JNIUtilities.h"
|
||||
#define KEEP_ALIVE_INC 4
|
||||
|
||||
@implementation MTLLayer
|
||||
|
||||
@ -42,6 +43,7 @@
|
||||
@synthesize leftInset;
|
||||
@synthesize nextDrawableCount;
|
||||
@synthesize displayLink;
|
||||
@synthesize displayLinkCount;
|
||||
|
||||
- (id) initWithJavaLayer:(jobject)layer
|
||||
{
|
||||
@ -74,12 +76,15 @@
|
||||
self.opaque = YES;
|
||||
CVDisplayLinkCreateWithActiveCGDisplays(&displayLink);
|
||||
CVDisplayLinkSetOutputCallback(displayLink, &displayLinkCallback, (__bridge void*)self);
|
||||
self.displayLinkCount = 0;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) blitTexture {
|
||||
if (self.ctx == NULL || self.javaLayer == NULL || self.buffer == nil || self.ctx.device == nil) {
|
||||
J2dTraceLn4(J2D_TRACE_VERBOSE, "MTLLayer.blitTexture: uninitialized (mtlc=%p, javaLayer=%p, buffer=%p, devide=%p)", self.ctx, self.javaLayer, self.buffer, ctx.device);
|
||||
J2dTraceLn4(J2D_TRACE_VERBOSE,
|
||||
"MTLLayer.blitTexture: uninitialized (mtlc=%p, javaLayer=%p, buffer=%p, devide=%p)", self.ctx,
|
||||
self.javaLayer, self.buffer, ctx.device);
|
||||
[self stopDisplayLink];
|
||||
return;
|
||||
}
|
||||
@ -100,9 +105,9 @@
|
||||
NSUInteger src_h = self.buffer.height - src_y;
|
||||
|
||||
if (src_h <= 0 || src_w <= 0) {
|
||||
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer.blitTexture: Invalid src width or height.");
|
||||
[self stopDisplayLink];
|
||||
return;
|
||||
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer.blitTexture: Invalid src width or height.");
|
||||
[self stopDisplayLink];
|
||||
return;
|
||||
}
|
||||
|
||||
id<MTLCommandBuffer> commandBuf = [self.ctx createBlitCommandBuffer];
|
||||
@ -134,7 +139,11 @@
|
||||
}];
|
||||
|
||||
[commandBuf commit];
|
||||
[self stopDisplayLink];
|
||||
|
||||
if (--self.displayLinkCount <= 0) {
|
||||
self.displayLinkCount = 0;
|
||||
[self stopDisplayLink];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,13 +186,18 @@
|
||||
}
|
||||
|
||||
- (void) startDisplayLink {
|
||||
if (!CVDisplayLinkIsRunning(self.displayLink))
|
||||
if (!CVDisplayLinkIsRunning(self.displayLink)) {
|
||||
CVDisplayLinkStart(self.displayLink);
|
||||
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer_startDisplayLink");
|
||||
}
|
||||
displayLinkCount += KEEP_ALIVE_INC; // Keep alive displaylink counter
|
||||
}
|
||||
|
||||
- (void) stopDisplayLink {
|
||||
if (CVDisplayLinkIsRunning(self.displayLink))
|
||||
if (CVDisplayLinkIsRunning(self.displayLink)) {
|
||||
CVDisplayLinkStop(self.displayLink);
|
||||
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer_stopDisplayLink");
|
||||
}
|
||||
}
|
||||
|
||||
CVReturn displayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp* now, const CVTimeStamp* outputTime, CVOptionFlags flagsIn, CVOptionFlags* flagsOut, void* displayLinkContext)
|
||||
|
Loading…
x
Reference in New Issue
Block a user