Fixed zero refresh rate on some monitors.

This commit is contained in:
Camilla Berglund 2013-10-09 19:45:39 +02:00
parent 99784fb8f0
commit aab08712dd
4 changed files with 31 additions and 7 deletions

View File

@ -356,13 +356,15 @@ if (_GLFW_COCOA AND _GLFW_NSGL)
find_library(COCOA_FRAMEWORK Cocoa)
find_library(IOKIT_FRAMEWORK IOKit)
find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation)
find_library(CORE_VIDEO_FRAMEWORK CoreVideo)
list(APPEND glfw_LIBRARIES ${COCOA_FRAMEWORK}
${OPENGL_gl_LIBRARY}
${IOKIT_FRAMEWORK}
${CORE_FOUNDATION_FRAMEWORK})
${CORE_FOUNDATION_FRAMEWORK}
${CORE_VIDEO_FRAMEWORK})
set(GLFW_PKG_DEPS "")
set(GLFW_PKG_LIBS "-framework Cocoa -framework OpenGL -framework IOKit -framework CoreFoundation")
set(GLFW_PKG_LIBS "-framework Cocoa -framework OpenGL -framework IOKit -framework CoreFoundation -framework CoreVideo")
endif()
#--------------------------------------------------------------------

View File

@ -223,6 +223,7 @@ See the [GLFW documentation](http://www.glfw.org/docs/latest/).
with Xcode 5
- [Cocoa] Bugfix: The cursor remained visible if moved onto client area after
having been set to hidden outside it
- [Cocoa] Bugfix: The refresh rate was zero for all modes of certain monitors
- [X11] Added setting of the `WM_CLASS` property to the initial window title
@ -309,6 +310,7 @@ skills.
- Matt Sealey
- SephiRok
- Steve Sexton
- Systemcluster
- Dmitri Shuralyov
- Daniel Skorupski
- Bradley Smith

View File

@ -189,7 +189,7 @@ If you are using the dynamic library version of GLFW, simply add it to the
project dependencies.
If you are using the static library version of GLFW, add it and the Cocoa,
OpenGL and IOKit frameworks to the project as dependencies.
OpenGL, IOKit and CoreVideo frameworks to the project as dependencies.
@subsection build_link_osx With command-line on OS X
@ -198,7 +198,7 @@ If you do not wish to use pkg-config, you need to add the required frameworks
and libraries to your command-line using the `-l` and `-framework` switches,
i.e.:
cc -o myprog myprog.c -lglfw -framework Cocoa -framework OpenGL -framework IOKit
cc -o myprog myprog.c -lglfw -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo
Note that you do not add the `.framework` extension to a framework when adding
it from the command-line.

View File

@ -31,6 +31,8 @@
#include <limits.h>
#include <IOKit/graphics/IOGraphicsLib.h>
#include <IOKit/graphics/IOGraphicsLib.h>
#include <CoreVideo/CVBase.h>
// Get the name of the specified display
@ -94,13 +96,21 @@ static GLboolean modeIsGood(CGDisplayModeRef mode)
// Convert Core Graphics display mode to GLFW video mode
//
static GLFWvidmode vidmodeFromCGDisplayMode(CGDisplayModeRef mode)
static GLFWvidmode vidmodeFromCGDisplayMode(CGDisplayModeRef mode,
CVDisplayLinkRef link)
{
GLFWvidmode result;
result.width = (int) CGDisplayModeGetWidth(mode);
result.height = (int) CGDisplayModeGetHeight(mode);
result.refreshRate = (int) CGDisplayModeGetRefreshRate(mode);
if (result.refreshRate == 0)
{
const CVTime time = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(link);
if (!(time.flags & kCVTimeIsIndefinite))
result.refreshRate = (int) (time.timeScale / (double) time.timeValue);
}
CFStringRef format = CGDisplayModeCopyPixelEncoding(mode);
if (CFStringCompare(format, CFSTR(IO16BitDirectPixels), 0) == 0)
@ -334,6 +344,9 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
CFArrayRef modes;
CFIndex count, i;
GLFWvidmode* result;
CVDisplayLinkRef link;
CVDisplayLinkCreateWithCGDisplay(monitor->ns.displayID, &link);
modes = CGDisplayCopyAllDisplayModes(monitor->ns.displayID, NULL);
count = CFArrayGetCount(modes);
@ -348,21 +361,28 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
mode = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i);
if (modeIsGood(mode))
{
result[*found] = vidmodeFromCGDisplayMode(mode);
result[*found] = vidmodeFromCGDisplayMode(mode, link);
(*found)++;
}
}
CFRelease(modes);
CVDisplayLinkRelease(link);
return result;
}
void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode *mode)
{
CGDisplayModeRef displayMode;
CVDisplayLinkRef link;
CVDisplayLinkCreateWithCGDisplay(monitor->ns.displayID, &link);
displayMode = CGDisplayCopyDisplayMode(monitor->ns.displayID);
*mode = vidmodeFromCGDisplayMode(displayMode);
*mode = vidmodeFromCGDisplayMode(displayMode, link);
CGDisplayModeRelease(displayMode);
CVDisplayLinkRelease(link);
}