Skip to content

Commit b461e2b

Browse files
committed
gfxlib2/darwin: use CVDisplayLink as a fallback
1 parent 636667c commit b461e2b

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed

contrib/manifest/FreeBASIC-darwin-x86_64.lst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ examples/GUI/wx-c/fonts_and_colours.bas
115115
examples/GUI/wx-c/mdi.bas
116116
examples/GUI/wx-c/sizers.bas
117117
examples/GUI/wx-c/wx-c_demo.bas
118+
examples/Makefile
119+
examples/OptimizePureAbstractTypes/OptimizePureAbstractTypes.bas
120+
examples/OptimizePureAbstractTypes/PureAbstractTypes.bas
121+
examples/OptimizePureAbstractTypes/TestPureAbstractTypes.PNG
122+
examples/OptimizePureAbstractTypes/inc/EXCEL.bi
123+
examples/OptimizePureAbstractTypes/inc/FBCom.bi
124+
examples/OptimizePureAbstractTypes/inc/MSO.bi
125+
examples/OptimizePureAbstractTypes/inc/VBE6EXT.bi
126+
examples/OptimizePureAbstractTypes/inc/stdole2.bi
118127
examples/allocate.bas
119128
examples/arrays.bas
120129
examples/bitfield.bas
@@ -261,10 +270,13 @@ examples/graphics/OpenGL/NeHe/lesson34.bas
261270
examples/graphics/OpenGL/NeHe/lesson36.bas
262271
examples/graphics/OpenGL/NeHe/milkshapemodel.bi
263272
examples/graphics/OpenGL/NeHe/tgaloader.bi
273+
examples/graphics/OpenGL/fbgfx_opengl
264274
examples/graphics/OpenGL/fbgfx_opengl.bas
265275
examples/graphics/OpenGL/fbgfx_texture.bas
266276
examples/graphics/OpenGL/fbgl/fbgl.bas
267277
examples/graphics/OpenGL/fbgl/fbgl.bi
278+
examples/graphics/OpenGL/fbgl/libfbgl.a
279+
examples/graphics/OpenGL/fbgl/line
268280
examples/graphics/OpenGL/fbgl/line.bas
269281
examples/graphics/OpenGL/gl_test.bas
270282
examples/graphics/OpenGL/glext_test.bas
@@ -1590,6 +1602,7 @@ examples/sound/data/example.mo3
15901602
examples/sound/data/example1.ogg
15911603
examples/sound/data/example2.ogg
15921604
examples/sound/data/prodigy.wav
1605+
examples/sound/portaudio-sine.bas
15931606
examples/structs.bas
15941607
examples/threads/consumer-producer.bas
15951608
examples/threads/threaddetach.bas

src/gfxlib2/darwin/gfx_driver_opengl_cocoa.m

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,20 @@
4343
static dispatch_semaphore_t vsyncSema = NULL;
4444

4545
@interface OpenGLView : NSOpenGLView
46+
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 140000
4647
@property (nonatomic, strong) CADisplayLink *displayLink;
48+
#endif
4749
@end
4850

51+
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 140000
52+
static CVDisplayLinkRef cvDisplayLink = NULL;
53+
static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink,
54+
const CVTimeStamp *now,
55+
const CVTimeStamp *outputTime,
56+
CVOptionFlags flagsIn,
57+
CVOptionFlags *flagsOut,
58+
void *displayLinkContext);
59+
#endif
4960
@implementation OpenGLView
5061
- (BOOL)acceptsFirstResponder
5162
{
@@ -54,10 +65,14 @@ - (BOOL)acceptsFirstResponder
5465
- (void)createDisplayLink
5566
{
5667
vsyncSema = dispatch_semaphore_create(0);
57-
self.displayLink = [self displayLinkWithTarget:self
58-
selector:@selector(waitVSync)];
59-
[self.displayLink addToRunLoop:[NSRunLoop currentRunLoop]
60-
forMode:NSDefaultRunLoopMode];
68+
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 140000
69+
self.displayLink = [self displayLinkWithTarget:self selector:@selector(waitVSync)];
70+
[self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
71+
#else
72+
CVDisplayLinkCreateWithActiveCGDisplays(&cvDisplayLink);
73+
CVDisplayLinkSetOutputCallback(cvDisplayLink, &DisplayLinkCallback, (__bridge void *)self);
74+
CVDisplayLinkStart(cvDisplayLink);
75+
#endif
6176
}
6277

6378
- (void)waitVSync
@@ -67,14 +82,33 @@ - (void)waitVSync
6782

6883
- (void)dealloc
6984
{
70-
[self.displayLink invalidate];
71-
self.displayLink = nil;
85+
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 140000
86+
[self.displayLink invalidate];
87+
self.displayLink = nil;
88+
#else
89+
CVDisplayLinkStop(cvDisplayLink);
90+
CVDisplayLinkRelease(cvDisplayLink);
91+
#endif
7292
dispatch_release(vsyncSema);
7393
[super dealloc];
7494
}
7595

7696
@end
7797

98+
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 140000
99+
static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink,
100+
const CVTimeStamp *now,
101+
const CVTimeStamp *outputTime,
102+
CVOptionFlags flagsIn,
103+
CVOptionFlags *flagsOut,
104+
void *displayLinkContext)
105+
{
106+
OpenGLView *self = (__bridge OpenGLView *)displayLinkContext;
107+
[self waitVSync];
108+
return kCVReturnSuccess;
109+
}
110+
#endif
111+
78112
extern char **_NSGetProgname(void);
79113

80114
static void create_menu_bar(void)

0 commit comments

Comments
 (0)