< prev index next >

src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.m

Print this page
*** 37,11 ***
  @synthesize javaLayer;
  @synthesize ctx;
  @synthesize bufferWidth;
  @synthesize bufferHeight;
  @synthesize buffer;
! @synthesize nextDrawableCount;
  @synthesize topInset;
  @synthesize leftInset;
  
  - (id) initWithJavaLayer:(JNFWeakJObjectWrapper *)layer
  {
--- 37,13 ---
  @synthesize javaLayer;
  @synthesize ctx;
  @synthesize bufferWidth;
  @synthesize bufferHeight;
  @synthesize buffer;
! @synthesize mtlDrawable;
+ @synthesize blitCommandBuf;
+ @synthesize blitEncoder;
  @synthesize topInset;
  @synthesize leftInset;
  
  - (id) initWithJavaLayer:(JNFWeakJObjectWrapper *)layer
  {

*** 68,57 ***
      self.actions = actions;
      [actions release];
      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
                  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];
  
!         [commandBuf presentDrawable:mtlDrawable];
  
!         [commandBuf addCompletedHandler:^(id <MTLCommandBuffer> commandBuf) {
-             self.nextDrawableCount--;
-         }];
- 
-         [commandBuf commit];
      }
  }
  
  - (void) dealloc {
      self.javaLayer = nil;
--- 70,25 ---
      self.actions = actions;
      [actions release];
      self.topInset = 0;
      self.leftInset = 0;
      self.framebufferOnly = NO;
      return self;
  }
  
  - (void) blitTexture {
      @autoreleasepool {
!         [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:self.mtlDrawable.texture destinationSlice:0 destinationLevel:0 destinationOrigin:MTLOriginMake(0, 0, 0)];
!         [self.blitEncoder endEncoding];
  
!         [self.blitCommandBuf presentDrawable:self.mtlDrawable];
  
!         [self.blitCommandBuf commit];
      }
  }
  
  - (void) dealloc {
      self.javaLayer = nil;

*** 138,13 ***
--- 108,44 ---
  
      JNFCallVoidMethod(env, javaLayerLocalRef, jm_drawInMTLContext);
      (*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];
  }
  @end
  
< prev index next >