Merge commit '26c8cc348eacea01237cd64e1a68d0df8141e848'

This commit is contained in:
2024-05-31 19:26:05 -05:00
165 changed files with 33591 additions and 14989 deletions

View File

@ -1,5 +1,5 @@
//========================================================================
// GLFW 3.3 macOS - www.glfw.org
// GLFW 3.4 macOS - www.glfw.org
//------------------------------------------------------------------------
// Copyright (c) 2002-2006 Marcus Geelnard
// Copyright (c) 2006-2019 Camilla Löwy <elmindreda@glfw.org>
@ -24,11 +24,11 @@
// distribution.
//
//========================================================================
// It is fine to use C99 in this file because it will not be built with VS
//========================================================================
#include "internal.h"
#if defined(_GLFW_COCOA)
#include <stdlib.h>
#include <limits.h>
#include <math.h>
@ -98,11 +98,7 @@ static char* getMonitorName(CGDirectDisplayID displayID, NSScreen* screen)
IOObjectRelease(it);
if (!service)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Cocoa: Failed to find service port for display");
return _glfw_strdup("Display");
}
CFDictionaryRef names =
CFDictionaryGetValue(info, CFSTR(kDisplayProductName));
@ -120,7 +116,7 @@ static char* getMonitorName(CGDirectDisplayID displayID, NSScreen* screen)
const CFIndex size =
CFStringGetMaximumSizeForEncoding(CFStringGetLength(nameRef),
kCFStringEncodingUTF8);
char* name = calloc(size + 1, 1);
char* name = _glfw_calloc(size + 1, 1);
CFStringGetCString(nameRef, name, size, kCFStringEncodingUTF8);
CFRelease(info);
@ -297,11 +293,11 @@ static double getFallbackRefreshRate(CGDirectDisplayID displayID)
// Poll for changes in the set of connected monitors
//
void _glfwPollMonitorsNS(void)
void _glfwPollMonitorsCocoa(void)
{
uint32_t displayCount;
CGGetOnlineDisplayList(0, NULL, &displayCount);
CGDirectDisplayID* displays = calloc(displayCount, sizeof(CGDirectDisplayID));
CGDirectDisplayID* displays = _glfw_calloc(displayCount, sizeof(CGDirectDisplayID));
CGGetOnlineDisplayList(displayCount, displays, &displayCount);
for (int i = 0; i < _glfw.monitorCount; i++)
@ -311,7 +307,7 @@ void _glfwPollMonitorsNS(void)
uint32_t disconnectedCount = _glfw.monitorCount;
if (disconnectedCount)
{
disconnected = calloc(_glfw.monitorCount, sizeof(_GLFWmonitor*));
disconnected = _glfw_calloc(_glfw.monitorCount, sizeof(_GLFWmonitor*));
memcpy(disconnected,
_glfw.monitors,
_glfw.monitorCount * sizeof(_GLFWmonitor*));
@ -363,7 +359,7 @@ void _glfwPollMonitorsNS(void)
monitor->ns.unitNumber = unitNumber;
monitor->ns.screen = screen;
free(name);
_glfw_free(name);
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displays[i]);
if (CGDisplayModeGetRefreshRate(mode) == 0.0)
@ -379,16 +375,16 @@ void _glfwPollMonitorsNS(void)
_glfwInputMonitor(disconnected[i], GLFW_DISCONNECTED, 0);
}
free(disconnected);
free(displays);
_glfw_free(disconnected);
_glfw_free(displays);
}
// Change the current video mode
//
void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired)
void _glfwSetVideoModeCocoa(_GLFWmonitor* monitor, const GLFWvidmode* desired)
{
GLFWvidmode current;
_glfwPlatformGetVideoMode(monitor, &current);
_glfwGetVideoModeCocoa(monitor, &current);
const GLFWvidmode* best = _glfwChooseVideoMode(monitor, desired);
if (_glfwCompareVideoModes(&current, best) == 0)
@ -428,7 +424,7 @@ void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired)
// Restore the previously saved (original) video mode
//
void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor)
void _glfwRestoreVideoModeCocoa(_GLFWmonitor* monitor)
{
if (monitor->ns.previousMode)
{
@ -447,11 +443,11 @@ void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor)
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor)
void _glfwFreeMonitorCocoa(_GLFWmonitor* monitor)
{
}
void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos)
void _glfwGetMonitorPosCocoa(_GLFWmonitor* monitor, int* xpos, int* ypos)
{
@autoreleasepool {
@ -465,8 +461,8 @@ void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos)
} // autoreleasepool
}
void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor,
float* xscale, float* yscale)
void _glfwGetMonitorContentScaleCocoa(_GLFWmonitor* monitor,
float* xscale, float* yscale)
{
@autoreleasepool {
@ -487,9 +483,9 @@ void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor,
} // autoreleasepool
}
void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor,
int* xpos, int* ypos,
int* width, int* height)
void _glfwGetMonitorWorkareaCocoa(_GLFWmonitor* monitor,
int* xpos, int* ypos,
int* width, int* height)
{
@autoreleasepool {
@ -504,7 +500,7 @@ void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor,
if (xpos)
*xpos = frameRect.origin.x;
if (ypos)
*ypos = _glfwTransformYNS(frameRect.origin.y + frameRect.size.height - 1);
*ypos = _glfwTransformYCocoa(frameRect.origin.y + frameRect.size.height - 1);
if (width)
*width = frameRect.size.width;
if (height)
@ -513,7 +509,7 @@ void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor,
} // autoreleasepool
}
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
GLFWvidmode* _glfwGetVideoModesCocoa(_GLFWmonitor* monitor, int* count)
{
@autoreleasepool {
@ -521,7 +517,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
CFArrayRef modes = CGDisplayCopyAllDisplayModes(monitor->ns.displayID, NULL);
const CFIndex found = CFArrayGetCount(modes);
GLFWvidmode* result = calloc(found, sizeof(GLFWvidmode));
GLFWvidmode* result = _glfw_calloc(found, sizeof(GLFWvidmode));
for (CFIndex i = 0; i < found; i++)
{
@ -553,23 +549,30 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
} // autoreleasepool
}
void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode *mode)
GLFWbool _glfwGetVideoModeCocoa(_GLFWmonitor* monitor, GLFWvidmode *mode)
{
@autoreleasepool {
CGDisplayModeRef native = CGDisplayCopyDisplayMode(monitor->ns.displayID);
if (!native)
{
_glfwInputError(GLFW_PLATFORM_ERROR, "Cocoa: Failed to query display mode");
return GLFW_FALSE;
}
*mode = vidmodeFromCGDisplayMode(native, monitor->ns.fallbackRefreshRate);
CGDisplayModeRelease(native);
return GLFW_TRUE;
} // autoreleasepool
}
GLFWbool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
GLFWbool _glfwGetGammaRampCocoa(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
{
@autoreleasepool {
uint32_t size = CGDisplayGammaTableCapacity(monitor->ns.displayID);
CGGammaValue* values = calloc(size * 3, sizeof(CGGammaValue));
CGGammaValue* values = _glfw_calloc(size * 3, sizeof(CGGammaValue));
CGGetDisplayTransferByTable(monitor->ns.displayID,
size,
@ -587,17 +590,17 @@ GLFWbool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
ramp->blue[i] = (unsigned short) (values[i + size * 2] * 65535);
}
free(values);
_glfw_free(values);
return GLFW_TRUE;
} // autoreleasepool
}
void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
void _glfwSetGammaRampCocoa(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
{
@autoreleasepool {
CGGammaValue* values = calloc(ramp->size * 3, sizeof(CGGammaValue));
CGGammaValue* values = _glfw_calloc(ramp->size * 3, sizeof(CGGammaValue));
for (unsigned int i = 0; i < ramp->size; i++)
{
@ -612,7 +615,7 @@ void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
values + ramp->size,
values + ramp->size * 2);
free(values);
_glfw_free(values);
} // autoreleasepool
}
@ -626,6 +629,15 @@ GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* handle)
{
_GLFWmonitor* monitor = (_GLFWmonitor*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(kCGNullDirectDisplay);
if (_glfw.platform.platformID != GLFW_PLATFORM_COCOA)
{
_glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "Cocoa: Platform not initialized");
return kCGNullDirectDisplay;
}
return monitor->ns.displayID;
}
#endif // _GLFW_COCOA