Re: [AD] X vsync emulation (timing)

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


Anyway, I had another think about this and here's the sound of a forehead being smacked. Patch attached.

Peter
Index: src/x/xwin.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/x/xwin.c,v
retrieving revision 1.79
diff -u -r1.79 xwin.c
--- src/x/xwin.c	18 Nov 2004 03:45:10 -0000	1.79
+++ src/x/xwin.c	19 Nov 2004 08:21:27 -0000
@@ -194,7 +194,7 @@
 static void _xwin_private_set_matching_colors(AL_CONST PALETTE p, int from, int to);
 static void _xwin_private_set_truecolor_colors(AL_CONST PALETTE p, int from, int to);
 static void _xwin_private_set_palette_colors(AL_CONST PALETTE p, int from, int to);
-static void _xwin_private_set_palette_range(AL_CONST PALETTE p, int from, int to, int vsync);
+static void _xwin_private_set_palette_range(AL_CONST PALETTE p, int from, int to);
 static void _xwin_private_set_window_defaults(void);
 static void _xwin_private_flush_buffers(void);
 static void _xwin_private_resize_window(int w, int h);
@@ -2047,16 +2047,12 @@
    }
 }
 
-static void _xwin_private_set_palette_range(AL_CONST PALETTE p, int from, int to, int vsync)
+static void _xwin_private_set_palette_range(AL_CONST PALETTE p, int from, int to)
 {
    RGB *pal;
    int c;
    unsigned char temp;
 
-   /* Wait for VBI.  */
-   if (vsync)
-      _xwin_vsync();
-
    if (_xwin.set_colors != 0) {
       if (blitter_func) {
          if (use_bgr_palette_hack && (from >= 0) && (to < 256)) {
@@ -2090,8 +2086,12 @@
 
 void _xwin_set_palette_range(AL_CONST PALETTE p, int from, int to, int vsync)
 {
+   if (vsync) {
+      _xwin_vsync();
+   }
+
    XLOCK();
-   _xwin_private_set_palette_range(p, from, to, vsync);
+   _xwin_private_set_palette_range(p, from, to);
    XUNLOCK();
 }
 
@@ -2160,15 +2160,25 @@
  */
 void _xwin_vsync(void)
 {
-   /* This does not wait for the VBI - but it waits until X11 has synchronized,
-    * i.e. until actual changes are visible. So it has a similar effect. A
-    * better solution might be waiting a specific time to simulate a VBI (but
-    * the X11 mutex might be locked by the timer thread), or using the XSync
-    * extension.
-    */
-   XLOCK();
-   XSync(_xwin.display, False);
-   XUNLOCK();
+   if (_timer_installed) {
+      int prev = retrace_count;
+
+      XLOCK();
+      XSync(_xwin.display, False);
+      XUNLOCK();
+
+      do {
+      } while (retrace_count == prev);
+   }
+   else {
+      /* This does not wait for the VBI - but it waits until X11 has
+       * synchronized, i.e. until actual changes are visible. So it
+       * has a similar effect.
+       */
+      XLOCK();
+      XSync(_xwin.display, False);
+      XUNLOCK();
+   }
 }
 
 


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