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 */
41 #include <X11/Xlibint.h>
42 #include <X11/extensions/Xext.h>
43 #include <X11/extensions/extutil.h>
45 #include "xf86dristr.h"
47 static XExtensionInfo _xf86dri_info_data
;
48 static XExtensionInfo
*xf86dri_info
= &_xf86dri_info_data
;
49 static char xf86dri_extension_name
[] = XF86DRINAME
;
51 #define XF86DRICheckExtension(dpy,i,val) \
52 XextCheckExtension (dpy, i, xf86dri_extension_name, val)
54 /*****************************************************************************
56 * private utility routines *
58 *****************************************************************************/
60 static int close_display(Display
*dpy
, XExtCodes
*extCodes
);
61 static /* const */ XExtensionHooks xf86dri_extension_hooks
= {
66 NULL
, /* create_font */
68 close_display
, /* close_display */
69 NULL
, /* wire_to_event */
70 NULL
, /* event_to_wire */
72 NULL
, /* error_string */
75 static XEXT_GENERATE_FIND_DISPLAY (find_display
, xf86dri_info
,
76 xf86dri_extension_name
,
77 &xf86dri_extension_hooks
,
80 static XEXT_GENERATE_CLOSE_DISPLAY (close_display
, xf86dri_info
)
83 /*****************************************************************************
85 * public XFree86-DRI Extension routines *
87 *****************************************************************************/
91 #define TRACE(msg) fprintf(stderr,"XF86DRI%s\n", msg);
97 PUBLIC Bool
XF86DRIQueryExtension (dpy
, event_basep
, error_basep
)
99 int *event_basep
, *error_basep
;
101 XExtDisplayInfo
*info
= find_display (dpy
);
103 TRACE("QueryExtension...");
104 if (XextHasExtension(info
)) {
105 *event_basep
= info
->codes
->first_event
;
106 *error_basep
= info
->codes
->first_error
;
107 TRACE("QueryExtension... return True");
110 TRACE("QueryExtension... return False");
115 PUBLIC Bool
XF86DRIQueryVersion(dpy
, majorVersion
, minorVersion
, patchVersion
)
121 XExtDisplayInfo
*info
= find_display (dpy
);
122 xXF86DRIQueryVersionReply rep
;
123 xXF86DRIQueryVersionReq
*req
;
125 TRACE("QueryVersion...");
126 XF86DRICheckExtension (dpy
, info
, False
);
129 GetReq(XF86DRIQueryVersion
, req
);
130 req
->reqType
= info
->codes
->major_opcode
;
131 req
->driReqType
= X_XF86DRIQueryVersion
;
132 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
135 TRACE("QueryVersion... return False");
138 *majorVersion
= rep
.majorVersion
;
139 *minorVersion
= rep
.minorVersion
;
140 *patchVersion
= rep
.patchVersion
;
143 TRACE("QueryVersion... return True");
147 PUBLIC Bool
XF86DRIQueryDirectRenderingCapable(dpy
, screen
, isCapable
)
152 XExtDisplayInfo
*info
= find_display (dpy
);
153 xXF86DRIQueryDirectRenderingCapableReply rep
;
154 xXF86DRIQueryDirectRenderingCapableReq
*req
;
156 TRACE("QueryDirectRenderingCapable...");
157 XF86DRICheckExtension (dpy
, info
, False
);
160 GetReq(XF86DRIQueryDirectRenderingCapable
, req
);
161 req
->reqType
= info
->codes
->major_opcode
;
162 req
->driReqType
= X_XF86DRIQueryDirectRenderingCapable
;
163 req
->screen
= screen
;
164 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
167 TRACE("QueryDirectRenderingCapable... return False");
170 *isCapable
= rep
.isCapable
;
173 TRACE("QueryDirectRenderingCapable... return True");
177 PUBLIC Bool
XF86DRIOpenConnection(dpy
, screen
, hSAREA
, busIdString
)
180 drm_handle_t
* hSAREA
;
183 XExtDisplayInfo
*info
= find_display (dpy
);
184 xXF86DRIOpenConnectionReply rep
;
185 xXF86DRIOpenConnectionReq
*req
;
187 TRACE("OpenConnection...");
188 XF86DRICheckExtension (dpy
, info
, False
);
191 GetReq(XF86DRIOpenConnection
, req
);
192 req
->reqType
= info
->codes
->major_opcode
;
193 req
->driReqType
= X_XF86DRIOpenConnection
;
194 req
->screen
= screen
;
195 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
198 TRACE("OpenConnection... return False");
202 *hSAREA
= rep
.hSAREALow
;
203 if (sizeof(drm_handle_t
) == 8) {
204 const int shift
= 32; /* var to prevent warning on next line */
205 *hSAREA
|= ((drm_handle_t
) rep
.hSAREAHigh
) << shift
;
209 if (!(*busIdString
= (char *)Xcalloc(rep
.busIdStringLength
+ 1, 1))) {
210 _XEatData(dpy
, ((rep
.busIdStringLength
+3) & ~3));
213 TRACE("OpenConnection... return False");
216 _XReadPad(dpy
, *busIdString
, rep
.busIdStringLength
);
222 TRACE("OpenConnection... return True");
226 PUBLIC Bool
XF86DRIAuthConnection(dpy
, screen
, magic
)
231 XExtDisplayInfo
*info
= find_display (dpy
);
232 xXF86DRIAuthConnectionReq
*req
;
233 xXF86DRIAuthConnectionReply rep
;
235 TRACE("AuthConnection...");
236 XF86DRICheckExtension (dpy
, info
, False
);
239 GetReq(XF86DRIAuthConnection
, req
);
240 req
->reqType
= info
->codes
->major_opcode
;
241 req
->driReqType
= X_XF86DRIAuthConnection
;
242 req
->screen
= screen
;
244 rep
.authenticated
= 0;
245 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
) || !rep
.authenticated
) {
248 TRACE("AuthConnection... return False");
253 TRACE("AuthConnection... return True");
257 PUBLIC Bool
XF86DRICloseConnection(dpy
, screen
)
261 XExtDisplayInfo
*info
= find_display (dpy
);
262 xXF86DRICloseConnectionReq
*req
;
264 TRACE("CloseConnection...");
266 XF86DRICheckExtension (dpy
, info
, False
);
269 GetReq(XF86DRICloseConnection
, req
);
270 req
->reqType
= info
->codes
->major_opcode
;
271 req
->driReqType
= X_XF86DRICloseConnection
;
272 req
->screen
= screen
;
275 TRACE("CloseConnection... return True");
279 PUBLIC Bool
XF86DRIGetClientDriverName(dpy
, screen
, ddxDriverMajorVersion
,
280 ddxDriverMinorVersion
, ddxDriverPatchVersion
, clientDriverName
)
283 int* ddxDriverMajorVersion
;
284 int* ddxDriverMinorVersion
;
285 int* ddxDriverPatchVersion
;
286 char** clientDriverName
;
288 XExtDisplayInfo
*info
= find_display (dpy
);
289 xXF86DRIGetClientDriverNameReply rep
;
290 xXF86DRIGetClientDriverNameReq
*req
;
292 TRACE("GetClientDriverName...");
293 XF86DRICheckExtension (dpy
, info
, False
);
296 GetReq(XF86DRIGetClientDriverName
, req
);
297 req
->reqType
= info
->codes
->major_opcode
;
298 req
->driReqType
= X_XF86DRIGetClientDriverName
;
299 req
->screen
= screen
;
300 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
303 TRACE("GetClientDriverName... return False");
307 *ddxDriverMajorVersion
= rep
.ddxDriverMajorVersion
;
308 *ddxDriverMinorVersion
= rep
.ddxDriverMinorVersion
;
309 *ddxDriverPatchVersion
= rep
.ddxDriverPatchVersion
;
312 if (!(*clientDriverName
= (char *)Xcalloc(rep
.clientDriverNameLength
+ 1, 1))) {
313 _XEatData(dpy
, ((rep
.clientDriverNameLength
+3) & ~3));
316 TRACE("GetClientDriverName... return False");
319 _XReadPad(dpy
, *clientDriverName
, rep
.clientDriverNameLength
);
321 *clientDriverName
= NULL
;
325 TRACE("GetClientDriverName... return True");
329 PUBLIC Bool
XF86DRICreateContextWithConfig(dpy
, screen
, configID
, context
,
335 drm_context_t
* hHWContext
;
337 XExtDisplayInfo
*info
= find_display (dpy
);
338 xXF86DRICreateContextReply rep
;
339 xXF86DRICreateContextReq
*req
;
341 TRACE("CreateContext...");
342 XF86DRICheckExtension (dpy
, info
, False
);
345 GetReq(XF86DRICreateContext
, req
);
346 req
->reqType
= info
->codes
->major_opcode
;
347 req
->driReqType
= X_XF86DRICreateContext
;
348 req
->visual
= configID
;
349 req
->screen
= screen
;
350 *context
= XAllocID(dpy
);
351 req
->context
= *context
;
352 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
355 TRACE("CreateContext... return False");
358 *hHWContext
= rep
.hHWContext
;
361 TRACE("CreateContext... return True");
365 PUBLIC Bool
XF86DRICreateContext(dpy
, screen
, visual
, context
, hHWContext
)
370 drm_context_t
* hHWContext
;
372 return XF86DRICreateContextWithConfig( dpy
, screen
, visual
->visualid
,
373 context
, hHWContext
);
376 PUBLIC GLboolean
XF86DRIDestroyContext( __DRInativeDisplay
* ndpy
, int screen
,
379 Display
* const dpy
= (Display
*) ndpy
;
380 XExtDisplayInfo
*info
= find_display (dpy
);
381 xXF86DRIDestroyContextReq
*req
;
383 TRACE("DestroyContext...");
384 XF86DRICheckExtension (dpy
, info
, False
);
387 GetReq(XF86DRIDestroyContext
, req
);
388 req
->reqType
= info
->codes
->major_opcode
;
389 req
->driReqType
= X_XF86DRIDestroyContext
;
390 req
->screen
= screen
;
391 req
->context
= context
;
394 TRACE("DestroyContext... return True");
398 PUBLIC GLboolean
XF86DRICreateDrawable( __DRInativeDisplay
* ndpy
, int screen
,
399 __DRIid drawable
, drm_drawable_t
* hHWDrawable
)
401 Display
* const dpy
= (Display
*) ndpy
;
402 XExtDisplayInfo
*info
= find_display (dpy
);
403 xXF86DRICreateDrawableReply rep
;
404 xXF86DRICreateDrawableReq
*req
;
406 TRACE("CreateDrawable...");
407 XF86DRICheckExtension (dpy
, info
, False
);
410 GetReq(XF86DRICreateDrawable
, req
);
411 req
->reqType
= info
->codes
->major_opcode
;
412 req
->driReqType
= X_XF86DRICreateDrawable
;
413 req
->screen
= screen
;
414 req
->drawable
= drawable
;
415 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
418 TRACE("CreateDrawable... return False");
421 *hHWDrawable
= rep
.hHWDrawable
;
424 TRACE("CreateDrawable... return True");
428 PUBLIC GLboolean
XF86DRIDestroyDrawable( __DRInativeDisplay
* ndpy
, int screen
,
431 Display
* const dpy
= (Display
*) ndpy
;
432 XExtDisplayInfo
*info
= find_display (dpy
);
433 xXF86DRIDestroyDrawableReq
*req
;
435 TRACE("DestroyDrawable...");
436 XF86DRICheckExtension (dpy
, info
, False
);
439 GetReq(XF86DRIDestroyDrawable
, req
);
440 req
->reqType
= info
->codes
->major_opcode
;
441 req
->driReqType
= X_XF86DRIDestroyDrawable
;
442 req
->screen
= screen
;
443 req
->drawable
= drawable
;
446 TRACE("DestroyDrawable... return True");
450 PUBLIC Bool
XF86DRIGetDrawableInfo(Display
* dpy
, int screen
, Drawable drawable
,
451 unsigned int* index
, unsigned int* stamp
,
452 int* X
, int* Y
, int* W
, int* H
,
453 int* numClipRects
, drm_clip_rect_t
** pClipRects
,
454 int* backX
, int* backY
,
455 int* numBackClipRects
, drm_clip_rect_t
** pBackClipRects
)
457 XExtDisplayInfo
*info
= find_display (dpy
);
458 xXF86DRIGetDrawableInfoReply rep
;
459 xXF86DRIGetDrawableInfoReq
*req
;
462 TRACE("GetDrawableInfo...");
463 XF86DRICheckExtension (dpy
, info
, False
);
466 GetReq(XF86DRIGetDrawableInfo
, req
);
467 req
->reqType
= info
->codes
->major_opcode
;
468 req
->driReqType
= X_XF86DRIGetDrawableInfo
;
469 req
->screen
= screen
;
470 req
->drawable
= drawable
;
472 if (!_XReply(dpy
, (xReply
*)&rep
, 1, xFalse
))
476 TRACE("GetDrawableInfo... return False");
479 *index
= rep
.drawableTableIndex
;
480 *stamp
= rep
.drawableTableStamp
;
481 *X
= (int)rep
.drawableX
;
482 *Y
= (int)rep
.drawableY
;
483 *W
= (int)rep
.drawableWidth
;
484 *H
= (int)rep
.drawableHeight
;
485 *numClipRects
= rep
.numClipRects
;
486 total_rects
= *numClipRects
;
490 *numBackClipRects
= rep
.numBackClipRects
;
491 total_rects
+= *numBackClipRects
;
494 /* Because of the fix in Xserver/GL/dri/xf86dri.c, this check breaks
495 * backwards compatibility (Because of the >> 2 shift) but the fix
496 * enables multi-threaded apps to work.
498 if (rep
.length
!= ((((SIZEOF(xXF86DRIGetDrawableInfoReply
) -
499 SIZEOF(xGenericReply
) +
500 total_rects
* sizeof(drm_clip_rect_t
)) + 3) & ~3) >> 2)) {
501 _XEatData(dpy
, rep
.length
);
504 TRACE("GetDrawableInfo... return False");
510 int len
= sizeof(drm_clip_rect_t
) * (*numClipRects
);
512 *pClipRects
= (drm_clip_rect_t
*)Xcalloc(len
, 1);
514 _XRead(dpy
, (char*)*pClipRects
, len
);
519 if (*numBackClipRects
) {
520 int len
= sizeof(drm_clip_rect_t
) * (*numBackClipRects
);
522 *pBackClipRects
= (drm_clip_rect_t
*)Xcalloc(len
, 1);
524 _XRead(dpy
, (char*)*pBackClipRects
, len
);
526 *pBackClipRects
= NULL
;
531 TRACE("GetDrawableInfo... return True");
535 PUBLIC Bool
XF86DRIGetDeviceInfo(dpy
, screen
, hFrameBuffer
,
536 fbOrigin
, fbSize
, fbStride
, devPrivateSize
, pDevPrivate
)
539 drm_handle_t
* hFrameBuffer
;
546 XExtDisplayInfo
*info
= find_display (dpy
);
547 xXF86DRIGetDeviceInfoReply rep
;
548 xXF86DRIGetDeviceInfoReq
*req
;
550 TRACE("GetDeviceInfo...");
551 XF86DRICheckExtension (dpy
, info
, False
);
554 GetReq(XF86DRIGetDeviceInfo
, req
);
555 req
->reqType
= info
->codes
->major_opcode
;
556 req
->driReqType
= X_XF86DRIGetDeviceInfo
;
557 req
->screen
= screen
;
558 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
561 TRACE("GetDeviceInfo... return False");
565 *hFrameBuffer
= rep
.hFrameBufferLow
;
566 if (sizeof(drm_handle_t
) == 8) {
567 const int shift
= 32; /* var to prevent warning on next line */
568 *hFrameBuffer
|= ((drm_handle_t
) rep
.hFrameBufferHigh
) << shift
;
571 *fbOrigin
= rep
.framebufferOrigin
;
572 *fbSize
= rep
.framebufferSize
;
573 *fbStride
= rep
.framebufferStride
;
574 *devPrivateSize
= rep
.devPrivateSize
;
577 if (!(*pDevPrivate
= (void *)Xcalloc(rep
.devPrivateSize
, 1))) {
578 _XEatData(dpy
, ((rep
.devPrivateSize
+3) & ~3));
581 TRACE("GetDeviceInfo... return False");
584 _XRead(dpy
, (char*)*pDevPrivate
, rep
.devPrivateSize
);
591 TRACE("GetDeviceInfo... return True");
595 PUBLIC Bool
XF86DRIOpenFullScreen(dpy
, screen
, drawable
)
600 /* This function and the underlying X protocol are deprecated.
608 PUBLIC Bool
XF86DRICloseFullScreen(dpy
, screen
, drawable
)
613 /* This function and the underlying X protocol are deprecated.