diff options
-rw-r--r-- | include/SDL_video.h | 51 | ||||
-rw-r--r-- | src/SDL_compat.c | 32 | ||||
-rw-r--r-- | src/video/SDL_sysvideo.h | 8 | ||||
-rw-r--r-- | src/video/SDL_video.c | 134 | ||||
-rw-r--r-- | src/video/x11/SDL_x11opengl.c | 2 | ||||
-rw-r--r-- | test/common.c | 8 | ||||
-rw-r--r-- | test/testgl2.c | 2 | ||||
-rw-r--r-- | test/testime.c | 11 | ||||
-rw-r--r-- | test/testvidinfo.c | 8 |
9 files changed, 90 insertions, 166 deletions
diff --git a/include/SDL_video.h b/include/SDL_video.h index b5b94ee7..3cd069c2 100644 --- a/include/SDL_video.h +++ b/include/SDL_video.h @@ -236,7 +236,6 @@ extern DECLSPEC const char *SDLCALL SDL_GetCurrentVideoDriver(void); * \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 @@ extern DECLSPEC int SDLCALL SDL_GetNumVideoDisplays(void); * * \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 @@ extern DECLSPEC int SDLCALL SDL_GetNumDisplayModes(void); * * \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 @@ extern DECLSPEC int SDLCALL SDL_GetCurrentDisplayMode(SDL_DisplayMode * mode); * \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 @@ extern DECLSPEC int SDLCALL SDL_SetWindowDisplayMode(SDL_Window * window, /** * \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() diff --git a/src/SDL_compat.c b/src/SDL_compat.c index 7d875512..d67fc5ad 100644 --- a/src/SDL_compat.c +++ b/src/SDL_compat.c @@ -71,15 +71,17 @@ SDL_VideoDriverName(char *namebuf, int maxlen) 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 @@ SDL_GetVideoInfo(void) 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 @@ SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags) 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 @@ SDL_ListModes(const SDL_PixelFormat * format, Uint32 flags) return NULL; } - SelectVideoDisplay(); - if (!(flags & SDL_FULLSCREEN)) { return (SDL_Rect **) (-1); } @@ -160,11 +156,11 @@ SDL_ListModes(const SDL_PixelFormat * format, Uint32 flags) /* 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 @@ GetEnvironmentWindowPosition(int w, int h, int *x, int *y) } 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 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) } } - SelectVideoDisplay(); - - SDL_GetDesktopDisplayMode(&desktop_mode); + SDL_GetDesktopDisplayMode(GetVideoDisplay(), &desktop_mode); if (width == 0) { width = desktop_mode.w; diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 2c59e401..f66ae232 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -322,18 +322,10 @@ extern VideoBootStrap Android_bootstrap; 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); diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 384dab4f..196a023d 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -96,6 +96,17 @@ static SDL_VideoDevice *_this = NULL; 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 @@ SDL_GetNumVideoDisplays(void) } 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 @@ SDL_GetDisplayBounds(int index, SDL_Rect * rect) } } 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 @@ SDL_GetDisplayBounds(int index, SDL_Rect * rect) 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 @@ SDL_AddDisplayMode(SDL_VideoDisplay * display, const SDL_DisplayMode * mode) return SDL_TRUE; } -int +static int SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display) { if (!display->num_display_modes && _this->GetDisplayModes) { @@ -689,17 +667,21 @@ SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display) } 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 @@ SDL_GetDisplayModeForDisplay(SDL_VideoDisplay * display, int index, SDL_DisplayM } 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 @@ SDL_GetDesktopDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode } 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_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display, } 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 @@ SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * } /* See if there's anything left to do */ - SDL_GetCurrentDisplayModeForDisplay(display, ¤t_mode); + current_mode = display->current_mode; if (SDL_memcmp(&display_mode, ¤t_mode, sizeof(display_mode)) == 0) { return 0; } @@ -1054,7 +1022,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) } 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_CreateWindowFrom(const void *data) 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 @@ SDL_GetFocusWindow(void) 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; diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c index 59847dfc..4e897271 100644 --- a/src/video/x11/SDL_x11opengl.c +++ b/src/video/x11/SDL_x11opengl.c @@ -220,7 +220,7 @@ static void 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; diff --git a/test/common.c b/test/common.c index 623842ba..880421b2 100644 --- a/test/common.c +++ b/test/common.c @@ -594,9 +594,8 @@ CommonInit(CommonState * state) 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 @@ CommonInit(CommonState * state) } /* 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 @@ CommonInit(CommonState * state) } } - SDL_SelectVideoDisplay(state->display); if (state->verbose & VERBOSE_RENDER) { SDL_RendererInfo info; diff --git a/test/testgl2.c b/test/testgl2.c index 1ae8abde..8e82c648 100644 --- a/test/testgl2.c +++ b/test/testgl2.c @@ -234,7 +234,7 @@ main(int argc, char *argv[]) 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)); diff --git a/test/testime.c b/test/testime.c index bc25f4ab..a8d3cab9 100644 --- a/test/testime.c +++ b/test/testime.c @@ -122,12 +122,9 @@ void InitVideo(int argc, char *argv[]) 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 @@ int main(int argc, char *argv[]) CleanupVideo(); return 0; } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/testvidinfo.c b/test/testvidinfo.c index a9e7964d..48e63f06 100644 --- a/test/testvidinfo.c +++ b/test/testvidinfo.c @@ -455,9 +455,7 @@ main(int argc, char *argv[]) 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 @@ main(int argc, char *argv[]) } /* 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, |