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 /****************************************************************************************/
37 static void dummy_func()
42 /****************************************************************************************/
46 /****************************************************************************************/
50 #include <X11/extensions/XShm.h>
52 #include "x11_hostlib.h"
54 #include <proto/hostlib.h>
56 static void *xext_handle
= NULL
;
57 static void *shm_handle
= NULL
;
60 Status (*XShmDetach
) ( Display
* , XShmSegmentInfo
* );
61 Status (*XShmPutImage
) ( Display
* , Drawable
, GC
, XImage
* , int , int , int , int , unsigned int , unsigned int , Bool
);
62 Status (*XShmGetImage
) ( Display
* , Drawable
, XImage
* , int , int , unsigned long );
63 XImage
* (*XShmCreateImage
) ( Display
* , Visual
* , unsigned int , int , char* , XShmSegmentInfo
* , unsigned int , unsigned int );
64 Bool (*XShmQueryVersion
) ( Display
* , int* , int* , Bool
* );
65 Status (*XShmAttach
) ( Display
* , XShmSegmentInfo
* );
68 static const char *xext_func_names
[] = {
77 #define XEXT_SOFILE "libXext.so.6"
79 #define XEXTCALL(func,...) (xext_func.func(__VA_ARGS__))
81 extern void *x11_hostlib_load_so(const char *, const char **, int, void **);
83 static int xext_hostlib_init(void *libbase
) {
84 D(bug("[x11] xext hostlib init\n"));
86 if ((xext_handle
= x11_hostlib_load_so(XEXT_SOFILE
, xext_func_names
, 6, (void **) &xext_func
)) == NULL
)
92 static int xext_hostlib_expunge(void *libbase
) {
93 D(bug("[x11] xext hostlib expunge\n"));
95 if (xext_handle
!= NULL
)
96 HostLib_Close(xext_handle
, NULL
);
101 ADD2INITLIB(xext_hostlib_init
, 1)
102 ADD2EXPUNGELIB(xext_hostlib_expunge
, 1)
105 /****************************************************************************************/
107 void *init_shared_mem(Display
*display
)
109 #warning "Also check if this is a local display"
111 XShmSegmentInfo
*shminfo
;
112 int xshm_major
, xshm_minor
;
115 if (XEXTCALL(XShmQueryVersion
, display
, &xshm_major
, &xshm_minor
, &xshm_pixmaps
))
118 shminfo
= (XShmSegmentInfo
*)AllocVec(sizeof(*shminfo
), MEMF_PUBLIC
);
120 shminfo
= (XShmSegmentInfo
*)malloc(sizeof(*shminfo
));
128 * Try and get a key for us to use. The idea is to use a
129 * filename that isn't likely to change all that often. This
130 * is made somewhat easier since we must be run from the AROS
131 * root directory (atm). So, I shall choose the path "C",
132 * since the inode number isn't likely to change all that
135 key
= CCALL(ftok
, "./C", 'A');
138 kprintf("Hmm, path \"./C\" doesn't seem to exist?\n");
143 kprintf("Using shared memory key %d\n", key
);
146 memset(shminfo
, 0, sizeof (*shminfo
));
148 /* Allocate shared memory */
149 shminfo
->shmid
= CCALL(shmget
, key
, XSHM_MEMSIZE
, IPC_CREAT
|0777);
151 if (shminfo
->shmid
>= 0)
153 /* Attach the mem to our process */
154 shminfo
->shmaddr
= CCALL(shmat
, shminfo
->shmid
, NULL
, 0);
155 if (NULL
!= shminfo
->shmaddr
)
157 shminfo
->readOnly
= False
;
158 if (XEXTCALL(XShmAttach
, display
, shminfo
))
163 CCALL(shmdt
, shminfo
->shmaddr
);
166 CCALL(shmctl
, shminfo
->shmid
, IPC_RMID
, NULL
);
176 } /* If has XShm extension */
182 /****************************************************************************************/
184 void cleanup_shared_mem(Display
*display
, void *meminfo
)
186 XShmSegmentInfo
*shminfo
= (XShmSegmentInfo
*)meminfo
;
191 XEXTCALL(XShmDetach
, display
, shminfo
);
192 CCALL(shmdt
, shminfo
->shmaddr
);
193 CCALL(shmctl
, shminfo
->shmid
, IPC_RMID
, 0);
203 /****************************************************************************************/
205 XImage
*create_xshm_ximage(Display
*display
, Visual
*visual
, int depth
, int format
,
206 int width
, int height
, void *xshminfo
)
208 XShmSegmentInfo
*shminfo
;
211 shminfo
= (XShmSegmentInfo
*)xshminfo
;
213 image
= XEXTCALL(XShmCreateImage
, display
, visual
, depth
, format
, shminfo
->shmaddr
,
214 shminfo
, width
, height
);
219 /****************************************************************************************/
221 void put_xshm_ximage(Display
*display
, Drawable d
, GC gc
, XImage
*image
,
222 int xsrc
, int ysrc
, int xdest
, int ydest
,
223 int width
, int height
, Bool send_event
)
225 XEXTCALL(XShmPutImage
, display
, d
, gc
, image
, xsrc
, ysrc
, xdest
, ydest
,
226 width
, height
, send_event
);
227 XCALL(XSync
, display
, False
);
230 /****************************************************************************************/
232 void get_xshm_ximage(Display
*display
, Drawable d
, XImage
*image
, int x
, int y
)
234 XCALL(XSync
, display
, False
);
235 XEXTCALL(XShmGetImage
, display
, d
, image
, x
, y
, AllPlanes
);
238 /****************************************************************************************/
240 void destroy_xshm_ximage(XImage
*image
)
242 XDestroyImage(image
);
245 /****************************************************************************************/
247 #endif /* USE_XSHM */
249 /****************************************************************************************/