Cleaned up monitor and video mode enumeration.

This commit is contained in:
Camilla Berglund
2015-03-23 00:08:28 +01:00
parent 6412dcb896
commit 49cf82a0ac
3 changed files with 83 additions and 100 deletions

View File

@@ -200,8 +200,8 @@ void _glfwRestoreVideoMode(_GLFWmonitor* monitor)
_GLFWmonitor** _glfwPlatformGetMonitors(int* count)
{
int i, j, k, size = 0, found = 0;
_GLFWmonitor** monitors = NULL;
int i, j, k, found = 0;
_GLFWmonitor** monitors;
*count = 0;
@@ -214,6 +214,8 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
RROutput primary = XRRGetOutputPrimary(_glfw.x11.display,
_glfw.x11.root);
monitors = calloc(sizeof(_GLFWmonitor*), sr->noutput);
if (_glfw.x11.xinerama.available)
screens = XineramaQueryScreens(_glfw.x11.display, &screenCount);
@@ -225,6 +227,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
for (j = 0; j < ci->noutput; j++)
{
int widthMM, heightMM;
_GLFWmonitor* monitor;
XRROutputInfo* oi = XRRGetOutputInfo(_glfw.x11.display,
sr, ci->outputs[j]);
if (oi->connection != RR_Connected)
@@ -233,12 +236,6 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
continue;
}
if (found == size)
{
size += 4;
monitors = realloc(monitors, sizeof(_GLFWmonitor*) * size);
}
if (ci->rotation == RR_Rotate_90 || ci->rotation == RR_Rotate_270)
{
widthMM = oi->mm_height;
@@ -250,9 +247,9 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
heightMM = oi->mm_height;
}
monitors[found] = _glfwAllocMonitor(oi->name, widthMM, heightMM);
monitors[found]->x11.output = ci->outputs[j];
monitors[found]->x11.crtc = oi->crtc;
monitor = _glfwAllocMonitor(oi->name, widthMM, heightMM);
monitor->x11.output = ci->outputs[j];
monitor->x11.crtc = oi->crtc;
for (k = 0; k < screenCount; k++)
{
@@ -261,17 +258,18 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
screens[k].width == ci->width &&
screens[k].height == ci->height)
{
monitors[found]->x11.index = k;
monitor->x11.index = k;
break;
}
}
XRRFreeOutputInfo(oi);
if (ci->outputs[j] == primary)
_GLFW_SWAP_POINTERS(monitors[0], monitors[found]);
found++;
monitors[found - 1] = monitor;
if (ci->outputs[j] == primary)
_GLFW_SWAP_POINTERS(monitors[0], monitors[found - 1]);
}
XRRFreeCrtcInfo(ci);
@@ -286,7 +284,10 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"X11: RandR monitor support seems broken");
_glfw.x11.randr.monitorBroken = GL_TRUE;
free(monitors);
monitors = NULL;
}
}
@@ -330,13 +331,11 @@ void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos)
}
}
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
{
GLFWvidmode* result;
*found = 0;
// Build array of available resolutions
*count = 0;
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken)
{
@@ -359,20 +358,18 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
const GLFWvidmode mode = vidmodeFromModeInfo(mi, ci);
for (j = 0; j < *found; j++)
for (j = 0; j < *count; j++)
{
if (_glfwCompareVideoModes(result + j, &mode) == 0)
break;
}
if (j < *found)
{
// This is a duplicate, so skip it
// Skip duplicate modes
if (j < *count)
continue;
}
result[*found] = mode;
(*found)++;
(*count)++;
result[*count - 1] = mode;
}
XRRFreeOutputInfo(oi);
@@ -381,7 +378,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
}
else
{
*found = 1;
*count = 1;
result = calloc(1, sizeof(GLFWvidmode));
_glfwPlatformGetVideoMode(monitor, result);
}