Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Direct surface publishing using SyphonServerBase #96

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Syphon.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#import <Syphon/SyphonOpenGLServer.h>
#import <Syphon/SyphonOpenGLClient.h>
#import <Syphon/SyphonOpenGLImage.h>
#import <Syphon/SyphonServerBase.h>

/*
Deprecated headers
Expand Down
11 changes: 11 additions & 0 deletions SyphonServerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/

#import <Foundation/Foundation.h>
#import <IOSurface/IOSurface.h>

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -64,6 +65,16 @@ extern NSString * const SyphonServerOptionIsPrivate;
*/
@property (readonly) BOOL hasClients;


/*!
Direclty publish an IOSurface you own. Note your surface MUST have kIOSurfaceIsGlobal property set to true, otherwise you will fail to publish and silently die
This API circumvents normal Syphon Server operations, and does not opt in to IOSurface re-use, which makes this sub optimal in most, but not all situations.

This function will retain the surface until the next publishSurface: call, at which point the surface will be released, and the new incoming surface will be retained.
*/
- (void)publishSurface:(IOSurfaceRef)surface;


/*!
Stops the server instance. Use of this method is optional and releasing all references to the server has the same effect.
*/
Expand Down
20 changes: 20 additions & 0 deletions SyphonServerBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,25 @@ - (IOSurfaceRef)newSurfaceForWidth:(size_t)width height:(size_t)height options:(
return _surface;
}

- (void)publishSurface:(IOSurfaceRef)surface
{
if (_surface)
{
CFRelease(_surface);
}

_surface = surface;

if (_surface)
{
// Return retained (caller releases)
CFRetain(_surface);
_pushPending = true;
}

[self publish];
}

- (void)publish
{
if (_pushPending)
Expand All @@ -276,6 +295,7 @@ - (void)publish
}
[(SyphonServerConnectionManager *)_connectionManager publishNewFrame];
}

#pragma mark Notification Handling for Server Presence
/*
Broadcast and discovery is done via NSDistributedNotificationCenter. Servers notify announce, change (currently only affects name) and retirement.
Expand Down