1 #import <CoreVideo/CVDisplayLink.h>
2 #import <Foundation/NSRaise.h>
4 // FIXME: use only one timer for all the display links, this will reduce run loop overhead
6 @interface CVDisplayLink : NSObject {
8 CVDisplayLinkOutputCallback _callback;
14 @implementation CVDisplayLink
26 -(void)displayLinkTimer:(NSTimer *)timer {
28 _callback(self,NULL,NULL,0,NULL,_userInfo);
32 _timer=[[NSTimer scheduledTimerWithTimeInterval:1.0/60.0 target:self selector:@selector(displayLinkTimer:) userInfo:nil repeats:YES] retain];
41 CVReturn CVDisplayLinkCreateWithActiveCGDisplays(CVDisplayLinkRef *result) {
42 *result=[[CVDisplayLink alloc] init];
43 return kCVReturnSuccess;
46 CVReturn CVDisplayLinkSetOutputCallback(CVDisplayLinkRef self,CVDisplayLinkOutputCallback callback,void *userInfo) {
47 self->_callback=callback;
48 self->_userInfo=userInfo;
49 return kCVReturnSuccess;
52 CVReturn CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(CVDisplayLinkRef self,CGLContextObj cglContext,CGLPixelFormatObj cglPixelFormat) {
53 return kCVReturnSuccess;
56 CVReturn CVDisplayLinkStart(CVDisplayLinkRef self) {
57 if (CVDisplayLinkIsRunning(self))
58 return kCVReturnDisplayLinkAlreadyRunning;
60 return kCVReturnSuccess;
63 CVReturn CVDisplayLinkStop(CVDisplayLinkRef self) {
64 if (!CVDisplayLinkIsRunning(self))
65 return kCVReturnDisplayLinkNotRunning;
67 return kCVReturnSuccess;
70 Boolean CVDisplayLinkIsRunning (CVDisplayLinkRef self) {
71 return (self->_timer != nil);
74 CVDisplayLinkRef CVDisplayLinkRetain(CVDisplayLinkRef self) {
78 void CVDisplayLinkRelease(CVDisplayLinkRef self) {