2 Copyright © 1995-2017, 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
14 #include "x11_debug.h"
16 #include <aros/config.h>
17 #include <aros/symbolsets.h>
19 #include "x11_types.h"
22 /****************************************************************************************/
24 /* stegerg: maybe more safe, even if Unix malloc is used and not AROS malloc */
27 /****************************************************************************************/
30 #include <proto/exec.h>
33 /****************************************************************************************/
37 /****************************************************************************************/
39 #include <X11/extensions/XShm.h>
41 #include "x11_hostlib.h"
43 static void *xext_handle
= NULL
;
46 Status (*XShmDetach
) ( Display
* , XShmSegmentInfo
* );
47 Status (*XShmPutImage
) ( Display
* , Drawable
, GC
, XImage
* , int , int , int , int , unsigned int , unsigned int , Bool
);
48 Status (*XShmGetImage
) ( Display
* , Drawable
, XImage
* , int , int , unsigned long );
49 XImage
* (*XShmCreateImage
) ( Display
* , Visual
* , unsigned int , int , char* , XShmSegmentInfo
* , unsigned int , unsigned int );
50 Bool (*XShmQueryVersion
) ( Display
* , int* , int* , Bool
* );
51 Status (*XShmAttach
) ( Display
* , XShmSegmentInfo
* );
54 static const char *xext_func_names
[] = {
64 #define XEXT_SOFILE "libXext.so.6"
68 #define XEXT_SOFILE "/usr/X11/lib/libXext.6.dylib"
72 #define XEXT_SOFILE "libXext.so"
75 #define XEXTCALL(func,...) (xext_func.func(__VA_ARGS__))
77 extern void *x11_hostlib_load_so(const char *, const char **, int, void **);
79 static int xext_hostlib_init(void *libbase
) {
80 D(bug("[x11] xext hostlib init\n"));
82 if ((xext_handle
= x11_hostlib_load_so(XEXT_SOFILE
, xext_func_names
, 6, (void **) &xext_func
)) == NULL
)
88 static int xext_hostlib_expunge(void *libbase
) {
89 D(bug("[x11] xext hostlib expunge\n"));
91 if (xext_handle
!= NULL
)
92 HostLib_Close(xext_handle
, NULL
);
97 ADD2INITLIB(xext_hostlib_init
, 1)
98 ADD2EXPUNGELIB(xext_hostlib_expunge
, 1)
101 /****************************************************************************************/
103 void *init_shared_mem(Display
*display
)
105 /* TODO: Also check if this is a local display */
107 XShmSegmentInfo
*shminfo
;
108 int xshm_major
, xshm_minor
;
111 if (XEXTCALL(XShmQueryVersion
, display
, &xshm_major
, &xshm_minor
, &xshm_pixmaps
))
114 shminfo
= (XShmSegmentInfo
*)AllocVec(sizeof(*shminfo
), MEMF_PUBLIC
);
116 shminfo
= (XShmSegmentInfo
*)malloc(sizeof(*shminfo
));
124 * Try and get a key for us to use. The idea is to use a
125 * filename that isn't likely to change all that often. This
126 * is made somewhat easier since we must be run from the AROS
127 * root directory (atm). So, I shall choose the path "C",
128 * since the inode number isn't likely to change all that
134 key
= CCALL(ftok
, "./C", 'A');
137 kprintf("Hmm, path \"./C\" doesn't seem to exist?\n");
142 kprintf("Using shared memory key %d\n", key
);
145 memset(shminfo
, 0, sizeof (*shminfo
));
147 /* Allocate shared memory */
148 shminfo
->shmid
= CCALL(shmget
, key
, XSHM_MEMSIZE
, IPC_CREAT
|0777);
150 if (shminfo
->shmid
>= 0)
152 /* Attach the mem to our process */
153 shminfo
->shmaddr
= CCALL(shmat
, shminfo
->shmid
, NULL
, 0);
154 if (NULL
!= shminfo
->shmaddr
)
156 shminfo
->readOnly
= False
;
157 if (XEXTCALL(XShmAttach
, display
, shminfo
))
162 CCALL(shmdt
, shminfo
->shmaddr
);
165 CCALL(shmctl
, shminfo
->shmid
, IPC_RMID
, NULL
);
175 } /* If has XShm extension */
181 /****************************************************************************************/
183 void cleanup_shared_mem(Display
*display
, void *meminfo
)
185 XShmSegmentInfo
*shminfo
= (XShmSegmentInfo
*)meminfo
;
190 XEXTCALL(XShmDetach
, display
, shminfo
);
191 CCALL(shmdt
, shminfo
->shmaddr
);
192 CCALL(shmctl
, shminfo
->shmid
, IPC_RMID
, 0);
202 /****************************************************************************************/
204 XImage
*create_xshm_ximage(Display
*display
, Visual
*visual
, int depth
, int format
,
205 int width
, int height
, void *xshminfo
)
207 XShmSegmentInfo
*shminfo
;
210 shminfo
= (XShmSegmentInfo
*)xshminfo
;
212 image
= XEXTCALL(XShmCreateImage
, display
, visual
, depth
, format
, shminfo
->shmaddr
,
213 shminfo
, width
, height
);
218 /****************************************************************************************/
220 void put_xshm_ximage(Display
*display
, Drawable d
, GC gc
, XImage
*image
,
221 int xsrc
, int ysrc
, int xdest
, int ydest
,
222 int width
, int height
, Bool send_event
)
224 XEXTCALL(XShmPutImage
, display
, d
, gc
, image
, xsrc
, ysrc
, xdest
, ydest
,
225 width
, height
, send_event
);
226 XCALL(XSync
, display
, False
);
229 /****************************************************************************************/
231 int get_xshm_ximage(Display
*display
, Drawable d
, XImage
*image
, int x
, int y
)
233 XCALL(XSync
, display
, False
);
234 XEXTCALL(XShmGetImage
, display
, d
, image
, x
, y
, AllPlanes
);
236 return (int)XEXTCALL(XShmGetImage
, display
, d
, image
, x
, y
, AllPlanes
);
239 /****************************************************************************************/
241 void destroy_xshm_ximage(XImage
*image
)
243 XDestroyImage(image
);
246 /****************************************************************************************/
248 #endif /* USE_XSHM */
250 /****************************************************************************************/