1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-27 04:28:52 -05:00

Moved X11 gamma ramp init to gamma module.

This commit is contained in:
Camilla Berglund 2012-05-24 11:36:43 +02:00
parent 6059523b6d
commit 1a37788143
3 changed files with 64 additions and 57 deletions

View File

@ -31,6 +31,66 @@
#include <limits.h>
#include <string.h>
#include <stdio.h>
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Detect gamma ramp support and save original gamma ramp, if available
//========================================================================
void _glfwInitGammaRamp(void)
{
#ifdef _GLFW_HAS_XRANDR
// RandR gamma support is only available with version 1.2 and above
if (_glfwLibrary.X11.RandR.available &&
(_glfwLibrary.X11.RandR.majorVersion > 1 ||
(_glfwLibrary.X11.RandR.majorVersion == 1 &&
_glfwLibrary.X11.RandR.minorVersion >= 2)))
{
// FIXME: Assumes that all monitors have the same size gamma tables
// This is reasonable as I suspect the that if they did differ, it
// would imply that setting the gamma size to an arbitary size is
// possible as well.
XRRScreenResources* rr = XRRGetScreenResources(_glfwLibrary.X11.display,
_glfwLibrary.X11.root);
_glfwLibrary.originalRampSize = XRRGetCrtcGammaSize(_glfwLibrary.X11.display,
rr->crtcs[0]);
if (!_glfwLibrary.originalRampSize)
{
// This is probably Nvidia RandR with broken gamma support
// Flag it as useless and try Xf86VidMode below, if available
_glfwLibrary.X11.RandR.gammaBroken = GL_TRUE;
fprintf(stderr,
"Ignoring broken nVidia implementation of RandR 1.2+ gamma\n");
}
XRRFreeScreenResources(rr);
}
#endif /*_GLFW_HAS_XRANDR*/
#if defined(_GLFW_HAS_XF86VIDMODE)
if (_glfwLibrary.X11.VidMode.available &&
!_glfwLibrary.originalRampSize)
{
// Get the gamma size using XF86VidMode
XF86VidModeGetGammaRampSize(_glfwLibrary.X11.display,
_glfwLibrary.X11.screen,
&_glfwLibrary.originalRampSize);
}
#endif /*_GLFW_HAS_XF86VIDMODE*/
if (!_glfwLibrary.originalRampSize)
fprintf(stderr, "No supported gamma ramp API found\n");
// Save the original gamma ramp
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
_glfwLibrary.currentRamp = _glfwLibrary.originalRamp;
}
//////////////////////////////////////////////////////////////////////////

View File

@ -30,7 +30,6 @@
#include "internal.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
@ -621,61 +620,6 @@ static GLboolean initDisplay(void)
}
//========================================================================
// Detect gamma ramp support and save original gamma ramp, if available
//========================================================================
static void initGammaRamp(void)
{
#ifdef _GLFW_HAS_XRANDR
// RandR gamma support is only available with version 1.2 and above
if (_glfwLibrary.X11.RandR.available &&
(_glfwLibrary.X11.RandR.majorVersion > 1 ||
(_glfwLibrary.X11.RandR.majorVersion == 1 &&
_glfwLibrary.X11.RandR.minorVersion >= 2)))
{
// FIXME: Assumes that all monitors have the same size gamma tables
// This is reasonable as I suspect the that if they did differ, it
// would imply that setting the gamma size to an arbitary size is
// possible as well.
XRRScreenResources* rr = XRRGetScreenResources(_glfwLibrary.X11.display,
_glfwLibrary.X11.root);
_glfwLibrary.originalRampSize = XRRGetCrtcGammaSize(_glfwLibrary.X11.display,
rr->crtcs[0]);
if (!_glfwLibrary.originalRampSize)
{
// This is probably Nvidia RandR with broken gamma support
// Flag it as useless and try Xf86VidMode below, if available
_glfwLibrary.X11.RandR.gammaBroken = GL_TRUE;
fprintf(stderr,
"Ignoring broken nVidia implementation of RandR 1.2+ gamma\n");
}
XRRFreeScreenResources(rr);
}
#endif /*_GLFW_HAS_XRANDR*/
#if defined(_GLFW_HAS_XF86VIDMODE)
if (_glfwLibrary.X11.VidMode.available &&
!_glfwLibrary.originalRampSize)
{
// Get the gamma size using XF86VidMode
XF86VidModeGetGammaRampSize(_glfwLibrary.X11.display,
_glfwLibrary.X11.screen,
&_glfwLibrary.originalRampSize);
}
#endif /*_GLFW_HAS_XF86VIDMODE*/
if (!_glfwLibrary.originalRampSize)
fprintf(stderr, "No supported gamma ramp API found\n");
// Save the original gamma ramp
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
_glfwLibrary.currentRamp = _glfwLibrary.originalRamp;
}
//========================================================================
// Create a blank cursor (for locked mouse mode)
//========================================================================
@ -739,7 +683,7 @@ int _glfwPlatformInit(void)
if (!initDisplay())
return GL_FALSE;
initGammaRamp();
_glfwInitGammaRamp();
initEWMH();

View File

@ -283,6 +283,9 @@ GLFWGLOBAL struct {
// Time
void _glfwInitTimer(void);
// Gamma
void _glfwInitGammaRamp(void);
// Fullscreen support
int _glfwGetClosestVideoMode(int* width, int* height, int* rate);
void _glfwSetVideoModeMODE(int mode, int rate);