From a546277f88fb50926b6f1cc0190b07adc5b91c3c Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 19 Mar 2016 22:53:37 -0400 Subject: [PATCH] Added the simplest mechanism to decouple emulation from the display link queue. --- OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m index edc816354..9e08fbd99 100644 --- a/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m +++ b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m @@ -12,6 +12,7 @@ @implementation CSOpenGLView { CVDisplayLinkRef _displayLink; + uint32_t _updateIsOngoing; } - (void)prepareOpenGL @@ -51,9 +52,15 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt - (void)drawAtTime:(const CVTimeStamp *)now { - NSLog(@"%0.4f", (double)now->videoTime / (double)now->videoTimeScale); - [self.delegate openGLView:self didUpdateToTime:*now]; - [self drawViewOnlyIfDirty:YES]; + const uint32_t activityMask = 0x01; + if(!OSAtomicTestAndSet(activityMask, &_updateIsOngoing)) + { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ + [self.delegate openGLView:self didUpdateToTime:*now]; + [self drawViewOnlyIfDirty:YES]; + OSAtomicTestAndClear(activityMask, &_updateIsOngoing); + }); + } } - (void)invalidate