Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8244193: Remove nextDrawableCount and lock RQ only during the blit op… #41

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -41,7 +41,9 @@
float bufferWidth;
float bufferHeight;
id<MTLTexture> buffer;
int nextDrawableCount;
id<CAMetalDrawable> mtlDrawable;
id<MTLCommandBuffer> blitCommandBuf;
id<MTLBlitCommandEncoder> blitEncoder;
int topInset;
int leftInset;
}
@@ -51,7 +53,9 @@
@property (readwrite, assign) float bufferWidth;
@property (readwrite, assign) float bufferHeight;
@property (readwrite, assign) id<MTLTexture> buffer;
@property (readwrite, assign) int nextDrawableCount;
@property (readwrite, assign) id<CAMetalDrawable> mtlDrawable;
@property (readwrite, assign) id<MTLCommandBuffer> blitCommandBuf;
@property (readwrite, assign) id<MTLBlitCommandEncoder> blitEncoder;
@property (readwrite, assign) int topInset;
@property (readwrite, assign) int leftInset;

@@ -66,6 +70,7 @@
DY2:(jfloat)dy2;
- (void) blitCallback;
- (void) display;
- (void) initBlit;
@end

#endif /* CGLLayer_h_Included */
@@ -39,7 +39,9 @@ @implementation MTLLayer
@synthesize bufferWidth;
@synthesize bufferHeight;
@synthesize buffer;
@synthesize nextDrawableCount;
@synthesize mtlDrawable;
@synthesize blitCommandBuf;
@synthesize blitEncoder;
@synthesize topInset;
@synthesize leftInset;

@@ -70,53 +72,21 @@ - (id) initWithJavaLayer:(JNFWeakJObjectWrapper *)layer
self.topInset = 0;
self.leftInset = 0;
self.framebufferOnly = NO;
self.nextDrawableCount = 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);
return;
}

if (self.nextDrawableCount != 0)
return;

@autoreleasepool {
if ((self.buffer.width == 0) || (self.buffer.height == 0)) {
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer.blitTexture: cannot create drawable of size 0");
return;
}

id<MTLCommandBuffer> commandBuf = [self.ctx createBlitCommandBuffer];
if (commandBuf == nil) {
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer.blitTexture: nothing to do (commandBuf is null)");
return;
}

id<CAMetalDrawable> mtlDrawable = [self nextDrawable];
if (mtlDrawable == nil) {
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer.blitTexture: nextDrawable is null)");
return;
}
self.nextDrawableCount++;
J2dTraceLn6(J2D_TRACE_VERBOSE, "MTLLayer.blitTexture: src tex=%p (w=%d, h=%d), dst tex=%p (w=%d, h=%d)", self.buffer, self.buffer.width, self.buffer.height, mtlDrawable.texture, mtlDrawable.texture.width, mtlDrawable.texture.height);
id <MTLBlitCommandEncoder> blitEncoder = [commandBuf blitCommandEncoder];
[blitEncoder
[self.blitEncoder
copyFromTexture:self.buffer sourceSlice:0 sourceLevel:0
sourceOrigin:MTLOriginMake((jint)(self.leftInset*self.contentsScale), (jint)(self.topInset*self.contentsScale), 0)
sourceSize:MTLSizeMake(self.buffer.width, self.buffer.height, 1)
toTexture:mtlDrawable.texture destinationSlice:0 destinationLevel:0 destinationOrigin:MTLOriginMake(0, 0, 0)];
[blitEncoder endEncoding];
toTexture:self.mtlDrawable.texture destinationSlice:0 destinationLevel:0 destinationOrigin:MTLOriginMake(0, 0, 0)];
[self.blitEncoder endEncoding];

[commandBuf presentDrawable:mtlDrawable];
[self.blitCommandBuf presentDrawable:self.mtlDrawable];

[commandBuf addCompletedHandler:^(id <MTLCommandBuffer> commandBuf) {
self.nextDrawableCount--;
}];

[commandBuf commit];
[self.blitCommandBuf commit];
}
}

@@ -140,9 +110,40 @@ - (void) blitCallback {
(*env)->DeleteLocalRef(env, javaLayerLocalRef);
}

- (void) initBlit {
if (self.ctx == NULL || self.javaLayer == NULL || self.buffer == nil || self.ctx.device == nil) {
J2dTraceLn4(J2D_TRACE_VERBOSE, "MTLLayer.initBlit: uninitialized (mtlc=%p, javaLayer=%p, buffer=%p, devide=%p)", self.ctx, self.javaLayer, self.buffer, ctx.device);
return;
}

if ((self.buffer.width == 0) || (self.buffer.height == 0)) {
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer.initBlit: cannot create drawable of size 0");
return;
}
self.blitCommandBuf = [self.ctx createBlitCommandBuffer];
if (self.blitCommandBuf == nil) {
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer.initBlit: nothing to do (commandBuf is null)");
return;
}

self.blitEncoder = [self.blitCommandBuf blitCommandEncoder];
if (self.blitEncoder == nil) {
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer.initBlit: blitEncoder is null)");
return;
}

self.mtlDrawable = [self nextDrawable];
if (self.mtlDrawable == nil) {
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer.initBlit: nextDrawable is null)");
return;
}
J2dTraceLn6(J2D_TRACE_VERBOSE, "MTLLayer.initBlit: src tex=%p (w=%d, h=%d), dst tex=%p (w=%d, h=%d)", self.buffer, self.buffer.width, self.buffer.height, self.mtlDrawable.texture, self.mtlDrawable.texture.width, self.mtlDrawable.texture.height);
}

- (void) display {
AWT_ASSERT_APPKIT_THREAD;
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer_display() called");
[self initBlit];
[self blitCallback];
[super display];
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.