blob: 5c181d6db9eae5755e2119b7f6fa7ab9ff5efcc5 [file] [log] [blame]
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001/**************************************************************************
2
3Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
4Copyright 2000 VA Linux Systems, Inc.
5All Rights Reserved.
6
7Permission is hereby granted, free of charge, to any person obtaining a
8copy of this software and associated documentation files (the
9"Software"), to deal in the Software without restriction, including
10without limitation the rights to use, copy, modify, merge, publish,
11distribute, sub license, and/or sell copies of the Software, and to
12permit persons to whom the Software is furnished to do so, subject to
13the following conditions:
14
15The above copyright notice and this permission notice (including the
16next paragraph) shall be included in all copies or substantial portions
17of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
23ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
27**************************************************************************/
28
29/*
30 * Authors:
31 * Kevin E. Martin <martin@valinux.com>
32 * Jens Owen <jens@tungstengraphics.com>
33 * Rickard E. (Rik) Faith <faith@valinux.com>
34 *
35 */
36
37/* THIS IS NOT AN X CONSORTIUM STANDARD */
38
Jeremy Huddleston80b280d2010-04-02 01:35:19 -070039#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Adam Jacksonbe85fde2006-08-10 20:19:57 +000040
Adam Jacksoncb3610e2004-10-25 21:09:16 +000041#include <X11/Xlibint.h>
Kristian Høgsberg38c51a72010-07-28 10:20:41 -040042#include <X11/Xfuncproto.h>
Adam Jacksoncb3610e2004-10-25 21:09:16 +000043#include <X11/extensions/Xext.h>
Brian Paul82dfd4b2005-08-11 14:18:53 +000044#include <X11/extensions/extutil.h>
Adam Jackson1074eae2005-01-08 03:54:38 +000045#include "xf86dristr.h"
Adam Jacksoncb3610e2004-10-25 21:09:16 +000046
47static XExtensionInfo _xf86dri_info_data;
48static XExtensionInfo *xf86dri_info = &_xf86dri_info_data;
Adam Jackson5dd18e92004-11-03 18:55:20 +000049static char xf86dri_extension_name[] = XF86DRINAME;
Adam Jacksoncb3610e2004-10-25 21:09:16 +000050
51#define XF86DRICheckExtension(dpy,i,val) \
52 XextCheckExtension (dpy, i, xf86dri_extension_name, val)
53
54/*****************************************************************************
55 * *
56 * private utility routines *
57 * *
58 *****************************************************************************/
59
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +020060static int close_display(Display * dpy, XExtCodes * extCodes);
Adam Jacksoncb3610e2004-10-25 21:09:16 +000061static /* const */ XExtensionHooks xf86dri_extension_hooks = {
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +020062 NULL, /* create_gc */
63 NULL, /* copy_gc */
64 NULL, /* flush_gc */
65 NULL, /* free_gc */
66 NULL, /* create_font */
67 NULL, /* free_font */
68 close_display, /* close_display */
69 NULL, /* wire_to_event */
70 NULL, /* event_to_wire */
71 NULL, /* error */
72 NULL, /* error_string */
Adam Jacksoncb3610e2004-10-25 21:09:16 +000073};
74
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +020075static
76XEXT_GENERATE_FIND_DISPLAY(find_display, xf86dri_info,
77 xf86dri_extension_name,
78 &xf86dri_extension_hooks, 0, NULL)
Adam Jacksoncb3610e2004-10-25 21:09:16 +000079
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +020080static
81XEXT_GENERATE_CLOSE_DISPLAY(close_display, xf86dri_info)
Adam Jacksoncb3610e2004-10-25 21:09:16 +000082
83
84/*****************************************************************************
85 * *
86 * public XFree86-DRI Extension routines *
87 * *
88 *****************************************************************************/
Adam Jacksoncb3610e2004-10-25 21:09:16 +000089#if 0
90#include <stdio.h>
91#define TRACE(msg) fprintf(stderr,"XF86DRI%s\n", msg);
92#else
93#define TRACE(msg)
94#endif
95
Kristian Høgsberg697e2212010-02-05 11:04:48 -050096Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +020097XF86DRIQueryExtension(Display * dpy, int *event_basep,
98 int *error_basep)
Adam Jacksoncb3610e2004-10-25 21:09:16 +000099{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200100 XExtDisplayInfo *info = find_display(dpy);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000101
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200102 TRACE("QueryExtension...");
103 if (XextHasExtension(info)) {
104 *event_basep = info->codes->first_event;
105 *error_basep = info->codes->first_error;
106 TRACE("QueryExtension... return True");
107 return True;
108 }
109 else {
110 TRACE("QueryExtension... return False");
111 return False;
112 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000113}
114
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500115Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200116XF86DRIQueryVersion(Display * dpy, int *majorVersion, int *minorVersion,
117 int *patchVersion)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000118{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200119 XExtDisplayInfo *info = find_display(dpy);
120 xXF86DRIQueryVersionReply rep;
121 xXF86DRIQueryVersionReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000122
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200123 TRACE("QueryVersion...");
124 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000125
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200126 LockDisplay(dpy);
127 GetReq(XF86DRIQueryVersion, req);
128 req->reqType = info->codes->major_opcode;
129 req->driReqType = X_XF86DRIQueryVersion;
130 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
131 UnlockDisplay(dpy);
132 SyncHandle();
133 TRACE("QueryVersion... return False");
134 return False;
135 }
136 *majorVersion = rep.majorVersion;
137 *minorVersion = rep.minorVersion;
138 *patchVersion = rep.patchVersion;
139 UnlockDisplay(dpy);
140 SyncHandle();
141 TRACE("QueryVersion... return True");
142 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000143}
144
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500145Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200146XF86DRIQueryDirectRenderingCapable(Display * dpy, int screen,
147 Bool * isCapable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000148{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200149 XExtDisplayInfo *info = find_display(dpy);
150 xXF86DRIQueryDirectRenderingCapableReply rep;
151 xXF86DRIQueryDirectRenderingCapableReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000152
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200153 TRACE("QueryDirectRenderingCapable...");
154 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000155
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200156 LockDisplay(dpy);
157 GetReq(XF86DRIQueryDirectRenderingCapable, req);
158 req->reqType = info->codes->major_opcode;
159 req->driReqType = X_XF86DRIQueryDirectRenderingCapable;
160 req->screen = screen;
161 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
162 UnlockDisplay(dpy);
163 SyncHandle();
164 TRACE("QueryDirectRenderingCapable... return False");
165 return False;
166 }
167 *isCapable = rep.isCapable;
168 UnlockDisplay(dpy);
169 SyncHandle();
170 TRACE("QueryDirectRenderingCapable... return True");
171 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000172}
173
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500174Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200175XF86DRIOpenConnection(Display * dpy, int screen, drm_handle_t * hSAREA,
176 char **busIdString)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000177{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200178 XExtDisplayInfo *info = find_display(dpy);
179 xXF86DRIOpenConnectionReply rep;
180 xXF86DRIOpenConnectionReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000181
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200182 TRACE("OpenConnection...");
183 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000184
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200185 LockDisplay(dpy);
186 GetReq(XF86DRIOpenConnection, req);
187 req->reqType = info->codes->major_opcode;
188 req->driReqType = X_XF86DRIOpenConnection;
189 req->screen = screen;
190 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
191 UnlockDisplay(dpy);
192 SyncHandle();
193 TRACE("OpenConnection... return False");
194 return False;
195 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000196
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200197 *hSAREA = rep.hSAREALow;
198 if (sizeof(drm_handle_t) == 8) {
199 int shift = 32; /* var to prevent warning on next line */
200 *hSAREA |= ((drm_handle_t) rep.hSAREAHigh) << shift;
201 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000202
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200203 if (rep.length) {
204 if (!(*busIdString = (char *) Xcalloc(rep.busIdStringLength + 1, 1))) {
205 _XEatData(dpy, ((rep.busIdStringLength + 3) & ~3));
206 UnlockDisplay(dpy);
207 SyncHandle();
208 TRACE("OpenConnection... return False");
209 return False;
210 }
211 _XReadPad(dpy, *busIdString, rep.busIdStringLength);
212 }
213 else {
214 *busIdString = NULL;
215 }
216 UnlockDisplay(dpy);
217 SyncHandle();
218 TRACE("OpenConnection... return True");
219 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000220}
221
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500222Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200223XF86DRIAuthConnection(Display * dpy, int screen, drm_magic_t magic)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000224{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200225 XExtDisplayInfo *info = find_display(dpy);
226 xXF86DRIAuthConnectionReq *req;
227 xXF86DRIAuthConnectionReply rep;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000228
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200229 TRACE("AuthConnection...");
230 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000231
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200232 LockDisplay(dpy);
233 GetReq(XF86DRIAuthConnection, req);
234 req->reqType = info->codes->major_opcode;
235 req->driReqType = X_XF86DRIAuthConnection;
236 req->screen = screen;
237 req->magic = magic;
238 rep.authenticated = 0;
239 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse) || !rep.authenticated) {
240 UnlockDisplay(dpy);
241 SyncHandle();
242 TRACE("AuthConnection... return False");
243 return False;
244 }
245 UnlockDisplay(dpy);
246 SyncHandle();
247 TRACE("AuthConnection... return True");
248 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000249}
250
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500251Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200252XF86DRICloseConnection(Display * dpy, int screen)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000253{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200254 XExtDisplayInfo *info = find_display(dpy);
255 xXF86DRICloseConnectionReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000256
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200257 TRACE("CloseConnection...");
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000258
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200259 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000260
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200261 LockDisplay(dpy);
262 GetReq(XF86DRICloseConnection, req);
263 req->reqType = info->codes->major_opcode;
264 req->driReqType = X_XF86DRICloseConnection;
265 req->screen = screen;
266 UnlockDisplay(dpy);
267 SyncHandle();
268 TRACE("CloseConnection... return True");
269 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000270}
271
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500272Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200273XF86DRIGetClientDriverName(Display * dpy, int screen,
274 int *ddxDriverMajorVersion,
275 int *ddxDriverMinorVersion,
276 int *ddxDriverPatchVersion,
277 char **clientDriverName)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000278{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200279 XExtDisplayInfo *info = find_display(dpy);
280 xXF86DRIGetClientDriverNameReply rep;
281 xXF86DRIGetClientDriverNameReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000282
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200283 TRACE("GetClientDriverName...");
284 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000285
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200286 LockDisplay(dpy);
287 GetReq(XF86DRIGetClientDriverName, req);
288 req->reqType = info->codes->major_opcode;
289 req->driReqType = X_XF86DRIGetClientDriverName;
290 req->screen = screen;
291 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
292 UnlockDisplay(dpy);
293 SyncHandle();
294 TRACE("GetClientDriverName... return False");
295 return False;
296 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000297
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200298 *ddxDriverMajorVersion = rep.ddxDriverMajorVersion;
299 *ddxDriverMinorVersion = rep.ddxDriverMinorVersion;
300 *ddxDriverPatchVersion = rep.ddxDriverPatchVersion;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000301
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200302 if (rep.length) {
303 if (!
304 (*clientDriverName =
305 (char *) Xcalloc(rep.clientDriverNameLength + 1, 1))) {
306 _XEatData(dpy, ((rep.clientDriverNameLength + 3) & ~3));
307 UnlockDisplay(dpy);
308 SyncHandle();
309 TRACE("GetClientDriverName... return False");
310 return False;
311 }
312 _XReadPad(dpy, *clientDriverName, rep.clientDriverNameLength);
313 }
314 else {
315 *clientDriverName = NULL;
316 }
317 UnlockDisplay(dpy);
318 SyncHandle();
319 TRACE("GetClientDriverName... return True");
320 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000321}
322
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500323Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200324XF86DRICreateContextWithConfig(Display * dpy, int screen, int configID,
325 XID * context, drm_context_t * hHWContext)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000326{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200327 XExtDisplayInfo *info = find_display(dpy);
328 xXF86DRICreateContextReply rep;
329 xXF86DRICreateContextReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000330
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200331 TRACE("CreateContext...");
332 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000333
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200334 LockDisplay(dpy);
335 GetReq(XF86DRICreateContext, req);
336 req->reqType = info->codes->major_opcode;
337 req->driReqType = X_XF86DRICreateContext;
338 req->visual = configID;
339 req->screen = screen;
340 *context = XAllocID(dpy);
341 req->context = *context;
342 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
343 UnlockDisplay(dpy);
344 SyncHandle();
345 TRACE("CreateContext... return False");
346 return False;
347 }
348 *hHWContext = rep.hHWContext;
349 UnlockDisplay(dpy);
350 SyncHandle();
351 TRACE("CreateContext... return True");
352 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000353}
354
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500355Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200356XF86DRICreateContext(Display * dpy, int screen, Visual * visual,
357 XID * context, drm_context_t * hHWContext)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000358{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200359 return XF86DRICreateContextWithConfig(dpy, screen, visual->visualid,
360 context, hHWContext);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000361}
362
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500363Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200364XF86DRIDestroyContext(Display * dpy, int screen, XID context)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000365{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200366 XExtDisplayInfo *info = find_display(dpy);
367 xXF86DRIDestroyContextReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000368
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200369 TRACE("DestroyContext...");
370 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000371
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200372 LockDisplay(dpy);
373 GetReq(XF86DRIDestroyContext, req);
374 req->reqType = info->codes->major_opcode;
375 req->driReqType = X_XF86DRIDestroyContext;
376 req->screen = screen;
377 req->context = context;
378 UnlockDisplay(dpy);
379 SyncHandle();
380 TRACE("DestroyContext... return True");
381 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000382}
383
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500384Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200385XF86DRICreateDrawable(Display * dpy, int screen,
386 XID drawable, drm_drawable_t * hHWDrawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000387{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200388 XExtDisplayInfo *info = find_display(dpy);
389 xXF86DRICreateDrawableReply rep;
390 xXF86DRICreateDrawableReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000391
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200392 TRACE("CreateDrawable...");
393 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000394
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200395 LockDisplay(dpy);
396 GetReq(XF86DRICreateDrawable, req);
397 req->reqType = info->codes->major_opcode;
398 req->driReqType = X_XF86DRICreateDrawable;
399 req->screen = screen;
400 req->drawable = drawable;
401 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
402 UnlockDisplay(dpy);
403 SyncHandle();
404 TRACE("CreateDrawable... return False");
405 return False;
406 }
407 *hHWDrawable = rep.hHWDrawable;
408 UnlockDisplay(dpy);
409 SyncHandle();
410 TRACE("CreateDrawable... return True");
411 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000412}
413
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200414static int
415noopErrorHandler(Display * dpy, XErrorEvent * xerr)
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500416{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200417 return 0;
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500418}
419
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500420Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200421XF86DRIDestroyDrawable(Display * dpy, int screen, XID drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000422{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200423 XExtDisplayInfo *info = find_display(dpy);
424 xXF86DRIDestroyDrawableReq *req;
425 int (*oldXErrorHandler) (Display *, XErrorEvent *);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000426
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200427 TRACE("DestroyDrawable...");
428 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000429
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200430 /* This is called from the DRI driver, which used call it like this
431 *
432 * if (windowExists(drawable))
433 * destroyDrawable(drawable);
434 *
435 * which is a textbook race condition - the window may disappear
436 * from the server between checking for its existance and
437 * destroying it. Instead we change the semantics of
438 * __DRIinterfaceMethodsRec::destroyDrawable() to succeed even if
439 * the windows is gone, by wrapping the destroy call in an error
440 * handler. */
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500441
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200442 XSync(dpy, False);
443 oldXErrorHandler = XSetErrorHandler(noopErrorHandler);
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500444
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200445 LockDisplay(dpy);
446 GetReq(XF86DRIDestroyDrawable, req);
447 req->reqType = info->codes->major_opcode;
448 req->driReqType = X_XF86DRIDestroyDrawable;
449 req->screen = screen;
450 req->drawable = drawable;
451 UnlockDisplay(dpy);
452 SyncHandle();
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500453
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200454 XSetErrorHandler(oldXErrorHandler);
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500455
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200456 TRACE("DestroyDrawable... return True");
457 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000458}
459
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500460Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200461XF86DRIGetDrawableInfo(Display * dpy, int screen, Drawable drawable,
462 unsigned int *index, unsigned int *stamp,
463 int *X, int *Y, int *W, int *H,
464 int *numClipRects, drm_clip_rect_t ** pClipRects,
465 int *backX, int *backY,
466 int *numBackClipRects,
467 drm_clip_rect_t ** pBackClipRects)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000468{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200469 XExtDisplayInfo *info = find_display(dpy);
470 xXF86DRIGetDrawableInfoReply rep;
471 xXF86DRIGetDrawableInfoReq *req;
472 int total_rects;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000473
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200474 TRACE("GetDrawableInfo...");
475 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000476
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200477 LockDisplay(dpy);
478 GetReq(XF86DRIGetDrawableInfo, req);
479 req->reqType = info->codes->major_opcode;
480 req->driReqType = X_XF86DRIGetDrawableInfo;
481 req->screen = screen;
482 req->drawable = drawable;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000483
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200484 if (!_XReply(dpy, (xReply *) & rep, 1, xFalse)) {
485 UnlockDisplay(dpy);
486 SyncHandle();
487 TRACE("GetDrawableInfo... return False");
488 return False;
489 }
490 *index = rep.drawableTableIndex;
491 *stamp = rep.drawableTableStamp;
492 *X = (int) rep.drawableX;
493 *Y = (int) rep.drawableY;
494 *W = (int) rep.drawableWidth;
495 *H = (int) rep.drawableHeight;
496 *numClipRects = rep.numClipRects;
497 total_rects = *numClipRects;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000498
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200499 *backX = rep.backX;
500 *backY = rep.backY;
501 *numBackClipRects = rep.numBackClipRects;
502 total_rects += *numBackClipRects;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000503
504#if 0
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200505 /* Because of the fix in Xserver/GL/dri/xf86dri.c, this check breaks
506 * backwards compatibility (Because of the >> 2 shift) but the fix
507 * enables multi-threaded apps to work.
508 */
509 if (rep.length != ((((SIZEOF(xXF86DRIGetDrawableInfoReply) -
510 SIZEOF(xGenericReply) +
511 total_rects * sizeof(drm_clip_rect_t)) +
512 3) & ~3) >> 2)) {
513 _XEatData(dpy, rep.length);
514 UnlockDisplay(dpy);
515 SyncHandle();
516 TRACE("GetDrawableInfo... return False");
517 return False;
518 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000519#endif
520
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200521 if (*numClipRects) {
522 int len = sizeof(drm_clip_rect_t) * (*numClipRects);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000523
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200524 *pClipRects = (drm_clip_rect_t *) Xcalloc(len, 1);
525 if (*pClipRects)
526 _XRead(dpy, (char *) *pClipRects, len);
527 }
528 else {
529 *pClipRects = NULL;
530 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000531
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200532 if (*numBackClipRects) {
533 int len = sizeof(drm_clip_rect_t) * (*numBackClipRects);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000534
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200535 *pBackClipRects = (drm_clip_rect_t *) Xcalloc(len, 1);
536 if (*pBackClipRects)
537 _XRead(dpy, (char *) *pBackClipRects, len);
538 }
539 else {
540 *pBackClipRects = NULL;
541 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000542
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200543 UnlockDisplay(dpy);
544 SyncHandle();
545 TRACE("GetDrawableInfo... return True");
546 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000547}
548
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500549Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200550XF86DRIGetDeviceInfo(Display * dpy, int screen, drm_handle_t * hFrameBuffer,
551 int *fbOrigin, int *fbSize, int *fbStride,
552 int *devPrivateSize, void **pDevPrivate)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000553{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200554 XExtDisplayInfo *info = find_display(dpy);
555 xXF86DRIGetDeviceInfoReply rep;
556 xXF86DRIGetDeviceInfoReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000557
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200558 TRACE("GetDeviceInfo...");
559 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000560
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200561 LockDisplay(dpy);
562 GetReq(XF86DRIGetDeviceInfo, req);
563 req->reqType = info->codes->major_opcode;
564 req->driReqType = X_XF86DRIGetDeviceInfo;
565 req->screen = screen;
566 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
567 UnlockDisplay(dpy);
568 SyncHandle();
569 TRACE("GetDeviceInfo... return False");
570 return False;
571 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000572
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200573 *hFrameBuffer = rep.hFrameBufferLow;
574 if (sizeof(drm_handle_t) == 8) {
575 int shift = 32; /* var to prevent warning on next line */
576 *hFrameBuffer |= ((drm_handle_t) rep.hFrameBufferHigh) << shift;
577 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000578
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200579 *fbOrigin = rep.framebufferOrigin;
580 *fbSize = rep.framebufferSize;
581 *fbStride = rep.framebufferStride;
582 *devPrivateSize = rep.devPrivateSize;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000583
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200584 if (rep.length) {
585 if (!(*pDevPrivate = (void *) Xcalloc(rep.devPrivateSize, 1))) {
586 _XEatData(dpy, ((rep.devPrivateSize + 3) & ~3));
587 UnlockDisplay(dpy);
588 SyncHandle();
589 TRACE("GetDeviceInfo... return False");
590 return False;
591 }
592 _XRead(dpy, (char *) *pDevPrivate, rep.devPrivateSize);
593 }
594 else {
595 *pDevPrivate = NULL;
596 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000597
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200598 UnlockDisplay(dpy);
599 SyncHandle();
600 TRACE("GetDeviceInfo... return True");
601 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000602}
603
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500604Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200605XF86DRIOpenFullScreen(Display * dpy, int screen, Drawable drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000606{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200607 /* This function and the underlying X protocol are deprecated.
608 */
609 (void) dpy;
610 (void) screen;
611 (void) drawable;
612 return False;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000613}
614
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500615Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200616XF86DRICloseFullScreen(Display * dpy, int screen, Drawable drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000617{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200618 /* This function and the underlying X protocol are deprecated.
619 */
620 (void) dpy;
621 (void) screen;
622 (void) drawable;
623 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000624}
Adam Jacksonbe85fde2006-08-10 20:19:57 +0000625
626#endif /* GLX_DIRECT_RENDERING */