Author: cazfi
Date: Thu Feb 19 19:28:14 2015
New Revision: 28216

URL: http://svn.gna.org/viewcvs/freeciv?rev=28216&view=rev
Log:
Made main surface private to graphics.c module in sdl2-client

See patch #5826

Modified:
    trunk/client/gui-sdl2/graphics.c
    trunk/client/gui-sdl2/graphics.h
    trunk/client/gui-sdl2/gui_mouse.c
    trunk/client/gui-sdl2/mapview.c
    trunk/client/gui-sdl2/widget.c

Modified: trunk/client/gui-sdl2/graphics.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/graphics.c?rev=28216&r1=28215&r2=28216&view=diff
==============================================================================
--- trunk/client/gui-sdl2/graphics.c    (original)
+++ trunk/client/gui-sdl2/graphics.c    Thu Feb 19 19:28:14 2015
@@ -54,6 +54,8 @@
 
 struct main Main;
 
+static SDL_Surface *main_surface;
+
 /**************************************************************************
   Allocate new gui_layer.
 **************************************************************************/
@@ -199,6 +201,15 @@
 }
 
 /**************************************************************************
+  Execute alphablit to the main surface
+**************************************************************************/
+int screen_blit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Rect *dstrect,
+                unsigned char alpha_mod)
+{
+  return alphablit(src, srcrect, main_surface, dstrect, alpha_mod);
+}
+
+/**************************************************************************
   Create new surface (pRect->w x pRect->h size) and copy pRect area of
   pSource.
   if pRect == NULL then create copy of entire pSource.
@@ -360,24 +371,32 @@
    create an surface with format
    MUST NOT BE USED IF NO SDLSCREEN IS SET
 **************************************************************************/
-SDL_Surface *create_surf_with_format(SDL_PixelFormat *pSpf,
-                                     int iWidth, int iHeight,
-                                     Uint32 iFlags)
-{
-  SDL_Surface *pSurf = SDL_CreateRGBSurface(iFlags, iWidth, iHeight,
-                                            pSpf->BitsPerPixel,
-                                            pSpf->Rmask,
-                                            pSpf->Gmask,
-                                            pSpf->Bmask, pSpf->Amask);
-
-  if (!pSurf) {
+SDL_Surface *create_surf_with_format(SDL_PixelFormat *pf,
+                                     int width, int height,
+                                     Uint32 flags)
+{
+  SDL_Surface *surf = SDL_CreateRGBSurface(flags, width, height,
+                                           pf->BitsPerPixel,
+                                           pf->Rmask,
+                                           pf->Gmask,
+                                           pf->Bmask, pf->Amask);
+
+  if (surf == NULL) {
     log_error(_("Unable to create Sprite (Surface) of size "
                 "%d x %d %d Bits in format %d"),
-              iWidth, iHeight, pSpf->BitsPerPixel, iFlags);
+              width, height, pf->BitsPerPixel, flags);
     return NULL;
   }
 
-  return pSurf;
+  return surf;
+}
+
+/**************************************************************************
+  Create surface with the same format as main window
+**************************************************************************/
+SDL_Surface *create_surf(int width, int height, Uint32 flags)
+{
+  return create_surf_with_format(main_surface->format, width, height, flags);
 }
 
 /**************************************************************************
@@ -623,7 +642,7 @@
                                  iWidth, iHeight,
                                  0);
 
-  Main.mainsurf = SDL_CreateRGBSurface(0, iWidth, iHeight, 32,
+  main_surface = SDL_CreateRGBSurface(0, iWidth, iHeight, 32,
 #if SDL_BYTEORDER != SDL_LIL_ENDIAN
                 0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF
 #else
@@ -717,10 +736,26 @@
 void update_main_screen(void)
 {
   SDL_UpdateTexture(Main.maintext, NULL,
-                    Main.mainsurf->pixels, Main.mainsurf->pitch);
+                    main_surface->pixels, main_surface->pitch);
   SDL_RenderClear(Main.renderer);
   SDL_RenderCopy(Main.renderer, Main.maintext, NULL, NULL);
   SDL_RenderPresent(Main.renderer);
+}
+
+/**************************************************************************
+  Return width of the main window
+**************************************************************************/
+int main_window_width(void)
+{
+  return main_surface->w;
+}
+
+/**************************************************************************
+  Return height of the main window
+**************************************************************************/
+int main_window_height(void)
+{
+  return main_surface->h;
 }
 
 /**************************************************************************

Modified: trunk/client/gui-sdl2/graphics.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/graphics.h?rev=28216&r1=28215&r2=28216&view=diff
==============================================================================
--- trunk/client/gui-sdl2/graphics.h    (original)
+++ trunk/client/gui-sdl2/graphics.h    Thu Feb 19 19:28:14 2015
@@ -190,7 +190,6 @@
   int guis_count;              /* gui buffers array counter */
   SDL_Rect rects[RECT_LIMIT];  /* update rect. list */
   SDL_Window *screen;           /* main screen buffer */
-  SDL_Surface *mainsurf;
   SDL_Surface *map;            /* map buffer */
   SDL_Surface *dummy;           /* dummy surface for missing sprites */
   SDL_Texture *maintext;
@@ -226,12 +225,15 @@
 int alphablit(SDL_Surface *src, SDL_Rect *srcrect,
               SDL_Surface *dst, SDL_Rect *dstrect,
               unsigned char alpha_mod);
+int screen_blit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Rect *dstrect,
+                unsigned char alpha_mod);
 
 SDL_Surface *load_surf(const char *pFname);
 SDL_Surface *load_surf_with_flags(const char *pFname, int iFlags);
 
