mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-23 03:32:32 +00:00
Switch to obtaining refresh periods ephemerally.
Which simplifies the necessary delegate protocol.
This commit is contained in:
parent
09132306e4
commit
f615d096ca
@ -707,11 +707,6 @@ struct ActivityObserver: public Activity::Observer {
|
|||||||
|
|
||||||
#pragma mark - Timer
|
#pragma mark - Timer
|
||||||
|
|
||||||
- (void)openGLView:(CSOpenGLView *)view didUpdateDisplayLink:(CVDisplayLinkRef)displayLink {
|
|
||||||
_refreshPeriod = CVDisplayLinkGetActualOutputVideoRefreshPeriod(displayLink);
|
|
||||||
NSLog(@"Refresh period: %0.5f (%0.5f)", _refreshPeriod, 1.0 / _refreshPeriod);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)openGLViewDisplayLinkDidFire:(CSOpenGLView *)view now:(const CVTimeStamp *)now outputTime:(const CVTimeStamp *)outputTime {
|
- (void)openGLViewDisplayLinkDidFire:(CSOpenGLView *)view now:(const CVTimeStamp *)now outputTime:(const CVTimeStamp *)outputTime {
|
||||||
// First order of business: grab a timestamp.
|
// First order of business: grab a timestamp.
|
||||||
const auto timeNow = std::chrono::high_resolution_clock::now().time_since_epoch().count();
|
const auto timeNow = std::chrono::high_resolution_clock::now().time_since_epoch().count();
|
||||||
@ -729,6 +724,9 @@ struct ActivityObserver: public Activity::Observer {
|
|||||||
|
|
||||||
// Also crib the current view pixel size.
|
// Also crib the current view pixel size.
|
||||||
_pixelSize = pixelSize;
|
_pixelSize = pixelSize;
|
||||||
|
|
||||||
|
// Set the current refresh period.
|
||||||
|
_refreshPeriod = double(now->videoRefreshPeriod) / double(now->videoTimeScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the current output. (TODO: do this within the timer if either raster racing or, at least, sync matching).
|
// Draw the current output. (TODO: do this within the timer if either raster racing or, at least, sync matching).
|
||||||
|
@ -111,12 +111,6 @@ typedef NS_ENUM(NSInteger, CSOpenGLViewRedrawEvent) {
|
|||||||
*/
|
*/
|
||||||
@protocol CSOpenGLViewDisplayLinkDelegate
|
@protocol CSOpenGLViewDisplayLinkDelegate
|
||||||
|
|
||||||
/*!
|
|
||||||
Informs the delegate that from now on, the display link @c displayLink will be used for update notifications
|
|
||||||
and/or that the frequency or phase or @c displayLink has changed.
|
|
||||||
*/
|
|
||||||
- (void)openGLView:(nonnull CSOpenGLView *)view didUpdateDisplayLink:(nonnull CVDisplayLinkRef)displayLink;
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Informs the delegate that the display link has fired.
|
Informs the delegate that the display link has fired.
|
||||||
*/
|
*/
|
||||||
|
@ -22,8 +22,6 @@
|
|||||||
NSTrackingArea *_mouseTrackingArea;
|
NSTrackingArea *_mouseTrackingArea;
|
||||||
NSTimer *_mouseHideTimer;
|
NSTimer *_mouseHideTimer;
|
||||||
BOOL _mouseIsCaptured;
|
BOOL _mouseIsCaptured;
|
||||||
|
|
||||||
id<CSOpenGLViewDisplayLinkDelegate> _displayLinkDelegate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)prepareOpenGL {
|
- (void)prepareOpenGL {
|
||||||
@ -65,30 +63,10 @@
|
|||||||
CGLPixelFormatObj cglPixelFormat = [[self pixelFormat] CGLPixelFormatObj];
|
CGLPixelFormatObj cglPixelFormat = [[self pixelFormat] CGLPixelFormatObj];
|
||||||
CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(_displayLink, cglContext, cglPixelFormat);
|
CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(_displayLink, cglContext, cglPixelFormat);
|
||||||
|
|
||||||
// Give a shout-out.
|
|
||||||
[self.displayLinkDelegate openGLView:self didUpdateDisplayLink:_displayLink];
|
|
||||||
|
|
||||||
// Activate the display link
|
// Activate the display link
|
||||||
CVDisplayLinkStart(_displayLink);
|
CVDisplayLinkStart(_displayLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setDisplayLinkDelegate:(id<CSOpenGLViewDisplayLinkDelegate>)displayLinkDelegate {
|
|
||||||
@synchronized(self) {
|
|
||||||
_displayLinkDelegate = displayLinkDelegate;
|
|
||||||
|
|
||||||
// Seed with the current _displayLink, if any.
|
|
||||||
if(_displayLink) {
|
|
||||||
[displayLinkDelegate openGLView:self didUpdateDisplayLink:_displayLink];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id<CSOpenGLViewDisplayLinkDelegate>)displayLinkDelegate {
|
|
||||||
@synchronized(self) {
|
|
||||||
return _displayLinkDelegate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp *now, const CVTimeStamp *outputTime, CVOptionFlags flagsIn, CVOptionFlags *flagsOut, void *displayLinkContext) {
|
static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp *now, const CVTimeStamp *outputTime, CVOptionFlags flagsIn, CVOptionFlags *flagsOut, void *displayLinkContext) {
|
||||||
CSOpenGLView *const view = (__bridge CSOpenGLView *)displayLinkContext;
|
CSOpenGLView *const view = (__bridge CSOpenGLView *)displayLinkContext;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user