2
* Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
4
* This is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This software is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this software; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21
* shm.c - code to set up shared memory extension.
24
#include <demoviewer.h>
27
#include <X11/extensions/XShm.h>
28
static XShmSegmentInfo shminfo;
30
static Bool caughtShmError = False;
31
static Bool needShmCleanup = False;
36
fprintf(stderr,"ShmCleanup called\n");
38
shmdt(shminfo.shmaddr);
39
shmctl(shminfo.shmid, IPC_RMID, 0);
40
needShmCleanup = False;
45
ShmCreationXErrorHandler(Display *dpy, XErrorEvent *error)
47
caughtShmError = True;
55
XErrorHandler oldXErrorHandler;
57
if (!XShmQueryExtension(dpy))
60
image = XShmCreateImage(dpy, vis, visdepth, ZPixmap, NULL, &shminfo,
61
si.framebufferWidth, si.framebufferHeight);
62
if (!image) return NULL;
64
shminfo.shmid = shmget(IPC_PRIVATE,
65
image->bytes_per_line * image->height,
68
if (shminfo.shmid == -1) {
73
shminfo.shmaddr = image->data = shmat(shminfo.shmid, 0, 0);
75
if (shminfo.shmaddr == (char *)-1) {
77
shmctl(shminfo.shmid, IPC_RMID, 0);
81
shminfo.readOnly = True;
83
oldXErrorHandler = XSetErrorHandler(ShmCreationXErrorHandler);
84
XShmAttach(dpy, &shminfo);
86
XSetErrorHandler(oldXErrorHandler);
90
shmdt(shminfo.shmaddr);
91
shmctl(shminfo.shmid, IPC_RMID, 0);
95
needShmCleanup = True;
97
fprintf(stderr,"Using shared memory PutImage\n");