diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index 986d799e7..d90baabd7 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -467,9 +467,14 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode *mode) CVDisplayLinkRelease(link); } +int _glfwPlatformGetGammaRampSize(_GLFWmonitor* monitor) +{ + return CGDisplayGammaTableCapacity(monitor->ns.displayID); +} + void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) { - uint32_t i, size = CGDisplayGammaTableCapacity(monitor->ns.displayID); + uint32_t i, size = _glfwPlatformGetGammaRampSize(monitor); CGGammaValue* values = calloc(size * 3, sizeof(CGGammaValue)); CGGetDisplayTransferByTable(monitor->ns.displayID, diff --git a/src/internal.h b/src/internal.h index 7be2b267c..fa2fe8fd0 100644 --- a/src/internal.h +++ b/src/internal.h @@ -611,6 +611,7 @@ void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor, float* xscale, float* yscale); GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count); void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode); +int _glfwPlatformGetGammaRampSize(_GLFWmonitor* monitor); void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp); void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp); diff --git a/src/null_monitor.c b/src/null_monitor.c index 84b41c7e3..2698bd083 100644 --- a/src/null_monitor.c +++ b/src/null_monitor.c @@ -58,6 +58,11 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) { } +int _glfwPlatformGetGammaRampSize(_GLFWmonitor* monitor) +{ + return 0; +} + void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) { } diff --git a/src/win32_monitor.c b/src/win32_monitor.c index b7a24e615..fe5c36799 100644 --- a/src/win32_monitor.c +++ b/src/win32_monitor.c @@ -455,6 +455,11 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) &mode->blueBits); } +int _glfwPlatformGetGammaRampSize(_GLFWmonitor* monitor) +{ + return 256; +} + void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) { HDC dc; diff --git a/src/wl_monitor.c b/src/wl_monitor.c index f033fb6ec..9aca88a5c 100644 --- a/src/wl_monitor.c +++ b/src/wl_monitor.c @@ -180,6 +180,11 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) *mode = monitor->modes[monitor->wl.currentMode]; } +int _glfwPlatformGetGammaRampSize(_GLFWmonitor* monitor) +{ + return 0; +} + void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) { _glfwInputError(GLFW_PLATFORM_ERROR, diff --git a/src/x11_monitor.c b/src/x11_monitor.c index f557fe472..c8d4d4f74 100644 --- a/src/x11_monitor.c +++ b/src/x11_monitor.c @@ -422,17 +422,28 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) } } +int _glfwPlatformGetGammaRampSize(_GLFWmonitor* monitor) +{ + int size = 0; + + if (_glfw.x11.randr.available && !_glfw.x11.randr.gammaBroken) + size = XRRGetCrtcGammaSize(_glfw.x11.display, monitor->x11.crtc); + else if (_glfw.x11.vidmode.available) + XF86VidModeGetGammaRampSize(_glfw.x11.display, _glfw.x11.screen, &size); + + return size; +} + void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) { + int size = _glfwPlatformGetGammaRampSize(monitor); + + _glfwAllocGammaArrays(ramp, size); + if (_glfw.x11.randr.available && !_glfw.x11.randr.gammaBroken) { - const size_t size = XRRGetCrtcGammaSize(_glfw.x11.display, - monitor->x11.crtc); XRRCrtcGamma* gamma = XRRGetCrtcGamma(_glfw.x11.display, monitor->x11.crtc); - - _glfwAllocGammaArrays(ramp, size); - memcpy(ramp->red, gamma->red, size * sizeof(unsigned short)); memcpy(ramp->green, gamma->green, size * sizeof(unsigned short)); memcpy(ramp->blue, gamma->blue, size * sizeof(unsigned short)); @@ -441,11 +452,6 @@ void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) } else if (_glfw.x11.vidmode.available) { - int size; - XF86VidModeGetGammaRampSize(_glfw.x11.display, _glfw.x11.screen, &size); - - _glfwAllocGammaArrays(ramp, size); - XF86VidModeGetGammaRamp(_glfw.x11.display, _glfw.x11.screen, ramp->size, ramp->red, ramp->green, ramp->blue);