diff --git a/CapturePlugins/CSDeckLinkCapturePlugin/CSDeckLinkCapturePlugin/CSDeckLinkLayer.mm b/CapturePlugins/CSDeckLinkCapturePlugin/CSDeckLinkCapturePlugin/CSDeckLinkLayer.mm index 2bcf9c1d..3a309483 100644 --- a/CapturePlugins/CSDeckLinkCapturePlugin/CSDeckLinkCapturePlugin/CSDeckLinkLayer.mm +++ b/CapturePlugins/CSDeckLinkCapturePlugin/CSDeckLinkCapturePlugin/CSDeckLinkLayer.mm @@ -17,6 +17,7 @@ { self.asynchronous = NO; self.needsDisplayOnBoundsChange = YES; + _deckLinkOGL = CreateOpenGLScreenPreviewHelper(); _deckLinkOGL->AddRef(); } @@ -46,6 +47,17 @@ +-(void)setContentsRect:(CGRect)contentsRect +{ + _privateCropRect = contentsRect; + [self setNeedsDisplay]; +} + +-(CGRect)contentsRect +{ + return _privateCropRect; +} + -(void)setRenderFrame:(IDeckLinkVideoFrame *)frame @@ -66,34 +78,57 @@ glClear(GL_COLOR_BUFFER_BIT); - + NSSize useSize = self.bounds.size; CGRect newCrop; + newCrop.origin.x = _deckLinkFrameSize.width * _privateCropRect.origin.x; + newCrop.origin.y = _deckLinkFrameSize.height * _privateCropRect.origin.y; + newCrop.size.width = _deckLinkFrameSize.width * _privateCropRect.size.width; + newCrop.size.height = _deckLinkFrameSize.height * _privateCropRect.size.height; + + if ([self.contentsGravity isEqualToString:kCAGravityResizeAspect]) + { + float wr = newCrop.size.width / self.bounds.size.width; + float hr = newCrop.size.height / self.bounds.size.height; + + float ratio = (hr < wr ? wr : hr); + useSize = NSMakeSize(newCrop.size.width / ratio, newCrop.size.height / ratio); + } + + GLint vpx = (self.bounds.size.width - useSize.width)/2; GLint vpy = (self.bounds.size.height - useSize.height)/2; - + glViewport(vpx, vpy, useSize.width, useSize.height); - + glMatrixMode(GL_PROJECTION); glLoadIdentity(); - + glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - + NSRect cropRect; glMatrixMode(GL_TEXTURE); glLoadIdentity(); + GLfloat yt = 1.0 - (_privateCropRect.origin.y + _privateCropRect.size.height); + + + glScalef(_privateCropRect.size.width, _privateCropRect.size.height, 1); + glTranslatef(_privateCropRect.origin.x * _deckLinkFrameSize.width, yt * _deckLinkFrameSize.height, 0); + + + if (_deckLinkOGL) { _deckLinkOGL->PaintGL(); } - + [super drawInCGLContext:ctx pixelFormat:pf forLayerTime:t displayTime:ts]; diff --git a/CocoaSplit.xcodeproj/project.xcworkspace/xcuserdata/zakk.xcuserdatad/UserInterfaceState.xcuserstate b/CocoaSplit.xcodeproj/project.xcworkspace/xcuserdata/zakk.xcuserdatad/UserInterfaceState.xcuserstate index 3fe482a7..aefa0c87 100644 Binary files a/CocoaSplit.xcodeproj/project.xcworkspace/xcuserdata/zakk.xcuserdatad/UserInterfaceState.xcuserstate and b/CocoaSplit.xcodeproj/project.xcworkspace/xcuserdata/zakk.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/CocoaSplit/InputSource.m b/CocoaSplit/InputSource.m index 2eafbc0e..3876f87b 100644 --- a/CocoaSplit/InputSource.m +++ b/CocoaSplit/InputSource.m @@ -1301,7 +1301,6 @@ static NSArray *_sourceTypes = nil; -(void)dealloc { - NSLog(@"DEALLOC INPUT"); [self deregisterVideoInput:self.videoInput]; for(id vInput in self.videoSources) { @@ -1892,12 +1891,13 @@ static NSArray *_sourceTypes = nil; -(void)autoFit { + float wr = self.size.width / self.canvas_width; float hr = self.size.height / self.canvas_height; float ratio = (hr < wr ? wr : hr); [self directSize:self.size.width / ratio height:self.size.height / ratio]; - CGFloat newX = (self.canvas_width/2) - self.layer.bounds.size.width/2; - CGFloat newY = (self.canvas_height/2) - self.layer.bounds.size.height/2; + CGFloat newX = (self.canvas_width/2) - self.layer.frame.size.width/2; + CGFloat newY = (self.canvas_height/2) - self.layer.frame.size.height/2; [self positionOrigin:newX y:newY]; } @@ -1934,7 +1934,11 @@ static NSArray *_sourceTypes = nil; NSRect iRect = NSIntegralRect(newLayout); - self.layer.bounds = newLayout; + [CATransaction begin]; + self.layer.frame = newLayout; + [CATransaction commit]; + + }