Skip to content
This repository has been archived by the owner. It is now read-only.

8246239: Revert JDK-8244193 as it causes performance regression #49

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -41,8 +41,7 @@
float bufferWidth;
float bufferHeight;
id<MTLTexture> buffer;
id<CAMetalDrawable> mtlDrawable;
id<MTLCommandBuffer> blitCommandBuf;
int nextDrawableCount;
int topInset;
int leftInset;
}
@@ -52,8 +51,7 @@
@property (readwrite, assign) float bufferWidth;
@property (readwrite, assign) float bufferHeight;
@property (readwrite, assign) id<MTLTexture> buffer;
@property (readwrite, assign) id<CAMetalDrawable> mtlDrawable;
@property (readwrite, assign) id<MTLCommandBuffer> blitCommandBuf;
@property (readwrite, assign) int nextDrawableCount;
@property (readwrite, assign) int topInset;
@property (readwrite, assign) int leftInset;

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

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

- (id) initWithJavaLayer:(JNFWeakJObjectWrapper *)layer
{
@@ -69,23 +68,49 @@ - (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 {
id <MTLBlitCommandEncoder> blitEncoder = [self.blitCommandBuf blitCommandEncoder];
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: commandBuf is null");
return;
}
id<CAMetalDrawable> mtlDrawable = [self nextDrawable];
if (mtlDrawable == nil) {
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer.blitTexture: nextDrawable is null)");
return;
}
self.nextDrawableCount++;
id <MTLBlitCommandEncoder> blitEncoder = [commandBuf blitCommandEncoder];

[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:self.mtlDrawable.texture destinationSlice:0 destinationLevel:0 destinationOrigin:MTLOriginMake(0, 0, 0)];
toTexture:mtlDrawable.texture destinationSlice:0 destinationLevel:0 destinationOrigin:MTLOriginMake(0, 0, 0)];
[blitEncoder endEncoding];

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

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

@@ -109,34 +134,9 @@ - (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.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];
}