changeset 5249:762e40fb8e28

Be explicit about what display you're querying. The default display is 0.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 10 Feb 2011 12:14:37 -0800
parents 3a8a452b49f0
children 329d435f97f4
files include/SDL_video.h src/SDL_compat.c src/video/SDL_sysvideo.h src/video/SDL_video.c src/video/x11/SDL_x11opengl.c test/common.c test/testgl2.c test/testime.c test/testvidinfo.c
diffstat 9 files changed, 90 insertions(+), 166 deletions(-) [+]
line wrap: on
line diff
--- a/include/SDL_video.h	Thu Feb 10 11:39:08 2011 -0800
+++ b/include/SDL_video.h	Thu Feb 10 12:14:37 2011 -0800
@@ -236,7 +236,6 @@
  *  \brief Returns the number of available video displays.
  *  
  *  \sa SDL_GetDisplayBounds()
- *  \sa SDL_SelectVideoDisplay()
  */
 extern DECLSPEC int SDLCALL SDL_GetNumVideoDisplays(void);
 
@@ -248,34 +247,14 @@
  *  
  *  \sa SDL_GetNumVideoDisplays()
  */
-extern DECLSPEC int SDLCALL SDL_GetDisplayBounds(int index, SDL_Rect * rect);
+extern DECLSPEC int SDLCALL SDL_GetDisplayBounds(int displayIndex, SDL_Rect * rect);
 
 /**
- *  \brief Set the index of the currently selected display.
- *  
- *  \return 0 on success, or -1 if the index is out of range.
- *  
- *  \sa SDL_GetNumVideoDisplays()
- *  \sa SDL_GetCurrentVideoDisplay()
- */
-extern DECLSPEC int SDLCALL SDL_SelectVideoDisplay(int index);
-
-/**
- *  \brief Get the index of the currently selected display.
- *  
- *  \return The index of the currently selected display.
- *  
- *  \sa SDL_GetNumVideoDisplays()
- *  \sa SDL_SelectVideoDisplay()
- */
-extern DECLSPEC int SDLCALL SDL_GetCurrentVideoDisplay(void);
-
-/**
- *  \brief Returns the number of available display modes for the current display.
+ *  \brief Returns the number of available display modes.
  *  
  *  \sa SDL_GetDisplayMode()
  */
-extern DECLSPEC int SDLCALL SDL_GetNumDisplayModes(void);
+extern DECLSPEC int SDLCALL SDL_GetNumDisplayModes(int displayIndex);
 
 /**
  *  \brief Fill in information about a specific display mode.
@@ -288,19 +267,18 @@
  *  
  *  \sa SDL_GetNumDisplayModes()
  */
-extern DECLSPEC int SDLCALL SDL_GetDisplayMode(int index,
+extern DECLSPEC int SDLCALL SDL_GetDisplayMode(int displayIndex, int modeIndex,
                                                SDL_DisplayMode * mode);
 
 /**
- *  \brief Fill in information about the desktop display mode for the current 
- *         display.
+ *  \brief Fill in information about the desktop display mode.
  */
-extern DECLSPEC int SDLCALL SDL_GetDesktopDisplayMode(SDL_DisplayMode * mode);
+extern DECLSPEC int SDLCALL SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode * mode);
 
 /**
  *  \brief Fill in information about the current display mode.
  */
-extern DECLSPEC int SDLCALL SDL_GetCurrentDisplayMode(SDL_DisplayMode * mode);
+extern DECLSPEC int SDLCALL SDL_GetCurrentDisplayMode(int displayIndex, SDL_DisplayMode * mode);
 
 
 /**
@@ -323,16 +301,13 @@
  *  \sa SDL_GetNumDisplayModes()
  *  \sa SDL_GetDisplayMode()
  */
