moved redundant code to new function
[rocksndiamonds.git] / src / libgame / sdl.c
index a73bae86f314896acace4666261f575344b0cb36..4d303910b57628c4ed7169b4839d0ffc341e30ba 100644 (file)
@@ -49,6 +49,21 @@ void SDLLimitScreenUpdates(boolean enable)
   limit_screen_updates = enable;
 }
 
+static void FinalizeScreen()
+{
+  // copy global animations to render target buffer, if defined (below border)
+  if (gfx.draw_global_anim_function != NULL)
+    gfx.draw_global_anim_function(DRAW_GLOBAL_ANIM_STAGE_1);
+
+  // copy global masked border to render target buffer, if defined
+  if (gfx.draw_global_border_function != NULL)
+    gfx.draw_global_border_function(DRAW_BORDER_TO_SCREEN);
+
+  // copy global animations to render target buffer, if defined (above border)
+  if (gfx.draw_global_anim_function != NULL)
+    gfx.draw_global_anim_function(DRAW_GLOBAL_ANIM_STAGE_2);
+}
+
 static void UpdateScreen(SDL_Rect *rect)
 {
   static unsigned int update_screen_delay = 0;
@@ -88,17 +103,7 @@ static void UpdateScreen(SDL_Rect *rect)
     BlitBitmap(backbuffer, gfx.final_screen_bitmap, 0, 0,
               gfx.win_xsize, gfx.win_ysize, 0, 0);
 
-    // copy global animations to render target buffer, if defined (below border)
-    if (gfx.draw_global_anim_function != NULL)
-      gfx.draw_global_anim_function(DRAW_GLOBAL_ANIM_STAGE_1);
-
-    // copy global masked border to render target buffer, if defined
-    if (gfx.draw_global_border_function != NULL)
-      gfx.draw_global_border_function(DRAW_BORDER_TO_SCREEN);
-
-    // copy global animations to render target buffer, if defined (above border)
-    if (gfx.draw_global_anim_function != NULL)
-      gfx.draw_global_anim_function(DRAW_GLOBAL_ANIM_STAGE_2);
+    FinalizeScreen();
 
     screen = gfx.final_screen_bitmap->surface;
 
@@ -145,17 +150,7 @@ static void UpdateScreen(SDL_Rect *rect)
 #endif
 
 #if !USE_FINAL_SCREEN_BITMAP
-  // copy global animations to render target buffer, if defined (below border)
-  if (gfx.draw_global_anim_function != NULL)
-    gfx.draw_global_anim_function(DRAW_GLOBAL_ANIM_STAGE_1);
-
-  // copy global masked border to render target buffer, if defined
-  if (gfx.draw_global_border_function != NULL)
-    gfx.draw_global_border_function(DRAW_BORDER_TO_SCREEN);
-
-  // copy global animations to render target buffer, if defined (above border)
-  if (gfx.draw_global_anim_function != NULL)
-    gfx.draw_global_anim_function(DRAW_GLOBAL_ANIM_STAGE_2);
+  FinalizeScreen();
 #endif
 
 #if USE_TARGET_TEXTURE
@@ -383,8 +378,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 +392,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,10 +420,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 boolean SDLCreateScreen(DrawBuffer **backbuffer, boolean fullscreen)
+static boolean SDLCreateScreen(boolean fullscreen)
 {
   SDL_Surface *new_surface = NULL;
 
@@ -605,21 +599,21 @@ static boolean SDLCreateScreen(DrawBuffer **backbuffer, boolean fullscreen)
     fullscreen_enabled = fullscreen;
 #endif
 
-  if (*backbuffer == NULL)
-    *backbuffer = CreateBitmapStruct();
+  if (backbuffer == NULL)
+    backbuffer = CreateBitmapStruct();
 
-  (*backbuffer)->width  = video.width;
-  (*backbuffer)->height = video.height;
+  backbuffer->width  = video.width;
+  backbuffer->height = video.height;
 
-  if ((*backbuffer)->surface)
-    SDL_FreeSurface((*backbuffer)->surface);
+  if (backbuffer->surface)
+    SDL_FreeSurface(backbuffer->surface);
 
-  (*backbuffer)->surface = new_surface;
+  backbuffer->surface = new_surface;
 
   return (new_surface != NULL);
 }
 
-boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen)
+boolean SDLSetVideoMode(boolean fullscreen)
 {
   boolean success = FALSE;
 
@@ -628,7 +622,7 @@ boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen)
   if (fullscreen && !video.fullscreen_enabled && video.fullscreen_available)
   {
     /* switch display to fullscreen mode, if available */
-    success = SDLCreateScreen(backbuffer, TRUE);
+    success = SDLCreateScreen(TRUE);
 
     if (!success)
     {
@@ -644,7 +638,7 @@ boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen)
   if ((!fullscreen && video.fullscreen_enabled) || !success)
   {
     /* switch display to window mode */
-    success = SDLCreateScreen(backbuffer, FALSE);
+    success = SDLCreateScreen(FALSE);
 
     if (!success)
     {
@@ -918,20 +912,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,