From: Holger Schemel Date: Thu, 3 Apr 2003 22:13:16 +0000 (+0200) Subject: rnd-20030404-1-src X-Git-Tag: 3.0.0^2~115 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=34ed45c14d923459972fecf7a3b46f44d7e03670;p=rocksndiamonds.git rnd-20030404-1-src --- diff --git a/src/conftime.h b/src/conftime.h index d0a15b16..ec91edc0 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2003-04-03 23:55]" +#define COMPILE_DATE_STRING "[2003-04-04 00:11]" diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 635816c7..9403b2a7 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -172,6 +172,34 @@ inline boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen) return success; } +inline void SDLCreateBitmapContent(Bitmap *new_bitmap, + int width, int height, int depth) +{ + SDL_Surface *surface_tmp, *surface_native; + + if ((surface_tmp = SDL_CreateRGBSurface(SURFACE_FLAGS, width, height, depth, + 0, 0, 0, 0)) + == NULL) + Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError()); + + if ((surface_native = SDL_DisplayFormat(surface_tmp)) == NULL) + Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError()); + + SDL_FreeSurface(surface_tmp); + + new_bitmap->surface = surface_native; +} + +inline void SDLFreeBitmapPointers(Bitmap *bitmap) +{ + if (bitmap->surface) + SDL_FreeSurface(bitmap->surface); + if (bitmap->surface_masked) + SDL_FreeSurface(bitmap->surface_masked); + bitmap->surface = NULL; + bitmap->surface_masked = NULL; +} + inline void SDLCopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap, int src_x, int src_y, int width, int height, diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index 528b763a..d574cd6b 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -324,6 +324,8 @@ struct XY inline void SDLInitVideoDisplay(void); inline void SDLInitVideoBuffer(DrawBuffer **, DrawWindow **, boolean); inline boolean SDLSetVideoMode(DrawBuffer **, boolean); +inline void SDLCreateBitmapContent(Bitmap *, int, int, int); +inline void SDLFreeBitmapPointers(Bitmap *); inline void SDLCopyArea(Bitmap *, Bitmap *, int, int, int, int, int, int, int); inline void SDLFillRectangle(Bitmap *, int, int, int, int, Uint32); inline void SDLDrawSimpleLine(Bitmap *, int, int, int, int, Uint32); diff --git a/src/libgame/system.c b/src/libgame/system.c index 680ff2d5..8e432101 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -311,7 +311,6 @@ inline void CloseVideoDisplay(void) #if defined(TARGET_SDL) SDL_QuitSubSystem(SDL_INIT_VIDEO); #else - if (display) XCloseDisplay(display); #endif @@ -349,36 +348,9 @@ inline Bitmap *CreateBitmap(int width, int height, int depth) int real_depth = GetRealDepth(depth); #ifdef TARGET_SDL - SDL_Surface *surface_tmp, *surface_native; - - if ((surface_tmp = SDL_CreateRGBSurface(SURFACE_FLAGS, width, height, - real_depth, 0, 0, 0, 0)) - == NULL) - Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError()); - - if ((surface_native = SDL_DisplayFormat(surface_tmp)) == NULL) - Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError()); - - SDL_FreeSurface(surface_tmp); - - new_bitmap->surface = surface_native; + SDLCreateBitmapContent(new_bitmap, width, height, real_depth); #else - Pixmap pixmap; - - if ((pixmap = XCreatePixmap(display, window->drawable, - width, height, real_depth)) - == None) - Error(ERR_EXIT, "cannot create pixmap"); - - new_bitmap->drawable = pixmap; - - if (window == NULL) - Error(ERR_EXIT, "Window GC needed for Bitmap -- create Window first"); - - new_bitmap->gc = window->gc; - - new_bitmap->line_gc[0] = window->line_gc[0]; - new_bitmap->line_gc[1] = window->line_gc[1]; + X11CreateBitmapContent(new_bitmap, width, height, real_depth); #endif new_bitmap->width = width; @@ -393,28 +365,9 @@ inline static void FreeBitmapPointers(Bitmap *bitmap) return; #ifdef TARGET_SDL - if (bitmap->surface) - SDL_FreeSurface(bitmap->surface); - if (bitmap->surface_masked) - SDL_FreeSurface(bitmap->surface_masked); - bitmap->surface = NULL; - bitmap->surface_masked = NULL; + SDLFreeBitmapPointers(bitmap); #else - /* The X11 version seems to have a memory leak here -- although - "XFreePixmap()" is called, the corresponding memory seems not - to be freed (according to "ps"). The SDL version apparently - does not have this problem. */ - - if (bitmap->drawable) - XFreePixmap(display, bitmap->drawable); - if (bitmap->clip_mask) - XFreePixmap(display, bitmap->clip_mask); - if (bitmap->stored_clip_gc) - XFreeGC(display, bitmap->stored_clip_gc); - /* the other GCs are only pointers to GCs used elsewhere */ - bitmap->drawable = None; - bitmap->clip_mask = None; - bitmap->stored_clip_gc = None; + X11FreeBitmapPointers(bitmap); #endif if (bitmap->source_filename) diff --git a/src/libgame/x11.c b/src/libgame/x11.c index f93b2cdb..907b9f71 100644 --- a/src/libgame/x11.c +++ b/src/libgame/x11.c @@ -327,6 +327,45 @@ Bitmap *X11LoadImage(char *filename) return new_bitmap; } +inline void X11CreateBitmapContent(Bitmap *new_bitmap, + int width, int height, int depth) +{ + Pixmap pixmap; + + if ((pixmap = XCreatePixmap(display, window->drawable, width, height, depth)) + == None) + Error(ERR_EXIT, "cannot create pixmap"); + + new_bitmap->drawable = pixmap; + + if (window == NULL) + Error(ERR_EXIT, "Window GC needed for Bitmap -- create Window first"); + + new_bitmap->gc = window->gc; + + new_bitmap->line_gc[0] = window->line_gc[0]; + new_bitmap->line_gc[1] = window->line_gc[1]; +} + +inline void X11FreeBitmapPointers(Bitmap *bitmap) +{ + /* The X11 version seems to have a memory leak here -- although + "XFreePixmap()" is called, the corresponding memory seems not + to be freed (according to "ps"). The SDL version apparently + does not have this problem. */ + + if (bitmap->drawable) + XFreePixmap(display, bitmap->drawable); + if (bitmap->clip_mask) + XFreePixmap(display, bitmap->clip_mask); + if (bitmap->stored_clip_gc) + XFreeGC(display, bitmap->stored_clip_gc); + /* the other GCs are only pointers to GCs used elsewhere */ + bitmap->drawable = None; + bitmap->clip_mask = None; + bitmap->stored_clip_gc = None; +} + inline void X11CopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap, int src_x, int src_y, int width, int height, int dst_x, int dst_y, int mask_mode) diff --git a/src/libgame/x11.h b/src/libgame/x11.h index b0a50365..bce8ea69 100644 --- a/src/libgame/x11.h +++ b/src/libgame/x11.h @@ -308,6 +308,8 @@ inline void X11InitVideoBuffer(DrawBuffer **, DrawWindow **); void X11ZoomBitmap(Bitmap *, Bitmap *); Bitmap *X11LoadImage(char *); +inline void X11CreateBitmapContent(Bitmap *, int, int, int); +inline void X11FreeBitmapPointers(Bitmap *); inline void X11CopyArea(Bitmap *, Bitmap *, int, int, int, int, int, int, int); inline void X11FillRectangle(Bitmap *, int, int, int, int, Pixel); inline Pixel X11GetPixel(Bitmap *, int, int);