Implemented display aware glfwVideoModes function for X11 XRandR and win32.

This commit is contained in:
Marcel Metz 2011-10-02 16:13:47 -04:00
parent a905e671b3
commit 58d4323ece
8 changed files with 80 additions and 15 deletions

View File

@ -110,13 +110,19 @@ GLFWAPI int glfwGetVideoModes(GLFWdisplay display, GLFWvidmode* list, int maxcou
return 0; return 0;
} }
if (display == GLFW_DISPLAY_INVALID_HANDLE)
{
_glfwSetError(GLFW_INVALID_VALUE, "Display handle is invalid.");
return 0;
}
if (maxcount <= 0 || list == NULL) if (maxcount <= 0 || list == NULL)
{ {
// TODO: Figure out if this is an error // TODO: Figure out if this is an error
return 0; return 0;
} }
count = _glfwPlatformGetVideoModes(list, maxcount); count = _glfwPlatformGetVideoModes(display, list, maxcount);
if (count > 0) if (count > 0)
qsort(list, count, sizeof(GLFWvidmode), _glfwCompareVideoModes); qsort(list, count, sizeof(GLFWvidmode), _glfwCompareVideoModes);

View File

@ -232,6 +232,9 @@ struct _GLFWdisplay
// logical orientation of the screen on the desktop // logical orientation of the screen on the desktop
int screenXPosition; int screenXPosition;
int screenYPosition; int screenYPosition;
// These are defined in the current port's platform.h
_GLFW_PLATFORM_DISPLAY_STATE;
}; };
//------------------------------------------------------------------------ //------------------------------------------------------------------------
@ -298,7 +301,7 @@ void _glfwPlatformEnableSystemKeys(_GLFWwindow* window);
void _glfwPlatformDisableSystemKeys(_GLFWwindow* window); void _glfwPlatformDisableSystemKeys(_GLFWwindow* window);
// Fullscreen // Fullscreen
int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount); int _glfwPlatformGetVideoModes(GLFWdisplay display, GLFWvidmode* list, int maxcount);
void _glfwPlatformGetDesktopMode(GLFWvidmode* mode); void _glfwPlatformGetDesktopMode(GLFWvidmode* mode);
// Gamma ramp // Gamma ramp

View File

@ -57,6 +57,8 @@ _GLFWdisplay** _glfwCreateDisplay(_GLFWdisplay** current, DISPLAY_DEVICE* adapte
(*current)->screenXPosition = setting->dmPosition.x; (*current)->screenXPosition = setting->dmPosition.x;
(*current)->screenYPosition = setting->dmPosition.y; (*current)->screenYPosition = setting->dmPosition.y;
memcpy((*current)->Win32.DeviceName, adapter->DeviceName, 32);
return &((*current)->next); return &((*current)->next);
} }

View File

@ -182,7 +182,7 @@ void _glfwRestoreVideoMode(void)
// Get a list of available video modes // Get a list of available video modes
//======================================================================== //========================================================================
int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) int _glfwPlatformGetVideoModes(GLFWdisplay display, GLFWvidmode* list, int maxcount)
{ {
DEVMODE deviceMode; DEVMODE deviceMode;
DWORD deviceModeNum; DWORD deviceModeNum;
@ -197,7 +197,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
vidModes = NULL; vidModes = NULL;
vidModesCount = 0; vidModesCount = 0;
while (EnumDisplaySettings(NULL, deviceModeNum, &deviceMode) && (!list || (vidModesCount < maxcount))) while (EnumDisplaySettings(display->Win32.DeviceName, deviceModeNum, &deviceMode) && (!list || (vidModesCount < maxcount)))
{ {
deviceModeNum++; deviceModeNum++;

View File

@ -202,6 +202,7 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void);
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 Win32 #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 Win32
#define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryWin32 Win32 #define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryWin32 Win32
#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextWGL WGL #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextWGL WGL
#define _GLFW_PLATFORM_DISPLAY_STATE _GLFWdisplayWin32 Win32
//======================================================================== //========================================================================
@ -310,6 +311,13 @@ typedef struct _GLFWlibraryWin32
} _GLFWlibraryWin32; } _GLFWlibraryWin32;
//------------------------------------------------------------------------
// Platform-specific display structure
//------------------------------------------------------------------------
typedef struct _GLFWdisplayWin32
{
char DeviceName[32];
} _GLFWdisplayWin32;
//======================================================================== //========================================================================
// Prototypes for platform specific internal functions // Prototypes for platform specific internal functions

View File

@ -51,6 +51,8 @@ _GLFWdisplay** _glfwCreateDisplay(_GLFWdisplay** current, XRROutputInfo* outputI
(*current)->screenXPosition = crtcInfo->x; (*current)->screenXPosition = crtcInfo->x;
(*current)->screenYPosition = crtcInfo->y; (*current)->screenYPosition = crtcInfo->y;
(*current)->X11.output = outputInfo;
return &((*current)->next); return &((*current)->next);
} }
@ -60,6 +62,8 @@ _GLFWdisplay* _glfwDestroyDisplay(_GLFWdisplay* display)
result = display->next; result = display->next;
XRRFreeOutputInfo(display->X11.output);
_glfwFree(display); _glfwFree(display);
return result; return result;
@ -105,10 +109,9 @@ void _glfwInitDisplays(void)
curDisplay = _glfwCreateDisplay(curDisplay, outputInfo, crtcInfo); curDisplay = _glfwCreateDisplay(curDisplay, outputInfo, crtcInfo);
// Freeing of the outputInfo is done in _glfwDestroyDisplay
XRRFreeCrtcInfo(crtcInfo); XRRFreeCrtcInfo(crtcInfo);
} }
XRRFreeOutputInfo(outputInfo);
} }
} }
} }

