diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 06f75b5..e2424ea 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -277,18 +277,7 @@ GMenu2X::GMenu2X() { quit(); } - s = new Surface(); -#ifdef TARGET_GP2X - { - //I use a tmp variable to hide the cursor as soon as possible (and create the double buffer surface only after that) - //I'm forced to use SW surfaces since with HW there are issuse with changing the clock frequency - SDL_Surface *tmps = SDL_SetVideoMode(resX, resY, confInt["videoBpp"], SDL_SWSURFACE); - SDL_ShowCursor(0); - s->enableVirtualDoubleBuffer(tmps); - } -#else - s->raw = SDL_SetVideoMode(resX, resY, confInt["videoBpp"], SDL_HWSURFACE|SDL_DOUBLEBUF); -#endif + s = Surface::openOutputSurface(resX, resY, confInt["videoBpp"]); bg = NULL; font = NULL; diff --git a/src/surface.cpp b/src/surface.cpp index 20808b8..52bcfc3 100644 --- a/src/surface.cpp +++ b/src/surface.cpp @@ -37,13 +37,20 @@ RGBAColor strtorgba(const string &strColor) { return c; } -Surface::Surface() { - raw = NULL; - dblbuffer = NULL; +Surface *Surface::openOutputSurface(int width, int height, int bitsperpixel) { + SDL_ShowCursor(SDL_DISABLE); + SDL_Surface *raw = SDL_SetVideoMode( + width, height, bitsperpixel, SDL_HWSURFACE | SDL_DOUBLEBUF); + return raw ? new Surface(raw, false) : NULL; +} + +Surface::Surface(SDL_Surface *raw_, bool freeWhenDone_) + : raw(raw_) + , freeWhenDone(freeWhenDone_) +{ } Surface::Surface(Surface *s) { - dblbuffer = NULL; raw = SDL_DisplayFormat(s->raw); halfW = raw->w/2; halfH = raw->h/2; @@ -51,7 +58,6 @@ Surface::Surface(Surface *s) { Surface::Surface(const string &img, const string &skin) { raw = NULL; - dblbuffer = NULL; load(img, skin); halfW = raw->w/2; halfH = raw->h/2; @@ -61,14 +67,10 @@ Surface::~Surface() { free(); } -void Surface::enableVirtualDoubleBuffer(SDL_Surface *surface) { - dblbuffer = surface; - raw = SDL_DisplayFormat(dblbuffer); -} - void Surface::free() { - if (raw!=NULL) SDL_FreeSurface( raw ); - if (dblbuffer!=NULL) SDL_FreeSurface( dblbuffer ); + if (freeWhenDone) { + SDL_FreeSurface(raw); + } } SDL_PixelFormat *Surface::format() { @@ -97,12 +99,7 @@ void Surface::load(const string &img, const string &skin) { } void Surface::flip() { - if (dblbuffer!=NULL) { - this->blit(dblbuffer,0,0); - SDL_Flip(dblbuffer); - } else { - SDL_Flip(raw); - } + SDL_Flip(raw); } bool Surface::blit(SDL_Surface *destination, int x, int y, int w, int h, int a) { diff --git a/src/surface.h b/src/surface.h index 98fbdcc..4785ccb 100644 --- a/src/surface.h +++ b/src/surface.h @@ -39,13 +39,12 @@ RGBAColor strtorgba(const string &strColor); */ class Surface { public: - Surface(); + static Surface *openOutputSurface(int width, int height, int bitsperpixel); + Surface(Surface *s); Surface(const string &img, const string &skin=""); ~Surface(); - void enableVirtualDoubleBuffer(SDL_Surface *surface); - SDL_Surface *raw; void free(); @@ -74,15 +73,16 @@ public: int hline(Sint16, Sint16, Sint16, Uint8, Uint8, Uint8, Uint8); private: + Surface(SDL_Surface *raw, bool freeWhenDone); SDL_PixelFormat *format(); void load(const string &img, const string &skin); bool blit(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1); bool blitCenter(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1); bool blitRight(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1); + bool freeWhenDone; bool locked; int halfW, halfH; - SDL_Surface *dblbuffer; }; #endif