From 97986ad7e91dcf0350c99c9491a9725ffa076a37 Mon Sep 17 00:00:00 2001 From: Zakk Date: Tue, 2 Oct 2018 17:12:24 -0400 Subject: [PATCH] Update to latest syphon framework --- .gitmodules | 2 +- .../CSSyphonCaptureLayer.h | 2 +- .../CSSyphonCaptureLayer.m | 11 ++++++-- .../CSSyphonCapturePlugin/SyphonCapture.h | 1 + .../CSSyphonCapturePlugin/SyphonCapture.m | 28 ++++++++++++------- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/.gitmodules b/.gitmodules index c2991a0d..d4b0feef 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "CapturePlugins/CSSyphonCapturePlugin/Syphon-Framework"] path = CapturePlugins/CSSyphonCapturePlugin/Syphon-Framework - url = https://github.com/palana/Syphon-Framework.git + url = https://github.com/Syphon/Syphon-Framework.git ignore = all diff --git a/CapturePlugins/CSSyphonCapturePlugin/CSSyphonCapturePlugin/CSSyphonCaptureLayer.h b/CapturePlugins/CSSyphonCapturePlugin/CSSyphonCapturePlugin/CSSyphonCaptureLayer.h index 39ee7e99..6bbb04cd 100644 --- a/CapturePlugins/CSSyphonCapturePlugin/CSSyphonCapturePlugin/CSSyphonCaptureLayer.h +++ b/CapturePlugins/CSSyphonCapturePlugin/CSSyphonCapturePlugin/CSSyphonCaptureLayer.h @@ -27,6 +27,6 @@ @property (strong) SyphonClient *syphonClient; @property (assign) bool flipImage; @property (assign) NSSize lastImageSize; - +@property (assign) CGLContextObj sharedContext; @end diff --git a/CapturePlugins/CSSyphonCapturePlugin/CSSyphonCapturePlugin/CSSyphonCaptureLayer.m b/CapturePlugins/CSSyphonCapturePlugin/CSSyphonCapturePlugin/CSSyphonCaptureLayer.m index eb7854a5..96a61e8d 100644 --- a/CapturePlugins/CSSyphonCapturePlugin/CSSyphonCapturePlugin/CSSyphonCaptureLayer.m +++ b/CapturePlugins/CSSyphonCapturePlugin/CSSyphonCapturePlugin/CSSyphonCaptureLayer.m @@ -20,6 +20,8 @@ self.asynchronous = NO; self.needsDisplayOnBoundsChange = YES; self.flipImage = NO; + _lastImageSize = NSZeroSize; + } return self; @@ -70,8 +72,10 @@ -(CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pf { - _myCGLContext = [super copyCGLContextForPixelFormat:pf]; - + + //_myCGLContext = [super copyCGLContextForPixelFormat:pf]; + + CGLCreateContext(pf, self.sharedContext, &_myCGLContext); return _myCGLContext; } @@ -95,7 +99,7 @@ glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT); - SyphonImage *image = [self.syphonClient newFrameImageForContext:cgl_ctx]; + SyphonImage *image = [self.syphonClient newFrameImage]; if (!image) @@ -103,6 +107,7 @@ return; } + _lastImageSize = image.textureSize; self.textureSize = _lastImageSize; diff --git a/CapturePlugins/CSSyphonCapturePlugin/CSSyphonCapturePlugin/SyphonCapture.h b/CapturePlugins/CSSyphonCapturePlugin/CSSyphonCapturePlugin/SyphonCapture.h index 4b25b4b2..681dc9e1 100644 --- a/CapturePlugins/CSSyphonCapturePlugin/CSSyphonCapturePlugin/SyphonCapture.h +++ b/CapturePlugins/CSSyphonCapturePlugin/CSSyphonCapturePlugin/SyphonCapture.h @@ -31,6 +31,7 @@ uint32_t _surfaceSeed; bool _dummyFrameUpdate; + CGLContextObj _cgl_ctx; CATransform3D _flipTransform; } diff --git a/CapturePlugins/CSSyphonCapturePlugin/CSSyphonCapturePlugin/SyphonCapture.m b/CapturePlugins/CSSyphonCapturePlugin/CSSyphonCapturePlugin/SyphonCapture.m index 17255929..116bce34 100644 --- a/CapturePlugins/CSSyphonCapturePlugin/CSSyphonCapturePlugin/SyphonCapture.m +++ b/CapturePlugins/CSSyphonCapturePlugin/CSSyphonCapturePlugin/SyphonCapture.m @@ -94,6 +94,12 @@ -(void) commonInit { + CGLPixelFormatAttribute attrib[] = {kCGLPFANoRecovery, kCGLPFAAccelerated, 0}; + CGLPixelFormatObj pixelFormat = NULL; + GLint numPixelFormats = 0; + CGLChoosePixelFormat (attrib, &pixelFormat, &numPixelFormats); + CGLCreateContext(pixelFormat, NULL, &_cgl_ctx); + _renderType = kCSRenderFrameArrived; self.canProvideTiming = YES; @@ -118,6 +124,8 @@ { CSSyphonCaptureLayer *newLayer = [CSSyphonCaptureLayer layer]; + newLayer.sharedContext = _cgl_ctx; + if (_syphon_client) { newLayer.syphonClient = _syphon_client; @@ -194,16 +202,11 @@ if (_syphonServer) { - _syphon_client = [[SyphonClient alloc] initWithServerDescription:_syphonServer.copy options:nil newFrameHandler:^(SyphonClient *client) { + _syphon_client = [[SyphonClient alloc] initWithServerDescription:_syphonServer.copy context:_cgl_ctx options:nil newFrameHandler:^(SyphonClient *client) { //Big stupid hack to force at least one layer to update the size before we kick a framedata block off - if (NSEqualSizes(self->_last_frame_size, NSZeroSize)) - { - [self updateLayersWithBlock:^(CALayer *layer) { - self->_last_frame_size = ((CSSyphonCaptureLayer *)layer).lastImageSize; - }]; - } else if (self->_dummyFrameUpdate) { + if (self->_dummyFrameUpdate) { [self updateLayersWithFramedataBlock:^(CALayer *layer) { return; }]; @@ -212,19 +215,24 @@ } - + if (!self->_dummyFrameUpdate) { [self updateLayersWithFramedataBlock:^(CALayer *layer) { - [((CSSyphonCaptureLayer *)layer) setNeedsDisplay]; }]; [self frameArrived]; } - + if (NSEqualSizes(self->_last_frame_size, NSZeroSize)) + { + [self updateLayersWithBlock:^(CALayer *layer) { + self->_last_frame_size = ((CSSyphonCaptureLayer *)layer).lastImageSize; + NSLog(@"LAST SIZE %@", NSStringFromSize(self->_last_frame_size)); + }]; + } }];