-extern DECLSPEC SDL_DisplayMode *SDLCALL SDL_GetClosestDisplayMode(const
-                                                                   SDL_DisplayMode
-                                                                   * mode,
-                                                                   SDL_DisplayMode
-                                                                   * closest);
+extern DECLSPEC SDL_DisplayMode * SDLCALL SDL_GetClosestDisplayMode(int displayIndex, const SDL_DisplayMode * mode, SDL_DisplayMode * closest);
 
 /**
- *  \brief Set the display mode used when a fullscreen window is visible
- *         on the currently selected display.  By default the window's
- *         dimensions and the desktop format and refresh rate are used.
+ *  \brief Set the display mode used when a fullscreen window is visible.
+ *
+ *  By default the window's dimensions and the desktop format and refresh rate
+ *  are used.
  *  
  *  \param mode The mode to use, or NULL for the default mode.
  *  
@@ -347,7 +322,7 @@
 
 /**
  *  \brief Fill in information about the display mode used when a fullscreen
- *         window is visible on the currently selected display.
+ *         window is visible.
  *
  *  \sa SDL_SetWindowDisplayMode()
  *  \sa SDL_SetWindowFullscreen()
--- a/src/SDL_compat.c	Thu Feb 10 11:39:08 2011 -0800
+++ b/src/SDL_compat.c	Thu Feb 10 12:14:37 2011 -0800
@@ -71,15 +71,17 @@
     return NULL;
 }
 
-static void
-SelectVideoDisplay()
+static int
+GetVideoDisplay()
 {
     const char *variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_DISPLAY");
     if ( !variable ) {
         variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_HEAD");
     }
     if ( variable ) {
-        SDL_SelectVideoDisplay(SDL_atoi(variable));
+        SDL_atoi(variable);
+    } else {
+        return 0;
     }
 }
 
@@ -89,10 +91,8 @@
     static SDL_VideoInfo info;
     SDL_DisplayMode mode;
 
-    SelectVideoDisplay();
-
     /* Memory leak, compatibility code, who cares? */
-    if (!info.vfmt && SDL_GetDesktopDisplayMode(&mode) == 0) {
+    if (!info.vfmt && SDL_GetDesktopDisplayMode(GetVideoDisplay(), &mode) == 0) {
         int bpp;
         Uint32 Rmask, Gmask, Bmask, Amask;
 
@@ -114,17 +114,15 @@
         return 0;
     }
 
-    SelectVideoDisplay();
-
     if (!(flags & SDL_FULLSCREEN)) {
         SDL_DisplayMode mode;
-        SDL_GetDesktopDisplayMode(&mode);
+        SDL_GetDesktopDisplayMode(GetVideoDisplay(), &mode);
         return SDL_BITSPERPIXEL(mode.format);
     }
 
-    for (i = 0; i < SDL_GetNumDisplayModes(); ++i) {
+    for (i = 0; i < SDL_GetNumDisplayModes(GetVideoDisplay()); ++i) {
         SDL_DisplayMode mode;
-        SDL_GetDisplayMode(i, &mode);
+        SDL_GetDisplayMode(GetVideoDisplay(), i, &mode);
         if (!mode.w || !mode.h || (width == mode.w && height == mode.h)) {
             if (!mode.format) {
                 return bpp;
@@ -147,8 +145,6 @@
         return NULL;
     }
 
-    SelectVideoDisplay();
-
     if (!(flags & SDL_FULLSCREEN)) {
         return (SDL_Rect **) (-1);
     }
@@ -160,11 +156,11 @@
     /* Memory leak, but this is a compatibility function, who cares? */
     nmodes = 0;
     modes = NULL;
-    for (i = 0; i < SDL_GetNumDisplayModes(); ++i) {
+    for (i = 0; i < SDL_GetNumDisplayModes(GetVideoDisplay()); ++i) {
         SDL_DisplayMode mode;
         int bpp;
 
-        SDL_GetDisplayMode(i, &mode);
+        SDL_GetDisplayMode(GetVideoDisplay(), i, &mode);
         if (!mode.w || !mode.h) {
             return (SDL_Rect **) (-1);
         }
@@ -342,7 +338,7 @@
     }
     if (center) {
         SDL_DisplayMode mode;
-        SDL_GetDesktopDisplayMode(&mode);
+        SDL_GetDesktopDisplayMode(GetVideoDisplay(), &mode);
         *x = (mode.w - w) / 2;
         *y = (mode.h - h) / 2;
     }
@@ -453,9 +449,7 @@
         }
     }
 
-    SelectVideoDisplay();
-
-    SDL_GetDesktopDisplayMode(&desktop_mode);
+    SDL_GetDesktopDisplayMode(GetVideoDisplay(), &desktop_mode);
 
     if (width == 0) {
         width = desktop_mode.w;
--- a/src/video/SDL_sysvideo.h	Thu Feb 10 11:39:08 2011 -0800
+++ b/src/video/SDL_sysvideo.h	Thu Feb 10 12:14:37 2011 -0800
@@ -322,18 +322,10 @@
 extern VideoBootStrap DUMMY_bootstrap;
 #endif
 
-#define SDL_CurrentDisplay	(&_this->displays[_this->current_display])
-
 extern SDL_VideoDevice *SDL_GetVideoDevice(void);
 extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
 extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
 extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
-extern int SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display);
-extern int SDL_GetDisplayModeForDisplay(SDL_VideoDisplay * display, int index, SDL_DisplayMode * mode);
-extern int SDL_GetDesktopDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode);
-extern int SDL_GetCurrentDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode);
-extern SDL_DisplayMode * SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode, SDL_DisplayMode * closest);
-extern int SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode);
 
 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
 
