diff src/video/SDL_video.c @ 1967:01e29c3e9a29

In general, fill in pointers to structures, rather than return them.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 05 Aug 2006 22:34:23 +0000
parents a788656ca29a
children 5d3724f64f2b
line wrap: on
line diff
--- a/src/video/SDL_video.c	Sat Aug 05 17:12:22 2006 +0000
+++ b/src/video/SDL_video.c	Sat Aug 05 22:34:23 2006 +0000
@@ -422,33 +422,44 @@
     return 0;
 }
 
-const SDL_DisplayMode *
-SDL_GetDisplayMode(int index)
+int
+SDL_GetDisplayMode(int index, SDL_DisplayMode * mode)
 {
     if (index < 0 || index >= SDL_GetNumDisplayModes()) {
         SDL_SetError("index must be in the range of 0 - %d",
                      SDL_GetNumDisplayModes() - 1);
-        return NULL;
+        return -1;
     }
-    return &SDL_CurrentDisplay.display_modes[index];
+    if (mode) {
+        *mode = SDL_CurrentDisplay.display_modes[index];
+    }
+    return 0;
 }
 
-const SDL_DisplayMode *
-SDL_GetDesktopDisplayMode(void)
+int
+SDL_GetDesktopDisplayMode(SDL_DisplayMode * mode)
 {
-    if (_this) {
-        return &SDL_CurrentDisplay.desktop_mode;
+    if (!_this) {
+        SDL_UninitializedVideo();
+        return -1;
     }
-    return NULL;
+    if (mode) {
+        *mode = SDL_CurrentDisplay.desktop_mode;
+    }
+    return 0;
 }
 
-const SDL_DisplayMode *
-SDL_GetCurrentDisplayMode(void)
+int
+SDL_GetCurrentDisplayMode(SDL_DisplayMode * mode)
 {
-    if (_this) {
-        return &SDL_CurrentDisplay.current_mode;
+    if (!_this) {
+        SDL_UninitializedVideo();
+        return -1;
     }
-    return NULL;
+    if (mode) {
+        *mode = SDL_CurrentDisplay.current_mode;
+    }
+    return 0;
 }
 
 SDL_DisplayMode *
@@ -549,6 +560,7 @@
 {
     SDL_VideoDisplay *display;
     SDL_DisplayMode display_mode;
+    SDL_DisplayMode current_mode;
     int i, ncolors;
 
     if (!_this) {
@@ -556,10 +568,10 @@
         return -1;
     }
 
+    display = &SDL_CurrentDisplay;
     if (!mode) {
-        mode = SDL_GetDesktopDisplayMode();
+        mode = &display->desktop_mode;
     }
-    display = &SDL_CurrentDisplay;
     display_mode = *mode;
 
     /* Default to the current mode */
@@ -584,9 +596,8 @@
     }
 
     /* See if there's anything left to do */
-    if (SDL_memcmp
-        (&display_mode, SDL_GetCurrentDisplayMode(),
-         sizeof(display_mode)) == 0) {
+    SDL_GetCurrentDisplayMode(&current_mode);
+    if (SDL_memcmp(&display_mode, &current_mode, sizeof(display_mode)) == 0) {
         return 0;
     }
 
@@ -659,13 +670,17 @@
     return 0;
 }
 
-const SDL_DisplayMode *
-SDL_GetFullscreenDisplayMode(void)
+int
+SDL_GetFullscreenDisplayMode(SDL_DisplayMode * mode)
 {
-    if (_this) {
-        return SDL_CurrentDisplay.fullscreen_mode;
+    if (!_this) {
+        SDL_UninitializedVideo();
+        return -1;
     }
-    return NULL;
+    if (mode) {
+        *mode = *SDL_CurrentDisplay.fullscreen_mode;
+    }
+    return 0;
 }
 
 int