-
- if (force_slowpath && shm_supported) {
-
- // if the shared memory area is unsuitable, destroy it
-
- if (((XImage*)shm_ximage) != NULL && (dx2 - dx1 != ((XImage*)shm_ximage)->width || dy2 - dy1 != ((XImage*)shm_ximage)->height)) {
- XShmDetach(display, &shm_info);
- XDestroyImage(((XImage*)shm_ximage));
- }
-
- // FIXME: replace 4 with something sensible
- if (((XImage*)shm_ximage) != NULL && (dx2 - dx1) * (dy2 - dy1) * 4 < old_shmsize) {
- shmdt(shm_info.shmaddr);
- shmctl(shm_info.shmid, IPC_RMID, 0);
- memset(&shm_info, 0, sizeof(XShmSegmentInfo));
- shm_info.shmaddr = NULL;
- }
-
- // if we need to recreate the shared memory area
- if (shm_info.shmaddr == NULL) {
- old_shmsize = xi->bytes_per_line * xi->height;
- memset(&shm_info, 0, sizeof(XShmSegmentInfo));
- shm_info.shmid = shmget(IPC_PRIVATE, xi->bytes_per_line * xi->height, IPC_CREAT | 0777 | IPC_EXCL);
- shm_info.shmaddr = xi->data = (char*)shmat(shm_info.shmid, 0, 0);
- shm_info.readOnly = False;
-
- XSync(display, False);
- shmctl(shm_info.shmid, IPC_RMID, 0);
- XShmAttach(display, &shm_info);
- XSync(display, False);
- }
-
- xi = ((XImage*)shm_ximage) = XShmCreateImage(display, visual, colorDepth, ZPixmap, shm_info.shmaddr, &shm_info, dx2 - dx1, dy2 - dy1);
-
- } else if (shared_pixmap && shm_supported) {
- xi = ((XImage*)mxi);
+
+ // FASTEST: shared pixmap; twiddle bits in video ram directly
+ if (shared_pixmap) {
+ XSync(display, False); // ensure that all pending operations have rendered
+ xi = (XImage*)fake_ximage;
+
+ // MEDIUM: write to a shared ximage, then ask the server to do the blit
+ } else if (shm_supported) {
+ xi = XShmCreateImage(display, visual, colorDepth, ZPixmap, NULL, &shm_info, dx2 - dx1, dy2 - dy1);
+ ensureShmSize(xi->bytes_per_line * xi->height);
+ xi->data = shm_info.shmaddr;
+ XShmGetImage(display, (*((Pixmap*)pm)), xi, dx1, dy1, AllPlanes);