--- a/src/video/SDL_video.c	Thu Feb 10 11:39:08 2011 -0800
+++ b/src/video/SDL_video.c	Thu Feb 10 12:14:37 2011 -0800
@@ -96,6 +96,17 @@
         return retval; \
     }
 
+#define CHECK_DISPLAY_INDEX(displayIndex, retval) \
+    if (!_this) { \
+        SDL_UninitializedVideo(); \
+        return retval; \
+    } \
+    if (displayIndex < 0 || displayIndex >= _this->num_displays) { \
+        SDL_SetError("displayIndex must be in the range 0 - %d", \
+                     _this->num_displays - 1); \
+        return retval; \
+    }
+
 /* Various local functions */
 static void SDL_UpdateWindowGrab(SDL_Window * window);
 
@@ -581,19 +592,12 @@
 }
 
 int
-SDL_GetDisplayBounds(int index, SDL_Rect * rect)
+SDL_GetDisplayBounds(int displayIndex, SDL_Rect * rect)
 {
-    if (!_this) {
-        SDL_UninitializedVideo();
-        return -1;
-    }
-    if (index < 0 || index >= _this->num_displays) {
-        SDL_SetError("index must be in the range 0 - %d",
-                     _this->num_displays - 1);
-        return -1;
-    }
+    CHECK_DISPLAY_INDEX(displayIndex, -1);
+
     if (rect) {
-        SDL_VideoDisplay *display = &_this->displays[index];
+        SDL_VideoDisplay *display = &_this->displays[displayIndex];
 
         if (_this->GetDisplayBounds) {
             if (_this->GetDisplayBounds(_this, display, rect) < 0) {
@@ -601,11 +605,11 @@
             }
         } else {
             /* Assume that the displays are left to right */
-            if (index == 0) {
+            if (displayIndex == 0) {
                 rect->x = 0;
                 rect->y = 0;
             } else {
-                SDL_GetDisplayBounds(index-1, rect);
+                SDL_GetDisplayBounds(displayIndex-1, rect);
                 rect->x += rect->w;
             }
             rect->w = display->desktop_mode.w;
@@ -615,32 +619,6 @@
     return 0;
 }
 
-int
-SDL_SelectVideoDisplay(int index)
-{
-    if (!_this) {
-        SDL_UninitializedVideo();
-        return (-1);
-    }
-    if (index < 0 || index >= _this->num_displays) {
-        SDL_SetError("index must be in the range 0 - %d",
-                     _this->num_displays - 1);
-        return -1;
-    }
-    _this->current_display = index;
-    return 0;
-}
-
-int
-SDL_GetCurrentVideoDisplay(void)
-{
-    if (!_this) {
-        SDL_UninitializedVideo();
-        return (-1);
-    }
-    return _this->current_display;
-}
-
 SDL_bool
 SDL_AddDisplayMode(SDL_VideoDisplay * display,  const SDL_DisplayMode * mode)
 {
@@ -677,7 +655,7 @@
     return SDL_TRUE;
 }
 
-int
+static int
 SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display)
 {
     if (!display->num_display_modes && _this->GetDisplayModes) {
@@ -689,17 +667,21 @@
 }
 
 int
-SDL_GetNumDisplayModes()
+SDL_GetNumDisplayModes(int displayIndex)
 {
-    if (_this) {
-        return SDL_GetNumDisplayModesForDisplay(SDL_CurrentDisplay);
-    }
-    return 0;
+    CHECK_DISPLAY_INDEX(displayIndex, -1);
+
+    return SDL_GetNumDisplayModesForDisplay(&_this->displays[displayIndex]);
 }
 
 int
-SDL_GetDisplayModeForDisplay(SDL_VideoDisplay * display, int index, SDL_DisplayMode * mode)
+SDL_GetDisplayMode(int displayIndex, int index, SDL_DisplayMode * mode)
 {
+    SDL_VideoDisplay *display;
+
+    CHECK_DISPLAY_INDEX(displayIndex, -1);
+
+    display = &_this->displays[displayIndex];
     if (index < 0 || index >= SDL_GetNumDisplayModesForDisplay(display)) {
         SDL_SetError("index must be in the range of 0 - %d",
                      SDL_GetNumDisplayModesForDisplay(display) - 1);
@@ -712,14 +694,13 @@
 }
 
 int
-SDL_GetDisplayMode(int index, SDL_DisplayMode * mode)
+SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode * mode)
 {
-    return SDL_GetDisplayModeForDisplay(SDL_CurrentDisplay, index, mode);
-}
+    SDL_VideoDisplay *display;
 
-int
-SDL_GetDesktopDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode)
-{
+    CHECK_DISPLAY_INDEX(displayIndex, -1);
+
+    display = &_this->displays[displayIndex];
     if (mode) {
         *mode = display->desktop_mode;
     }
@@ -727,35 +708,20 @@
 }
 
 int
-SDL_GetDesktopDisplayMode(SDL_DisplayMode * mode)
+SDL_GetCurrentDisplayMode(int displayIndex, SDL_DisplayMode * mode)
 {
-    if (!_this) {
-        SDL_UninitializedVideo();
-        return -1;
-    }
-    return SDL_GetDesktopDisplayModeForDisplay(SDL_CurrentDisplay, mode);
-}
+    SDL_VideoDisplay *display;
 
-int
-SDL_GetCurrentDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode)
-{
+    CHECK_DISPLAY_INDEX(displayIndex, -1);
+
+    display = &_this->displays[displayIndex];
     if (mode) {
         *mode = display->current_mode;
     }
     return 0;
 }
 
-int
-SDL_GetCurrentDisplayMode(SDL_DisplayMode * mode)
-{
-    if (!_this) {
-        SDL_UninitializedVideo();
-        return -1;
-    }
-    return SDL_GetCurrentDisplayModeForDisplay(SDL_CurrentDisplay, mode);
-}
-
-SDL_DisplayMode *
+static SDL_DisplayMode *
 SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display,
                                     const SDL_DisplayMode * mode,
                                     SDL_DisplayMode * closest)
