blob: 885ec93db5520486b323f0d0b892492b2ffa1582 [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>
José Fonseca87712852014-01-17 16:27:50 +000032 * Jens Owen <jowen@vmware.com>
Adam Jacksoncb3610e2004-10-25 21:09:16 +000033 * 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"
Alan Coopersmith2e5a2682013-04-26 16:31:58 -070046#include <limits.h>
Adam Jacksoncb3610e2004-10-25 21:09:16 +000047
48static XExtensionInfo _xf86dri_info_data;
49static XExtensionInfo *xf86dri_info = &_xf86dri_info_data;
Adam Jackson5dd18e92004-11-03 18:55:20 +000050static char xf86dri_extension_name[] = XF86DRINAME;
Adam Jacksoncb3610e2004-10-25 21:09:16 +000051
52#define XF86DRICheckExtension(dpy,i,val) \
53 XextCheckExtension (dpy, i, xf86dri_extension_name, val)
54
55/*****************************************************************************
56 * *
57 * private utility routines *
58 * *
59 *****************************************************************************/
60
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +020061static int close_display(Display * dpy, XExtCodes * extCodes);
Adam Jacksoncb3610e2004-10-25 21:09:16 +000062static /* const */ XExtensionHooks xf86dri_extension_hooks = {
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +020063 NULL, /* create_gc */
64 NULL, /* copy_gc */
65 NULL, /* flush_gc */
66 NULL, /* free_gc */
67 NULL, /* create_font */
68 NULL, /* free_font */
69 close_display, /* close_display */
70 NULL, /* wire_to_event */
71 NULL, /* event_to_wire */
72 NULL, /* error */
73 NULL, /* error_string */
Adam Jacksoncb3610e2004-10-25 21:09:16 +000074};
75
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +020076static
77XEXT_GENERATE_FIND_DISPLAY(find_display, xf86dri_info,
78 xf86dri_extension_name,
79 &xf86dri_extension_hooks, 0, NULL)
Adam Jacksoncb3610e2004-10-25 21:09:16 +000080
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +020081static
82XEXT_GENERATE_CLOSE_DISPLAY(close_display, xf86dri_info)
Adam Jacksoncb3610e2004-10-25 21:09:16 +000083
84
85/*****************************************************************************
86 * *
87 * public XFree86-DRI Extension routines *
88 * *
89 *****************************************************************************/
Adam Jacksoncb3610e2004-10-25 21:09:16 +000090#if 0
91#include <stdio.h>
92#define TRACE(msg) fprintf(stderr,"XF86DRI%s\n", msg);
93#else
94#define TRACE(msg)
95#endif
96
Kristian Høgsberg697e2212010-02-05 11:04:48 -050097Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +020098XF86DRIQueryExtension(Display * dpy, int *event_basep,
99 int *error_basep)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000100{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200101 XExtDisplayInfo *info = find_display(dpy);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000102
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200103 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");
108 return True;
109 }
110 else {
111 TRACE("QueryExtension... return False");
112 return False;
113 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000114}
115
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500116Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200117XF86DRIQueryVersion(Display * dpy, int *majorVersion, int *minorVersion,
118 int *patchVersion)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000119{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200120 XExtDisplayInfo *info = find_display(dpy);
121 xXF86DRIQueryVersionReply rep;
122 xXF86DRIQueryVersionReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000123
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200124 TRACE("QueryVersion...");
125 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000126
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200127 LockDisplay(dpy);
128 GetReq(XF86DRIQueryVersion, req);
129 req->reqType = info->codes->major_opcode;
130 req->driReqType = X_XF86DRIQueryVersion;
131 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
132 UnlockDisplay(dpy);
133 SyncHandle();
134 TRACE("QueryVersion... return False");
135 return False;
136 }
137 *majorVersion = rep.majorVersion;
138 *minorVersion = rep.minorVersion;
139 *patchVersion = rep.patchVersion;
140 UnlockDisplay(dpy);
141 SyncHandle();
142 TRACE("QueryVersion... return True");
143 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000144}
145
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500146Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200147XF86DRIQueryDirectRenderingCapable(Display * dpy, int screen,
148 Bool * isCapable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000149{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200150 XExtDisplayInfo *info = find_display(dpy);
151 xXF86DRIQueryDirectRenderingCapableReply rep;
152 xXF86DRIQueryDirectRenderingCapableReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000153
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200154 TRACE("QueryDirectRenderingCapable...");
155 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000156
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200157 LockDisplay(dpy);
158 GetReq(XF86DRIQueryDirectRenderingCapable, req);
159 req->reqType = info->codes->major_opcode;
160 req->driReqType = X_XF86DRIQueryDirectRenderingCapable;
161 req->screen = screen;
162 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
163 UnlockDisplay(dpy);
164 SyncHandle();
165 TRACE("QueryDirectRenderingCapable... return False");
166 return False;
167 }
168 *isCapable = rep.isCapable;
169 UnlockDisplay(dpy);
170 SyncHandle();
171 TRACE("QueryDirectRenderingCapable... return True");
172 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000173}
174
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500175Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200176XF86DRIOpenConnection(Display * dpy, int screen, drm_handle_t * hSAREA,
177 char **busIdString)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000178{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200179 XExtDisplayInfo *info = find_display(dpy);
180 xXF86DRIOpenConnectionReply rep;
181 xXF86DRIOpenConnectionReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000182
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200183 TRACE("OpenConnection...");
184 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000185
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200186 LockDisplay(dpy);
187 GetReq(XF86DRIOpenConnection, req);
188 req->reqType = info->codes->major_opcode;
189 req->driReqType = X_XF86DRIOpenConnection;
190 req->screen = screen;
191 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
192 UnlockDisplay(dpy);
193 SyncHandle();
194 TRACE("OpenConnection... return False");
195 return False;
196 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000197
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200198 *hSAREA = rep.hSAREALow;
199 if (sizeof(drm_handle_t) == 8) {
200 int shift = 32; /* var to prevent warning on next line */
201 *hSAREA |= ((drm_handle_t) rep.hSAREAHigh) << shift;
202 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000203
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200204 if (rep.length) {
Alan Coopersmith2e5a2682013-04-26 16:31:58 -0700205 if (rep.busIdStringLength < INT_MAX)
206 *busIdString = calloc(rep.busIdStringLength + 1, 1);
207 else
208 *busIdString = NULL;
209 if (*busIdString == NULL) {
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200210 _XEatData(dpy, ((rep.busIdStringLength + 3) & ~3));
211 UnlockDisplay(dpy);
212 SyncHandle();
213 TRACE("OpenConnection... return False");
214 return False;
215 }
216 _XReadPad(dpy, *busIdString, rep.busIdStringLength);
217 }
218 else {
219 *busIdString = NULL;
220 }
221 UnlockDisplay(dpy);
222 SyncHandle();
223 TRACE("OpenConnection... return True");
224 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000225}
226
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500227Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200228XF86DRIAuthConnection(Display * dpy, int screen, drm_magic_t magic)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000229{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200230 XExtDisplayInfo *info = find_display(dpy);
231 xXF86DRIAuthConnectionReq *req;
232 xXF86DRIAuthConnectionReply rep;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000233
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200234 TRACE("AuthConnection...");
235 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000236
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200237 LockDisplay(dpy);
238 GetReq(XF86DRIAuthConnection, req);
239 req->reqType = info->codes->major_opcode;
240 req->driReqType = X_XF86DRIAuthConnection;
241 req->screen = screen;
242 req->magic = magic;
243 rep.authenticated = 0;
244 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse) || !rep.authenticated) {
245 UnlockDisplay(dpy);
246 SyncHandle();
247 TRACE("AuthConnection... return False");
248 return False;
249 }
250 UnlockDisplay(dpy);
251 SyncHandle();
252 TRACE("AuthConnection... return True");
253 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000254}
255
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500256Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200257XF86DRICloseConnection(Display * dpy, int screen)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000258{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200259 XExtDisplayInfo *info = find_display(dpy);
260 xXF86DRICloseConnectionReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000261
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200262 TRACE("CloseConnection...");
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000263
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200264 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000265
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200266 LockDisplay(dpy);
267 GetReq(XF86DRICloseConnection, req);
268 req->reqType = info->codes->major_opcode;
269 req->driReqType = X_XF86DRICloseConnection;
270 req->screen = screen;
271 UnlockDisplay(dpy);
272 SyncHandle();
273 TRACE("CloseConnection... return True");
274 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000275}
276
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500277Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200278XF86DRIGetClientDriverName(Display * dpy, int screen,
279 int *ddxDriverMajorVersion,
280 int *ddxDriverMinorVersion,
281 int *ddxDriverPatchVersion,
282 char **clientDriverName)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000283{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200284 XExtDisplayInfo *info = find_display(dpy);
285 xXF86DRIGetClientDriverNameReply rep;
286 xXF86DRIGetClientDriverNameReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000287
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200288 TRACE("GetClientDriverName...");
289 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000290
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200291 LockDisplay(dpy);
292 GetReq(XF86DRIGetClientDriverName, req);
293 req->reqType = info->codes->major_opcode;
294 req->driReqType = X_XF86DRIGetClientDriverName;
295 req->screen = screen;
296 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
297 UnlockDisplay(dpy);
298 SyncHandle();
299 TRACE("GetClientDriverName... return False");
300 return False;
301 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000302
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200303 *ddxDriverMajorVersion = rep.ddxDriverMajorVersion;
304 *ddxDriverMinorVersion = rep.ddxDriverMinorVersion;
305 *ddxDriverPatchVersion = rep.ddxDriverPatchVersion;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000306
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200307 if (rep.length) {
Alan Coopersmith306f6302013-04-26 16:33:03 -0700308 if (rep.clientDriverNameLength < INT_MAX)
309 *clientDriverName = calloc(rep.clientDriverNameLength + 1, 1);
310 else
311 *clientDriverName = NULL;
312 if (*clientDriverName == NULL) {
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200313 _XEatData(dpy, ((rep.clientDriverNameLength + 3) & ~3));
314 UnlockDisplay(dpy);
315 SyncHandle();
316 TRACE("GetClientDriverName... return False");
317 return False;
318 }
319 _XReadPad(dpy, *clientDriverName, rep.clientDriverNameLength);
320 }
321 else {
322 *clientDriverName = NULL;
323 }
324 UnlockDisplay(dpy);
325 SyncHandle();
326 TRACE("GetClientDriverName... return True");
327 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000328}
329
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500330Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200331XF86DRICreateContextWithConfig(Display * dpy, int screen, int configID,
332 XID * context, drm_context_t * hHWContext)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000333{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200334 XExtDisplayInfo *info = find_display(dpy);
335 xXF86DRICreateContextReply rep;
336 xXF86DRICreateContextReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000337
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200338 TRACE("CreateContext...");
339 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000340
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200341 LockDisplay(dpy);
342 GetReq(XF86DRICreateContext, req);
343 req->reqType = info->codes->major_opcode;
344 req->driReqType = X_XF86DRICreateContext;
345 req->visual = configID;
346 req->screen = screen;
347 *context = XAllocID(dpy);
348 req->context = *context;
349 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
350 UnlockDisplay(dpy);
351 SyncHandle();
352 TRACE("CreateContext... return False");
353 return False;
354 }
355 *hHWContext = rep.hHWContext;
356 UnlockDisplay(dpy);
357 SyncHandle();
358 TRACE("CreateContext... return True");
359 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000360}
361
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500362Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200363XF86DRICreateContext(Display * dpy, int screen, Visual * visual,
364 XID * context, drm_context_t * hHWContext)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000365{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200366 return XF86DRICreateContextWithConfig(dpy, screen, visual->visualid,
367 context, hHWContext);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000368}
369
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500370Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200371XF86DRIDestroyContext(Display * dpy, int screen, XID context)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000372{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200373 XExtDisplayInfo *info = find_display(dpy);
374 xXF86DRIDestroyContextReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000375
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200376 TRACE("DestroyContext...");
377 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000378
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200379 LockDisplay(dpy);
380 GetReq(XF86DRIDestroyContext, req);
381 req->reqType = info->codes->major_opcode;
382 req->driReqType = X_XF86DRIDestroyContext;
383 req->screen = screen;
384 req->context = context;
385 UnlockDisplay(dpy);
386 SyncHandle();
387 TRACE("DestroyContext... return True");
388 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000389}
390
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500391Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200392XF86DRICreateDrawable(Display * dpy, int screen,
393 XID drawable, drm_drawable_t * hHWDrawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000394{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200395 XExtDisplayInfo *info = find_display(dpy);
396 xXF86DRICreateDrawableReply rep;
397 xXF86DRICreateDrawableReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000398
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200399 TRACE("CreateDrawable...");
400 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000401
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200402 LockDisplay(dpy);
403 GetReq(XF86DRICreateDrawable, req);
404 req->reqType = info->codes->major_opcode;
405 req->driReqType = X_XF86DRICreateDrawable;
406 req->screen = screen;
407 req->drawable = drawable;
408 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
409 UnlockDisplay(dpy);
410 SyncHandle();
411 TRACE("CreateDrawable... return False");
412 return False;
413 }
414 *hHWDrawable = rep.hHWDrawable;
415 UnlockDisplay(dpy);
416 SyncHandle();
417 TRACE("CreateDrawable... return True");
418 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000419}
420
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200421static int
422noopErrorHandler(Display * dpy, XErrorEvent * xerr)
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500423{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200424 return 0;
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500425}
426
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500427Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200428XF86DRIDestroyDrawable(Display * dpy, int screen, XID drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000429{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200430 XExtDisplayInfo *info = find_display(dpy);
431 xXF86DRIDestroyDrawableReq *req;
432 int (*oldXErrorHandler) (Display *, XErrorEvent *);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000433
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200434 TRACE("DestroyDrawable...");
435 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000436
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200437 /* This is called from the DRI driver, which used call it like this
438 *
439 * if (windowExists(drawable))
440 * destroyDrawable(drawable);
441 *
442 * which is a textbook race condition - the window may disappear
Zoë Blade05e7f7f2015-04-22 11:33:17 +0100443 * from the server between checking for its existence and
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200444 * destroying it. Instead we change the semantics of
445 * __DRIinterfaceMethodsRec::destroyDrawable() to succeed even if
446 * the windows is gone, by wrapping the destroy call in an error
447 * handler. */
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500448
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200449 XSync(dpy, False);
450 oldXErrorHandler = XSetErrorHandler(noopErrorHandler);
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500451
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200452 LockDisplay(dpy);
453 GetReq(XF86DRIDestroyDrawable, req);
454 req->reqType = info->codes->major_opcode;
455 req->driReqType = X_XF86DRIDestroyDrawable;
456 req->screen = screen;
457 req->drawable = drawable;
458 UnlockDisplay(dpy);
459 SyncHandle();
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500460
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200461 XSetErrorHandler(oldXErrorHandler);
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500462
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200463 TRACE("DestroyDrawable... return True");
464 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000465}
466
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500467Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200468XF86DRIGetDrawableInfo(Display * dpy, int screen, Drawable drawable,
469 unsigned int *index, unsigned int *stamp,
470 int *X, int *Y, int *W, int *H,
471 int *numClipRects, drm_clip_rect_t ** pClipRects,
472 int *backX, int *backY,
473 int *numBackClipRects,
474 drm_clip_rect_t ** pBackClipRects)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000475{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200476 XExtDisplayInfo *info = find_display(dpy);
477 xXF86DRIGetDrawableInfoReply rep;
478 xXF86DRIGetDrawableInfoReq *req;
479 int total_rects;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000480
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200481 TRACE("GetDrawableInfo...");
482 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000483
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200484 LockDisplay(dpy);
485 GetReq(XF86DRIGetDrawableInfo, req);
486 req->reqType = info->codes->major_opcode;
487 req->driReqType = X_XF86DRIGetDrawableInfo;
488 req->screen = screen;
489 req->drawable = drawable;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000490
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200491 if (!_XReply(dpy, (xReply *) & rep, 1, xFalse)) {
492 UnlockDisplay(dpy);
493 SyncHandle();
494 TRACE("GetDrawableInfo... return False");
495 return False;
496 }
497 *index = rep.drawableTableIndex;
498 *stamp = rep.drawableTableStamp;
499 *X = (int) rep.drawableX;
500 *Y = (int) rep.drawableY;
501 *W = (int) rep.drawableWidth;
502 *H = (int) rep.drawableHeight;
503 *numClipRects = rep.numClipRects;
504 total_rects = *numClipRects;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000505
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200506 *backX = rep.backX;
507 *backY = rep.backY;
508 *numBackClipRects = rep.numBackClipRects;
509 total_rects += *numBackClipRects;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000510
511#if 0
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200512 /* Because of the fix in Xserver/GL/dri/xf86dri.c, this check breaks
513 * backwards compatibility (Because of the >> 2 shift) but the fix
514 * enables multi-threaded apps to work.
515 */
516 if (rep.length != ((((SIZEOF(xXF86DRIGetDrawableInfoReply) -
517 SIZEOF(xGenericReply) +
518 total_rects * sizeof(drm_clip_rect_t)) +
519 3) & ~3) >> 2)) {
520 _XEatData(dpy, rep.length);
521 UnlockDisplay(dpy);
522 SyncHandle();
523 TRACE("GetDrawableInfo... return False");
524 return False;
525 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000526#endif
527
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200528 if (*numClipRects) {
529 int len = sizeof(drm_clip_rect_t) * (*numClipRects);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000530
Matt Turner2b7a9722012-09-03 19:44:00 -0700531 *pClipRects = calloc(len, 1);
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200532 if (*pClipRects)
533 _XRead(dpy, (char *) *pClipRects, len);
534 }
535 else {
536 *pClipRects = NULL;
537 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000538
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200539 if (*numBackClipRects) {
540 int len = sizeof(drm_clip_rect_t) * (*numBackClipRects);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000541
Matt Turner2b7a9722012-09-03 19:44:00 -0700542 *pBackClipRects = calloc(len, 1);
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200543 if (*pBackClipRects)
544 _XRead(dpy, (char *) *pBackClipRects, len);
545 }
546 else {
547 *pBackClipRects = NULL;
548 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000549
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200550 UnlockDisplay(dpy);
551 SyncHandle();
552 TRACE("GetDrawableInfo... return True");
553 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000554}
555
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500556Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200557XF86DRIGetDeviceInfo(Display * dpy, int screen, drm_handle_t * hFrameBuffer,
558 int *fbOrigin, int *fbSize, int *fbStride,
559 int *devPrivateSize, void **pDevPrivate)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000560{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200561 XExtDisplayInfo *info = find_display(dpy);
562 xXF86DRIGetDeviceInfoReply rep;
563 xXF86DRIGetDeviceInfoReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000564
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200565 TRACE("GetDeviceInfo...");
566 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000567
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200568 LockDisplay(dpy);
569 GetReq(XF86DRIGetDeviceInfo, req);
570 req->reqType = info->codes->major_opcode;
571 req->driReqType = X_XF86DRIGetDeviceInfo;
572 req->screen = screen;
573 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
574 UnlockDisplay(dpy);
575 SyncHandle();
576 TRACE("GetDeviceInfo... return False");
577 return False;
578 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000579
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200580 *hFrameBuffer = rep.hFrameBufferLow;
581 if (sizeof(drm_handle_t) == 8) {
582 int shift = 32; /* var to prevent warning on next line */
583 *hFrameBuffer |= ((drm_handle_t) rep.hFrameBufferHigh) << shift;
584 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000585
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200586 *fbOrigin = rep.framebufferOrigin;
587 *fbSize = rep.framebufferSize;
588 *fbStride = rep.framebufferStride;
589 *devPrivateSize = rep.devPrivateSize;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000590
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200591 if (rep.length) {
Matt Turner2b7a9722012-09-03 19:44:00 -0700592 if (!(*pDevPrivate = calloc(rep.devPrivateSize, 1))) {
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200593 _XEatData(dpy, ((rep.devPrivateSize + 3) & ~3));
594 UnlockDisplay(dpy);
595 SyncHandle();
596 TRACE("GetDeviceInfo... return False");
597 return False;
598 }
599 _XRead(dpy, (char *) *pDevPrivate, rep.devPrivateSize);
600 }
601 else {
602 *pDevPrivate = NULL;
603 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000604
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200605 UnlockDisplay(dpy);
606 SyncHandle();
607 TRACE("GetDeviceInfo... return True");
608 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000609}
610
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500611Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200612XF86DRIOpenFullScreen(Display * dpy, int screen, Drawable drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000613{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200614 /* This function and the underlying X protocol are deprecated.
615 */
616 (void) dpy;
617 (void) screen;
618 (void) drawable;
619 return False;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000620}
621
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500622Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200623XF86DRICloseFullScreen(Display * dpy, int screen, Drawable drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000624{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200625 /* This function and the underlying X protocol are deprecated.
626 */
627 (void) dpy;
628 (void) screen;
629 (void) drawable;
630 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000631}
Adam Jacksonbe85fde2006-08-10 20:19:57 +0000632
633#endif /* GLX_DIRECT_RENDERING */