1 /* $XFree86: xc/lib/GL/dri/XF86dri.c,v 1.12 2001/08/27 17:40:57 dawes Exp $ */
2 /**************************************************************************
4 Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
5 Copyright 2000 VA Linux Systems, Inc.
6 Copyright (c) 2002, 2008 Apple Computer, Inc.
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sub license, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial portions
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
24 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
25 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 **************************************************************************/
33 * Kevin E. Martin <martin@valinux.com>
34 * Jens Owen <jens@valinux.com>
35 * Rickard E. (Rik) Faith <faith@valinux.com>
39 /* THIS IS NOT AN X CONSORTIUM STANDARD */
41 #include <X11/Xlibint.h>
42 #include "appledristr.h"
43 #include <X11/extensions/Xext.h>
44 #include <X11/extensions/extutil.h>
47 static XExtensionInfo _appledri_info_data
;
48 static XExtensionInfo
*appledri_info
= &_appledri_info_data
;
49 static char *appledri_extension_name
= APPLEDRINAME
;
51 #define AppleDRICheckExtension(dpy,i,val) \
52 XextCheckExtension (dpy, i, appledri_extension_name, val)
54 /*****************************************************************************
56 * private utility routines *
58 *****************************************************************************/
60 static int close_display(Display
* dpy
, XExtCodes
* extCodes
);
61 static Bool
wire_to_event(Display
* dpy
, XEvent
* re
, xEvent
* event
);
63 static /* const */ XExtensionHooks appledri_extension_hooks
= {
68 NULL
, /* create_font */
70 close_display
, /* close_display */
71 wire_to_event
, /* wire_to_event */
72 NULL
, /* event_to_wire */
74 NULL
, /* error_string */
78 XEXT_GENERATE_FIND_DISPLAY(find_display
, appledri_info
,
79 appledri_extension_name
,
80 &appledri_extension_hooks
,
81 AppleDRINumberEvents
, NULL
)
83 static XEXT_GENERATE_CLOSE_DISPLAY(close_display
, appledri_info
)
85 static void (*surface_notify_handler
) ();
87 void *XAppleDRISetSurfaceNotifyHandler(void (*fun
) ())
89 void *old
= surface_notify_handler
;
90 surface_notify_handler
= fun
;
95 wire_to_event(Display
*dpy
, XEvent
*re
, xEvent
*event
)
97 XExtDisplayInfo
*info
= find_display(dpy
);
98 xAppleDRINotifyEvent
*sevent
;
100 AppleDRICheckExtension(dpy
, info
, False
);
102 switch ((event
->u
.u
.type
& 0x7f) - info
->codes
->first_event
) {
103 case AppleDRISurfaceNotify
:
104 sevent
= (xAppleDRINotifyEvent
*) event
;
105 if (surface_notify_handler
!= NULL
) {
106 (*surface_notify_handler
) (dpy
, (unsigned int) sevent
->arg
,
114 /*****************************************************************************
116 * public Apple-DRI Extension routines *
118 *****************************************************************************/
122 #define TRACE(msg) fprintf(stderr, "AppleDRI%s\n", msg);
129 XAppleDRIQueryExtension(dpy
, event_basep
, error_basep
)
131 int *event_basep
, *error_basep
;
133 XExtDisplayInfo
*info
= find_display(dpy
);
135 TRACE("QueryExtension...");
136 if (XextHasExtension(info
)) {
137 *event_basep
= info
->codes
->first_event
;
138 *error_basep
= info
->codes
->first_error
;
139 TRACE("QueryExtension... return True");
143 TRACE("QueryExtension... return False");
149 XAppleDRIQueryVersion(dpy
, majorVersion
, minorVersion
, patchVersion
)
155 XExtDisplayInfo
*info
= find_display(dpy
);
156 xAppleDRIQueryVersionReply rep
;
157 xAppleDRIQueryVersionReq
*req
;
159 TRACE("QueryVersion...");
160 AppleDRICheckExtension(dpy
, info
, False
);
163 GetReq(AppleDRIQueryVersion
, req
);
164 req
->reqType
= info
->codes
->major_opcode
;
165 req
->driReqType
= X_AppleDRIQueryVersion
;
166 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
169 TRACE("QueryVersion... return False");
172 *majorVersion
= rep
.majorVersion
;
173 *minorVersion
= rep
.minorVersion
;
174 *patchVersion
= rep
.patchVersion
;
177 TRACE("QueryVersion... return True");
182 XAppleDRIQueryDirectRenderingCapable(dpy
, screen
, isCapable
)
187 XExtDisplayInfo
*info
= find_display(dpy
);
188 xAppleDRIQueryDirectRenderingCapableReply rep
;
189 xAppleDRIQueryDirectRenderingCapableReq
*req
;
191 TRACE("QueryDirectRenderingCapable...");
192 AppleDRICheckExtension(dpy
, info
, False
);
195 GetReq(AppleDRIQueryDirectRenderingCapable
, req
);
196 req
->reqType
= info
->codes
->major_opcode
;
197 req
->driReqType
= X_AppleDRIQueryDirectRenderingCapable
;
198 req
->screen
= screen
;
199 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
202 TRACE("QueryDirectRenderingCapable... return False");
205 *isCapable
= rep
.isCapable
;
208 TRACE("QueryDirectRenderingCapable... return True");
213 XAppleDRIAuthConnection(dpy
, screen
, magic
)
218 XExtDisplayInfo
*info
= find_display(dpy
);
219 xAppleDRIAuthConnectionReq
*req
;
220 xAppleDRIAuthConnectionReply rep
;
222 TRACE("AuthConnection...");
223 AppleDRICheckExtension(dpy
, info
, False
);
226 GetReq(AppleDRIAuthConnection
, req
);
227 req
->reqType
= info
->codes
->major_opcode
;
228 req
->driReqType
= X_AppleDRIAuthConnection
;
229 req
->screen
= screen
;
231 rep
.authenticated
= 0;
232 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
) || !rep
.authenticated
) {
235 TRACE("AuthConnection... return False");
240 TRACE("AuthConnection... return True");
245 XAppleDRICreateSurface(dpy
, screen
, drawable
, client_id
, key
, uid
)
249 unsigned int client_id
;
253 XExtDisplayInfo
*info
= find_display(dpy
);
254 xAppleDRICreateSurfaceReply rep
;
255 xAppleDRICreateSurfaceReq
*req
;
257 TRACE("CreateSurface...");
258 AppleDRICheckExtension(dpy
, info
, False
);
261 GetReq(AppleDRICreateSurface
, req
);
262 req
->reqType
= info
->codes
->major_opcode
;
263 req
->driReqType
= X_AppleDRICreateSurface
;
264 req
->screen
= screen
;
265 req
->drawable
= drawable
;
266 req
->client_id
= client_id
;
267 rep
.key_0
= rep
.key_1
= rep
.uid
= 0;
268 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
) || !rep
.key_0
) {
271 TRACE("CreateSurface... return False");
279 TRACE("CreateSurface... return True");
284 XAppleDRIDestroySurface(dpy
, screen
, drawable
)
289 XExtDisplayInfo
*info
= find_display(dpy
);
290 xAppleDRIDestroySurfaceReq
*req
;
292 TRACE("DestroySurface...");
293 AppleDRICheckExtension(dpy
, info
, False
);
296 GetReq(AppleDRIDestroySurface
, req
);
297 req
->reqType
= info
->codes
->major_opcode
;
298 req
->driReqType
= X_AppleDRIDestroySurface
;
299 req
->screen
= screen
;
300 req
->drawable
= drawable
;
303 TRACE("DestroySurface... return True");
308 XAppleDRICreateSharedBuffer(Display
* dpy
, int screen
, Drawable drawable
,
309 Bool doubleSwap
, char *path
, size_t pathlen
,
310 int *width
, int *height
)
312 XExtDisplayInfo
*info
= find_display(dpy
);
313 xAppleDRICreateSharedBufferReq
*req
;
314 xAppleDRICreateSharedBufferReply rep
;
316 AppleDRICheckExtension(dpy
, info
, False
);
319 GetReq(AppleDRICreateSharedBuffer
, req
);
320 req
->reqType
= info
->codes
->major_opcode
;
321 req
->driReqType
= X_AppleDRICreateSharedBuffer
;
322 req
->screen
= screen
;
323 req
->drawable
= drawable
;
324 req
->doubleSwap
= doubleSwap
;
327 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
335 /* printf("rep.stringLength %d\n", (int) rep.stringLength); */
337 if (rep
.stringLength
> 0 && rep
.stringLength
<= pathlen
) {
338 _XReadPad(dpy
, path
, rep
.stringLength
);
340 /* printf("path: %s\n", path); */
343 *height
= rep
.height
;
357 XAppleDRISwapBuffers(Display
* dpy
, int screen
, Drawable drawable
)
359 XExtDisplayInfo
*info
= find_display(dpy
);
360 xAppleDRISwapBuffersReq
*req
;
362 AppleDRICheckExtension(dpy
, info
, False
);
365 GetReq(AppleDRISwapBuffers
, req
);
366 req
->reqType
= info
->codes
->major_opcode
;
367 req
->driReqType
= X_AppleDRISwapBuffers
;
368 req
->screen
= screen
;
369 req
->drawable
= drawable
;
377 XAppleDRICreatePixmap(Display
* dpy
, int screen
, Drawable drawable
,
378 int *width
, int *height
, int *pitch
, int *bpp
,
379 size_t * size
, char *bufname
, size_t bufnamesize
)
381 XExtDisplayInfo
*info
= find_display(dpy
);
382 xAppleDRICreatePixmapReq
*req
;
383 xAppleDRICreatePixmapReply rep
;
385 AppleDRICheckExtension(dpy
, info
, False
);
388 GetReq(AppleDRICreatePixmap
, req
);
389 req
->reqType
= info
->codes
->major_opcode
;
390 req
->driReqType
= X_AppleDRICreatePixmap
;
391 req
->screen
= screen
;
392 req
->drawable
= drawable
;
394 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
401 printf("rep.stringLength %d\n", (int) rep.stringLength);
404 if (rep
.stringLength
> 0 && rep
.stringLength
<= bufnamesize
) {
405 _XReadPad(dpy
, bufname
, rep
.stringLength
);
407 /* printf("path: %s\n", bufname); */
410 *height
= rep
.height
;
419 else if (rep
.stringLength
> 0) {
420 _XEatData(dpy
, rep
.stringLength
);
430 * Call it a drawable, because we really don't know what it is
431 * until it reaches the server, and we should keep that in mind.
434 XAppleDRIDestroyPixmap(Display
* dpy
, Pixmap drawable
)
436 XExtDisplayInfo
*info
= find_display(dpy
);
437 xAppleDRIDestroyPixmapReq
*req
;
439 AppleDRICheckExtension(dpy
, info
, False
);
442 GetReq(AppleDRIDestroyPixmap
, req
);
443 req
->reqType
= info
->codes
->major_opcode
;
444 req
->driReqType
= X_AppleDRIDestroyPixmap
;
445 req
->drawable
= drawable
;