2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
6 /* I have to put his in its own file because of include file
7 conflicts between AROS includes and system includes */
10 /* NOTE !!! All these functions need to be
11 singlethreded by the LOCK_X11/UNLOCK_X11 macros form the outside
15 #include <X11/Xutil.h>
19 #include <aros/debug.h>
21 #include <aros/symbolsets.h>
23 /****************************************************************************************/
25 /* stegerg: maybe more safe, even if Unix malloc is used and not AROS malloc */
28 /****************************************************************************************/
31 #include <exec/memory.h>
32 #include <proto/exec.h>
35 /****************************************************************************************/
39 /****************************************************************************************/
43 #include <X11/extensions/XShm.h>
45 #include "x11_hostlib.h"
47 #include <proto/hostlib.h>
49 static void *xext_handle
= NULL
;
52 Status (*XShmDetach
) ( Display
* , XShmSegmentInfo
* );
53 Status (*XShmPutImage
) ( Display
* , Drawable
, GC
, XImage
* , int , int , int , int , unsigned int , unsigned int , Bool
);
54 Status (*XShmGetImage
) ( Display
* , Drawable
, XImage
* , int , int , unsigned long );
55 XImage
* (*XShmCreateImage
) ( Display
* , Visual
* , unsigned int , int , char* , XShmSegmentInfo
* , unsigned int , unsigned int );
56 Bool (*XShmQueryVersion
) ( Display
* , int* , int* , Bool
* );
57 Status (*XShmAttach
) ( Display
* , XShmSegmentInfo
* );
60 static const char *xext_func_names
[] = {
70 #define XEXT_SOFILE "libXext.so.6"
74 #define XEXT_SOFILE "/usr/X11/lib/libXext.6.dylib"
78 #define XEXT_SOFILE "libXext.so"
81 #define XEXTCALL(func,...) (xext_func.func(__VA_ARGS__))
83 extern void *x11_hostlib_load_so(const char *, const char **, int, void **);
85 static int xext_hostlib_init(void *libbase
) {
86 D(bug("[x11] xext hostlib init\n"));
88 if ((xext_handle
= x11_hostlib_load_so(XEXT_SOFILE
, xext_func_names
, 6, (void **) &xext_func
)) == NULL
)
94 static int xext_hostlib_expunge(void *libbase
) {
95 D(bug("[x11] xext hostlib expunge\n"));
97 if (xext_handle
!= NULL
)
98 HostLib_Close(xext_handle
, NULL
);
103 ADD2INITLIB(xext_hostlib_init
, 1)
104 ADD2EXPUNGELIB(xext_hostlib_expunge
, 1)
107 /****************************************************************************************/
109 void *init_shared_mem(Display
*display
)
111 /* TODO: Also check if this is a local display */
113 XShmSegmentInfo
*shminfo
;
114 int xshm_major
, xshm_minor
;
117 if (XEXTCALL(XShmQueryVersion
, display
, &xshm_major
, &xshm_minor
, &xshm_pixmaps
))
120 shminfo
= (XShmSegmentInfo
*)AllocVec(sizeof(*shminfo
), MEMF_PUBLIC
);
122 shminfo
= (XShmSegmentInfo
*)malloc(sizeof(*shminfo
));
130 * Try and get a key for us to use. The idea is to use a
131 * filename that isn't likely to change all that often. This
132 * is made somewhat easier since we must be run from the AROS
133 * root directory (atm). So, I shall choose the path "C",
134 * since the inode number isn't likely to change all that
140 key
= CCALL(ftok
, "./C", 'A');
143 kprintf("Hmm, path \"./C\" doesn't seem to exist?\n");
148 kprintf("Using shared memory key %d\n", key
);
151 memset(shminfo
, 0, sizeof (*shminfo
));
153 /* Allocate shared memory */
154 shminfo
->shmid
= CCALL(shmget
, key
, XSHM_MEMSIZE
, IPC_CREAT
|0777);
156 if (shminfo
->shmid
>= 0)
158 /* Attach the mem to our process */
159 shminfo
->shmaddr
= CCALL(shmat
, shminfo
->shmid
, NULL
, 0);
160 if (NULL
!= shminfo
->shmaddr
)
162 shminfo
->readOnly
= False
;
163 if (XEXTCALL(XShmAttach
, display
, shminfo
))
168 CCALL(shmdt
, shminfo
->shmaddr
);
171 CCALL(shmctl
, shminfo
->shmid
, IPC_RMID
, NULL
);
181 } /* If has XShm extension */
187 /****************************************************************************************/
189 void cleanup_shared_mem(Display
*display
, void *meminfo
)
191 XShmSegmentInfo
*shminfo
= (XShmSegmentInfo
*)meminfo
;
196 XEXTCALL(XShmDetach
, display
, shminfo
);
197 CCALL(shmdt
, shminfo
->shmaddr
);
198 CCALL(shmctl
, shminfo
->shmid
, IPC_RMID
, 0);
208 /****************************************************************************************/
210 XImage
*create_xshm_ximage(Display
*display
, Visual
*visual
, int depth
, int format
,
211 int width
, int height
, void *xshminfo
)
213 XShmSegmentInfo
*shminfo
;
216 shminfo
= (XShmSegmentInfo
*)xshminfo
;
218 image
= XEXTCALL(XShmCreateImage
, display
, visual
, depth
, format
, shminfo
->shmaddr
,
219 shminfo
, width
, height
);
224 /****************************************************************************************/
226 void put_xshm_ximage(Display
*display
, Drawable d
, GC gc
, XImage
*image
,
227 int xsrc
, int ysrc
, int xdest
, int ydest
,
228 int width
, int height
, Bool send_event
)
230 XEXTCALL(XShmPutImage
, display
, d
, gc
, image
, xsrc
, ysrc
, xdest
, ydest
,
231 width
, height
, send_event
);
232 XCALL(XSync
, display
, False
);
235 /****************************************************************************************/
237 int get_xshm_ximage(Display
*display
, Drawable d
, XImage
*image
, int x
, int y
)
239 XCALL(XSync
, display
, False
);
240 XEXTCALL(XShmGetImage
, display
, d
, image
, x
, y
, AllPlanes
);
242 return (int)XEXTCALL(XShmGetImage
, display
, d
, image
, x
, y
, AllPlanes
);
245 /****************************************************************************************/
247 void destroy_xshm_ximage(XImage
*image
)
249 XDestroyImage(image
);
252 /****************************************************************************************/
254 #endif /* USE_XSHM */
256 /****************************************************************************************/