Monitor: factor out _glfwPlatformGetGammaRampSize

Factor out a helper function to retrieve current gamma ramp size out of
_glfwPlatformGetGammaRamp implementations on Cocoa and X11, and add a
trivial implementation for Windows.  No functional change.
This commit is contained in:
Alexander Monakov 2018-11-24 18:31:03 +03:00
parent 95341ef9fd
commit 776d431ded
6 changed files with 38 additions and 11 deletions

View File

@ -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,

View File

@ -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);

View File

@ -58,6 +58,11 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
{
}
int _glfwPlatformGetGammaRampSize(_GLFWmonitor* monitor)
{
return 0;
}
void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
{
}

View File

@ -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;

View File

@ -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,

View File

@ -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);