Replace deprecated Automake INCLUDES variable with AM_CPPFLAGS
[free-sw/xcb/demo] / tests / lissajoux.c
index ab58fc3..2fa4378 100644 (file)
@@ -8,11 +8,11 @@
 #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>
-#include <X11/XCB/xcb_image.h>
+#include <xcb/xcb.h>
+#include <xcb/shm.h>
+#include <xcb/xcb_aux.h>
+#include <xcb/xcb_image.h>
+#define XCB_ALL_PLANES ~0
 
 #include "lissajoux.h"
 
@@ -28,7 +28,7 @@ int    do_shm = 0;
 double tab_cos[3600];
 double tab_sin[3600];
 
-XCBShmSegmentInfo shminfo;
+xcb_shm_segment_info_t shminfo;
 
 double
 get_time(void)
@@ -50,17 +50,17 @@ draw_lissajoux (Data *datap)
   
   if (do_shm)
     { 
-      i = XCBImageSHMGet (datap->conn, datap->draw,
+      i = xcb_image_shm_get (datap->conn, datap->draw,
                          datap->image, shminfo,
                          0, 0,
-                         AllPlanes);
+                         XCB_ALL_PLANES);
       assert(i);
     }
   else
     {
-      datap->image = XCBImageGet (datap->conn, datap->draw,
+      datap->image = xcb_image_get (datap->conn, datap->draw,
                                   0, 0, W_W, W_H,
-                                  AllPlanes, datap->format);
+                                  XCB_ALL_PLANES, datap->format);
       assert(datap->image);
     }
   
@@ -76,7 +76,7 @@ draw_lissajoux (Data *datap)
       {
        x = tab_cos[(int)(a1*i + p1*nbr) % 3600];
        y = tab_sin[(int)(a2*i + p2*nbr) % 3600];
-       XCBImagePutPixel (datap->image,
+       xcb_image_put_pixel (datap->image,
                          (int)((double)(W_W-5)*(x+1)/2.0),
                          (int)((double)(W_H-5)*(y+1)/2.0), 65535);
       }
@@ -88,20 +88,20 @@ draw_lissajoux (Data *datap)
       {
        x = tab_cos[(int)(a1*i + p1*nbr) % 3600];
        y = tab_sin[(int)(a2*i + p2*nbr) % 3600];
-       XCBImagePutPixel (datap->image,
+       xcb_image_put_pixel (datap->image,
                          (int)((double)(W_W-5)*(x+1)/2.0),
                          (int)((double)(W_H-5)*(y+1)/2.0), 0);
       }
 
   if (do_shm)
-    XCBImageSHMPut (datap->conn, datap->draw, datap->gc,
+    xcb_image_shm_put (datap->conn, datap->draw, datap->gc,
                    datap->image, shminfo,
                    0, 0, 0, 0, W_W, W_H, 0);
   else
     {
-      XCBImagePut (datap->conn, datap->draw, datap->gc, datap->image,
-                   0, 0, 0, 0, W_W, W_H);
-      XCBImageDestroy (datap->image);
+      xcb_image_put (datap->conn, datap->draw, datap->gc, datap->image,
+                   0, 0, 0);
+      xcb_image_destroy (datap->image);
     }
 }
 
@@ -111,7 +111,7 @@ step (Data *datap)
   loop_count++;
   t = get_time () - time_start;
 
-  if (t <= 20.0)
+  if (t <= 2.0)
     {
       draw_lissajoux (datap);
     }
@@ -120,7 +120,7 @@ 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);
-      XCBDisconnect (datap->conn);
+      xcb_disconnect (datap->conn);
       exit(0);
     }
 }
