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.
6 Copyright 2007 Intel Corporation
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@tungstengraphics.com>
35 * Rickard E. (Rik) Faith <faith@valinux.com>
39 /* THIS IS NOT AN X CONSORTIUM STANDARD */
42 #include <X11/Xlibint.h>
43 #include <X11/extensions/Xext.h>
44 #include <X11/extensions/extutil.h>
45 #include "va_dristr.h"
49 static XExtensionInfo _va_dri_info_data;
50 static XExtensionInfo *va_dri_info = &_va_dri_info_data;
51 static char va_dri_extension_name[] = VA_DRINAME;
53 #define VA_DRICheckExtension(dpy,i,val) \
54 XextCheckExtension (dpy, i, va_dri_extension_name, val)
56 /*****************************************************************************
58 * private utility routines *
60 *****************************************************************************/
62 static int close_display(Display *dpy, XExtCodes *extCodes);
63 static /* const */ XExtensionHooks va_dri_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, va_dri_info,
78 va_dri_extension_name,
79 &va_dri_extension_hooks,
82 static XEXT_GENERATE_CLOSE_DISPLAY (close_display, va_dri_info)
85 /*****************************************************************************
87 * public XFree86-DRI Extension routines *
89 *****************************************************************************/
93 #define TRACE(msg) fprintf(stderr,"XF86DRI%s\n", msg);
99 PUBLIC Bool VA_DRIQueryExtension (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 VA_DRIQueryVersion(dpy, majorVersion, minorVersion, patchVersion)
123 XExtDisplayInfo *info = find_display (dpy);
124 xVA_DRIQueryVersionReply rep;
125 xVA_DRIQueryVersionReq *req;
127 TRACE("QueryVersion...");
128 VA_DRICheckExtension (dpy, info, False);
131 GetReq(VA_DRIQueryVersion, req);
132 req->reqType = info->codes->major_opcode;
133 req->driReqType = X_VA_DRIQueryVersion;
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 VA_DRIQueryDirectRenderingCapable(dpy, screen, isCapable)
154 XExtDisplayInfo *info = find_display (dpy);
155 xVA_DRIQueryDirectRenderingCapableReply rep;
156 xVA_DRIQueryDirectRenderingCapableReq *req;
158 TRACE("QueryDirectRenderingCapable...");
159 VA_DRICheckExtension (dpy, info, False);
162 GetReq(VA_DRIQueryDirectRenderingCapable, req);
163 req->reqType = info->codes->major_opcode;
164 req->driReqType = X_VA_DRIQueryDirectRenderingCapable;
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 VA_DRIOpenConnection(dpy, screen, hSAREA, busIdString)
182 drm_handle_t * hSAREA;
185 XExtDisplayInfo *info = find_display (dpy);
186 xVA_DRIOpenConnectionReply rep;
187 xVA_DRIOpenConnectionReq *req;
189 TRACE("OpenConnection...");
190 VA_DRICheckExtension (dpy, info, False);
193 GetReq(VA_DRIOpenConnection, req);
194 req->reqType = info->codes->major_opcode;
195 req->driReqType = X_VA_DRIOpenConnection;
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 VA_DRIAuthConnection(dpy, screen, magic)
233 XExtDisplayInfo *info = find_display (dpy);
234 xVA_DRIAuthConnectionReq *req;
235 xVA_DRIAuthConnectionReply rep;
237 TRACE("AuthConnection...");
238 VA_DRICheckExtension (dpy, info, False);
241 GetReq(VA_DRIAuthConnection, req);
242 req->reqType = info->codes->major_opcode;
243 req->driReqType = X_VA_DRIAuthConnection;
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 VA_DRICloseConnection(dpy, screen)
263 XExtDisplayInfo *info = find_display (dpy);
264 xVA_DRICloseConnectionReq *req;
266 TRACE("CloseConnection...");
268 VA_DRICheckExtension (dpy, info, False);
271 GetReq(VA_DRICloseConnection, req);
272 req->reqType = info->codes->major_opcode;
273 req->driReqType = X_VA_DRICloseConnection;
274 req->screen = screen;
277 TRACE("CloseConnection... return True");
281 PUBLIC Bool VA_DRIGetClientDriverName(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 xVA_DRIGetClientDriverNameReply rep;
292 xVA_DRIGetClientDriverNameReq *req;
294 TRACE("GetClientDriverName...");
295 VA_DRICheckExtension (dpy, info, False);
298 GetReq(VA_DRIGetClientDriverName, req);
299 req->reqType = info->codes->major_opcode;
300 req->driReqType = X_VA_DRIGetClientDriverName;
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 VA_DRICreateContextWithConfig(dpy, screen, configID, context,
337 drm_context_t * hHWContext;
339 XExtDisplayInfo *info = find_display (dpy);
340 xVA_DRICreateContextReply rep;
341 xVA_DRICreateContextReq *req;
343 TRACE("CreateContext...");
344 VA_DRICheckExtension (dpy, info, False);
347 GetReq(VA_DRICreateContext, req);
348 req->reqType = info->codes->major_opcode;
349 req->driReqType = X_VA_DRICreateContext;
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 VA_DRICreateContext(dpy, screen, visual, context, hHWContext)
372 drm_context_t * hHWContext;
374 return VA_DRICreateContextWithConfig( dpy, screen, visual->visualid,
375 context, hHWContext );
378 PUBLIC Bool VA_DRIDestroyContext( __DRInativeDisplay * ndpy, int screen,
381 Display * const dpy = (Display *) ndpy;
382 XExtDisplayInfo *info = find_display (dpy);
383 xVA_DRIDestroyContextReq *req;
385 TRACE("DestroyContext...");
386 VA_DRICheckExtension (dpy, info, False);
389 GetReq(VA_DRIDestroyContext, req);
390 req->reqType = info->codes->major_opcode;
391 req->driReqType = X_VA_DRIDestroyContext;
392 req->screen = screen;
393 req->context = context;
396 TRACE("DestroyContext... return True");
400 PUBLIC Bool VA_DRICreateDrawable( __DRInativeDisplay * ndpy, int screen,
401 __DRIid drawable, drm_drawable_t * hHWDrawable )
403 Display * const dpy = (Display *) ndpy;
404 XExtDisplayInfo *info = find_display (dpy);
405 xVA_DRICreateDrawableReply rep;
406 xVA_DRICreateDrawableReq *req;
408 TRACE("CreateDrawable...");
409 VA_DRICheckExtension (dpy, info, False);
412 GetReq(VA_DRICreateDrawable, req);
413 req->reqType = info->codes->major_opcode;
414 req->driReqType = X_VA_DRICreateDrawable;
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 Bool VA_DRIDestroyDrawable( __DRInativeDisplay * ndpy, int screen,
433 Display * const dpy = (Display *) ndpy;
434 XExtDisplayInfo *info = find_display (dpy);
435 xVA_DRIDestroyDrawableReq *req;
437 TRACE("DestroyDrawable...");
438 VA_DRICheckExtension (dpy, info, False);
441 GetReq(VA_DRIDestroyDrawable, req);
442 req->reqType = info->codes->major_opcode;
443 req->driReqType = X_VA_DRIDestroyDrawable;
444 req->screen = screen;
445 req->drawable = drawable;
448 TRACE("DestroyDrawable... return True");
452 PUBLIC Bool VA_DRIGetDrawableInfo(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 xVA_DRIGetDrawableInfoReply rep;
461 xVA_DRIGetDrawableInfoReq *req;
464 TRACE("GetDrawableInfo...");
465 VA_DRICheckExtension (dpy, info, False);
468 GetReq(VA_DRIGetDrawableInfo, req);
469 req->reqType = info->codes->major_opcode;
470 req->driReqType = X_VA_DRIGetDrawableInfo;
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(xVA_DRIGetDrawableInfoReply) -
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 VA_DRIGetDeviceInfo(dpy, screen, hFrameBuffer,
538 fbOrigin, fbSize, fbStride, devPrivateSize, pDevPrivate)
541 drm_handle_t * hFrameBuffer;
548 XExtDisplayInfo *info = find_display (dpy);
549 xVA_DRIGetDeviceInfoReply rep;
550 xVA_DRIGetDeviceInfoReq *req;
552 TRACE("GetDeviceInfo...");
553 VA_DRICheckExtension (dpy, info, False);
556 GetReq(VA_DRIGetDeviceInfo, req);
557 req->reqType = info->codes->major_opcode;
558 req->driReqType = X_VA_DRIGetDeviceInfo;
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 VA_DRIOpenFullScreen(dpy, screen, drawable)
602 /* This function and the underlying X protocol are deprecated.
610 PUBLIC Bool VA_DRICloseFullScreen(dpy, screen, drawable)
615 /* This function and the underlying X protocol are deprecated.