1 /* $XFree86: xc/lib/GL/dri/XF86dri.c,v 1.13 2002/10/30 12:51:25 alanh Exp $ */
2 /**************************************************************************
4 Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
5 Copyright 2000 VA Linux Systems, Inc.
8 Permission is hereby granted, free of charge, to any person obtaining a
9 copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sub license, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
16 The above copyright notice and this permission notice (including the
17 next paragraph) shall be included in all copies or substantial portions
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
24 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 **************************************************************************/
32 * Kevin E. Martin <martin@valinux.com>
33 * Jens Owen <jens@tungstengraphics.com>
34 * Rickard E. (Rik) Faith <faith@valinux.com>
38 /* THIS IS NOT AN X CONSORTIUM STANDARD */
40 #ifdef GLX_DIRECT_RENDERING
43 #include <X11/Xlibint.h>
44 #include <X11/extensions/Xext.h>
45 #include <X11/extensions/extutil.h>
47 #include "xf86dristr.h"
49 static XExtensionInfo _xf86dri_info_data
;
50 static XExtensionInfo
*xf86dri_info
= &_xf86dri_info_data
;
51 static char xf86dri_extension_name
[] = XF86DRINAME
;
53 #define XF86DRICheckExtension(dpy,i,val) \
54 XextCheckExtension (dpy, i, xf86dri_extension_name, val)
56 /*****************************************************************************
58 * private utility routines *
60 *****************************************************************************/
62 static int close_display(Display
*dpy
, XExtCodes
*extCodes
);
63 static /* const */ XExtensionHooks xf86dri_extension_hooks
= {
68 NULL
, /* create_font */
70 close_display
, /* close_display */
71 NULL
, /* wire_to_event */
72 NULL
, /* event_to_wire */
74 NULL
, /* error_string */
77 static XEXT_GENERATE_FIND_DISPLAY (find_display
, xf86dri_info
,
78 xf86dri_extension_name
,
79 &xf86dri_extension_hooks
,
82 static XEXT_GENERATE_CLOSE_DISPLAY (close_display
, xf86dri_info
)
85 /*****************************************************************************
87 * public XFree86-DRI Extension routines *
89 *****************************************************************************/
93 #define TRACE(msg) fprintf(stderr,"XF86DRI%s\n", msg);
99 PUBLIC Bool
XF86DRIQueryExtension (dpy
, event_basep
, error_basep
)
101 int *event_basep
, *error_basep
;
103 XExtDisplayInfo
*info
= find_display (dpy
);
105 TRACE("QueryExtension...");
106 if (XextHasExtension(info
)) {
107 *event_basep
= info
->codes
->first_event
;
108 *error_basep
= info
->codes
->first_error
;
109 TRACE("QueryExtension... return True");
112 TRACE("QueryExtension... return False");
117 PUBLIC Bool
XF86DRIQueryVersion(dpy
, majorVersion
, minorVersion
, patchVersion
)
123 XExtDisplayInfo
*info
= find_display (dpy
);
124 xXF86DRIQueryVersionReply rep
;
125 xXF86DRIQueryVersionReq
*req
;
127 TRACE("QueryVersion...");
128 XF86DRICheckExtension (dpy
, info
, False
);
131 GetReq(XF86DRIQueryVersion
, req
);
132 req
->reqType
= info
->codes
->major_opcode
;
133 req
->driReqType
= X_XF86DRIQueryVersion
;
134 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
137 TRACE("QueryVersion... return False");
140 *majorVersion
= rep
.majorVersion
;
141 *minorVersion
= rep
.minorVersion
;
142 *patchVersion
= rep
.patchVersion
;
145 TRACE("QueryVersion... return True");
149 PUBLIC Bool
XF86DRIQueryDirectRenderingCapable(dpy
, screen
, isCapable
)
154 XExtDisplayInfo
*info
= find_display (dpy
);
155 xXF86DRIQueryDirectRenderingCapableReply rep
;
156 xXF86DRIQueryDirectRenderingCapableReq
*req
;
158 TRACE("QueryDirectRenderingCapable...");
159 XF86DRICheckExtension (dpy
, info
, False
);
162 GetReq(XF86DRIQueryDirectRenderingCapable
, req
);
163 req
->reqType
= info
->codes
->major_opcode
;
164 req
->driReqType
= X_XF86DRIQueryDirectRenderingCapable
;
165 req
->screen
= screen
;
166 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
169 TRACE("QueryDirectRenderingCapable... return False");
172 *isCapable
= rep
.isCapable
;
175 TRACE("QueryDirectRenderingCapable... return True");
179 PUBLIC Bool
XF86DRIOpenConnection(dpy
, screen
, hSAREA
, busIdString
)
182 drm_handle_t
* hSAREA
;
185 XExtDisplayInfo
*info
= find_display (dpy
);
186 xXF86DRIOpenConnectionReply rep
;
187 xXF86DRIOpenConnectionReq
*req
;
189 TRACE("OpenConnection...");
190 XF86DRICheckExtension (dpy
, info
, False
);
193 GetReq(XF86DRIOpenConnection
, req
);
194 req
->reqType
= info
->codes
->major_opcode
;
195 req
->driReqType
= X_XF86DRIOpenConnection
;
196 req
->screen
= screen
;
197 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
200 TRACE("OpenConnection... return False");
204 *hSAREA
= rep
.hSAREALow
;
205 if (sizeof(drm_handle_t
) == 8) {
206 int shift
= 32; /* var to prevent warning on next line */
207 *hSAREA
|= ((drm_handle_t
) rep
.hSAREAHigh
) << shift
;
211 if (!(*busIdString
= (char *)Xcalloc(rep
.busIdStringLength
+ 1, 1))) {
212 _XEatData(dpy
, ((rep
.busIdStringLength
+3) & ~3));
215 TRACE("OpenConnection... return False");
218 _XReadPad(dpy
, *busIdString
, rep
.busIdStringLength
);
224 TRACE("OpenConnection... return True");
228 PUBLIC Bool
XF86DRIAuthConnection(dpy
, screen
, magic
)
233 XExtDisplayInfo
*info
= find_display (dpy
);
234 xXF86DRIAuthConnectionReq
*req
;
235 xXF86DRIAuthConnectionReply rep
;
237 TRACE("AuthConnection...");
238 XF86DRICheckExtension (dpy
, info
, False
);
241 GetReq(XF86DRIAuthConnection
, req
);
242 req
->reqType
= info
->codes
->major_opcode
;
243 req
->driReqType
= X_XF86DRIAuthConnection
;
244 req
->screen
= screen
;
246 rep
.authenticated
= 0;
247 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
) || !rep
.authenticated
) {
250 TRACE("AuthConnection... return False");
255 TRACE("AuthConnection... return True");
259 PUBLIC Bool
XF86DRICloseConnection(dpy
, screen
)
263 XExtDisplayInfo
*info
= find_display (dpy
);
264 xXF86DRICloseConnectionReq
*req
;
266 TRACE("CloseConnection...");
268 XF86DRICheckExtension (dpy
, info
, False
);
271 GetReq(XF86DRICloseConnection
, req
);
272 req
->reqType
= info
->codes
->major_opcode
;
273 req
->driReqType
= X_XF86DRICloseConnection
;
274 req
->screen
= screen
;
277 TRACE("CloseConnection... return True");
281 PUBLIC Bool
XF86DRIGetClientDriverName(dpy
, screen
, ddxDriverMajorVersion
,
282 ddxDriverMinorVersion
, ddxDriverPatchVersion
, clientDriverName
)
285 int* ddxDriverMajorVersion
;
286 int* ddxDriverMinorVersion
;
287 int* ddxDriverPatchVersion
;
288 char** clientDriverName
;
290 XExtDisplayInfo
*info
= find_display (dpy
);
291 xXF86DRIGetClientDriverNameReply rep
;
292 xXF86DRIGetClientDriverNameReq
*req
;
294 TRACE("GetClientDriverName...");
295 XF86DRICheckExtension (dpy
, info
, False
);
298 GetReq(XF86DRIGetClientDriverName
, req
);
299 req
->reqType
= info
->codes
->major_opcode
;
300 req
->driReqType
= X_XF86DRIGetClientDriverName
;
301 req
->screen
= screen
;
302 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
305 TRACE("GetClientDriverName... return False");
309 *ddxDriverMajorVersion
= rep
.ddxDriverMajorVersion
;
310 *ddxDriverMinorVersion
= rep
.ddxDriverMinorVersion
;
311 *ddxDriverPatchVersion
= rep
.ddxDriverPatchVersion
;
314 if (!(*clientDriverName
= (char *)Xcalloc(rep
.clientDriverNameLength
+ 1, 1))) {
315 _XEatData(dpy
, ((rep
.clientDriverNameLength
+3) & ~3));
318 TRACE("GetClientDriverName... return False");
321 _XReadPad(dpy
, *clientDriverName
, rep
.clientDriverNameLength
);
323 *clientDriverName
= NULL
;
327 TRACE("GetClientDriverName... return True");
331 PUBLIC Bool
XF86DRICreateContextWithConfig(dpy
, screen
, configID
, context
,
337 drm_context_t
* hHWContext
;
339 XExtDisplayInfo
*info
= find_display (dpy
);
340 xXF86DRICreateContextReply rep
;
341 xXF86DRICreateContextReq
*req
;
343 TRACE("CreateContext...");
344 XF86DRICheckExtension (dpy
, info
, False
);
347 GetReq(XF86DRICreateContext
, req
);
348 req
->reqType
= info
->codes
->major_opcode
;
349 req
->driReqType
= X_XF86DRICreateContext
;
350 req
->visual
= configID
;
351 req
->screen
= screen
;
352 *context
= XAllocID(dpy
);
353 req
->context
= *context
;
354 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
357 TRACE("CreateContext... return False");
360 *hHWContext
= rep
.hHWContext
;
363 TRACE("CreateContext... return True");
367 PUBLIC Bool
XF86DRICreateContext(dpy
, screen
, visual
, context
, hHWContext
)
372 drm_context_t
* hHWContext
;
374 return XF86DRICreateContextWithConfig( dpy
, screen
, visual
->visualid
,
375 context
, hHWContext
);
378 PUBLIC GLboolean
XF86DRIDestroyContext( __DRInativeDisplay
* ndpy
, int screen
,
381 Display
* const dpy
= (Display
*) ndpy
;
382 XExtDisplayInfo
*info
= find_display (dpy
);
383 xXF86DRIDestroyContextReq
*req
;
385 TRACE("DestroyContext...");
386 XF86DRICheckExtension (dpy
, info
, False
);
389 GetReq(XF86DRIDestroyContext
, req
);
390 req
->reqType
= info
->codes
->major_opcode
;
391 req
->driReqType
= X_XF86DRIDestroyContext
;
392 req
->screen
= screen
;
393 req
->context
= context
;
396 TRACE("DestroyContext... return True");
400 PUBLIC GLboolean
XF86DRICreateDrawable( __DRInativeDisplay
* ndpy
, int screen
,
401 __DRIid drawable
, drm_drawable_t
* hHWDrawable
)
403 Display
* const dpy
= (Display
*) ndpy
;
404 XExtDisplayInfo
*info
= find_display (dpy
);
405 xXF86DRICreateDrawableReply rep
;
406 xXF86DRICreateDrawableReq
*req
;
408 TRACE("CreateDrawable...");
409 XF86DRICheckExtension (dpy
, info
, False
);
412 GetReq(XF86DRICreateDrawable
, req
);
413 req
->reqType
= info
->codes
->major_opcode
;
414 req
->driReqType
= X_XF86DRICreateDrawable
;
415 req
->screen
= screen
;
416 req
->drawable
= drawable
;
417 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
420 TRACE("CreateDrawable... return False");
423 *hHWDrawable
= rep
.hHWDrawable
;
426 TRACE("CreateDrawable... return True");
430 PUBLIC GLboolean
XF86DRIDestroyDrawable( __DRInativeDisplay
* ndpy
, int screen
,
433 Display
* const dpy
= (Display
*) ndpy
;
434 XExtDisplayInfo
*info
= find_display (dpy
);
435 xXF86DRIDestroyDrawableReq
*req
;
437 TRACE("DestroyDrawable...");
438 XF86DRICheckExtension (dpy
, info
, False
);
441 GetReq(XF86DRIDestroyDrawable
, req
);
442 req
->reqType
= info
->codes
->major_opcode
;
443 req
->driReqType
= X_XF86DRIDestroyDrawable
;
444 req
->screen
= screen
;
445 req
->drawable
= drawable
;
448 TRACE("DestroyDrawable... return True");
452 PUBLIC Bool
XF86DRIGetDrawableInfo(Display
* dpy
, int screen
, Drawable drawable
,
453 unsigned int* index
, unsigned int* stamp
,
454 int* X
, int* Y
, int* W
, int* H
,
455 int* numClipRects
, drm_clip_rect_t
** pClipRects
,
456 int* backX
, int* backY
,
457 int* numBackClipRects
, drm_clip_rect_t
** pBackClipRects
)
459 XExtDisplayInfo
*info
= find_display (dpy
);
460 xXF86DRIGetDrawableInfoReply rep
;
461 xXF86DRIGetDrawableInfoReq
*req
;
464 TRACE("GetDrawableInfo...");
465 XF86DRICheckExtension (dpy
, info
, False
);
468 GetReq(XF86DRIGetDrawableInfo
, req
);
469 req
->reqType
= info
->codes
->major_opcode
;
470 req
->driReqType
= X_XF86DRIGetDrawableInfo
;
471 req
->screen
= screen
;
472 req
->drawable
= drawable
;
474 if (!_XReply(dpy
, (xReply
*)&rep
, 1, xFalse
))
478 TRACE("GetDrawableInfo... return False");
481 *index
= rep
.drawableTableIndex
;
482 *stamp
= rep
.drawableTableStamp
;
483 *X
= (int)rep
.drawableX
;
484 *Y
= (int)rep
.drawableY
;
485 *W
= (int)rep
.drawableWidth
;
486 *H
= (int)rep
.drawableHeight
;
487 *numClipRects
= rep
.numClipRects
;
488 total_rects
= *numClipRects
;
492 *numBackClipRects
= rep
.numBackClipRects
;
493 total_rects
+= *numBackClipRects
;
496 /* Because of the fix in Xserver/GL/dri/xf86dri.c, this check breaks
497 * backwards compatibility (Because of the >> 2 shift) but the fix
498 * enables multi-threaded apps to work.
500 if (rep
.length
!= ((((SIZEOF(xXF86DRIGetDrawableInfoReply
) -
501 SIZEOF(xGenericReply
) +
502 total_rects
* sizeof(drm_clip_rect_t
)) + 3) & ~3) >> 2)) {
503 _XEatData(dpy
, rep
.length
);
506 TRACE("GetDrawableInfo... return False");
512 int len
= sizeof(drm_clip_rect_t
) * (*numClipRects
);
514 *pClipRects
= (drm_clip_rect_t
*)Xcalloc(len
, 1);
516 _XRead(dpy
, (char*)*pClipRects
, len
);
521 if (*numBackClipRects
) {
522 int len
= sizeof(drm_clip_rect_t
) * (*numBackClipRects
);
524 *pBackClipRects
= (drm_clip_rect_t
*)Xcalloc(len
, 1);
526 _XRead(dpy
, (char*)*pBackClipRects
, len
);
528 *pBackClipRects
= NULL
;
533 TRACE("GetDrawableInfo... return True");
537 PUBLIC Bool
XF86DRIGetDeviceInfo(dpy
, screen
, hFrameBuffer
,
538 fbOrigin
, fbSize
, fbStride
, devPrivateSize
, pDevPrivate
)
541 drm_handle_t
* hFrameBuffer
;
548 XExtDisplayInfo
*info
= find_display (dpy
);
549 xXF86DRIGetDeviceInfoReply rep
;
550 xXF86DRIGetDeviceInfoReq
*req
;
552 TRACE("GetDeviceInfo...");
553 XF86DRICheckExtension (dpy
, info
, False
);
556 GetReq(XF86DRIGetDeviceInfo
, req
);
557 req
->reqType
= info
->codes
->major_opcode
;
558 req
->driReqType
= X_XF86DRIGetDeviceInfo
;
559 req
->screen
= screen
;
560 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
563 TRACE("GetDeviceInfo... return False");
567 *hFrameBuffer
= rep
.hFrameBufferLow
;
568 if (sizeof(drm_handle_t
) == 8) {
569 int shift
= 32; /* var to prevent warning on next line */
570 *hFrameBuffer
|= ((drm_handle_t
) rep
.hFrameBufferHigh
) << shift
;
573 *fbOrigin
= rep
.framebufferOrigin
;
574 *fbSize
= rep
.framebufferSize
;
575 *fbStride
= rep
.framebufferStride
;
576 *devPrivateSize
= rep
.devPrivateSize
;
579 if (!(*pDevPrivate
= (void *)Xcalloc(rep
.devPrivateSize
, 1))) {
580 _XEatData(dpy
, ((rep
.devPrivateSize
+3) & ~3));
583 TRACE("GetDeviceInfo... return False");
586 _XRead(dpy
, (char*)*pDevPrivate
, rep
.devPrivateSize
);
593 TRACE("GetDeviceInfo... return True");
597 PUBLIC Bool
XF86DRIOpenFullScreen(dpy
, screen
, drawable
)
602 /* This function and the underlying X protocol are deprecated.
610 PUBLIC Bool
XF86DRICloseFullScreen(dpy
, screen
, drawable
)
615 /* This function and the underlying X protocol are deprecated.
623 #endif /* GLX_DIRECT_RENDERING */