Date:2011-06-02 17:59:26 (12 years 9 months ago)
Author:Maarten ter Huurne
Commit:7dac306c16b0c089887d269fb497beda99035e13
Message: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.
Files: src/gmenu2x.cpp (1 diff)
src/surface.cpp (4 diffs)
src/surface.h (2 diffs)

Change Details

src/gmenu2x.cpp
277277        quit();
278278    }
279279
280    s = new Surface();
281#ifdef TARGET_GP2X
282    {
283        //I use a tmp variable to hide the cursor as soon as possible (and create the double buffer surface only after that)
284        //I'm forced to use SW surfaces since with HW there are issuse with changing the clock frequency
285        SDL_Surface *tmps = SDL_SetVideoMode(resX, resY, confInt["videoBpp"], SDL_SWSURFACE);
286        SDL_ShowCursor(0);
287        s->enableVirtualDoubleBuffer(tmps);
288    }
289#else
290    s->raw = SDL_SetVideoMode(resX, resY, confInt["videoBpp"], SDL_HWSURFACE|SDL_DOUBLEBUF);
291#endif
280    s = Surface::openOutputSurface(resX, resY, confInt["videoBpp"]);
292281
293282    bg = NULL;
294283    font = NULL;
src/surface.cpp
3737    return c;
3838}
3939
40Surface::Surface() {
41    raw = NULL;
42    dblbuffer = NULL;
40Surface *Surface::openOutputSurface(int width, int height, int bitsperpixel) {
41    SDL_ShowCursor(SDL_DISABLE);
42    SDL_Surface *raw = SDL_SetVideoMode(
43        width, height, bitsperpixel, SDL_HWSURFACE | SDL_DOUBLEBUF);
44    return raw ? new Surface(raw, false) : NULL;
45}
46
47Surface::Surface(SDL_Surface *raw_, bool freeWhenDone_)
48    : raw(raw_)
49    , freeWhenDone(freeWhenDone_)
50{
4351}
4452
4553Surface::Surface(Surface *s) {
46    dblbuffer = NULL;
4754    raw = SDL_DisplayFormat(s->raw);
4855    halfW = raw->w/2;
4956    halfH = raw->h/2;
...... 
5158
5259Surface::Surface(const string &img, const string &skin) {
5360    raw = NULL;
54    dblbuffer = NULL;
5561    load(img, skin);
5662    halfW = raw->w/2;
5763    halfH = raw->h/2;
...... 
6167    free();
6268}
6369
64void Surface::enableVirtualDoubleBuffer(SDL_Surface *surface) {
65    dblbuffer = surface;
66    raw = SDL_DisplayFormat(dblbuffer);
67}
68
6970void Surface::free() {
70    if (raw!=NULL) SDL_FreeSurface( raw );
71    if (dblbuffer!=NULL) SDL_FreeSurface( dblbuffer );
71    if (freeWhenDone) {
72        SDL_FreeSurface(raw);
73    }
7274}
7375
7476SDL_PixelFormat *Surface::format() {
...... 
9799}
98100
99101void Surface::flip() {
100    if (dblbuffer!=NULL) {
101        this->blit(dblbuffer,0,0);
102        SDL_Flip(dblbuffer);
103    } else {
104        SDL_Flip(raw);
105    }
102    SDL_Flip(raw);
106103}
107104
108105bool Surface::blit(SDL_Surface *destination, int x, int y, int w, int h, int a) {
src/surface.h
3939*/
4040class Surface {
4141public:
42    Surface();
42    static Surface *openOutputSurface(int width, int height, int bitsperpixel);
43
4344    Surface(Surface *s);
4445    Surface(const string &img, const string &skin="");
4546    ~Surface();
4647
47    void enableVirtualDoubleBuffer(SDL_Surface *surface);
48
4948    SDL_Surface *raw;
5049
5150    void free();
...... 
7473    int hline(Sint16, Sint16, Sint16, Uint8, Uint8, Uint8, Uint8);
7574
7675private:
76    Surface(SDL_Surface *raw, bool freeWhenDone);
7777    SDL_PixelFormat *format();
7878    void load(const string &img, const string &skin);
7979    bool blit(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
8080    bool blitCenter(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
8181    bool blitRight(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
8282
83    bool freeWhenDone;
8384    bool locked;
8485    int halfW, halfH;
85    SDL_Surface *dblbuffer;
8686};
8787
8888#endif

Archive Download the corresponding diff file



interactive