Skip to content

Commit

Permalink
v3.3/glfw: update to GLFW 3.3.2
Browse files Browse the repository at this point in the history
GLFW 3.3.2 was released on January 20, 2020.
See https://github.com/glfw/glfw/releases/tag/3.3.2.

Done using steps from https://github.com/go-gl/glfw/wiki/Development#updating-glfw-c-source:

	rm -rf ./glfw/
	git clone --depth 1 --branch latest https://github.com/glfw/glfw  # 'latest' branch points to latest stable release.
	cd ./glfw/
	git rev-parse HEAD > ../GLFW_C_REVISION.txt

	# Only keep the needed sources files in ./src, ./include and ./deps.
	rm -rf ./.git
	rm -rf ./.gitignore
	rm -rf ./.gitattributes
	rm -rf ./.mailmap
	rm -rf ./.appveyor.yml
	rm -rf ./.github
	rm -rf ./.travis.yml
	rm -rf ./CMake
	rm -rf ./CMakeLists.txt
	rm -rf ./src/CMakeLists.txt
	rm -rf ./src/*.in
	rm -rf ./README.md
	rm -rf ./cmake_uninstall.cmake.in
	rm -rf ./docs
	rm -rf ./examples
	rm -rf ./tests

Fixes #262.
  • Loading branch information
dmitshur committed Feb 16, 2020
1 parent 2298e66 commit 76ac453
Show file tree
Hide file tree
Showing 20 changed files with 532 additions and 352 deletions.
2 changes: 1 addition & 1 deletion v3.3/glfw/GLFW_C_REVISION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2bac7ee8da526257d808bd026b027246c98e4f2f
0a49ef0a00baa3ab520ddc452f0e3b1e099c5589
7 changes: 4 additions & 3 deletions v3.3/glfw/glfw/include/GLFW/glfw3.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ extern "C" {
* API changes.
* @ingroup init
*/
#define GLFW_VERSION_REVISION 1
#define GLFW_VERSION_REVISION 2
/*! @} */

