diff --git a/framework/Source/GPUImageOpenGLESContext.h b/framework/Source/GPUImageOpenGLESContext.h index a96ab96c6..5fab58215 100755 --- a/framework/Source/GPUImageOpenGLESContext.h +++ b/framework/Source/GPUImageOpenGLESContext.h @@ -16,6 +16,7 @@ typedef enum { kGPUImageNoRotation, kGPUImageRotateLeft, kGPUImageRotateRight, k @property(readonly, nonatomic) dispatch_queue_t contextQueue; @property(readwrite, retain, nonatomic) GLProgram *currentShaderProgram; ++ (void *)contextKey; + (GPUImageOpenGLESContext *)sharedImageProcessingOpenGLESContext; + (dispatch_queue_t)sharedOpenGLESQueue; + (void)useImageProcessingContext; diff --git a/framework/Source/GPUImageOpenGLESContext.m b/framework/Source/GPUImageOpenGLESContext.m index 118532dfd..0572c18b3 100755 --- a/framework/Source/GPUImageOpenGLESContext.m +++ b/framework/Source/GPUImageOpenGLESContext.m @@ -16,19 +16,27 @@ @implementation GPUImageOpenGLESContext @synthesize currentShaderProgram = _currentShaderProgram; @synthesize contextQueue = _contextQueue; +static void *openGLESContextQueueKey; + - (id)init; { if (!(self = [super init])) { return nil; } - + + openGLESContextQueueKey = &openGLESContextQueueKey; _contextQueue = dispatch_queue_create("com.sunsetlakesoftware.GPUImage.openGLESContextQueue", NULL); + dispatch_queue_set_specific(_contextQueue, openGLESContextQueueKey, (__bridge void *)self, NULL); shaderProgramCache = [[NSMutableDictionary alloc] init]; return self; } ++ (void *)contextKey { + return openGLESContextQueueKey; +} + // Based on Colin Wheeler's example here: http://cocoasamurai.blogspot.com/2011/04/singletons-your-doing-them-wrong.html + (GPUImageOpenGLESContext *)sharedImageProcessingOpenGLESContext; { diff --git a/framework/Source/GPUImageOutput.m b/framework/Source/GPUImageOutput.m index 2a7d43c97..314b77ddb 100755 --- a/framework/Source/GPUImageOutput.m +++ b/framework/Source/GPUImageOutput.m @@ -19,11 +19,10 @@ void runSynchronouslyOnVideoProcessingQueue(void (^block)(void)) { dispatch_queue_t videoProcessingQueue = [GPUImageOpenGLESContext sharedOpenGLESQueue]; - if (dispatch_get_current_queue() == videoProcessingQueue) + if(dispatch_get_specific([GPUImageOpenGLESContext contextKey])) { block(); - } - else + }else { dispatch_sync(videoProcessingQueue, block); } @@ -33,11 +32,10 @@ void runAsynchronouslyOnVideoProcessingQueue(void (^block)(void)) { dispatch_queue_t videoProcessingQueue = [GPUImageOpenGLESContext sharedOpenGLESQueue]; - if (dispatch_get_current_queue() == videoProcessingQueue) + if(dispatch_get_specific([GPUImageOpenGLESContext contextKey])) { block(); - } - else + }else { dispatch_async(videoProcessingQueue, block); }