This commit is contained in:
OlivierNemoz 2017-03-23 18:58:12 +00:00 committed by GitHub
commit ce4b6cd538
3 changed files with 74 additions and 103 deletions

View File

@ -525,31 +525,6 @@ static GLFWbool initExtensions(void)
if (_glfw.x11.randr.available) if (_glfw.x11.randr.available)
{ {
XRRScreenResources* sr = XRRGetScreenResourcesCurrent(_glfw.x11.display,
_glfw.x11.root);
if (!sr->ncrtc || !XRRGetCrtcGammaSize(_glfw.x11.display, sr->crtcs[0]))
{
// This is either a headless system or an older Nvidia binary driver
// with broken gamma support
// Flag it as useless and fall back to Xf86VidMode gamma, if
// available
_glfwInputError(GLFW_PLATFORM_ERROR,
"X11: Detected broken RandR gamma ramp support");
_glfw.x11.randr.gammaBroken = GLFW_TRUE;
}
if (!sr->ncrtc || !sr->noutput || !sr->nmode)
{
// This is either a headless system or broken Cygwin/X RandR
// Flag it as useless and fall back to Xlib display functions
_glfwInputError(GLFW_PLATFORM_ERROR,
"X11: Detected broken RandR monitor support");
_glfw.x11.randr.monitorBroken = GLFW_TRUE;
}
XRRFreeScreenResources(sr);
XRRSelectInput(_glfw.x11.display, _glfw.x11.root, XRRSelectInput(_glfw.x11.display, _glfw.x11.root,
RROutputChangeNotifyMask); RROutputChangeNotifyMask);
} }

View File

