Permalink
Browse files

cleanup and fixes

  • Loading branch information...
1 parent d301a4e commit 796a0272263e28cb927775afa87e15e960443361 @mrRay committed May 5, 2016
@@ -51,12 +51,10 @@ and then set up the VVBuffer to retain the underlying SyphonImage resource (whic
// set up the buffer i'm returning to use this callback when it's released- we'll free the SyphonImage in this callback
[returnMe setBackingReleaseCallback:VVBuffer_ReleaseSyphonImage];
// make sure the buffer i'm returning retains the image from the client!
- [returnMe setBackingReleaseCallbackContext:newImage];
- [newImage retain];
+ [returnMe setBackingReleaseCallbackContextObject:newImage];
- // the 'newImage' we got from the syphon client was retained, so release it (yes, i know this cancels out the 'retain' above it, i'm trying to be explicit)
+ // the 'newImage' we got from the syphon client was retained, so release it
[newImage release];
-
return returnMe;
}
@end
@@ -1,9 +1,9 @@
#import <TargetConditionals.h>
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
-#else
+#else // NOT TARGET_OS_IPHONE
#import <Cocoa/Cocoa.h>
-#endif
+#endif // TARGET_OS_IPHONE
#include <sys/time.h>
#import <unistd.h>
#include <libkern/OSAtomic.h>
@@ -209,7 +209,7 @@ - (void) _renderPrep {
if (context == nil)
return;
#if !TARGET_OS_IPHONE
- CGLContextObj cgl_ctx = [context CGLContextObj];
+ //CGLContextObj cgl_ctx = [context CGLContextObj];
/*
glPushAttrib(GL_ALL_ATTRIB_BITS);
glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
@@ -49,14 +49,14 @@ - (VVBuffer *) allocBufferForSyphonClient:(SyphonClient *)c {
NSLog(@"\t\terr: passed nil img %s",__func__);
return nil;
}
- // get a new image from the client
- SyphonImage *newImage = nil;
+ // probably not necessary, but ensures that nothing else uses the GL context while we are- unlock as soon as we're done working with the context
pthread_mutex_lock(&contextLock);
- newImage = [c newFrameImageForContext:[context CGLContextObj]];
+ // get a new image from the client!
+ SyphonImage *newImage = [c newFrameImageForContext:[context CGLContextObj]];
pthread_mutex_unlock(&contextLock);
- NSRect tmpRect = NSMakeRect(0,0,0,0);
- tmpRect.size = [newImage textureSize];
+ NSRect newSrcRect = NSMakeRect(0,0,0,0);
+ newSrcRect.size = [newImage textureSize];
/* make and configure the buffer i'll be returning. syphon actually created the GL texture,
so instead of asking the VVBufferPool framework to allocate a texture, we're just going to
@@ -80,18 +80,18 @@ and then set up the VVBuffer to retain the underlying SyphonImage resource (whic
desc->localSurfaceID = 0; // only used when working with associating textures with IOSurfaces- set to 0.
[returnMe setPreferDeletion:YES]; // we want to make sure that this buffer isn't pooled (the VVBuffer is just a wrapper around a syphon-created and syphon-controlled GL resource- it doesn't belong in this buffer pool)
- [returnMe setSize:tmpRect.size]; // set the buffer's size. the "size" is the size of the GL resource, and is always in pixels.
- [returnMe setSrcRect:tmpRect]; // set the buffer's "srcRect". the "srcRect" is the area of the GL resource that is used to describe the image this VVBuffer represents. the units are always in pixels (even if the buffer is a GL_TEXTURE_2D, and its tex coords are normalized). this is used to describe images that don't occupy the full region of a texture, and do zero-cost cropping. the srcRect is respected by everything in this framework.
- [returnMe setBackingSize:tmpRect.size]; // the backing size is the size (in pixels) of whatever's backing the GL resource. there's no CPU backing in this case- just set it to be the same as the buffer's "size".
+ [returnMe setSize:[newImage textureSize]]; // set the buffer's size. the "size" is the size of the GL resource, and is always in pixels.
+ [returnMe setSrcRect:newSrcRect]; // set the buffer's "srcRect". the "srcRect" is the area of the GL resource that is used to describe the image this VVBuffer represents. the units are always in pixels (even if the buffer is a GL_TEXTURE_2D, and its tex coords are normalized). this is used to describe images that don't occupy the full region of a texture, and do zero-cost cropping. the srcRect is respected by everything in this framework.
+ [returnMe setBackingSize:[newImage textureSize]]; // the backing size is the size (in pixels) of whatever's backing the GL resource. there's no CPU backing in this case- just set it to be the same as the buffer's "size".
[returnMe setBackingID:VVBufferBackID_Syphon]; // set the backing ID to indicate that this buffer was created by wrapping a syphon image.
- // make sure the buffer i'm returning retains the image from the client, then release it!
+ // set up the buffer i'm returning to use this callback when it's released- we'll free the SyphonImage in this callback
[returnMe setBackingReleaseCallback:VVBuffer_ReleaseSyphonImage];
- [returnMe setBackingReleaseCallbackContext:newImage];
-
- // do NOT release newImage- 'returnMe' will free it in its backing release callback when the buffer is finally dealloc'ed
- //VVRELEASE(newImage);
+ // make sure the buffer i'm returning retains the image from the client!
+ [returnMe setBackingReleaseCallbackContextObject:newImage];
+ // the 'newImage' we got from the syphon client was retained, so release it
+ [newImage release];
return returnMe;
}
#ifndef __LP64__
@@ -166,8 +166,7 @@ - (VVBuffer *) allocBufferForFFGLImage:(FFGLImage *)i {
[returnMe setBackingID:VVBufferBackID_VVFFGL];
}
[returnMe setBackingReleaseCallback:VVBuffer_ReleaseFFGLImage]; // this is the function that will be called when the VVBuffer is deallocated, and it's safe to release the underlying FFGLImage resource. this function frees the FFGLImage resource.
- [returnMe setBackingReleaseCallbackContext:i]; // set the callback context to the FFGLImage i was passed. the "release callback context" is the ptr passed to the "release callback" when the VVBuffer is freed.
- [i retain]; // retain the passed FFGLImage resource here. the FFGLImage is retained by the VVBuffer created from it as the callback context- we want the FFGLImage to persist as long as this VVBuffer, so one has to retain the other.
+ [returnMe setBackingReleaseCallbackContextObject:i]; // set the callback context to the FFGLImage i was passed. the "release callback context" is the ptr passed to the "release callback" when the VVBuffer is freed.
return returnMe;
}
@@ -315,6 +315,11 @@ VVBuffers conform to the NSCopying protocol, but this behavior isn't straightfor
@param n An arbitrary pointer to a resource that is assumed to be required by this VVBuffer. VVBuffer doesn't explicitly retain anything passed to this method (because it's unknown if it will even be a void* or an id)- you are responsible for ensuring that whatever you pass here is retained, and freed later in the backingReleaseCallback.
*/
- (void) setBackingReleaseCallbackContext:(void *)n;
+/// Similar to 'setBackingReleaseCallback:', but it expects to be passed a subclass of NSObject, which it retains
+/**
+@param n An NSObject instance of a resource that is assumed to be required by this VVBuffer. It is expected that this variable will be released (via the backingReleaseCallback) when the VVBuffer is destroyed.
+*/
+- (void) setBackingReleaseCallbackContextObject:(id)n;
- (void *) backingReleaseCallbackContext;
#if !TARGET_OS_IPHONE
/// If the receiver is a GL texture backed by an IOSurfaceRef, this returns the IOSurfaceRef. If you want to send a texture to another process, you want to call -[VVBufferPool allocBufferForTexBackedIOSurfaceSized:], render into the returned buffer, and then call "localSurfaceRef" to retrieve the IOSurface to be sent to another process.
@@ -619,6 +619,9 @@ - (VVBufferBackingReleaseCallback) backingReleaseCallback {
- (void) setBackingReleaseCallbackContext:(void *)n {
backingReleaseCallbackContext = n;
}
+- (void) setBackingReleaseCallbackContextObject:(id)n {
+ backingReleaseCallbackContext = (n==nil) ? nil : [n retain];
+}
- (void *) backingReleaseCallbackContext {
return backingReleaseCallbackContext;
}
@@ -1320,9 +1320,7 @@ - (VVBuffer *) allocBufferForBitmapRep:(NSBitmapImageRep *)rep prefer2DTexture:(
// the backing release callback should release a bitmap rep- set it, and the context (which is the rep)
[returnMe setBackingID:VVBufferBackID_NSBitImgRep];
[returnMe setBackingReleaseCallback:VVBuffer_ReleaseBitmapRep];
- [returnMe setBackingReleaseCallbackContext:rep];
- // don't forget to retain the rep (the buffer retains it, we increment the retain count here)
- [rep retain];
+ [returnMe setBackingReleaseCallbackContextObject:rep];
[returnMe setBackingSize:repSize];
return returnMe;
}
@@ -1987,8 +1985,7 @@ - (VVBuffer *) allocBufferForCGImageRef:(CGImageRef)n prefer2DTexture:(BOOL)pref
backingSize:imgSize];
[returnMe setBackingID:VVBufferBackID_External];
[returnMe setBackingReleaseCallback:VVBuffer_ReleaseBitmapRep];
- [returnMe setBackingReleaseCallbackContext:frameData];
- [frameData retain];
+ [returnMe setBackingReleaseCallbackContextObject:frameData];
[returnMe setPreferDeletion:YES];
[returnMe setFlipped:YES];
@@ -2017,9 +2014,9 @@ - (VVBuffer *) allocBufferForCGImageRef:(CGImageRef)n prefer2DTexture:(BOOL)pref
// draw the image in the bitmap context, flush it
CGContextDrawImage(ctx, CGRectMake(0,0,imgSize.width,imgSize.height), n);
CGContextFlush(ctx);
- CGContextRelease(ctx);
// the bitmap context we just drew into has premultiplied alpha, so we need to un-premultiply before uploading it
CGBitmapContextUnpremultiply(ctx);
+ CGContextRelease(ctx);
// set up the buffer descriptor that i'll be using to describe the texture i'm about to create
VVBufferDescriptor desc;
desc.type = VVBufferType_Tex;
@@ -2694,9 +2691,7 @@ - (VVBuffer *) allocTexRangeForNSBitmapRep:(NSBitmapImageRep *)rep prefer2DTextu
// the backing release callback should release a bitmap rep- set it, and the context (which is the rep)
[returnMe setBackingID:VVBufferBackID_NSBitImgRep];
[returnMe setBackingReleaseCallback:VVBuffer_ReleaseBitmapRep];
- [returnMe setBackingReleaseCallbackContext:rep];
- // don't forget to retain the rep (the buffer retains it, we increment the retain count here)
- [rep retain];
+ [returnMe setBackingReleaseCallbackContextObject:rep];
[returnMe setFlipped:YES];
[returnMe setBackingSize:repSize];
return returnMe;

0 comments on commit 796a027

Please sign in to comment.