mirror of
https://github.com/glfw/glfw.git
synced 2026-09-22 16:52:57 +00:00
New gamma ramp API.
This commit is contained in:
+16
-50
@@ -72,26 +72,18 @@ void _glfwInitGammaRamp(void)
|
||||
|
||||
void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
|
||||
{
|
||||
// TODO: Support ramp sizes other than 256
|
||||
|
||||
if (_glfw.x11.randr.available && !_glfw.x11.randr.gammaBroken)
|
||||
{
|
||||
XRRCrtcGamma* gamma;
|
||||
size_t size = GLFW_GAMMA_RAMP_SIZE * sizeof(unsigned short);
|
||||
const size_t size = XRRGetCrtcGammaSize(_glfw.x11.display,
|
||||
monitor->x11.crtc);
|
||||
XRRCrtcGamma* gamma = XRRGetCrtcGamma(_glfw.x11.display,
|
||||
monitor->x11.crtc);
|
||||
|
||||
if (XRRGetCrtcGammaSize(_glfw.x11.display, monitor->x11.crtc) !=
|
||||
GLFW_GAMMA_RAMP_SIZE)
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"X11: Only gamma ramps of size 256 supported");
|
||||
return;
|
||||
}
|
||||
_glfwAllocGammaRamp(ramp, size);
|
||||
|
||||
gamma = XRRGetCrtcGamma(_glfw.x11.display, monitor->x11.crtc);
|
||||
|
||||
memcpy(ramp->red, gamma->red, size);
|
||||
memcpy(ramp->green, gamma->green, size);
|
||||
memcpy(ramp->blue, gamma->blue, 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));
|
||||
|
||||
XRRFreeGamma(gamma);
|
||||
}
|
||||
@@ -100,17 +92,11 @@ void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
|
||||
int size;
|
||||
XF86VidModeGetGammaRampSize(_glfw.x11.display, _glfw.x11.screen, &size);
|
||||
|
||||
if (size != GLFW_GAMMA_RAMP_SIZE)
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"X11: Only gamma ramps of size 256 supported");
|
||||
return;
|
||||
}
|
||||
_glfwAllocGammaRamp(ramp, size);
|
||||
|
||||
XF86VidModeGetGammaRamp(_glfw.x11.display,
|
||||
_glfw.x11.screen,
|
||||
GLFW_GAMMA_RAMP_SIZE,
|
||||
ramp->red, ramp->green, ramp->blue);
|
||||
ramp->size, ramp->red, ramp->green, ramp->blue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,40 +104,20 @@ void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
|
||||
{
|
||||
if (_glfw.x11.randr.available && !_glfw.x11.randr.gammaBroken)
|
||||
{
|
||||
size_t size = GLFW_GAMMA_RAMP_SIZE * sizeof(unsigned short);
|
||||
XRRCrtcGamma* gamma;
|
||||
XRRCrtcGamma* gamma = XRRAllocGamma(ramp->size);
|
||||
|
||||
if (XRRGetCrtcGammaSize(_glfw.x11.display, monitor->x11.crtc) !=
|
||||
GLFW_GAMMA_RAMP_SIZE)
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"X11: Only gamma ramps of size 256 supported");
|
||||
return;
|
||||
}
|
||||
|
||||
gamma = XRRAllocGamma(GLFW_GAMMA_RAMP_SIZE);
|
||||
|
||||
memcpy(gamma->red, ramp->red, size);
|
||||
memcpy(gamma->green, ramp->green, size);
|
||||
memcpy(gamma->blue, ramp->blue, size);
|
||||
memcpy(gamma->red, ramp->red, ramp->size * sizeof(unsigned short));
|
||||
memcpy(gamma->green, ramp->green, ramp->size * sizeof(unsigned short));
|
||||
memcpy(gamma->blue, ramp->blue, ramp->size * sizeof(unsigned short));
|
||||
|
||||
XRRSetCrtcGamma(_glfw.x11.display, monitor->x11.crtc, gamma);
|
||||
XRRFreeGamma(gamma);
|
||||
}
|
||||
else if (_glfw.x11.vidmode.available)
|
||||
{
|
||||
int size;
|
||||
XF86VidModeGetGammaRampSize(_glfw.x11.display, _glfw.x11.screen, &size);
|
||||
|
||||
if (size != GLFW_GAMMA_RAMP_SIZE)
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"X11: Only gamma ramps of size 256 supported");
|
||||
return;
|
||||
}
|
||||
|
||||
XF86VidModeSetGammaRamp(_glfw.x11.display,
|
||||
_glfw.x11.screen,
|
||||
GLFW_GAMMA_RAMP_SIZE,
|
||||
ramp->size,
|
||||
(unsigned short*) ramp->red,
|
||||
(unsigned short*) ramp->green,
|
||||
(unsigned short*) ramp->blue);
|
||||
|
||||
Reference in New Issue
Block a user