From 29f8c3af953c75aa427f3b144f703c6b9291e282 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 27 Sep 2002 13:05:54 +0000 Subject: made init_size in the SDL backend reentrant svn-id: r5022 --- backends/sdl/sdl-common.cpp | 44 +++++++++++++++++++++++++++++++------------- backends/sdl/sdl-common.h | 7 ++++--- backends/sdl/sdl.cpp | 22 ++++++++++++---------- backends/sdl/sdl_gl.cpp | 1 + 4 files changed, 48 insertions(+), 26 deletions(-) (limited to 'backends/sdl') diff --git a/backends/sdl/sdl-common.cpp b/backends/sdl/sdl-common.cpp index b27b5ee5c1..4808515490 100644 --- a/backends/sdl/sdl-common.cpp +++ b/backends/sdl/sdl-common.cpp @@ -69,21 +69,39 @@ void OSystem_SDL_Common::set_timer(int timer, int (*callback)(int)) { SDL_SetTimer(timer, (SDL_TimerCallback) callback); } +OSystem_SDL_Common::OSystem_SDL_Common() + : sdl_screen(0), SCREEN_WIDTH(0), SCREEN_HEIGHT(0), + _dirty_checksums(0), _current_shake_pos(0), _new_shake_pos(0) +{ + // allocate palette storage + _cur_pal = (SDL_Color*)calloc(sizeof(SDL_Color), 256); + + // allocate the dirty rect storage + _mouse_backup = (byte*)malloc(MAX_MOUSE_W * MAX_MOUSE_H * MAX_SCALING * 2); +} + +OSystem_SDL_Common::~OSystem_SDL_Common() +{ + if (_dirty_checksums) + free(_dirty_checksums); + free(_cur_pal); + free(_mouse_backup); +} + void OSystem_SDL_Common::init_size(uint w, uint h) { - //if (w != SCREEN_WIDTH && h != SCREEN_HEIGHT) - // error("320x200 is the only game resolution supported"); + + // Avoid redundant res changes + if (w == SCREEN_WIDTH && h == SCREEN_HEIGHT) + return; SCREEN_WIDTH = w; SCREEN_HEIGHT = h; CKSUM_NUM = (SCREEN_WIDTH*SCREEN_HEIGHT/(8*8)); - /* allocate palette, it needs to be persistent across - * driver changes, so i'll alloc it here */ - _cur_pal = (SDL_Color*)calloc(sizeof(SDL_Color), 256); - - dirty_rect_list = (SDL_Rect*)calloc(NUM_DIRTY_RECT, sizeof(SDL_Rect)); - _mouse_backup = (byte*)malloc(MAX_MOUSE_W * MAX_MOUSE_H * MAX_SCALING * 2); - dirty_checksums = (uint32*)calloc(CKSUM_NUM*2, sizeof(uint32)); + if (_dirty_checksums) + free(_dirty_checksums); + _dirty_checksums = (uint32*)calloc(CKSUM_NUM*2, sizeof(uint32)); + unload_gfx_mode(); load_gfx_mode(); #ifdef MACOSX // Work around a bug in OS X 10.1 related to OpenGL in windowed mode @@ -179,7 +197,7 @@ void OSystem_SDL_Common::add_dirty_rect(int x, int y, int w, int h) { if (num_dirty_rects == NUM_DIRTY_RECT) force_full = true; else { - SDL_Rect *r = &dirty_rect_list[num_dirty_rects++]; + SDL_Rect *r = &_dirty_rect_list[num_dirty_rects++]; /* Update the dirty region by 1 pixel for graphics drivers * that "smear" the screen */ @@ -206,7 +224,7 @@ void OSystem_SDL_Common::add_dirty_rect(int x, int y, int w, int h) { #define ROL(a,n) a = (a<<(n)) | (a>>(32-(n))) #define DOLINE(x) a ^= ((uint32*)buf)[0+(x)*(SCREEN_WIDTH/4)]; b ^= ((uint32*)buf)[1+(x)*(SCREEN_WIDTH/4)] void OSystem_SDL_Common::mk_checksums(const byte *buf) { - uint32 *sums = dirty_checksums; + uint32 *sums = _dirty_checksums; uint x,y; const uint last_x = (uint)SCREEN_WIDTH/8; const uint last_y = (uint)SCREEN_HEIGHT/8; @@ -255,7 +273,7 @@ void OSystem_SDL_Common::add_dirty_rgn_auto(const byte *buf) { into bigger ones in a simple way */ if (!force_full) { int x,y,w; - uint32 *ck = dirty_checksums; + uint32 *ck = _dirty_checksums; for(y=0; y!=SCREEN_HEIGHT/8; y++) { for(x=0; x!=SCREEN_WIDTH/8; x++,ck++) { @@ -278,7 +296,7 @@ void OSystem_SDL_Common::add_dirty_rgn_auto(const byte *buf) { } else { get_out:; /* Copy old checksums to new */ - memcpy(dirty_checksums + CKSUM_NUM, dirty_checksums, CKSUM_NUM * sizeof(uint32)); + memcpy(_dirty_checksums + CKSUM_NUM, _dirty_checksums, CKSUM_NUM * sizeof(uint32)); } } diff --git a/backends/sdl/sdl-common.h b/backends/sdl/sdl-common.h index 3da878a6e6..b6d0463359 100644 --- a/backends/sdl/sdl-common.h +++ b/backends/sdl/sdl-common.h @@ -133,9 +133,9 @@ protected: }; int SCREEN_WIDTH, SCREEN_HEIGHT, CKSUM_NUM; - SDL_Rect *dirty_rect_list; + SDL_Rect _dirty_rect_list[100]; int num_dirty_rects; - uint32 *dirty_checksums; + uint32 *_dirty_checksums; int scaling; @@ -165,7 +165,8 @@ protected: uint _palette_changed_first, _palette_changed_last; - OSystem_SDL_Common() : _current_shake_pos(0), _new_shake_pos(0) {} + OSystem_SDL_Common(); + virtual ~OSystem_SDL_Common(); void add_dirty_rgn_auto(const byte *buf); void mk_checksums(const byte *buf); diff --git a/backends/sdl/sdl.cpp b/backends/sdl/sdl.cpp index cf8c39b0a4..2b2ae1d115 100644 --- a/backends/sdl/sdl.cpp +++ b/backends/sdl/sdl.cpp @@ -27,6 +27,8 @@ class OSystem_SDL_Normal : public OSystem_SDL_Common { public: + OSystem_SDL_Normal() : sdl_tmpscreen(0), sdl_hwscreen(0) {} + // Set colors of the palette void set_palette(const byte *colors, uint start, uint num); @@ -337,10 +339,10 @@ void OSystem_SDL_Normal::update_screen() { if (force_full) { num_dirty_rects = 1; - dirty_rect_list[0].x = 0; - dirty_rect_list[0].y = 0; - dirty_rect_list[0].w = SCREEN_WIDTH; - dirty_rect_list[0].h = SCREEN_HEIGHT; + _dirty_rect_list[0].x = 0; + _dirty_rect_list[0].y = 0; + _dirty_rect_list[0].w = SCREEN_WIDTH; + _dirty_rect_list[0].h = SCREEN_HEIGHT; } // Only draw anything if necessary @@ -348,12 +350,12 @@ void OSystem_SDL_Normal::update_screen() { SDL_Rect *r; uint32 srcPitch, dstPitch; - SDL_Rect *last_rect = dirty_rect_list + num_dirty_rects; + SDL_Rect *last_rect = _dirty_rect_list + num_dirty_rects; // Convert appropriate parts of the 8bpp image into 16bpp if (!_overlay_visible) { SDL_Rect dst; - for(r=dirty_rect_list; r!=last_rect; ++r) { + for(r=_dirty_rect_list; r!=last_rect; ++r) { dst = *r; dst.x++; // Shift rect by one since 2xSai needs to acces the data around dst.y++; // any pixel to scale it, and we want to avoid mem access crashes. @@ -368,7 +370,7 @@ void OSystem_SDL_Normal::update_screen() { srcPitch = sdl_tmpscreen->pitch; dstPitch = sdl_hwscreen->pitch; - for(r=dirty_rect_list; r!=last_rect; ++r) { + for(r=_dirty_rect_list; r!=last_rect; ++r) { register int dst_y = r->y + _current_shake_pos; register int dst_h = 0; if (dst_y < SCREEN_HEIGHT) { @@ -389,8 +391,8 @@ void OSystem_SDL_Normal::update_screen() { } if (force_full) { - dirty_rect_list[0].y = 0; - dirty_rect_list[0].h = SCREEN_HEIGHT * scaling; + _dirty_rect_list[0].y = 0; + _dirty_rect_list[0].h = SCREEN_HEIGHT * scaling; } SDL_UnlockSurface(sdl_tmpscreen); @@ -399,7 +401,7 @@ void OSystem_SDL_Normal::update_screen() { if (num_dirty_rects > 0) { /* Finally, blit all our changes to the screen */ - SDL_UpdateRects(sdl_hwscreen, num_dirty_rects, dirty_rect_list); + SDL_UpdateRects(sdl_hwscreen, num_dirty_rects, _dirty_rect_list); } num_dirty_rects = 0; diff --git a/backends/sdl/sdl_gl.cpp b/backends/sdl/sdl_gl.cpp index 00d0947f32..9e6e0f8e72 100644 --- a/backends/sdl/sdl_gl.cpp +++ b/backends/sdl/sdl_gl.cpp @@ -141,6 +141,7 @@ void OSystem_SDL_GL::update_screen() { _palette_changed_last = 0; } + // FIXME - this seems to be tied to 320x200 - what about Zak256 which needs 320x240 ? fb2gl.update(sdl_screen->pixels,320,200,320,0,_current_shake_pos); } -- cgit v1.2.3