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 */
43 #include <X11/Xlibint.h>
44 #include "appledristr.h"
45 #include <X11/extensions/Xext.h>
46 #include <X11/extensions/extutil.h>
49 static XExtensionInfo _appledri_info_data
;
50 static XExtensionInfo
*appledri_info
= &_appledri_info_data
;
51 static char *appledri_extension_name
= APPLEDRINAME
;
53 #define AppleDRICheckExtension(dpy,i,val) \
54 XextCheckExtension (dpy, i, appledri_extension_name, val)
56 /*****************************************************************************
58 * private utility routines *
60 *****************************************************************************/
62 static int close_display(Display
* dpy
, XExtCodes
* extCodes
);
63 static Bool
wire_to_event(Display
* dpy
, XEvent
* re
, xEvent
* event
);
65 static /* const */ XExtensionHooks appledri_extension_hooks
= {
70 NULL
, /* create_font */
72 close_display
, /* close_display */
73 wire_to_event
, /* wire_to_event */
74 NULL
, /* event_to_wire */
76 NULL
, /* error_string */
80 XEXT_GENERATE_FIND_DISPLAY(find_display
, appledri_info
,
81 appledri_extension_name
,
82 &appledri_extension_hooks
,
83 AppleDRINumberEvents
, NULL
)
85 static XEXT_GENERATE_CLOSE_DISPLAY(close_display
, appledri_info
)
87 static void (*surface_notify_handler
) ();
89 void *XAppleDRISetSurfaceNotifyHandler(void (*fun
) ())
91 void *old
= surface_notify_handler
;
92 surface_notify_handler
= fun
;
97 wire_to_event(Display
*dpy
, XEvent
*re
, xEvent
*event
)
99 XExtDisplayInfo
*info
= find_display(dpy
);
100 xAppleDRINotifyEvent
*sevent
;
102 AppleDRICheckExtension(dpy
, info
, False
);
104 switch ((event
->u
.u
.type
& 0x7f) - info
->codes
->first_event
) {
105 case AppleDRISurfaceNotify
:
106 sevent
= (xAppleDRINotifyEvent
*) event
;
107 if (surface_notify_handler
!= NULL
) {
108 (*surface_notify_handler
) (dpy
, (unsigned int) sevent
->arg
,
116 /*****************************************************************************
118 * public Apple-DRI Extension routines *
120 *****************************************************************************/
124 #define TRACE(msg) fprintf(stderr, "AppleDRI%s\n", msg);
131 XAppleDRIQueryExtension(dpy
, event_basep
, error_basep
)
133 int *event_basep
, *error_basep
;
135 XExtDisplayInfo
*info
= find_display(dpy
);
137 TRACE("QueryExtension...");
138 if (XextHasExtension(info
)) {
139 *event_basep
= info
->codes
->first_event
;
140 *error_basep
= info
->codes
->first_error
;
141 TRACE("QueryExtension... return True");
145 TRACE("QueryExtension... return False");
151 XAppleDRIQueryVersion(dpy
, majorVersion
, minorVersion
, patchVersion
)
157 XExtDisplayInfo
*info
= find_display(dpy
);
158 xAppleDRIQueryVersionReply rep
;
159 xAppleDRIQueryVersionReq
*req
;
161 TRACE("QueryVersion...");
162 AppleDRICheckExtension(dpy
, info
, False
);
165 GetReq(AppleDRIQueryVersion
, req
);
166 req
->reqType
= info
->codes
->major_opcode
;
167 req
->driReqType
= X_AppleDRIQueryVersion
;
168 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
171 TRACE("QueryVersion... return False");
174 *majorVersion
= rep
.majorVersion
;
175 *minorVersion
= rep
.minorVersion
;
176 *patchVersion
= rep
.patchVersion
;
179 TRACE("QueryVersion... return True");
184 XAppleDRIQueryDirectRenderingCapable(dpy
, screen
, isCapable
)
189 XExtDisplayInfo
*info
= find_display(dpy
);
190 xAppleDRIQueryDirectRenderingCapableReply rep
;
191 xAppleDRIQueryDirectRenderingCapableReq
*req
;
193 TRACE("QueryDirectRenderingCapable...");
194 AppleDRICheckExtension(dpy
, info
, False
);
197 GetReq(AppleDRIQueryDirectRenderingCapable
, req
);
198 req
->reqType
= info
->codes
->major_opcode
;
199 req
->driReqType
= X_AppleDRIQueryDirectRenderingCapable
;
200 req
->screen
= screen
;
201 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
204 TRACE("QueryDirectRenderingCapable... return False");
207 *isCapable
= rep
.isCapable
;
210 TRACE("QueryDirectRenderingCapable... return True");
215 XAppleDRIAuthConnection(dpy
, screen
, magic
)
220 XExtDisplayInfo
*info
= find_display(dpy
);
221 xAppleDRIAuthConnectionReq
*req
;
222 xAppleDRIAuthConnectionReply rep
;
224 TRACE("AuthConnection...");
225 AppleDRICheckExtension(dpy
, info
, False
);
228 GetReq(AppleDRIAuthConnection
, req
);
229 req
->reqType
= info
->codes
->major_opcode
;
230 req
->driReqType
= X_AppleDRIAuthConnection
;
231 req
->screen
= screen
;
233 rep
.authenticated
= 0;
234 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
) || !rep
.authenticated
) {
237 TRACE("AuthConnection... return False");
242 TRACE("AuthConnection... return True");
247 XAppleDRICreateSurface(dpy
, screen
, drawable
, client_id
, key
, uid
)
251 unsigned int client_id
;
255 XExtDisplayInfo
*info
= find_display(dpy
);
256 xAppleDRICreateSurfaceReply rep
;
257 xAppleDRICreateSurfaceReq
*req
;
259 TRACE("CreateSurface...");
260 AppleDRICheckExtension(dpy
, info
, False
);
263 GetReq(AppleDRICreateSurface
, req
);
264 req
->reqType
= info
->codes
->major_opcode
;
265 req
->driReqType
= X_AppleDRICreateSurface
;
266 req
->screen
= screen
;
267 req
->drawable
= drawable
;
268 req
->client_id
= client_id
;
269 rep
.key_0
= rep
.key_1
= rep
.uid
= 0;
270 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
) || !rep
.key_0
) {
273 TRACE("CreateSurface... return False");
281 TRACE("CreateSurface... return True");
286 XAppleDRIDestroySurface(dpy
, screen
, drawable
)
291 XExtDisplayInfo
*info
= find_display(dpy
);
292 xAppleDRIDestroySurfaceReq
*req
;
294 TRACE("DestroySurface...");
295 AppleDRICheckExtension(dpy
, info
, False
);
298 GetReq(AppleDRIDestroySurface
, req
);
299 req
->reqType
= info
->codes
->major_opcode
;
300 req
->driReqType
= X_AppleDRIDestroySurface
;
301 req
->screen
= screen
;
302 req
->drawable
= drawable
;
305 TRACE("DestroySurface... return True");
310 XAppleDRICreateSharedBuffer(Display
* dpy
, int screen
, Drawable drawable
,
311 Bool doubleSwap
, char *path
, size_t pathlen
,
312 int *width
, int *height
)
314 XExtDisplayInfo
*info
= find_display(dpy
);
315 xAppleDRICreateSharedBufferReq
*req
;
316 xAppleDRICreateSharedBufferReply rep
;
318 AppleDRICheckExtension(dpy
, info
, False
);
321 GetReq(AppleDRICreateSharedBuffer
, req
);
322 req
->reqType
= info
->codes
->major_opcode
;
323 req
->driReqType
= X_AppleDRICreateSharedBuffer
;
324 req
->screen
= screen
;
325 req
->drawable
= drawable
;
326 req
->doubleSwap
= doubleSwap
;
329 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
337 printf("rep.stringLength %d\n", (int) rep
.stringLength
);
339 if (rep
.stringLength
> 0 && rep
.stringLength
<= pathlen
) {
340 _XReadPad(dpy
, path
, rep
.stringLength
);
342 printf("path: %s\n", path
);
345 *height
= rep
.height
;
359 XAppleDRISwapBuffers(Display
* dpy
, int screen
, Drawable drawable
)
361 XExtDisplayInfo
*info
= find_display(dpy
);
362 xAppleDRISwapBuffersReq
*req
;
364 AppleDRICheckExtension(dpy
, info
, False
);
367 GetReq(AppleDRISwapBuffers
, req
);
368 req
->reqType
= info
->codes
->major_opcode
;
369 req
->driReqType
= X_AppleDRISwapBuffers
;
370 req
->screen
= screen
;
371 req
->drawable
= drawable
;
379 XAppleDRICreatePixmap(Display
* dpy
, int screen
, Drawable drawable
,
380 int *width
, int *height
, int *pitch
, int *bpp
,
381 size_t * size
, char *bufname
, size_t bufnamesize
)
383 XExtDisplayInfo
*info
= find_display(dpy
);
384 xAppleDRICreatePixmapReq
*req
;
385 xAppleDRICreatePixmapReply rep
;
387 AppleDRICheckExtension(dpy
, info
, False
);
390 GetReq(AppleDRICreatePixmap
, req
);
391 req
->reqType
= info
->codes
->major_opcode
;
392 req
->driReqType
= X_AppleDRICreatePixmap
;
393 req
->screen
= screen
;
394 req
->drawable
= drawable
;
396 if (!_XReply(dpy
, (xReply
*) & rep
, 0, xFalse
)) {
403 printf("rep.stringLength %d\n", (int) rep.stringLength);
406 if (rep
.stringLength
> 0 && rep
.stringLength
<= bufnamesize
) {
407 _XReadPad(dpy
, bufname
, rep
.stringLength
);
409 printf("path: %s\n", bufname
);
412 *height
= rep
.height
;
421 else if (rep
.stringLength
> 0) {
422 _XEatData(dpy
, rep
.stringLength
);
432 * Call it a drawable, because we really don't know what it is
433 * until it reaches the server, and we should keep that in mind.
436 XAppleDRIDestroyPixmap(Display
* dpy
, Pixmap drawable
)
438 XExtDisplayInfo
*info
= find_display(dpy
);
439 xAppleDRIDestroyPixmapReq
*req
;
441 AppleDRICheckExtension(dpy
, info
, False
);
444 GetReq(AppleDRIDestroyPixmap
, req
);
445 req
->reqType
= info
->codes
->major_opcode
;
446 req
->driReqType
= X_AppleDRIDestroyPixmap
;
447 req
->drawable
= drawable
;