/*! @brief One.
Expand Down Expand Up @@ -5677,8 +5677,9 @@ GLFWAPI int glfwVulkanSupported(void);
* returned array, as it is an error to specify an extension more than once in
* the `VkInstanceCreateInfo` struct.
*
* @remark @macos This function currently only supports the
* `VK_MVK_macos_surface` extension from MoltenVK.
* @remark @macos This function currently supports either the
* `VK_MVK_macos_surface` extension from MoltenVK or `VK_EXT_metal_surface`
* extension.
*
* @pointer_lifetime The returned array is allocated and freed by GLFW. You
* should not free it yourself. It is guaranteed to be valid only until the
Expand Down
35 changes: 30 additions & 5 deletions v3.3/glfw/glfw/src/cocoa_init.m
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,8 @@ - (void)applicationWillFinishLaunching:(NSNotification *)notification
// In case we are unbundled, make us a proper UI application
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];

// Menu bar setup must go between sharedApplication above and
// finishLaunching below, in order to properly emulate the behavior
// of NSApplicationMain
// Menu bar setup must go between sharedApplication and finishLaunching
// in order to properly emulate the behavior of NSApplicationMain

if ([[NSBundle mainBundle] pathForResource:@"MainMenu" ofType:@"nib"])
{
Expand All @@ -448,9 +447,9 @@ - (void)applicationWillFinishLaunching:(NSNotification *)notification

- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
[NSApp stop:nil];

_glfw.ns.finishedLaunching = GLFW_TRUE;
_glfwPlatformPostEmptyEvent();
[NSApp stop:nil];
}

- (void)applicationDidHide:(NSNotification *)notification
Expand All @@ -464,6 +463,32 @@ - (void)applicationDidHide:(NSNotification *)notification
@end // GLFWApplicationDelegate


//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////

void* _glfwLoadLocalVulkanLoaderNS(void)
{
CFBundleRef bundle = CFBundleGetMainBundle();
if (!bundle)
return NULL;

CFURLRef url =
CFBundleCopyAuxiliaryExecutableURL(bundle, CFSTR("libvulkan.1.dylib"));
if (!url)
return NULL;

char path[PATH_MAX];
void* handle = NULL;

if (CFURLGetFileSystemRepresentation(url, true, (UInt8*) path, sizeof(path) - 1))
handle = _glfw_dlopen(path);

CFRelease(url);
return handle;
}


//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion v3.3/glfw/glfw/src/cocoa_joystick.m
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void _glfwInitJoysticksNS(void)
return;
}

for (int i = 0; i < sizeof(usages) / sizeof(long); i++)
for (size_t i = 0; i < sizeof(usages) / sizeof(long); i++)
{
const long page = kHIDPage_GenericDesktop;

Expand Down
96 changes: 74 additions & 22 deletions v3.3/glfw/glfw/src/cocoa_monitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,15 @@ static GLFWbool modeIsGood(CGDisplayModeRef mode)
// Convert Core Graphics display mode to GLFW video mode
//
static GLFWvidmode vidmodeFromCGDisplayMode(CGDisplayModeRef mode,
CVDisplayLinkRef link)
double fallbackRefreshRate)
{
GLFWvidmode result;
result.width = (int) CGDisplayModeGetWidth(mode);
result.height = (int) CGDisplayModeGetHeight(mode);
result.refreshRate = (int) round(CGDisplayModeGetRefreshRate(mode));

if (result.refreshRate == 0)
{
const CVTime time = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(link);
if (!(time.flags & kCVTimeIsIndefinite))
result.refreshRate = (int) (time.timeScale / (double) time.timeValue);
}
result.refreshRate = (int) round(fallbackRefreshRate);

#if MAC_OS_X_VERSION_MAX_ALLOWED <= 101100
CFStringRef format = CGDisplayModeCopyPixelEncoding(mode);
Expand Down Expand Up @@ -238,6 +234,68 @@ static GLFWbool refreshMonitorScreen(_GLFWmonitor* monitor)
return GLFW_FALSE;
}

// Returns the display refresh rate queried from the I/O registry
//
static double getFallbackRefreshRate(CGDirectDisplayID displayID)
{
double refreshRate = 60.0;

io_iterator_t it;
io_service_t service;

if (IOServiceGetMatchingServices(kIOMasterPortDefault,
IOServiceMatching("IOFramebuffer"),
&it) != 0)
{
return refreshRate;
}

while ((service = IOIteratorNext(it)) != 0)
{
const CFNumberRef indexRef =
IORegistryEntryCreateCFProperty(service,
CFSTR("IOFramebufferOpenGLIndex"),
kCFAllocatorDefault,
kNilOptions);
if (!indexRef)
continue;

uint32_t index = 0;
CFNumberGetValue(indexRef, kCFNumberIntType, &index);
CFRelease(indexRef);

if (CGOpenGLDisplayMaskToDisplayID(1 << index) != displayID)
continue;

const CFNumberRef clockRef =
IORegistryEntryCreateCFProperty(service,
CFSTR("IOFBCurrentPixelClock"),
kCFAllocatorDefault,
kNilOptions);
const CFNumberRef countRef =
IORegistryEntryCreateCFProperty(service,
CFSTR("IOFBCurrentPixelCount"),
kCFAllocatorDefault,
kNilOptions);
if (!clockRef || !countRef)
break;

uint32_t clock = 0, count = 0;
CFNumberGetValue(clockRef, kCFNumberIntType, &clock);
CFNumberGetValue(countRef, kCFNumberIntType, &count);
CFRelease(clockRef);
CFRelease(countRef);

if (clock > 0 && count > 0)
refreshRate = clock / (double) count;

break;
}

IOObjectRelease(it);
return refreshRate;
}


//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
Expand Down Expand Up @@ -294,6 +352,11 @@ void _glfwPollMonitorsNS(void)

free(name);

CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displays[i]);
if (CGDisplayModeGetRefreshRate(mode) == 0.0)
monitor->ns.fallbackRefreshRate = getFallbackRefreshRate(displays[i]);
CGDisplayModeRelease(mode);

_glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_LAST);
}

Expand All @@ -318,9 +381,6 @@ void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired)
if (_glfwCompareVideoModes(&current, best) == 0)
return;

CVDisplayLinkRef link;
CVDisplayLinkCreateWithCGDisplay(monitor->ns.displayID, &link);

CFArrayRef modes = CGDisplayCopyAllDisplayModes(monitor->ns.displayID, NULL);
const CFIndex count = CFArrayGetCount(modes);
CGDisplayModeRef native = NULL;
Expand All @@ -331,7 +391,8 @@ void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired)
if (!modeIsGood(dm))
continue;

const GLFWvidmode mode = vidmodeFromCGDisplayMode(dm, link);
const GLFWvidmode mode =
vidmodeFromCGDisplayMode(dm, monitor->ns.fallbackRefreshRate);
if (_glfwCompareVideoModes(best, &mode) == 0)
{
native = dm;
Expand All @@ -350,7 +411,6 @@ void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired)
}

CFRelease(modes);
CVDisplayLinkRelease(link);
}

// Restore the previously saved (original) video mode
Expand Down Expand Up @@ -440,9 +500,6 @@ void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor,

*count = 0;

CVDisplayLinkRef link;
CVDisplayLinkCreateWithCGDisplay(monitor->ns.displayID, &link);

CFArrayRef modes = CGDisplayCopyAllDisplayModes(monitor->ns.displayID, NULL);
const CFIndex found = CFArrayGetCount(modes);
GLFWvidmode* result = calloc(found, sizeof(GLFWvidmode));
Expand All @@ -453,7 +510,8 @@ void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor,
if (!modeIsGood(dm))
continue;

const GLFWvidmode mode = vidmodeFromCGDisplayMode(dm, link);
const GLFWvidmode mode =
vidmodeFromCGDisplayMode(dm, monitor->ns.fallbackRefreshRate);
CFIndex j;

for (j = 0; j < *count; j++)
Expand All @@ -471,7 +529,6 @@ void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor,
}

CFRelease(modes);
CVDisplayLinkRelease(link);
return result;

} // autoreleasepool
Expand All @@ -481,15 +538,10 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode *mode)
{
@autoreleasepool {

CVDisplayLinkRef link;
CVDisplayLinkCreateWithCGDisplay(monitor->ns.displayID, &link);

CGDisplayModeRef native = CGDisplayCopyDisplayMode(monitor->ns.displayID);
*mode = vidmodeFromCGDisplayMode(native, link);
*mode = vidmodeFromCGDisplayMode(native, monitor->ns.fallbackRefreshRate);
CGDisplayModeRelease(native);

CVDisplayLinkRelease(link);

} // autoreleasepool
}

Expand Down
15 changes: 13 additions & 2 deletions v3.3/glfw/glfw/src/cocoa_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#include <dlfcn.h>

#include <Carbon/Carbon.h>
#include <CoreVideo/CVBase.h>
#include <CoreVideo/CVDisplayLink.h>

// NOTE: All of NSGL was deprecated in the 10.14 SDK
// This disables the pointless warnings for every symbol we use
Expand Down Expand Up @@ -63,6 +61,7 @@ typedef void* id;
#endif

typedef VkFlags VkMacOSSurfaceCreateFlagsMVK;
typedef VkFlags VkMetalSurfaceCreateFlagsEXT;

typedef struct VkMacOSSurfaceCreateInfoMVK
{
Expand All @@ -72,7 +71,16 @@ typedef struct VkMacOSSurfaceCreateInfoMVK
const void* pView;
} VkMacOSSurfaceCreateInfoMVK;

typedef struct VkMetalSurfaceCreateInfoEXT
{
VkStructureType sType;
const void* pNext;
VkMetalSurfaceCreateFlagsEXT flags;
const void* pLayer;
} VkMetalSurfaceCreateInfoEXT;

typedef VkResult (APIENTRY *PFN_vkCreateMacOSSurfaceMVK)(VkInstance,const VkMacOSSurfaceCreateInfoMVK*,const VkAllocationCallbacks*,VkSurfaceKHR*);
typedef VkResult (APIENTRY *PFN_vkCreateMetalSurfaceEXT)(VkInstance,const VkMetalSurfaceCreateInfoEXT*,const VkAllocationCallbacks*,VkSurfaceKHR*);

#include "posix_thread.h"
#include "cocoa_joystick.h"
Expand Down Expand Up @@ -170,6 +178,7 @@ typedef struct _GLFWmonitorNS
CGDisplayModeRef previousMode;
uint32_t unitNumber;
id screen;
double fallbackRefreshRate;

} _GLFWmonitorNS;

Expand Down Expand Up @@ -198,3 +207,5 @@ void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor);

float _glfwTransformYNS(float y);

void* _glfwLoadLocalVulkanLoaderNS(void);

Loading

0 comments on commit 76ac453

Please sign in to comment.