View File

@ -325,11 +325,26 @@ struct _glfwResolution
int height; int height;
}; };
int _glfwCompareResolution(const void* left, const void* right)
{
int result = 0;
const struct _glfwResolution* leftResolution = left;
const struct _glfwResolution* rightResolution = right;
result = leftResolution->height - rightResolution->height;
if (result == 0)
{
result = leftResolution->width - rightResolution->width;
}
return result;
}
//======================================================================== //========================================================================
// List available video modes // List available video modes
//======================================================================== //========================================================================
int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) int _glfwPlatformGetVideoModes(GLFWdisplay display, GLFWvidmode* list, int maxcount)
{ {
int count, k, l, r, g, b, rgba, gl; int count, k, l, r, g, b, rgba, gl;
int depth, screen; int depth, screen;
@ -397,19 +412,37 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
if (_glfwLibrary.X11.RandR.available) if (_glfwLibrary.X11.RandR.available)
{ {
#if defined(_GLFW_HAS_XRANDR) #if defined(_GLFW_HAS_XRANDR)
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, _glfwLibrary.X11.root); XRRScreenResources* resource;
sizelist = XRRConfigSizes(sc, &sizecount); unsigned int a;
resource = XRRGetScreenResources(_glfwLibrary.X11.display, _glfwLibrary.X11.root);
resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * sizecount); resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * display->X11.output->nmode);
for (k = 0; k < sizecount; k++) for (k = 0; k < display->X11.output->nmode; k++)
{ {
resarray[rescount].width = sizelist[k].width; for (a = 0; a < resource->nmode; a++)
resarray[rescount].height = sizelist[k].height; {
rescount++; if (resource->modes[a].id != display->X11.output->modes[k])
{
continue;
}
struct _glfwResolution res = {
resource->modes[a].width,
resource->modes[a].height
};
if (!bsearch(&res, resarray, rescount, sizeof(struct _glfwResolution), _glfwCompareResolution))
{
resarray[rescount].width = resource->modes[a].width;
resarray[rescount].height = resource->modes[a].height;
rescount++;
qsort(resarray, rescount, sizeof(struct _glfwResolution), _glfwCompareResolution);
}
}
} }
XRRFreeScreenConfigInfo(sc); XRRFreeScreenResources(resource);
#endif /*_GLFW_HAS_XRANDR*/ #endif /*_GLFW_HAS_XRANDR*/
} }
else if (_glfwLibrary.X11.VidMode.available) else if (_glfwLibrary.X11.VidMode.available)

View File

@ -88,6 +88,7 @@
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 X11 #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 X11
#define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryX11 X11 #define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryX11 X11
#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX GLX #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX GLX
#define _GLFW_PLATFORM_DISPLAY_STATE _GLFWdisplayX11 X11
//======================================================================== //========================================================================
@ -244,6 +245,15 @@ GLFWGLOBAL struct {
} _glfwJoy[GLFW_JOYSTICK_LAST + 1]; } _glfwJoy[GLFW_JOYSTICK_LAST + 1];
//------------------------------------------------------------------------
// Platform-specific window structure
//------------------------------------------------------------------------
typedef struct _GLFWdisplayX11
{
XRROutputInfo* output;
} _GLFWdisplayX11;
//======================================================================== //========================================================================
// Prototypes for platform specific internal functions // Prototypes for platform specific internal functions
//======================================================================== //========================================================================