@@ -129,14 +129,14 @@ step (Data *datap)
 void
 shm_test (Data *datap)
 {
-  XCBShmQueryVersionRep *rep;
+  xcb_shm_query_version_reply_t *rep;
 
-  rep = XCBShmQueryVersionReply (datap->conn,
-                                XCBShmQueryVersion (datap->conn),
+  rep = xcb_shm_query_version_reply (datap->conn,
+                                xcb_shm_query_version (datap->conn),
                                 NULL);
   if (rep)
     {
-      CARD8 format;
+      uint8_t format;
       int shmctl_status;
       
       if (rep->shared_pixmaps && 
@@ -144,23 +144,24 @@ shm_test (Data *datap)
        format = rep->pixmap_format;
       else
        format = 0;
-      datap->image = XCBImageSHMCreate (datap->conn, datap->depth,
-                                     format, NULL, W_W, W_H);
+      datap->image = xcb_image_create_native (datap->conn, W_W, W_H,
+                                        format, datap->depth, NULL, ~0, NULL);
       assert(datap->image);
 
       shminfo.shmid = shmget (IPC_PRIVATE,
-                             datap->image->bytes_per_line*datap->image->height,
+                             datap->image->stride*datap->image->height,
                              IPC_CREAT | 0777);
       assert(shminfo.shmid != -1);
       shminfo.shmaddr = shmat (shminfo.shmid, 0, 0);
       assert(shminfo.shmaddr);
       datap->image->data = shminfo.shmaddr;
 
-      shminfo.shmseg = XCBShmSEGNew (datap->conn);
-      XCBShmAttach (datap->conn, shminfo.shmseg,
+      shminfo.shmseg = xcb_generate_id (datap->conn);
+      xcb_shm_attach (datap->conn, shminfo.shmseg,
                    shminfo.shmid, 0);
       shmctl_status = shmctl(shminfo.shmid, IPC_RMID, 0);
       assert(shmctl_status != -1);
+      free (rep);
     }
 
   if (datap->image)
@@ -181,15 +182,15 @@ int
 main (int argc, char *argv[])
 {
   Data             data;
-  XCBSCREEN       *screen;
-  XCBDRAWABLE      win;
-  XCBDRAWABLE      rect;
-  XCBGCONTEXT      bgcolor;
-  CARD32           mask;
-  CARD32           valgc[2];
-  CARD32           valwin[3];
-  XCBRECTANGLE     rect_coord = { 0, 0, W_W, W_H};
-  XCBGenericEvent *e;
+  xcb_screen_t       *screen;
+  xcb_drawable_t      win;
+  xcb_drawable_t      rect;
+  xcb_gcontext_t      bgcolor;
+  uint32_t           mask;
+  uint32_t           valgc[2];
+  uint32_t           valwin[3];
+  xcb_rectangle_t     rect_coord = { 0, 0, W_W, W_H};
+  xcb_generic_event_t *e;
   int              try_shm;
   int              screen_num;
   int              i;
@@ -209,47 +210,47 @@ main (int argc, char *argv[])
   if (try_shm != 0)
     try_shm = 1;
 
-  data.conn = XCBConnect (0, &screen_num);
-  screen = XCBAuxGetScreen(data.conn, screen_num);
-  data.depth = XCBAuxGetDepth (data.conn, screen);
+  data.conn = xcb_connect (0, &screen_num);
+  screen = xcb_aux_get_screen(data.conn, screen_num);
+  data.depth = xcb_aux_get_depth (data.conn, screen);
 
-  win.window = screen->root;
+  win = screen->root;
 
-  data.gc = XCBGCONTEXTNew (data.conn);
-  mask = GCForeground | GCGraphicsExposures;
+  data.gc = xcb_generate_id (data.conn);
+  mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
   valgc[0] = screen->black_pixel;
   valgc[1] = 0; /* no graphics exposures */
-  XCBCreateGC (data.conn, data.gc, win, mask, valgc);
+  xcb_create_gc (data.conn, data.gc, win, mask, valgc);
 
-  bgcolor = XCBGCONTEXTNew (data.conn);
-  mask = GCForeground | GCGraphicsExposures;
+  bgcolor = xcb_generate_id (data.conn);
+  mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
   valgc[0] = screen->white_pixel;
   valgc[1] = 0; /* no graphics exposures */
-  XCBCreateGC (data.conn, bgcolor, win, mask, valgc);
+  xcb_create_gc (data.conn, bgcolor, win, mask, valgc);
 
-  data.draw.window = XCBWINDOWNew (data.conn);
-  mask = XCBCWBackPixel | XCBCWEventMask | XCBCWDontPropagate;
+  data.draw = xcb_generate_id (data.conn);
+  mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK | XCB_CW_DONT_PROPAGATE;
   valwin[0] = screen->white_pixel;
-  valwin[1] = KeyPressMask | ButtonReleaseMask | ExposureMask;
-  valwin[2] = ButtonPressMask;
-  XCBCreateWindow (data.conn, 0,
-                  data.draw.window,
+  valwin[1] = XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_EXPOSURE;
+  valwin[2] = XCB_EVENT_MASK_BUTTON_PRESS;
+  xcb_create_window (data.conn, 0,
+                  data.draw,
                   screen->root,
                   0, 0, W_W, W_H,
                   10,
-                  InputOutput,
+                  XCB_WINDOW_CLASS_INPUT_OUTPUT,
                   screen->root_visual,
                   mask, valwin);
-  XCBMapWindow (data.conn, data.draw.window);
+  xcb_map_window (data.conn, data.draw);
 
-  rect.pixmap = XCBPIXMAPNew (data.conn);
-  XCBCreatePixmap (data.conn, data.depth,
-                  rect.pixmap, data.draw,
+  rect = xcb_generate_id (data.conn);
+  xcb_create_pixmap (data.conn, data.depth,
+                  rect, data.draw,
                   W_W, W_H);
-  XCBPolyFillRectangle(data.conn, rect, bgcolor, 1, &rect_coord);
+  xcb_poly_fill_rectangle(data.conn, rect, bgcolor, 1, &rect_coord);
 
-  data.format = ZPixmap;
-  XCBSync (data.conn, 0); 
+  data.format = XCB_IMAGE_FORMAT_Z_PIXMAP;
+  xcb_flush (data.conn); 
 
   if (try_shm)
     shm_test (&data);
@@ -263,21 +264,20 @@ main (int argc, char *argv[])
   t_previous = 0.0;
   while (1)
     {
-      e = XCBPollForEvent(data.conn, NULL);
+      e = xcb_poll_for_event(data.conn);
       if (e)
        {
          switch (e->response_type)
            {
-           case XCBExpose:
-             XCBCopyArea(data.conn, rect, data.draw, bgcolor,
+           case XCB_EXPOSE:
+             xcb_copy_area(data.conn, rect, data.draw, bgcolor,
                          0, 0, 0, 0, W_W, W_H);
-             XCBSync (data.conn, 0);
              break;
            }
          free (e);
         }
       step (&data);
-      XCBFlush (data.conn);
+      xcb_flush (data.conn);
       t_previous = t;
     }
   /*NOTREACHED*/