@ -99,7 +99,7 @@ static GLFWvidmode vidmodeFromModeInfo(const XRRModeInfo* mi,
// //
void _glfwPollMonitorsX11(void) void _glfwPollMonitorsX11(void)
{ {
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken) if (_glfw.x11.randr.available)
{ {
int i, j, disconnectedCount, screenCount = 0; int i, j, disconnectedCount, screenCount = 0;
_GLFWmonitor** disconnected = NULL; _GLFWmonitor** disconnected = NULL;
@ -202,23 +202,6 @@ void _glfwPollMonitorsX11(void)
} }
free(disconnected); free(disconnected);
if (!_glfw.monitorCount)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"X11: RandR monitor support seems broken");
_glfw.x11.randr.monitorBroken = GLFW_TRUE;
}
}
if (!_glfw.monitorCount)
{
const int widthMM = DisplayWidthMM(_glfw.x11.display, _glfw.x11.screen);
const int heightMM = DisplayHeightMM(_glfw.x11.display, _glfw.x11.screen);
_glfwInputMonitor(_glfwAllocMonitor("Display", widthMM, heightMM),
GLFW_CONNECTED,
_GLFW_INSERT_FIRST);
} }
} }
@ -226,7 +209,7 @@ void _glfwPollMonitorsX11(void)
// //
GLFWbool _glfwSetVideoModeX11(_GLFWmonitor* monitor, const GLFWvidmode* desired) GLFWbool _glfwSetVideoModeX11(_GLFWmonitor* monitor, const GLFWvidmode* desired)
{ {
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken) if (_glfw.x11.randr.available && monitor->x11.crtc && monitor->x11.output)
{ {
XRRScreenResources* sr; XRRScreenResources* sr;
XRRCrtcInfo* ci; XRRCrtcInfo* ci;
@ -293,7 +276,7 @@ GLFWbool _glfwSetVideoModeX11(_GLFWmonitor* monitor, const GLFWvidmode* desired)
// //
void _glfwRestoreVideoModeX11(_GLFWmonitor* monitor) void _glfwRestoreVideoModeX11(_GLFWmonitor* monitor)
{ {
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken) if (_glfw.x11.randr.available && monitor->x11.crtc)
{ {
XRRScreenResources* sr; XRRScreenResources* sr;
XRRCrtcInfo* ci; XRRCrtcInfo* ci;
@ -327,7 +310,7 @@ void _glfwRestoreVideoModeX11(_GLFWmonitor* monitor)
void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos)
{ {
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken) if (_glfw.x11.randr.available && monitor->x11.crtc)
{ {
XRRScreenResources* sr; XRRScreenResources* sr;
XRRCrtcInfo* ci; XRRCrtcInfo* ci;
@ -351,7 +334,9 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
*count = 0; *count = 0;
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken) if (_glfw.x11.randr.available)
{
if (monitor->x11.crtc && monitor->x11.output)
{ {
int i, j; int i, j;
XRRScreenResources* sr; XRRScreenResources* sr;
@ -390,6 +375,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
XRRFreeCrtcInfo(ci); XRRFreeCrtcInfo(ci);
XRRFreeScreenResources(sr); XRRFreeScreenResources(sr);
} }
}
else else
{ {
*count = 1; *count = 1;
@ -402,7 +388,9 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
{ {
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken) if (_glfw.x11.randr.available)
{
if (monitor->x11.crtc)
{ {
XRRScreenResources* sr; XRRScreenResources* sr;
XRRCrtcInfo* ci; XRRCrtcInfo* ci;
@ -415,6 +403,7 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
XRRFreeCrtcInfo(ci); XRRFreeCrtcInfo(ci);
XRRFreeScreenResources(sr); XRRFreeScreenResources(sr);
} }
}
else else
{ {
mode->width = DisplayWidth(_glfw.x11.display, _glfw.x11.screen); mode->width = DisplayWidth(_glfw.x11.display, _glfw.x11.screen);
@ -428,10 +417,14 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
{ {
if (_glfw.x11.randr.available && !_glfw.x11.randr.gammaBroken) if (_glfw.x11.randr.available)
{
if (monitor->x11.crtc)
{ {
const size_t size = XRRGetCrtcGammaSize(_glfw.x11.display, const size_t size = XRRGetCrtcGammaSize(_glfw.x11.display,
monitor->x11.crtc); monitor->x11.crtc);
if (size)
{
XRRCrtcGamma* gamma = XRRGetCrtcGamma(_glfw.x11.display, XRRCrtcGamma* gamma = XRRGetCrtcGamma(_glfw.x11.display,
monitor->x11.crtc); monitor->x11.crtc);
@ -443,6 +436,8 @@ void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
XRRFreeGamma(gamma); XRRFreeGamma(gamma);
} }
}
}
else if (_glfw.x11.vidmode.available) else if (_glfw.x11.vidmode.available)
{ {
int size; int size;
@ -458,7 +453,9 @@ void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
{ {
if (_glfw.x11.randr.available && !_glfw.x11.randr.gammaBroken) if (_glfw.x11.randr.available)
{
if (monitor->x11.crtc)
{ {
XRRCrtcGamma* gamma = XRRAllocGamma(ramp->size); XRRCrtcGamma* gamma = XRRAllocGamma(ramp->size);
@ -469,6 +466,7 @@ void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
XRRSetCrtcGamma(_glfw.x11.display, monitor->x11.crtc, gamma); XRRSetCrtcGamma(_glfw.x11.display, monitor->x11.crtc, gamma);
XRRFreeGamma(gamma); XRRFreeGamma(gamma);
} }
}
else if (_glfw.x11.vidmode.available) else if (_glfw.x11.vidmode.available)
{ {
XF86VidModeSetGammaRamp(_glfw.x11.display, XF86VidModeSetGammaRamp(_glfw.x11.display,

View File

@ -231,8 +231,6 @@ typedef struct _GLFWlibraryX11
int errorBase; int errorBase;
int major; int major;
int minor; int minor;
GLFWbool gammaBroken;
GLFWbool monitorBroken;
} randr; } randr;
struct { struct {