@@ -863,14 +829,16 @@
 }
 
 SDL_DisplayMode *
-SDL_GetClosestDisplayMode(const SDL_DisplayMode * mode,
+SDL_GetClosestDisplayMode(int displayIndex,
+                          const SDL_DisplayMode * mode,
                           SDL_DisplayMode * closest)
 {
-    if (!_this) {
-        SDL_UninitializedVideo();
-        return NULL;
-    }
-    return SDL_GetClosestDisplayModeForDisplay(SDL_CurrentDisplay, mode, closest);
+    SDL_VideoDisplay *display;
+
+    CHECK_DISPLAY_INDEX(displayIndex, NULL);
+
+    display = &_this->displays[displayIndex];
+    return SDL_GetClosestDisplayModeForDisplay(display, mode, closest);
 }
 
 int
@@ -907,7 +875,7 @@
     }
 
     /* See if there's anything left to do */
-    SDL_GetCurrentDisplayModeForDisplay(display, &current_mode);
+    current_mode = display->current_mode;
     if (SDL_memcmp(&display_mode, &current_mode, sizeof(display_mode)) == 0) {
         return 0;
     }
@@ -1054,7 +1022,7 @@
         }
         SDL_GL_LoadLibrary(NULL);
     }
-    display = SDL_CurrentDisplay;
+    display = &_this->displays[0]; /* FIXME */
     window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
     window->magic = &_this->window_magic;
     window->id = _this->next_object_id++;
@@ -1102,7 +1070,7 @@
         SDL_UninitializedVideo();
         return NULL;
     }
-    display = SDL_CurrentDisplay;
+    display = &_this->displays[0]; /* FIXME */
     window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
     window->magic = &_this->window_magic;
     window->id = _this->next_object_id++;
@@ -1676,7 +1644,7 @@
     if (!_this) {
         return NULL;
     }
