blob: 36b43f0f84af100a26e9868c7f8fc37f54bb8125 [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>
Adam Jacksoncb3610e2004-10-25 21:09:16 +000042#include <X11/extensions/Xext.h>
Brian Paul82dfd4b2005-08-11 14:18:53 +000043#include <X11/extensions/extutil.h>
Adam Jackson1074eae2005-01-08 03:54:38 +000044#include "xf86dristr.h"
Adam Jacksoncb3610e2004-10-25 21:09:16 +000045
Brian Paul3537da82008-09-18 13:23:06 -060046
Ian Romanick016fc302010-03-03 16:02:45 -080047#if defined(__GNUC__)
Brian Paul3537da82008-09-18 13:23:06 -060048# define PUBLIC __attribute__((visibility("default")))
49# define USED __attribute__((used))
50#else
51# define PUBLIC
52# define USED
53#endif
54
55
56
Adam Jacksoncb3610e2004-10-25 21:09:16 +000057static XExtensionInfo _xf86dri_info_data;
58static XExtensionInfo *xf86dri_info = &_xf86dri_info_data;
Adam Jackson5dd18e92004-11-03 18:55:20 +000059static char xf86dri_extension_name[] = XF86DRINAME;
Adam Jacksoncb3610e2004-10-25 21:09:16 +000060
61#define XF86DRICheckExtension(dpy,i,val) \
62 XextCheckExtension (dpy, i, xf86dri_extension_name, val)
63
64/*****************************************************************************
65 * *
66 * private utility routines *
67 * *
68 *****************************************************************************/
69
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +020070static int close_display(Display * dpy, XExtCodes * extCodes);
Adam Jacksoncb3610e2004-10-25 21:09:16 +000071static /* const */ XExtensionHooks xf86dri_extension_hooks = {
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +020072 NULL, /* create_gc */
73 NULL, /* copy_gc */
74 NULL, /* flush_gc */
75 NULL, /* free_gc */
76 NULL, /* create_font */
77 NULL, /* free_font */
78 close_display, /* close_display */
79 NULL, /* wire_to_event */
80 NULL, /* event_to_wire */
81 NULL, /* error */
82 NULL, /* error_string */
Adam Jacksoncb3610e2004-10-25 21:09:16 +000083};
84
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +020085static
86XEXT_GENERATE_FIND_DISPLAY(find_display, xf86dri_info,
87 xf86dri_extension_name,
88 &xf86dri_extension_hooks, 0, NULL)
Adam Jacksoncb3610e2004-10-25 21:09:16 +000089
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +020090static
91XEXT_GENERATE_CLOSE_DISPLAY(close_display, xf86dri_info)
Adam Jacksoncb3610e2004-10-25 21:09:16 +000092
93
94/*****************************************************************************
95 * *
96 * public XFree86-DRI Extension routines *
97 * *
98 *****************************************************************************/
Adam Jacksoncb3610e2004-10-25 21:09:16 +000099#if 0
100#include <stdio.h>
101#define TRACE(msg) fprintf(stderr,"XF86DRI%s\n", msg);
102#else
103#define TRACE(msg)
104#endif
105
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500106Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200107XF86DRIQueryExtension(Display * dpy, int *event_basep,
108 int *error_basep)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000109{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200110 XExtDisplayInfo *info = find_display(dpy);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000111
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200112 TRACE("QueryExtension...");
113 if (XextHasExtension(info)) {
114 *event_basep = info->codes->first_event;
115 *error_basep = info->codes->first_error;
116 TRACE("QueryExtension... return True");
117 return True;
118 }
119 else {
120 TRACE("QueryExtension... return False");
121 return False;
122 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000123}
124
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500125Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200126XF86DRIQueryVersion(Display * dpy, int *majorVersion, int *minorVersion,
127 int *patchVersion)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000128{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200129 XExtDisplayInfo *info = find_display(dpy);
130 xXF86DRIQueryVersionReply rep;
131 xXF86DRIQueryVersionReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000132
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200133 TRACE("QueryVersion...");
134 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000135
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200136 LockDisplay(dpy);
137 GetReq(XF86DRIQueryVersion, req);
138 req->reqType = info->codes->major_opcode;
139 req->driReqType = X_XF86DRIQueryVersion;
140 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
141 UnlockDisplay(dpy);
142 SyncHandle();
143 TRACE("QueryVersion... return False");
144 return False;
145 }
146 *majorVersion = rep.majorVersion;
147 *minorVersion = rep.minorVersion;
148 *patchVersion = rep.patchVersion;
149 UnlockDisplay(dpy);
150 SyncHandle();
151 TRACE("QueryVersion... return True");
152 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000153}
154
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500155Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200156XF86DRIQueryDirectRenderingCapable(Display * dpy, int screen,
157 Bool * isCapable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000158{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200159 XExtDisplayInfo *info = find_display(dpy);
160 xXF86DRIQueryDirectRenderingCapableReply rep;
161 xXF86DRIQueryDirectRenderingCapableReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000162
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200163 TRACE("QueryDirectRenderingCapable...");
164 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000165
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200166 LockDisplay(dpy);
167 GetReq(XF86DRIQueryDirectRenderingCapable, req);
168 req->reqType = info->codes->major_opcode;
169 req->driReqType = X_XF86DRIQueryDirectRenderingCapable;
170 req->screen = screen;
171 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
172 UnlockDisplay(dpy);
173 SyncHandle();
174 TRACE("QueryDirectRenderingCapable... return False");
175 return False;
176 }
177 *isCapable = rep.isCapable;
178 UnlockDisplay(dpy);
179 SyncHandle();
180 TRACE("QueryDirectRenderingCapable... return True");
181 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000182}
183
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500184Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200185XF86DRIOpenConnection(Display * dpy, int screen, drm_handle_t * hSAREA,
186 char **busIdString)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000187{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200188 XExtDisplayInfo *info = find_display(dpy);
189 xXF86DRIOpenConnectionReply rep;
190 xXF86DRIOpenConnectionReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000191
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200192 TRACE("OpenConnection...");
193 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000194
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200195 LockDisplay(dpy);
196 GetReq(XF86DRIOpenConnection, req);
197 req->reqType = info->codes->major_opcode;
198 req->driReqType = X_XF86DRIOpenConnection;
199 req->screen = screen;
200 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
201 UnlockDisplay(dpy);
202 SyncHandle();
203 TRACE("OpenConnection... return False");
204 return False;
205 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000206
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200207 *hSAREA = rep.hSAREALow;
208 if (sizeof(drm_handle_t) == 8) {
209 int shift = 32; /* var to prevent warning on next line */
210 *hSAREA |= ((drm_handle_t) rep.hSAREAHigh) << shift;
211 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000212
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200213 if (rep.length) {
214 if (!(*busIdString = (char *) Xcalloc(rep.busIdStringLength + 1, 1))) {
215 _XEatData(dpy, ((rep.busIdStringLength + 3) & ~3));
216 UnlockDisplay(dpy);
217 SyncHandle();
218 TRACE("OpenConnection... return False");
219 return False;
220 }
221 _XReadPad(dpy, *busIdString, rep.busIdStringLength);
222 }
223 else {
224 *busIdString = NULL;
225 }
226 UnlockDisplay(dpy);
227 SyncHandle();
228 TRACE("OpenConnection... return True");
229 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000230}
231
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500232Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200233XF86DRIAuthConnection(Display * dpy, int screen, drm_magic_t magic)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000234{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200235 XExtDisplayInfo *info = find_display(dpy);
236 xXF86DRIAuthConnectionReq *req;
237 xXF86DRIAuthConnectionReply rep;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000238
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200239 TRACE("AuthConnection...");
240 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000241
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200242 LockDisplay(dpy);
243 GetReq(XF86DRIAuthConnection, req);
244 req->reqType = info->codes->major_opcode;
245 req->driReqType = X_XF86DRIAuthConnection;
246 req->screen = screen;
247 req->magic = magic;
248 rep.authenticated = 0;
249 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse) || !rep.authenticated) {
250 UnlockDisplay(dpy);
251 SyncHandle();
252 TRACE("AuthConnection... return False");
253 return False;
254 }
255 UnlockDisplay(dpy);
256 SyncHandle();
257 TRACE("AuthConnection... return True");
258 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000259}
260
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500261Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200262XF86DRICloseConnection(Display * dpy, int screen)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000263{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200264 XExtDisplayInfo *info = find_display(dpy);
265 xXF86DRICloseConnectionReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000266
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200267 TRACE("CloseConnection...");
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000268
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200269 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000270
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200271 LockDisplay(dpy);
272 GetReq(XF86DRICloseConnection, req);
273 req->reqType = info->codes->major_opcode;
274 req->driReqType = X_XF86DRICloseConnection;
275 req->screen = screen;
276 UnlockDisplay(dpy);
277 SyncHandle();
278 TRACE("CloseConnection... return True");
279 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000280}
281
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500282Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200283XF86DRIGetClientDriverName(Display * dpy, int screen,
284 int *ddxDriverMajorVersion,
285 int *ddxDriverMinorVersion,
286 int *ddxDriverPatchVersion,
287 char **clientDriverName)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000288{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200289 XExtDisplayInfo *info = find_display(dpy);
290 xXF86DRIGetClientDriverNameReply rep;
291 xXF86DRIGetClientDriverNameReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000292
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200293 TRACE("GetClientDriverName...");
294 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000295
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200296 LockDisplay(dpy);
297 GetReq(XF86DRIGetClientDriverName, req);
298 req->reqType = info->codes->major_opcode;
299 req->driReqType = X_XF86DRIGetClientDriverName;
300 req->screen = screen;
301 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
302 UnlockDisplay(dpy);
303 SyncHandle();
304 TRACE("GetClientDriverName... return False");
305 return False;
306 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000307
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200308 *ddxDriverMajorVersion = rep.ddxDriverMajorVersion;
309 *ddxDriverMinorVersion = rep.ddxDriverMinorVersion;
310 *ddxDriverPatchVersion = rep.ddxDriverPatchVersion;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000311
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200312 if (rep.length) {
313 if (!
314 (*clientDriverName =
315 (char *) Xcalloc(rep.clientDriverNameLength + 1, 1))) {
316 _XEatData(dpy, ((rep.clientDriverNameLength + 3) & ~3));
317 UnlockDisplay(dpy);
318 SyncHandle();
319 TRACE("GetClientDriverName... return False");
320 return False;
321 }
322 _XReadPad(dpy, *clientDriverName, rep.clientDriverNameLength);
323 }
324 else {
325 *clientDriverName = NULL;
326 }
327 UnlockDisplay(dpy);
328 SyncHandle();
329 TRACE("GetClientDriverName... return True");
330 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000331}
332
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500333Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200334XF86DRICreateContextWithConfig(Display * dpy, int screen, int configID,
335 XID * context, drm_context_t * hHWContext)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000336{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200337 XExtDisplayInfo *info = find_display(dpy);
338 xXF86DRICreateContextReply rep;
339 xXF86DRICreateContextReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000340
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200341 TRACE("CreateContext...");
342 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000343
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200344 LockDisplay(dpy);
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)) {
353 UnlockDisplay(dpy);
354 SyncHandle();
355 TRACE("CreateContext... return False");
356 return False;
357 }
358 *hHWContext = rep.hHWContext;
359 UnlockDisplay(dpy);
360 SyncHandle();
361 TRACE("CreateContext... return True");
362 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000363}
364
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500365Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200366XF86DRICreateContext(Display * dpy, int screen, Visual * visual,
367 XID * context, drm_context_t * hHWContext)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000368{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200369 return XF86DRICreateContextWithConfig(dpy, screen, visual->visualid,
370 context, hHWContext);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000371}
372
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500373Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200374XF86DRIDestroyContext(Display * dpy, int screen, XID context)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000375{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200376 XExtDisplayInfo *info = find_display(dpy);
377 xXF86DRIDestroyContextReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000378
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200379 TRACE("DestroyContext...");
380 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000381
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200382 LockDisplay(dpy);
383 GetReq(XF86DRIDestroyContext, req);
384 req->reqType = info->codes->major_opcode;
385 req->driReqType = X_XF86DRIDestroyContext;
386 req->screen = screen;
387 req->context = context;
388 UnlockDisplay(dpy);
389 SyncHandle();
390 TRACE("DestroyContext... return True");
391 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000392}
393
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500394Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200395XF86DRICreateDrawable(Display * dpy, int screen,
396 XID drawable, drm_drawable_t * hHWDrawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000397{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200398 XExtDisplayInfo *info = find_display(dpy);
399 xXF86DRICreateDrawableReply rep;
400 xXF86DRICreateDrawableReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000401
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200402 TRACE("CreateDrawable...");
403 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000404
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200405 LockDisplay(dpy);
406 GetReq(XF86DRICreateDrawable, req);
407 req->reqType = info->codes->major_opcode;
408 req->driReqType = X_XF86DRICreateDrawable;
409 req->screen = screen;
410 req->drawable = drawable;
411 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
412 UnlockDisplay(dpy);
413 SyncHandle();
414 TRACE("CreateDrawable... return False");
415 return False;
416 }
417 *hHWDrawable = rep.hHWDrawable;
418 UnlockDisplay(dpy);
419 SyncHandle();
420 TRACE("CreateDrawable... return True");
421 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000422}
423
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200424static int
425noopErrorHandler(Display * dpy, XErrorEvent * xerr)
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500426{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200427 return 0;
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500428}
429
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500430Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200431XF86DRIDestroyDrawable(Display * dpy, int screen, XID drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000432{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200433 XExtDisplayInfo *info = find_display(dpy);
434 xXF86DRIDestroyDrawableReq *req;
435 int (*oldXErrorHandler) (Display *, XErrorEvent *);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000436
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200437 TRACE("DestroyDrawable...");
438 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000439
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200440 /* This is called from the DRI driver, which used call it like this
441 *
442 * if (windowExists(drawable))
443 * destroyDrawable(drawable);
444 *
445 * which is a textbook race condition - the window may disappear
446 * from the server between checking for its existance and
447 * destroying it. Instead we change the semantics of
448 * __DRIinterfaceMethodsRec::destroyDrawable() to succeed even if
449 * the windows is gone, by wrapping the destroy call in an error
450 * handler. */
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500451
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200452 XSync(dpy, False);
453 oldXErrorHandler = XSetErrorHandler(noopErrorHandler);
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500454
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200455 LockDisplay(dpy);
456 GetReq(XF86DRIDestroyDrawable, req);
457 req->reqType = info->codes->major_opcode;
458 req->driReqType = X_XF86DRIDestroyDrawable;
459 req->screen = screen;
460 req->drawable = drawable;
461 UnlockDisplay(dpy);
462 SyncHandle();
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500463
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200464 XSetErrorHandler(oldXErrorHandler);
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500465
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200466 TRACE("DestroyDrawable... return True");
467 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000468}
469
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500470Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200471XF86DRIGetDrawableInfo(Display * dpy, int screen, Drawable drawable,
472 unsigned int *index, unsigned int *stamp,
473 int *X, int *Y, int *W, int *H,
474 int *numClipRects, drm_clip_rect_t ** pClipRects,
475 int *backX, int *backY,
476 int *numBackClipRects,
477 drm_clip_rect_t ** pBackClipRects)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000478{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200479 XExtDisplayInfo *info = find_display(dpy);
480 xXF86DRIGetDrawableInfoReply rep;
481 xXF86DRIGetDrawableInfoReq *req;
482 int total_rects;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000483
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200484 TRACE("GetDrawableInfo...");
485 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000486
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200487 LockDisplay(dpy);
488 GetReq(XF86DRIGetDrawableInfo, req);
489 req->reqType = info->codes->major_opcode;
490 req->driReqType = X_XF86DRIGetDrawableInfo;
491 req->screen = screen;
492 req->drawable = drawable;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000493
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200494 if (!_XReply(dpy, (xReply *) & rep, 1, xFalse)) {
495 UnlockDisplay(dpy);
496 SyncHandle();
497 TRACE("GetDrawableInfo... return False");
498 return False;
499 }
500 *index = rep.drawableTableIndex;
501 *stamp = rep.drawableTableStamp;
502 *X = (int) rep.drawableX;
503 *Y = (int) rep.drawableY;
504 *W = (int) rep.drawableWidth;
505 *H = (int) rep.drawableHeight;
506 *numClipRects = rep.numClipRects;
507 total_rects = *numClipRects;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000508
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200509 *backX = rep.backX;
510 *backY = rep.backY;
511 *numBackClipRects = rep.numBackClipRects;
512 total_rects += *numBackClipRects;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000513
514#if 0
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200515 /* Because of the fix in Xserver/GL/dri/xf86dri.c, this check breaks
516 * backwards compatibility (Because of the >> 2 shift) but the fix
517 * enables multi-threaded apps to work.
518 */
519 if (rep.length != ((((SIZEOF(xXF86DRIGetDrawableInfoReply) -
520 SIZEOF(xGenericReply) +
521 total_rects * sizeof(drm_clip_rect_t)) +
522 3) & ~3) >> 2)) {
523 _XEatData(dpy, rep.length);
524 UnlockDisplay(dpy);
525 SyncHandle();
526 TRACE("GetDrawableInfo... return False");
527 return False;
528 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000529#endif
530
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200531 if (*numClipRects) {
532 int len = sizeof(drm_clip_rect_t) * (*numClipRects);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000533
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200534 *pClipRects = (drm_clip_rect_t *) Xcalloc(len, 1);
535 if (*pClipRects)
536 _XRead(dpy, (char *) *pClipRects, len);
537 }
538 else {
539 *pClipRects = NULL;
540 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000541
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200542 if (*numBackClipRects) {
543 int len = sizeof(drm_clip_rect_t) * (*numBackClipRects);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000544
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200545 *pBackClipRects = (drm_clip_rect_t *) Xcalloc(len, 1);
546 if (*pBackClipRects)
547 _XRead(dpy, (char *) *pBackClipRects, len);
548 }
549 else {
550 *pBackClipRects = NULL;
551 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000552
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200553 UnlockDisplay(dpy);
554 SyncHandle();
555 TRACE("GetDrawableInfo... return True");
556 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000557}
558
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500559Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200560XF86DRIGetDeviceInfo(Display * dpy, int screen, drm_handle_t * hFrameBuffer,
561 int *fbOrigin, int *fbSize, int *fbStride,
562 int *devPrivateSize, void **pDevPrivate)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000563{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200564 XExtDisplayInfo *info = find_display(dpy);
565 xXF86DRIGetDeviceInfoReply rep;
566 xXF86DRIGetDeviceInfoReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000567
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200568 TRACE("GetDeviceInfo...");
569 XF86DRICheckExtension(dpy, info, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000570
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200571 LockDisplay(dpy);
572 GetReq(XF86DRIGetDeviceInfo, req);
573 req->reqType = info->codes->major_opcode;
574 req->driReqType = X_XF86DRIGetDeviceInfo;
575 req->screen = screen;
576 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
577 UnlockDisplay(dpy);
578 SyncHandle();
579 TRACE("GetDeviceInfo... return False");
580 return False;
581 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000582
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200583 *hFrameBuffer = rep.hFrameBufferLow;
584 if (sizeof(drm_handle_t) == 8) {
585 int shift = 32; /* var to prevent warning on next line */
586 *hFrameBuffer |= ((drm_handle_t) rep.hFrameBufferHigh) << shift;
587 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000588
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200589 *fbOrigin = rep.framebufferOrigin;
590 *fbSize = rep.framebufferSize;
591 *fbStride = rep.framebufferStride;
592 *devPrivateSize = rep.devPrivateSize;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000593
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200594 if (rep.length) {
595 if (!(*pDevPrivate = (void *) Xcalloc(rep.devPrivateSize, 1))) {
596 _XEatData(dpy, ((rep.devPrivateSize + 3) & ~3));
597 UnlockDisplay(dpy);
598 SyncHandle();
599 TRACE("GetDeviceInfo... return False");
600 return False;
601 }
602 _XRead(dpy, (char *) *pDevPrivate, rep.devPrivateSize);
603 }
604 else {
605 *pDevPrivate = NULL;
606 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000607
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200608 UnlockDisplay(dpy);
609 SyncHandle();
610 TRACE("GetDeviceInfo... return True");
611 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000612}
613
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500614Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200615XF86DRIOpenFullScreen(Display * dpy, int screen, Drawable drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000616{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200617 /* This function and the underlying X protocol are deprecated.
618 */
619 (void) dpy;
620 (void) screen;
621 (void) drawable;
622 return False;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000623}
624
Kristian Høgsberg697e2212010-02-05 11:04:48 -0500625Bool
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200626XF86DRICloseFullScreen(Display * dpy, int screen, Drawable drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000627{
RALOVICH, Kristóf4d2a3812008-10-13 15:03:13 +0200628 /* This function and the underlying X protocol are deprecated.
629 */
630 (void) dpy;
631 (void) screen;
632 (void) drawable;
633 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000634}
Adam Jacksonbe85fde2006-08-10 20:19:57 +0000635
636#endif /* GLX_DIRECT_RENDERING */