Replace another Sync -> Flush
[free-sw/xcb/demo] / tests / lissajoux.c
index 9ba2996..1e787bf 100644 (file)
@@ -8,7 +8,6 @@
 #include <sys/ipc.h>
 #include <sys/shm.h>
 
-#include <X11/Xlib.h>
 #include <X11/XCB/xcb.h>
 #include <X11/XCB/shm.h>
 #include <X11/XCB/xcb_aux.h>
@@ -25,6 +24,9 @@ double t_previous;
 double t;
 int    do_shm = 0;
 
+double tab_cos[3600];
+double tab_sin[3600];
+
 XCBShmSegmentInfo shminfo;
 
 double
@@ -50,14 +52,14 @@ draw_lissajoux (Data *datap)
       i = XCBImageSHMGet (datap->conn, datap->draw,
                          datap->image, shminfo,
                          0, 0,
-                         AllPlanes);
+                         XCBAllPlanes);
       assert(i);
     }
   else
     {
       datap->image = XCBImageGet (datap->conn, datap->draw,
                                   0, 0, W_W, W_H,
-                                  AllPlanes, datap->format);
+                                  XCBAllPlanes, datap->format);
       assert(datap->image);
     }
   
@@ -68,11 +70,11 @@ draw_lissajoux (Data *datap)
   p1 = 4.0*t_previous*pi*0.05;
   p2 = 0.0;
 
-  nbr = 1000;
+  nbr = 10000;
   for (i = 0 ; i < nbr ; i++)
       {
-       x = cos (a1*i*period/nbr + p1);
-       y = sin (a2*i*period/nbr + p2);
+       x = tab_cos[(int)(a1*i + p1*nbr) % 3600];
+       y = tab_sin[(int)(a2*i + p2*nbr) % 3600];
        XCBImagePutPixel (datap->image,
                          (int)((double)(W_W-5)*(x+1)/2.0),
                          (int)((double)(W_H-5)*(y+1)/2.0), 65535);
@@ -83,8 +85,8 @@ draw_lissajoux (Data *datap)
 
   for (i = 0 ; i < nbr ; i++)
       {
-       x = cos (a1*i*period/nbr + p1);
-       y = sin (a2*i*period/nbr + p2);
+       x = tab_cos[(int)(a1*i + p1*nbr) % 3600];
+       y = tab_sin[(int)(a2*i + p2*nbr) % 3600];
        XCBImagePutPixel (datap->image,
                          (int)((double)(W_W-5)*(x+1)/2.0),
                          (int)((double)(W_H-5)*(y+1)/2.0), 0);
@@ -108,7 +110,7 @@ step (Data *datap)
   loop_count++;
   t = get_time () - time_start;
 
-  if (t <= 20.0)
+  if (t <= 2.0)
     {
       draw_lissajoux (datap);
     }
@@ -117,12 +119,14 @@ step (Data *datap)
       printf("FRAME COUNT..: %i frames\n", loop_count);
       printf("TIME.........: %3.3f seconds\n", t);
       printf("AVERAGE FPS..: %3.3f fps\n", (double)loop_count / t);
+      if (do_shm)
+        XCBImageSHMDestroy (datap->image);
       XCBDisconnect (datap->conn);
       exit(0);
     }
 }
 
-/* Return 0 if shm is not availaible, 1 otherwise */
+/* Return 0 if shm is not available, 1 otherwise */
 void
 shm_test (Data *datap)
 {
@@ -142,7 +146,7 @@ shm_test (Data *datap)
       else
        format = 0;
       datap->image = XCBImageSHMCreate (datap->conn, datap->depth,
-                                     format, NULL, W_W, W_H);
+                                        format, NULL, W_W, W_H);
       assert(datap->image);
 
       shminfo.shmid = shmget (IPC_PRIVATE,
@@ -158,6 +162,7 @@ shm_test (Data *datap)
                    shminfo.shmid, 0);
       shmctl_status = shmctl(shminfo.shmid, IPC_RMID, 0);
       assert(shmctl_status != -1);
+      free (rep);
     }
 
   if (datap->image)
@@ -189,6 +194,7 @@ main (int argc, char *argv[])
   XCBGenericEvent *e;
   int              try_shm;
   int              screen_num;
+  int              i;
   
   try_shm = 0;
 
@@ -197,7 +203,7 @@ main (int argc, char *argv[])
     {
       printf ("Usage: lissajoux try_shm\n");
       printf ("         try_shm == 0: shm not used\n");
-      printf ("         try_shm != 0: shm is used (if availaible)\n");
+      printf ("         try_shm != 0: shm is used (if available)\n");
       exit (0);
     }
   if (argc >= 2)
@@ -212,13 +218,13 @@ main (int argc, char *argv[])
   win.window = screen->root;
 
   data.gc = XCBGCONTEXTNew (data.conn);
-  mask = GCForeground | GCGraphicsExposures;
+  mask = XCBGCForeground | XCBGCGraphicsExposures;
   valgc[0] = screen->black_pixel;
   valgc[1] = 0; /* no graphics exposures */
   XCBCreateGC (data.conn, data.gc, win, mask, valgc);
 
   bgcolor = XCBGCONTEXTNew (data.conn);
-  mask = GCForeground | GCGraphicsExposures;
+  mask = XCBGCForeground | XCBGCGraphicsExposures;
   valgc[0] = screen->white_pixel;
   valgc[1] = 0; /* no graphics exposures */
   XCBCreateGC (data.conn, bgcolor, win, mask, valgc);
@@ -226,14 +232,14 @@ main (int argc, char *argv[])
   data.draw.window = XCBWINDOWNew (data.conn);
   mask = XCBCWBackPixel | XCBCWEventMask | XCBCWDontPropagate;
   valwin[0] = screen->white_pixel;
-  valwin[1] = KeyPressMask | ButtonReleaseMask | ExposureMask;
-  valwin[2] = ButtonPressMask;
+  valwin[1] = XCBEventMaskKeyPress | XCBEventMaskButtonRelease | XCBEventMaskExposure;
+  valwin[2] = XCBEventMaskButtonPress;
   XCBCreateWindow (data.conn, 0,
                   data.draw.window,
                   screen->root,
                   0, 0, W_W, W_H,
                   10,
-                  InputOutput,
+                  XCBWindowClassInputOutput,
                   screen->root_visual,
                   mask, valwin);
   XCBMapWindow (data.conn, data.draw.window);
@@ -244,12 +250,17 @@ main (int argc, char *argv[])
                   W_W, W_H);
   XCBPolyFillRectangle(data.conn, rect, bgcolor, 1, &rect_coord);
 
-  data.format = ZPixmap;
-  XCBSync (data.conn, 0); 
+  data.format = XCBImageFormatZPixmap;
+  XCBFlush (data.conn); 
 
   if (try_shm)
     shm_test (&data);
 
+  for (i = 0; i < 3600; i++) {
+    tab_cos[i] = cos (2.0 * 3.1415926535897 * (double)i / 3600.0);
+    tab_sin[i] = sin (2.0 * 3.1415926535897 * (double)i / 3600.0);
+  }
+
   time_start = get_time ();
   t_previous = 0.0;
   while (1)
@@ -262,7 +273,6 @@ main (int argc, char *argv[])
            case XCBExpose:
              XCBCopyArea(data.conn, rect, data.draw, bgcolor,
                          0, 0, 0, 0, W_W, W_H);
-             XCBSync (data.conn, 0);
              break;
            }
          free (e);