diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.h b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.h index dceac2ad433..5f5eff992c0 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.h +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.h @@ -37,6 +37,7 @@ // intermediate buffer, used the RQ lock to synchronize MTLContext* ctx; + MTLClip* clip; float bufferWidth; float bufferHeight; id buffer; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.m index b99e697fe54..8c93f180c3d 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.m @@ -29,6 +29,7 @@ #import "LWCToolkit.h" #import "MTLSurfaceData.h" #import "JNIUtilities.h" +#import "MTLBlitLoops.h" @implementation MTLLayer @@ -74,6 +75,7 @@ - (id) initWithJavaLayer:(jobject)layer self.opaque = FALSE; CVDisplayLinkCreateWithActiveCGDisplays(&displayLink); CVDisplayLinkSetOutputCallback(displayLink, &displayLinkCallback, (__bridge void*)self); + clip = [[MTLClip alloc] init]; return self; } @@ -113,15 +115,27 @@ - (void) blitTexture { return; } self.nextDrawableCount++; - - id blitEncoder = [commandBuf blitCommandEncoder]; - - [blitEncoder - copyFromTexture:self.buffer sourceSlice:0 sourceLevel:0 - sourceOrigin:MTLOriginMake(src_x, src_y, 0) - sourceSize:MTLSizeMake(src_w, src_h, 1) - toTexture:mtlDrawable.texture destinationSlice:0 destinationLevel:0 destinationOrigin:MTLOriginMake(0, 0, 0)]; - [blitEncoder endEncoding]; + [clip copyFrom:self.ctx.clip]; + [self.ctx resetClip]; + drawTex2Tex(self.ctx, self.buffer, mtlDrawable.texture, JNI_TRUE, NO, INTERPOLATION_NEAREST_NEIGHBOR, + src_x, src_y, self.buffer.width, self.buffer.height, 0, 0, mtlDrawable.texture.width - src_x, mtlDrawable.texture.height - src_y); +// id blitEncoder = [commandBuf blitCommandEncoder]; +// +// [blitEncoder +// copyFromTexture:self.buffer sourceSlice:0 sourceLevel:0 +// sourceOrigin:MTLOriginMake(src_x, src_y, 0) +// sourceSize:MTLSizeMake(src_w, src_h, 1) +// toTexture:mtlDrawable.texture destinationSlice:0 destinationLevel:0 destinationOrigin:MTLOriginMake(0, 0, 0)]; +// [blitEncoder endEncoding]; + [self.ctx.encoderManager endEncoder]; + MTLCommandBufferWrapper *cbwrapper = [self.ctx pullCommandBufferWrapper]; + id commandbuf = [cbwrapper getCommandBuffer]; + [commandbuf addCompletedHandler:^(id commandbuf) { + [cbwrapper release]; + }]; + [commandbuf commit]; + [commandbuf waitUntilCompleted]; + [self.ctx.clip copyFrom:clip]; [commandBuf presentDrawable:mtlDrawable]; [commandBuf addCompletedHandler:^(id commandBuf) { @@ -136,6 +150,8 @@ - (void) blitTexture { - (void) dealloc { JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; (*env)->DeleteWeakGlobalRef(env, self.javaLayer); + [clip release]; + clip = nil; self.javaLayer = nil; [self stopDisplayLink]; CVDisplayLinkRelease(self.displayLink);