#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>
double t;
int do_shm = 0;
+double tab_cos[3600];
+double tab_sin[3600];
+
XCBShmSegmentInfo shminfo;
double
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);
}
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);
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);
loop_count++;
t = get_time () - time_start;
- if (t <= 20.0)
+ if (t <= 2.0)
{
draw_lissajoux (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)
{
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,
shminfo.shmid, 0);
shmctl_status = shmctl(shminfo.shmid, IPC_RMID, 0);
assert(shmctl_status != -1);
+ free (rep);
}
if (datap->image)
XCBGenericEvent *e;
int try_shm;
int screen_num;
+ int i;
try_shm = 0;
{
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)
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);
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);
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)
case XCBExpose:
XCBCopyArea(data.conn, rect, data.draw, bgcolor,
0, 0, 0, 0, W_W, W_H);
- XCBSync (data.conn, 0);
break;
}
free (e);