1
0
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:
Thomas Harte 2020-02-08 15:03:18 -05:00
parent 09132306e4
commit f615d096ca
3 changed files with 3 additions and 33 deletions

View File

@ -707,11 +707,6 @@ struct ActivityObserver: public Activity::Observer {
#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 {
// First order of business: grab a timestamp.
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.
_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).

View File

@ -111,12 +111,6 @@ typedef NS_ENUM(NSInteger, CSOpenGLViewRedrawEvent) {
*/
@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.
*/

View File

@ -22,8 +22,6 @@
NSTrackingArea *_mouseTrackingArea;
NSTimer *_mouseHideTimer;
BOOL _mouseIsCaptured;
id<CSOpenGLViewDisplayLinkDelegate> _displayLinkDelegate;
}
- (void)prepareOpenGL {
@ -65,30 +63,10 @@
CGLPixelFormatObj cglPixelFormat = [[self pixelFormat] CGLPixelFormatObj];
CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(_displayLink, cglContext, cglPixelFormat);
// Give a shout-out.
[self.displayLinkDelegate openGLView:self didUpdateDisplayLink:_displayLink];
// Activate the display link
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) {
CSOpenGLView *const view = (__bridge CSOpenGLView *)displayLinkContext;