-    display = SDL_CurrentDisplay;
+    display = &_this->displays[0]; /* FIXME */
     for (window = display->windows; window; window = window->next) {
         if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
             return window;
--- a/src/video/x11/SDL_x11opengl.c	Thu Feb 10 11:39:08 2011 -0800
+++ b/src/video/x11/SDL_x11opengl.c	Thu Feb 10 12:14:37 2011 -0800
@@ -220,7 +220,7 @@
 X11_GL_InitExtensions(_THIS)
 {
     Display *display = ((SDL_VideoData *) _this->driverdata)->display;
-    int screen = ((SDL_DisplayData *) SDL_CurrentDisplay->driverdata)->screen;
+    int screen = DefaultScreen(display);
     XVisualInfo *vinfo;
     XSetWindowAttributes xattr;
     Window w;
--- a/test/common.c	Thu Feb 10 11:39:08 2011 -0800
+++ b/test/common.c	Thu Feb 10 12:14:37 2011 -0800
@@ -594,9 +594,8 @@
             fprintf(stderr, "Number of displays: %d\n", n);
             for (i = 0; i < n; ++i) {
                 fprintf(stderr, "Display %d:\n", i);
-                SDL_SelectVideoDisplay(i);
 
-                SDL_GetDesktopDisplayMode(&mode);
+                SDL_GetDesktopDisplayMode(i, &mode);
                 SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask,
                                            &Bmask, &Amask);
                 fprintf(stderr,
@@ -612,13 +611,13 @@
                 }
 
                 /* Print available fullscreen video modes */
-                m = SDL_GetNumDisplayModes();
+                m = SDL_GetNumDisplayModes(i);
                 if (m == 0) {
                     fprintf(stderr, "No available fullscreen video modes\n");
                 } else {
                     fprintf(stderr, "  Fullscreen video modes:\n");
                     for (j = 0; j < m; ++j) {
-                        SDL_GetDisplayMode(j, &mode);
+                        SDL_GetDisplayMode(i, j, &mode);
                         SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask,
                                                    &Gmask, &Bmask, &Amask);
                         fprintf(stderr,
@@ -642,7 +641,6 @@
             }
         }
 
-        SDL_SelectVideoDisplay(state->display);
         if (state->verbose & VERBOSE_RENDER) {
             SDL_RendererInfo info;
 
--- a/test/testgl2.c	Thu Feb 10 11:39:08 2011 -0800
+++ b/test/testgl2.c	Thu Feb 10 12:14:37 2011 -0800
@@ -234,7 +234,7 @@
         SDL_GL_SetSwapInterval(0);
     }
 
-    SDL_GetCurrentDisplayMode(&mode);
+    SDL_GetCurrentDisplayMode(0, &mode);
     printf("Screen BPP: %d\n", SDL_BITSPERPIXEL(mode.format));
     printf("\n");
     printf("Vendor     : %s\n", glGetString(GL_VENDOR));
--- a/test/testime.c	Thu Feb 10 11:39:08 2011 -0800
+++ b/test/testime.c	Thu Feb 10 12:14:37 2011 -0800
@@ -122,12 +122,9 @@
 
     if (fullscreen)
     {
-        SDL_DisplayMode mode;
-        SDL_GetDesktopDisplayMode(&mode);
-
-        width = mode.w;
-        height = mode.h;
-        fprintf(stderr, "%dx%d\n", width, height);
+        /* Use the desktop mode */
+        width = 0;
+        height = 0;
         flags |= SDL_FULLSCREEN;
     }
 
@@ -375,3 +372,5 @@
     CleanupVideo();
     return 0;
 }
+
+/* vi: set ts=4 sw=4 expandtab: */
--- a/test/testvidinfo.c	Thu Feb 10 11:39:08 2011 -0800
+++ b/test/testvidinfo.c	Thu Feb 10 12:14:37 2011 -0800
@@ -455,9 +455,7 @@
         printf("Display %d: %dx%d at %d,%d\n", d,
                bounds.w, bounds.h, bounds.x, bounds.y);
 
-        SDL_SelectVideoDisplay(d);
-
-        SDL_GetDesktopDisplayMode(&mode);
+        SDL_GetDesktopDisplayMode(d, &mode);
         SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask, &Bmask,
                                    &Amask);
         printf("  Current mode: %dx%d@%dHz, %d bits-per-pixel\n", mode.w,
@@ -471,13 +469,13 @@
         }
 
         /* Print available fullscreen video modes */
-        nmodes = SDL_GetNumDisplayModes();
+        nmodes = SDL_GetNumDisplayModes(d);
         if (nmodes == 0) {
             printf("No available fullscreen video modes\n");
         } else {
             printf("  Fullscreen video modes:\n");
             for (i = 0; i < nmodes; ++i) {
-                SDL_GetDisplayMode(i, &mode);
+                SDL_GetDisplayMode(d, i, &mode);
                 SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask,
                                            &Gmask, &Bmask, &Amask);
                 printf("    Mode %d: %dx%d@%dHz, %d bits-per-pixel\n", i,