- if (use_shm) {
- printf("p=%X\n", p);
- free(p);
- image = XShmCreateImage(dpy, xgwa.visual, vdepth,
- ZPixmap, 0, &shm_info, width, height);
- shm_info.shmid = shmget(IPC_PRIVATE,
- image->bytes_per_line * image->height,
- IPC_CREAT | 0777);
- if (shm_info.shmid == -1)
- printf ("shmget failed!");
- shm_info.readOnly = False;
- p = shmat(shm_info.shmid, 0, 0);
- printf("p=%X %d\n", p, image->bytes_per_line);
- XShmAttach(dpy, &shm_info);
- XSync(dpy, False);
- } else
-#endif
- image = XCreateImage(dpy, xgwa.visual, vdepth,
- ZPixmap, 0, p,
- width, height, 8, 0);
+ if (use_shm)
+ {
+ image = create_xshm_image(dpy, xgwa.visual, vdepth,
+ ZPixmap, 0, &shm_info, width, height);
+ if (!image)
+ use_shm = False;
+ else
+ {
+ free(p);
+ p = image->data;
+ }
+ }
+#endif /* HAVE_XSHM_EXTENSION */
+
+ if (!image)
+ {
+ image = XCreateImage(dpy, xgwa.visual, vdepth,
+ ZPixmap, 0, p,
+ width, height, 8, 0);
+ }