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
138 key
= CCALL(ftok
, "./C", 'A');
141 kprintf("Hmm, path \"./C\" doesn't seem to exist?\n");
146 kprintf("Using shared memory key %d\n", key
);
149 memset(shminfo
, 0, sizeof (*shminfo
));
151 /* Allocate shared memory */
152 shminfo
->shmid
= CCALL(shmget
, key
, XSHM_MEMSIZE
, IPC_CREAT
|0777);
154 if (shminfo
->shmid
>= 0)
156 /* Attach the mem to our process */
157 shminfo
->shmaddr
= CCALL(shmat
, shminfo
->shmid
, NULL
, 0);
158 if (NULL
!= shminfo
->shmaddr
)
160 shminfo
->readOnly
= False
;
161 if (XEXTCALL(XShmAttach
, display
, shminfo
))
166 CCALL(shmdt
, shminfo
->shmaddr
);
169 CCALL(shmctl
, shminfo
->shmid
, IPC_RMID
, NULL
);
179 } /* If has XShm extension */
185 /****************************************************************************************/
187 void cleanup_shared_mem(Display
*display
, void *meminfo
)
189 XShmSegmentInfo
*shminfo
= (XShmSegmentInfo
*)meminfo
;
194 XEXTCALL(XShmDetach
, display
, shminfo
);
195 CCALL(shmdt
, shminfo
->shmaddr
);
196 CCALL(shmctl
, shminfo
->shmid
, IPC_RMID
, 0);
206 /****************************************************************************************/
208 XImage
*create_xshm_ximage(Display
*display
, Visual
*visual
, int depth
, int format
,
209 int width
, int height
, void *xshminfo
)
211 XShmSegmentInfo
*shminfo
;
214 shminfo
= (XShmSegmentInfo
*)xshminfo
;
216 image
= XEXTCALL(XShmCreateImage
, display
, visual
, depth
, format
, shminfo
->shmaddr
,
217 shminfo
, width
, height
);
222 /****************************************************************************************/
224 void put_xshm_ximage(Display
*display
, Drawable d
, GC gc
, XImage
*image
,
225 int xsrc
, int ysrc
, int xdest
, int ydest
,
226 int width
, int height
, Bool send_event
)
228 XEXTCALL(XShmPutImage
, display
, d
, gc
, image
, xsrc
, ysrc
, xdest
, ydest
,
229 width
, height
, send_event
);
230 XCALL(XSync
, display
, False
);
233 /****************************************************************************************/
235 void get_xshm_ximage(Display
*display
, Drawable d
, XImage
*image
, int x
, int y
)
237 XCALL(XSync
, display
, False
);
238 XEXTCALL(XShmGetImage
, display
, d
, image
, x
, y
, AllPlanes
);
241 /****************************************************************************************/
243 void destroy_xshm_ximage(XImage
*image
)
245 XDestroyImage(image
);
248 /****************************************************************************************/
250 #endif /* USE_XSHM */
252 /****************************************************************************************/