aboutsummaryrefslogtreecommitdiffstats
path: root/pugl/detail/mac.m
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-10-03 19:38:55 +0200
committerDavid Robillard <d@drobilla.net>2020-10-04 12:52:37 +0200
commit0b876c3d4e87b65ea3b3f05ec3274b16600e47fc (patch)
tree09f4cb47953ac769c8b740900ea9b54ac8639a52 /pugl/detail/mac.m
parenta36408b7c641e0b9052315aed87ce8e591a6a717 (diff)
downloadpugl-0b876c3d4e87b65ea3b3f05ec3274b16600e47fc.tar.gz
pugl-0b876c3d4e87b65ea3b3f05ec3274b16600e47fc.tar.bz2
pugl-0b876c3d4e87b65ea3b3f05ec3274b16600e47fc.zip
Add refresh rate hint
Diffstat (limited to 'pugl/detail/mac.m')
-rw-r--r--pugl/detail/mac.m20
1 files changed, 20 insertions, 0 deletions
diff --git a/pugl/detail/mac.m b/pugl/detail/mac.m
index 0c50d20..64590c6 100644
--- a/pugl/detail/mac.m
+++ b/pugl/detail/mac.m
@@ -880,6 +880,26 @@ puglRealize(PuglView* view)
view->hints[PUGL_ALPHA_BITS] = 8;
}
+ CGDirectDisplayID displayId = CGMainDisplayID();
+ CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displayId);
+
+ // Try to get refresh rate from mode (usually fails)
+ view->hints[PUGL_REFRESH_RATE] = (int)CGDisplayModeGetRefreshRate(mode);
+
+ CGDisplayModeRelease(mode);
+ if (view->hints[PUGL_REFRESH_RATE] == 0) {
+ // Get refresh rate from a display link
+ // TODO: Keep and actually use the display link for something?
+ CVDisplayLinkRef link;
+ CVDisplayLinkCreateWithCGDisplay(displayId, &link);
+
+ const CVTime p = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(link);
+ const double r = p.timeScale / (double)p.timeValue;
+ view->hints[PUGL_REFRESH_RATE] = (int)lrint(r);
+
+ CVDisplayLinkRelease(link);
+ }
+
if (view->frame.width == 0.0 && view->frame.height == 0.0) {
if (view->defaultWidth == 0.0 && view->defaultHeight == 0.0) {
return PUGL_BAD_CONFIGURATION;