mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-25 17:53:07 +02:00
Surface: Removed fake double buffering.
Use real double buffering instead. I checked the SDL code and if the hardware cannot provide double buffering it will use a shadow surface to ensure that a frame is not displayed until it has been fully painted. Also disable mouse cursor before opening the output surface. The reason it was disabled after the surface was opened is that SDL on GP2X has a bug. However, this means the cursor is visible for a short time during startup which looks ugly.
This commit is contained in:
parent
5b6d922f11
commit
7dac306c16
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user