rnd-20131212-1-src
[rocksndiamonds.git] / src / libgame / sdl.c
index 26cc7a7b103076df0c2d228ad8041f54744c506d..c7a2b1171561546dd2a9c5f4739283627dd48196 100644 (file)
@@ -26,8 +26,8 @@
 
 /* SDL internal variables */
 #if defined(TARGET_SDL2)
-// static SDL_Window *sdl_window = NULL;
-SDL_Window *sdl_window = NULL;
+static SDL_Window *sdl_window = NULL;
+// SDL_Window *sdl_window = NULL;
 // static SDL_Renderer *sdl_renderer = NULL;
 #endif
 
@@ -244,13 +244,20 @@ void SDLInitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window,
     }
   }
 
+#if 0
   /* set window icon */
   SDLSetWindowIcon(program.sdl_icon_filename);
+#endif
 
   /* open SDL video output device (window or fullscreen mode) */
   if (!SDLSetVideoMode(backbuffer, fullscreen))
     Error(ERR_EXIT, "setting video mode failed");
 
+#if 1
+  /* set window icon */
+  SDLSetWindowIcon(program.sdl_icon_filename);
+#endif
+
   /* set window and icon title */
 #if defined(TARGET_SDL2)
   SDL_SetWindowTitle(sdl_window, program.window_title);
@@ -470,7 +477,10 @@ void SDLCopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap,
 
 #if defined(TARGET_SDL2)
   if (dst_bitmap == window)
-    SDL_UpdateWindowSurface(sdl_window);
+  {
+    // SDL_UpdateWindowSurface(sdl_window);
+    SDL_UpdateWindowSurfaceRects(sdl_window, &dst_rect, 1);
+  }
 #else
   if (dst_bitmap == window)
     SDL_UpdateRect(backbuffer->surface, dst_x, dst_y, width, height);
@@ -498,7 +508,10 @@ void SDLFillRectangle(Bitmap *dst_bitmap, int x, int y, int width, int height,
 
 #if defined(TARGET_SDL2)
   if (dst_bitmap == window)
-    SDL_UpdateWindowSurface(sdl_window);
+  {
+    // SDL_UpdateWindowSurface(sdl_window);
+    SDL_UpdateWindowSurfaceRects(sdl_window, &rect, 1);
+  }
 #else
   if (dst_bitmap == window)
     SDL_UpdateRect(backbuffer->surface, x, y, width, height);
@@ -516,6 +529,9 @@ void SDLFadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height,
   SDL_Surface *surface_screen = backbuffer->surface;
   SDL_Surface *surface_cross = (bitmap_cross ? bitmap_cross->surface : NULL);
   SDL_Rect src_rect, dst_rect;
+#if defined(TARGET_SDL2)
+  SDL_Rect dst_rect2;
+#endif
   int src_x = x, src_y = y;
   int dst_x = x, dst_y = y;
   unsigned int time_last, time_current;
@@ -544,6 +560,10 @@ void SDLFadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height,
   dst_rect.w = width;          /* (ignored) */
   dst_rect.h = height;         /* (ignored) */
 
+#if defined(TARGET_SDL2)
+  dst_rect2 = dst_rect;
+#endif
+
   if (initialization_needed)
   {
 #if defined(TARGET_SDL2)
@@ -739,7 +759,8 @@ void SDLFadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height,
          draw_border_function();
 
 #if defined(TARGET_SDL2)
-       SDL_UpdateWindowSurface(sdl_window);
+       // SDL_UpdateWindowSurface(sdl_window);
+       SDL_UpdateWindowSurfaceRects(sdl_window, &dst_rect2, 1);
 #else
        SDL_UpdateRect(surface_screen, dst_x, dst_y, width, height);
 #endif
@@ -776,7 +797,8 @@ void SDLFadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height,
 #if 1
       /* only update the region of the screen that is affected from fading */
 #if defined(TARGET_SDL2)
-      SDL_UpdateWindowSurface(sdl_window);
+      // SDL_UpdateWindowSurface(sdl_window);
+      SDL_UpdateWindowSurfaceRects(sdl_window, &dst_rect, 1);
 #else
       SDL_UpdateRect(surface_screen, dst_x, dst_y, width, height);
 #endif
@@ -1788,6 +1810,10 @@ Bitmap *SDLLoadImage(char *filename)
   Bitmap *new_bitmap = CreateBitmapStruct();
   SDL_Surface *sdl_image_tmp;
 
+  print_timestamp_init("SDLLoadImage");
+
+  print_timestamp_time(getBaseNamePtr(filename));
+
   /* load image to temporary surface */
   if ((sdl_image_tmp = IMG_Load(filename)) == NULL)
   {
@@ -1796,6 +1822,8 @@ Bitmap *SDLLoadImage(char *filename)
     return NULL;
   }
 
+  print_timestamp_time("IMG_Load");
+
   UPDATE_BUSY_STATE();
 
   /* create native non-transparent surface for current image */
@@ -1806,6 +1834,8 @@ Bitmap *SDLLoadImage(char *filename)
     return NULL;
   }
 
+  print_timestamp_time("SDL_DisplayFormat (opaque)");
+
   UPDATE_BUSY_STATE();
 
   /* create native transparent surface for current image */
@@ -1818,6 +1848,8 @@ Bitmap *SDLLoadImage(char *filename)
     return NULL;
   }
 
+  print_timestamp_time("SDL_DisplayFormat (masked)");
+
   UPDATE_BUSY_STATE();
 
   /* free temporary surface */
@@ -1826,6 +1858,8 @@ Bitmap *SDLLoadImage(char *filename)
   new_bitmap->width = new_bitmap->surface->w;
   new_bitmap->height = new_bitmap->surface->h;
 
+  print_timestamp_done("SDLLoadImage");
+
   return new_bitmap;
 }