diff src/video/SDL_video.c @ 1970:db3ba6c0d0df

Allow the render context to do necessary work when the video mode changes.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 06 Aug 2006 04:39:13 +0000
parents 5d3724f64f2b
children 754847f19490
line wrap: on
line diff
--- a/src/video/SDL_video.c	Sun Aug 06 00:09:04 2006 +0000
+++ b/src/video/SDL_video.c	Sun Aug 06 04:39:13 2006 +0000
@@ -645,6 +645,7 @@
 SDL_SetFullscreenDisplayMode(const SDL_DisplayMode * mode)
 {
     SDL_VideoDisplay *display;
+    SDL_DisplayMode fullscreen_mode;
     int i;
 
     if (!_this) {
@@ -653,18 +654,29 @@
     }
 
     display = &SDL_CurrentDisplay;
-    if (mode) {
-        SDL_GetClosestDisplayMode(mode, &display->desired_mode);
-        display->fullscreen_mode = &display->desired_mode;
-    } else {
-        display->fullscreen_mode = NULL;
+    if (!mode) {
+        mode = &display->desktop_mode;
     }
 
+    SDL_GetClosestDisplayMode(mode, &fullscreen_mode);
+    if (SDL_memcmp
+        (&fullscreen_mode, &display->fullscreen_mode,
+         sizeof(fullscreen_mode)) == 0) {
+        /* Nothing to do... */
+        return 0;
+    }
+    display->fullscreen_mode = fullscreen_mode;
+
     /* Actually set the mode if we have a fullscreen window visible */
     for (i = 0; i < display->num_windows; ++i) {
         SDL_Window *window = &display->windows[i];
         if (FULLSCREEN_VISIBLE(window)) {
-            return SDL_SetDisplayMode(display->fullscreen_mode);
+            if (SDL_SetDisplayMode(&display->fullscreen_mode) < 0) {
+                return -1;
+            }
+        }
+        if (window->flags & SDL_WINDOW_FULLSCREEN) {
+            SDL_OnWindowResized(window);
         }
     }
     return 0;
@@ -678,7 +690,7 @@
         return -1;
     }
     if (mode) {
-        *mode = *SDL_CurrentDisplay.fullscreen_mode;
+        *mode = SDL_CurrentDisplay.fullscreen_mode;
     }
     return 0;
 }
@@ -1197,7 +1209,7 @@
                 }
             }
 
-            SDL_SetDisplayMode(display->fullscreen_mode);
+            SDL_SetDisplayMode(&display->fullscreen_mode);
         }
     } else {
         window->flags &= ~SDL_WINDOW_FULLSCREEN;
@@ -1252,12 +1264,22 @@
 }
 
 void
+SDL_OnWindowResized(SDL_Window * window)
+{
+    SDL_Renderer *renderer = window->renderer;
+
+    if (renderer && renderer->DisplayModeChanged) {
+        renderer->DisplayModeChanged(renderer);
+    }
+}
+
+void
 SDL_OnWindowFocusGained(SDL_Window * window)
 {
     SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
 
     if (window->flags & SDL_WINDOW_FULLSCREEN) {
-        SDL_SetDisplayMode(display->fullscreen_mode);
+        SDL_SetDisplayMode(&display->fullscreen_mode);
     }
     if (display->gamma && _this->SetDisplayGammaRamp) {
         _this->SetDisplayGammaRamp(_this, display->gamma);