mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-29 13:09:43 +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();
|
quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
s = new Surface();
|
s = Surface::openOutputSurface(resX, resY, confInt["videoBpp"]);
|
||||||
#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
|
|
||||||
|
|
||||||
bg = NULL;
|
bg = NULL;
|
||||||
font = NULL;
|
font = NULL;
|
||||||
|
@ -37,13 +37,20 @@ RGBAColor strtorgba(const string &strColor) {
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
Surface::Surface() {
|
Surface *Surface::openOutputSurface(int width, int height, int bitsperpixel) {
|
||||||
raw = NULL;
|
SDL_ShowCursor(SDL_DISABLE);
|
||||||
dblbuffer = NULL;
|
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) {
|
Surface::Surface(Surface *s) {
|
||||||
dblbuffer = NULL;
|
|
||||||
raw = SDL_DisplayFormat(s->raw);
|
raw = SDL_DisplayFormat(s->raw);
|
||||||
halfW = raw->w/2;
|
halfW = raw->w/2;
|
||||||
halfH = raw->h/2;
|
halfH = raw->h/2;
|
||||||
@ -51,7 +58,6 @@ Surface::Surface(Surface *s) {
|
|||||||
|
|
||||||
Surface::Surface(const string &img, const string &skin) {
|
Surface::Surface(const string &img, const string &skin) {
|
||||||
raw = NULL;
|
raw = NULL;
|
||||||
dblbuffer = NULL;
|
|
||||||
load(img, skin);
|
load(img, skin);
|
||||||
halfW = raw->w/2;
|
halfW = raw->w/2;
|
||||||
halfH = raw->h/2;
|
halfH = raw->h/2;
|
||||||
@ -61,14 +67,10 @@ Surface::~Surface() {
|
|||||||
free();
|
free();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Surface::enableVirtualDoubleBuffer(SDL_Surface *surface) {
|
|
||||||
dblbuffer = surface;
|
|
||||||
raw = SDL_DisplayFormat(dblbuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Surface::free() {
|
void Surface::free() {
|
||||||
if (raw!=NULL) SDL_FreeSurface( raw );
|
if (freeWhenDone) {
|
||||||
if (dblbuffer!=NULL) SDL_FreeSurface( dblbuffer );
|
SDL_FreeSurface(raw);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_PixelFormat *Surface::format() {
|
SDL_PixelFormat *Surface::format() {
|
||||||
@ -97,13 +99,8 @@ void Surface::load(const string &img, const string &skin) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Surface::flip() {
|
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) {
|
bool Surface::blit(SDL_Surface *destination, int x, int y, int w, int h, int a) {
|
||||||
if (destination == NULL || a==0) return false;
|
if (destination == NULL || a==0) return false;
|
||||||
|
@ -39,13 +39,12 @@ RGBAColor strtorgba(const string &strColor);
|
|||||||
*/
|
*/
|
||||||
class Surface {
|
class Surface {
|
||||||
public:
|
public:
|
||||||
Surface();
|
static Surface *openOutputSurface(int width, int height, int bitsperpixel);
|
||||||
|
|
||||||
Surface(Surface *s);
|
Surface(Surface *s);
|
||||||
Surface(const string &img, const string &skin="");
|
Surface(const string &img, const string &skin="");
|
||||||
~Surface();
|
~Surface();
|
||||||
|
|
||||||
void enableVirtualDoubleBuffer(SDL_Surface *surface);
|
|
||||||
|
|
||||||
SDL_Surface *raw;
|
SDL_Surface *raw;
|
||||||
|
|
||||||
void free();
|
void free();
|
||||||
@ -74,15 +73,16 @@ public:
|
|||||||
int hline(Sint16, Sint16, Sint16, Uint8, Uint8, Uint8, Uint8);
|
int hline(Sint16, Sint16, Sint16, Uint8, Uint8, Uint8, Uint8);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Surface(SDL_Surface *raw, bool freeWhenDone);
|
||||||
SDL_PixelFormat *format();
|
SDL_PixelFormat *format();
|
||||||
void load(const string &img, const string &skin);
|
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 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 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 blitRight(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
|
||||||
|
|
||||||
|
bool freeWhenDone;
|
||||||
bool locked;
|
bool locked;
|
||||||
int halfW, halfH;
|
int halfW, halfH;
|
||||||
SDL_Surface *dblbuffer;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user