-SDL_Surface *create_surf_with_format(SDL_PixelFormat *pSpf,
-                                     int w, int h, Uint32 f);
+SDL_Surface *create_surf_with_format(SDL_PixelFormat *pf,
+                                     int width, int height, Uint32 flags);
+SDL_Surface *create_surf(int width, int height, Uint32 flags);
 
 SDL_Surface *create_filled_surface(Uint16 w, Uint16 h, Uint32 iFlags,
                                    SDL_Color *pColor);
@@ -289,8 +291,8 @@
 
 void update_main_screen(void);
 
-#define main_window_width() Main.mainsurf->w
-#define main_window_height() Main.mainsurf->h
+int main_window_width(void);
+int main_window_height(void);
 
 /* Rect */
 bool correct_rect_region(SDL_Rect *pRect);
@@ -312,9 +314,6 @@
 
 SDL_Surface *crop_visible_part_from_surface(SDL_Surface *pSrc);
 SDL_Rect get_smaller_surface_rect(SDL_Surface *pSrc);
-
-#define create_surf(w, h, f) \
-  create_surf_with_format(Main.mainsurf->format, w , h, f)
 
 #define map_rgba(format, color) \
   SDL_MapRGBA(format, (color).r, (color).g, (color).b, (color).a)

Modified: trunk/client/gui-sdl2/gui_mouse.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/gui_mouse.c?rev=28216&r1=28215&r2=28216&view=diff
==============================================================================
--- trunk/client/gui-sdl2/gui_mouse.c   (original)
+++ trunk/client/gui-sdl2/gui_mouse.c   Thu Feb 19 19:28:14 2015
@@ -113,7 +113,7 @@
       area.h = current_color_cursor.cursor->h;
 
       /* show cursor */
-      alphablit(current_color_cursor.cursor, NULL, Main.mainsurf, &area, 255);
+      screen_blit(current_color_cursor.cursor, NULL, &area, 255);
       /* update screen */
       update_main_screen();
 #if 0

Modified: trunk/client/gui-sdl2/mapview.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/mapview.c?rev=28216&r1=28215&r2=28216&view=diff
==============================================================================
--- trunk/client/gui-sdl2/mapview.c     (original)
+++ trunk/client/gui-sdl2/mapview.c     Thu Feb 19 19:28:14 2015
@@ -116,13 +116,13 @@
       if (C_S_RUNNING == client_state()) {
         flush_mapcanvas(dst.x, dst.y, dst.w, dst.h);
       }
-      alphablit(Main.map, rect, Main.mainsurf, &dst, 255);
+      screen_blit(Main.map, rect, &dst, 255);
       if (Main.guis) {
         while ((i < Main.guis_count) && Main.guis[i]) {
           src = *rect;
           screen_rect_to_layer_rect(Main.guis[i], &src);
           dst = *rect;
-          alphablit(Main.guis[i++]->surface, &src, Main.mainsurf, &dst, 255);
+          screen_blit(Main.guis[i++]->surface, &src, &dst, 255);
         }
       }
       i = 0;
@@ -228,12 +228,12 @@
       flush_mapcanvas(0, 0, main_window_width(), main_window_height());
       refresh_overview();
     }
-    alphablit(Main.map, NULL, Main.mainsurf, NULL, 255);
+    screen_blit(Main.map, NULL, NULL, 255);
     if (Main.guis) {
       while((j < Main.guis_count) && Main.guis[j]) {
         SDL_Rect dst = Main.guis[j]->dest_rect;
 
-        alphablit(Main.guis[j++]->surface, NULL, Main.mainsurf, &dst, 255);
+        screen_blit(Main.guis[j++]->surface, NULL, &dst, 255);
       }
     }
     j = 0;
@@ -252,14 +252,14 @@
       if (C_S_RUNNING == client_state()) {
         flush_mapcanvas(dst.x, dst.y, dst.w, dst.h);
       }
-      alphablit(Main.map, &Main.rects[i], Main.mainsurf, &dst, 255);
+      screen_blit(Main.map, &Main.rects[i], &dst, 255);
 
       if (Main.guis) {
         while ((j < Main.guis_count) && Main.guis[j]) {
           src = Main.rects[i];
           screen_rect_to_layer_rect(Main.guis[j], &src);
           dst = Main.rects[i];
-          alphablit(Main.guis[j++]->surface, &src, Main.mainsurf, &dst, 255);
+          screen_blit(Main.guis[j++]->surface, &src, &dst, 255);
         }
       }
       j = 0;

Modified: trunk/client/gui-sdl2/widget.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/widget.c?rev=28216&r1=28215&r2=28216&view=diff
==============================================================================
--- trunk/client/gui-sdl2/widget.c      (original)
+++ trunk/client/gui-sdl2/widget.c      Thu Feb 19 19:28:14 2015
@@ -541,9 +541,9 @@
     srcrect.w = MIN((pInfo_Area->x + pInfo_Area->w), (rect->x + rect->w)) - 
dstrect.x;
     srcrect.h = MIN((pInfo_Area->y + pInfo_Area->h), (rect->y + rect->h)) - 
dstrect.y;
 
-    alphablit(info_label, &srcrect, Main.mainsurf, &dstrect, 255);
+    screen_blit(info_label, &srcrect, &dstrect, 255);
   } else {
-    alphablit(info_label, NULL, Main.mainsurf, pInfo_Area, 255);
+    screen_blit(info_label, NULL, pInfo_Area, 255);
   }
 
   if (correct_rect_region(pInfo_Area)) {


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to