[AD] X-windows screen updates

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Tom Fjellstrom wrote :

> If you only use the XWindow driver then allegro
> is bound to be slow as it internally uses a double buffer
> system to update the Window.

It made me realized that double-buffering is not useful under X-windows
since it already uses one internally. Anyway, it is slower to draw
directly to the screen than to draw to a BITMAP and blit it to the
screen. I discovered that direct drawing to the screen is slower because
the screen is updated every time someting is drawn onto it. I think that
we can use the acquire_screen / release_screen functions to tell the
X-windows driver not to update the screen (acquire_screen = stop
updating the screen, release_screen = update the screen and go back to
usual behaviour). This way direct draw is faster than double-buffering.
I have attached a small patch that perform that stuff. It works...
However, I think that a X-windows gourou should have a look at it ;-)

	Bertrand.
diff -urN allegro.old/src/x/xvtable.c allegro/src/x/xvtable.c
--- allegro.old/src/x/xvtable.c	Tue Sep 26 10:57:54 2000
+++ allegro/src/x/xvtable.c	Sun Feb 25 18:36:31 2001
@@ -26,6 +26,8 @@
 
 
 
+static void _xwin_acquire(BITMAP *bmp);
+static void _xwin_release(BITMAP *bmp);
 static void _xwin_putpixel(BITMAP *dst, int dx, int dy, int color);
 static void _xwin_vline(BITMAP *dst, int dx, int dy1, int dy2, int color);
 static void _xwin_hline(BITMAP *dst, int dx1, int dy, int dx2, int color);
@@ -63,6 +65,8 @@
 
    memcpy(&_xwin_vtable, vtable, sizeof(GFX_VTABLE));
 
+   vtable->acquire = _xwin_acquire;
+   vtable->release = _xwin_release;
    vtable->putpixel = _xwin_putpixel;
    vtable->vline = _xwin_vline;
    vtable->hline = _xwin_hline;
@@ -104,6 +108,32 @@
    _xwin_update_screen(x + dst->x_ofs, y + dst->y_ofs, w, h);
 }
 
+static int lock_nested = 0;
+
+/* _xwin_acquire:
+ *  Lock screen : stop updating screen.
+ */
+static void _xwin_acquire(BITMAP *bmp)
+{
+   _xwin_in_gfx_call = 1;
+   lock_nested++;
+}
+ 
+
+
+/* _xwin_release:
+ *  Unlock and update screen
+ */
+static void _xwin_release(BITMAP *bmp)
+{
+   if (lock_nested <= 0) return;
+   lock_nested--;
+   if (lock_nested == 0) {
+     _xwin_in_gfx_call = 0;
+     _xwin_update_screen(0, 0, _xwin.virtual_width, _xwin.virtual_height);
+   }
+}
+ 
 
 
 /* _xwin_putpixel:


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/