removed redundant code (again)
[rocksndiamonds.git] / src / libgame / sdl.c
index a204e45ff13332cb09019531c551f78e3c7a2119..08aec8dcbd0f5a9309a508d0d705c2e01560c359 100644 (file)
@@ -383,8 +383,7 @@ void SDLInitVideoDisplay(void)
 #endif
 }
 
-void SDLInitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window,
-                       boolean fullscreen)
+void SDLInitVideoBuffer(boolean fullscreen)
 {
   video.window_scaling_percent = setup.window_scaling_percent;
   video.window_scaling_quality = setup.window_scaling_quality;
@@ -398,7 +397,7 @@ void SDLInitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window,
 #endif
 
   /* open SDL video output device (window or fullscreen mode) */
-  if (!SDLSetVideoMode(backbuffer, fullscreen))
+  if (!SDLSetVideoMode(fullscreen))
     Error(ERR_EXIT, "setting video mode failed");
 
   /* !!! SDL2 can only set the window icon if the window already exists !!! */
@@ -426,11 +425,10 @@ void SDLInitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window,
      should never be drawn to directly, it would do no harm nevertheless. */
 
   /* create additional (symbolic) buffer for double-buffering */
-  ReCreateBitmap(window, video.width, video.height, video.depth);
+  ReCreateBitmap(&window, video.width, video.height, video.depth);
 }
 
-static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer,
-                                   boolean fullscreen)
+static boolean SDLCreateScreen(boolean fullscreen)
 {
   SDL_Surface *new_surface = NULL;
 
@@ -461,12 +459,6 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer,
   video.window_width  = window_scaling_factor * width;
   video.window_height = window_scaling_factor * height;
 
-  if ((*backbuffer)->surface)
-  {
-    SDL_FreeSurface((*backbuffer)->surface);
-    (*backbuffer)->surface = NULL;
-  }
-
 #if USE_TARGET_TEXTURE
   if (sdl_texture_stream)
   {
@@ -577,12 +569,6 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer,
 
 #else  // TARGET_SDL
 
-  if ((*backbuffer)->surface)
-  {
-    SDL_FreeSurface((*backbuffer)->surface);
-    (*backbuffer)->surface = NULL;
-  }
-
   if (gfx.final_screen_bitmap == NULL)
     gfx.final_screen_bitmap = CreateBitmapStruct();
 
@@ -618,65 +604,56 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer,
     fullscreen_enabled = fullscreen;
 #endif
 
-  return new_surface;
+  if (backbuffer == NULL)
+    backbuffer = CreateBitmapStruct();
+
+  backbuffer->width  = video.width;
+  backbuffer->height = video.height;
+
+  if (backbuffer->surface)
+    SDL_FreeSurface(backbuffer->surface);
+
+  backbuffer->surface = new_surface;
+
+  return (new_surface != NULL);
 }
 
-boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen)
+boolean SDLSetVideoMode(boolean fullscreen)
 {
-  boolean success = TRUE;
-  SDL_Surface *new_surface = NULL;
+  boolean success = FALSE;
 
   SetWindowTitle();
 
-  if (*backbuffer == NULL)
-    *backbuffer = CreateBitmapStruct();
-
-  /* (real bitmap might be larger in fullscreen mode with video offsets) */
-  (*backbuffer)->width  = video.width;
-  (*backbuffer)->height = video.height;
-
   if (fullscreen && !video.fullscreen_enabled && video.fullscreen_available)
   {
     /* switch display to fullscreen mode, if available */
-    new_surface = SDLCreateScreen(backbuffer, TRUE);
+    success = SDLCreateScreen(TRUE);
 
-    if (new_surface == NULL)
+    if (!success)
     {
       /* switching display to fullscreen mode failed -- do not try it again */
       video.fullscreen_available = FALSE;
-
-      success = FALSE;
     }
     else
     {
-      (*backbuffer)->surface = new_surface;
-
       video.fullscreen_enabled = TRUE;
-
-      success = TRUE;
     }
   }
 
-  if ((!fullscreen && video.fullscreen_enabled) || new_surface == NULL)
+  if ((!fullscreen && video.fullscreen_enabled) || !success)
   {
     /* switch display to window mode */
-    new_surface = SDLCreateScreen(backbuffer, FALSE);
+    success = SDLCreateScreen(FALSE);
 
-    if (new_surface == NULL)
+    if (!success)
     {
       /* switching display to window mode failed -- should not happen */
-
-      success = FALSE;
     }
     else
     {
-      (*backbuffer)->surface = new_surface;
-
       video.fullscreen_enabled = FALSE;
       video.window_scaling_percent = setup.window_scaling_percent;
       video.window_scaling_quality = setup.window_scaling_quality;
-
-      success = TRUE;
     }
   }
 
@@ -940,20 +917,8 @@ void SDLFillRectangle(Bitmap *dst_bitmap, int x, int y, int width, int height,
 
   SDL_FillRect(real_dst_bitmap->surface, &rect, color);
 
-#if defined(TARGET_SDL2)
   if (dst_bitmap == window)
-  {
-    // SDL_UpdateWindowSurface(sdl_window);
-    // SDL_UpdateWindowSurfaceRects(sdl_window, &rect, 1);
     UpdateScreen(&rect);
-  }
-#else
-  if (dst_bitmap == window)
-  {
-    // SDL_UpdateRect(backbuffer->surface, x, y, width, height);
-    UpdateScreen(&rect);
-  }
-#endif
 }
 
 void SDLFadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height,