85041ad5c510fd2ba9e4b5e2298507720dcf25c6
[mesa.git] / src / glx / glxcmds.c
1 /*
2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
29 */
30
31 /**
32 * \file glxcmds.c
33 * Client-side GLX interface.
34 */
35
36 #include "glxclient.h"
37 #include "glapi.h"
38 #include "glxextensions.h"
39 #include "indirect.h"
40 #include "glx_error.h"
41
42 #ifdef GLX_DIRECT_RENDERING
43 #ifdef GLX_USE_APPLEGL
44 #include "apple/apple_glx_context.h"
45 #include "apple/apple_glx.h"
46 #include "util/debug.h"
47 #else
48 #include <sys/time.h>
49 #ifndef GLX_USE_WINDOWSGL
50 #include <X11/extensions/xf86vmode.h>
51 #endif /* GLX_USE_WINDOWSGL */
52 #endif
53 #endif
54
55 #include <X11/Xlib-xcb.h>
56 #include <xcb/xcb.h>
57 #include <xcb/glx.h>
58 #include "GL/mesa_glinterop.h"
59
60 static const char __glXGLXClientVendorName[] = "Mesa Project and SGI";
61 static const char __glXGLXClientVersion[] = "1.4";
62
63 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
64
65 /**
66 * Get the __DRIdrawable for the drawable associated with a GLXContext
67 *
68 * \param dpy The display associated with \c drawable.
69 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
70 * \param scrn_num If non-NULL, the drawables screen is stored there
71 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
72 * the drawable is not associated with a direct-rendering context.
73 */
74 _X_HIDDEN __GLXDRIdrawable *
75 GetGLXDRIDrawable(Display * dpy, GLXDrawable drawable)
76 {
77 struct glx_display *priv = __glXInitialize(dpy);
78 __GLXDRIdrawable *pdraw;
79
80 if (priv == NULL)
81 return NULL;
82
83 if (__glxHashLookup(priv->drawHash, drawable, (void *) &pdraw) == 0)
84 return pdraw;
85
86 return NULL;
87 }
88
89 #endif
90
91 _X_HIDDEN struct glx_drawable *
92 GetGLXDrawable(Display *dpy, GLXDrawable drawable)
93 {
94 struct glx_display *priv = __glXInitialize(dpy);
95 struct glx_drawable *glxDraw;
96
97 if (priv == NULL)
98 return NULL;
99
100 if (__glxHashLookup(priv->glXDrawHash, drawable, (void *) &glxDraw) == 0)
101 return glxDraw;
102
103 return NULL;
104 }
105
106 _X_HIDDEN int
107 InitGLXDrawable(Display *dpy, struct glx_drawable *glxDraw, XID xDrawable,
108 GLXDrawable drawable)
109 {
110 struct glx_display *priv = __glXInitialize(dpy);
111
112 if (!priv)
113 return -1;
114
115 glxDraw->xDrawable = xDrawable;
116 glxDraw->drawable = drawable;
117 glxDraw->lastEventSbc = 0;
118 glxDraw->eventSbcWrap = 0;
119
120 return __glxHashInsert(priv->glXDrawHash, drawable, glxDraw);
121 }
122
123 _X_HIDDEN void
124 DestroyGLXDrawable(Display *dpy, GLXDrawable drawable)
125 {
126 struct glx_display *priv = __glXInitialize(dpy);
127 struct glx_drawable *glxDraw;
128
129 if (!priv)
130 return;
131
132 glxDraw = GetGLXDrawable(dpy, drawable);
133 __glxHashDelete(priv->glXDrawHash, drawable);
134 free(glxDraw);
135 }
136
137 /**
138 * Get the GLX per-screen data structure associated with a GLX context.
139 *
140 * \param dpy Display for which the GLX per-screen information is to be
141 * retrieved.
142 * \param scrn Screen on \c dpy for which the GLX per-screen information is
143 * to be retrieved.
144 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
145 * specify a valid GLX screen, or NULL otherwise.
146 *
147 * \todo Should this function validate that \c scrn is within the screen
148 * number range for \c dpy?
149 */
150
151 _X_HIDDEN struct glx_screen *
152 GetGLXScreenConfigs(Display * dpy, int scrn)
153 {
154 struct glx_display *const priv = __glXInitialize(dpy);
155
156 return (priv
157 && priv->screens !=
158 NULL) ? priv->screens[scrn] : NULL;
159 }
160
161
162 static int
163 GetGLXPrivScreenConfig(Display * dpy, int scrn, struct glx_display ** ppriv,
164 struct glx_screen ** ppsc)
165 {
166 /* Initialize the extension, if needed . This has the added value
167 * of initializing/allocating the display private
168 */
169
170 if (dpy == NULL) {
171 return GLX_NO_EXTENSION;
172 }
173
174 *ppriv = __glXInitialize(dpy);
175 if (*ppriv == NULL) {
176 return GLX_NO_EXTENSION;
177 }
178
179 /* Check screen number to see if its valid */
180 if ((scrn < 0) || (scrn >= ScreenCount(dpy))) {
181 return GLX_BAD_SCREEN;
182 }
183
184 /* Check to see if the GL is supported on this screen */
185 *ppsc = (*ppriv)->screens[scrn];
186 if ((*ppsc)->configs == NULL && (*ppsc)->visuals == NULL) {
187 /* No support for GL on this screen regardless of visual */
188 return GLX_BAD_VISUAL;
189 }
190
191 return Success;
192 }
193
194
195 /**
196 * Determine if a \c GLXFBConfig supplied by the application is valid.
197 *
198 * \param dpy Application supplied \c Display pointer.
199 * \param config Application supplied \c GLXFBConfig.
200 *
201 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
202 * \c struct glx_config structure is returned. Otherwise, \c NULL
203 * is returned.
204 */
205 static struct glx_config *
206 ValidateGLXFBConfig(Display * dpy, GLXFBConfig fbconfig)
207 {
208 struct glx_display *const priv = __glXInitialize(dpy);
209 int num_screens = ScreenCount(dpy);
210 unsigned i;
211 struct glx_config *config;
212
213 if (priv != NULL) {
214 for (i = 0; i < num_screens; i++) {
215 for (config = priv->screens[i]->configs; config != NULL;
216 config = config->next) {
217 if (config == (struct glx_config *) fbconfig) {
218 return config;
219 }
220 }
221 }
222 }
223
224 return NULL;
225 }
226
227 /**
228 * Verifies context's GLX_RENDER_TYPE value with config.
229 *
230 * \param config GLX FBConfig which will support the returned renderType.
231 * \param renderType The context render type to be verified.
232 * \return True if the value of context renderType was approved, or 0 if no
233 * valid value was found.
234 */
235 Bool
236 validate_renderType_against_config(const struct glx_config *config,
237 int renderType)
238 {
239 /* GLX_EXT_no_config_context supports any render type */
240 if (!config)
241 return renderType == GLX_DONT_CARE;
242
243 switch (renderType) {
244 case GLX_RGBA_TYPE:
245 return (config->renderType & GLX_RGBA_BIT) != 0;
246 case GLX_COLOR_INDEX_TYPE:
247 return (config->renderType & GLX_COLOR_INDEX_BIT) != 0;
248 case GLX_RGBA_FLOAT_TYPE_ARB:
249 return (config->renderType & GLX_RGBA_FLOAT_BIT_ARB) != 0;
250 case GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT:
251 return (config->renderType & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) != 0;
252 default:
253 break;
254 }
255 return 0;
256 }
257
258 _X_HIDDEN Bool
259 glx_context_init(struct glx_context *gc,
260 struct glx_screen *psc, struct glx_config *config)
261 {
262 gc->majorOpcode = __glXSetupForCommand(psc->display->dpy);
263 if (!gc->majorOpcode)
264 return False;
265
266 gc->screen = psc->scr;
267 gc->psc = psc;
268 gc->config = config;
269 gc->isDirect = GL_TRUE;
270 gc->currentContextTag = -1;
271
272 if (!config)
273 gc->renderType = GLX_DONT_CARE;
274
275 return True;
276 }
277
278 /**
279 * Determine if a context uses direct rendering.
280 *
281 * \param dpy Display where the context was created.
282 * \param contextID ID of the context to be tested.
283 * \param error Out parameter, set to True on error if not NULL
284 *
285 * \returns \c True if the context is direct rendering or not.
286 */
287 static Bool
288 __glXIsDirect(Display * dpy, GLXContextID contextID, Bool *error)
289 {
290 CARD8 opcode;
291 xcb_connection_t *c;
292 xcb_generic_error_t *err;
293 xcb_glx_is_direct_reply_t *reply;
294 Bool is_direct;
295
296 opcode = __glXSetupForCommand(dpy);
297 if (!opcode) {
298 return False;
299 }
300
301 c = XGetXCBConnection(dpy);
302 reply = xcb_glx_is_direct_reply(c, xcb_glx_is_direct(c, contextID), &err);
303 is_direct = (reply != NULL && reply->is_direct) ? True : False;
304
305 if (err != NULL) {
306 if (error)
307 *error = True;
308 __glXSendErrorForXcb(dpy, err);
309 free(err);
310 }
311
312 free(reply);
313
314 return is_direct;
315 }
316
317 /**
318 * Create a new context.
319 *
320 * \param renderType For FBConfigs, what is the rendering type?
321 */
322
323 static GLXContext
324 CreateContext(Display *dpy, int generic_id, struct glx_config *config,
325 GLXContext shareList_user, Bool allowDirect,
326 unsigned code, int renderType, int screen)
327 {
328 struct glx_context *gc;
329 struct glx_screen *psc;
330 struct glx_context *shareList = (struct glx_context *) shareList_user;
331 if (dpy == NULL)
332 return NULL;
333
334 psc = GetGLXScreenConfigs(dpy, screen);
335 if (psc == NULL)
336 return NULL;
337
338 if (generic_id == None)
339 return NULL;
340
341 gc = NULL;
342 #ifdef GLX_USE_APPLEGL
343 gc = applegl_create_context(psc, config, shareList, renderType);
344 #else
345 if (allowDirect && psc->vtable->create_context)
346 gc = psc->vtable->create_context(psc, config, shareList, renderType);
347 if (!gc)
348 gc = indirect_create_context(psc, config, shareList, renderType);
349 #endif
350 if (!gc)
351 return NULL;
352
353 LockDisplay(dpy);
354 switch (code) {
355 case X_GLXCreateContext: {
356 xGLXCreateContextReq *req;
357
358 /* Send the glXCreateContext request */
359 GetReq(GLXCreateContext, req);
360 req->reqType = gc->majorOpcode;
361 req->glxCode = X_GLXCreateContext;
362 req->context = gc->xid = XAllocID(dpy);
363 req->visual = generic_id;
364 req->screen = screen;
365 req->shareList = shareList ? shareList->xid : None;
366 req->isDirect = gc->isDirect;
367 break;
368 }
369
370 case X_GLXCreateNewContext: {
371 xGLXCreateNewContextReq *req;
372
373 /* Send the glXCreateNewContext request */
374 GetReq(GLXCreateNewContext, req);
375 req->reqType = gc->majorOpcode;
376 req->glxCode = X_GLXCreateNewContext;
377 req->context = gc->xid = XAllocID(dpy);
378 req->fbconfig = generic_id;
379 req->screen = screen;
380 req->renderType = renderType;
381 req->shareList = shareList ? shareList->xid : None;
382 req->isDirect = gc->isDirect;
383 break;
384 }
385
386 case X_GLXvop_CreateContextWithConfigSGIX: {
387 xGLXVendorPrivateWithReplyReq *vpreq;
388 xGLXCreateContextWithConfigSGIXReq *req;
389
390 /* Send the glXCreateNewContext request */
391 GetReqExtra(GLXVendorPrivateWithReply,
392 sz_xGLXCreateContextWithConfigSGIXReq -
393 sz_xGLXVendorPrivateWithReplyReq, vpreq);
394 req = (xGLXCreateContextWithConfigSGIXReq *) vpreq;
395 req->reqType = gc->majorOpcode;
396 req->glxCode = X_GLXVendorPrivateWithReply;
397 req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX;
398 req->context = gc->xid = XAllocID(dpy);
399 req->fbconfig = generic_id;
400 req->screen = screen;
401 req->renderType = renderType;
402 req->shareList = shareList ? shareList->xid : None;
403 req->isDirect = gc->isDirect;
404 break;
405 }
406
407 default:
408 /* What to do here? This case is the sign of an internal error. It
409 * should never be reachable.
410 */
411 break;
412 }
413
414 UnlockDisplay(dpy);
415 SyncHandle();
416
417 gc->share_xid = shareList ? shareList->xid : None;
418 gc->imported = GL_FALSE;
419
420 /* Unlike most X resource creation requests, we're about to return a handle
421 * with client-side state, not just an XID. To simplify error handling
422 * elsewhere in libGL, force a round-trip here to ensure the CreateContext
423 * request above succeeded.
424 */
425 {
426 Bool error = False;
427 int isDirect = __glXIsDirect(dpy, gc->xid, &error);
428
429 if (error != False || isDirect != gc->isDirect) {
430 gc->vtable->destroy(gc);
431 gc = NULL;
432 }
433 }
434
435 return (GLXContext) gc;
436 }
437
438 _GLX_PUBLIC GLXContext
439 glXCreateContext(Display * dpy, XVisualInfo * vis,
440 GLXContext shareList, Bool allowDirect)
441 {
442 struct glx_config *config = NULL;
443 int renderType = GLX_RGBA_TYPE;
444
445 #if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
446 struct glx_screen *const psc = GetGLXScreenConfigs(dpy, vis->screen);
447
448 if (psc)
449 config = glx_config_find_visual(psc->visuals, vis->visualid);
450
451 if (config == NULL) {
452 __glXSendError(dpy, BadValue, vis->visualid, X_GLXCreateContext, True);
453 return None;
454 }
455
456 /* Choose the context render type based on DRI config values. It is
457 * unusual to set this type from config, but we have no other choice, as
458 * this old API does not provide renderType parameter.
459 */
460 if (config->renderType & GLX_RGBA_FLOAT_BIT_ARB) {
461 renderType = GLX_RGBA_FLOAT_TYPE_ARB;
462 } else if (config->renderType & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) {
463 renderType = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
464 } else if (config->renderType & GLX_RGBA_BIT) {
465 renderType = GLX_RGBA_TYPE;
466 } else if (config->renderType & GLX_COLOR_INDEX_BIT) {
467 renderType = GLX_COLOR_INDEX_TYPE;
468 }
469 #endif
470
471 return CreateContext(dpy, vis->visualid, config, shareList, allowDirect,
472 X_GLXCreateContext, renderType, vis->screen);
473 }
474
475 static void
476 glx_send_destroy_context(Display *dpy, XID xid)
477 {
478 CARD8 opcode = __glXSetupForCommand(dpy);
479 xGLXDestroyContextReq *req;
480
481 LockDisplay(dpy);
482 GetReq(GLXDestroyContext, req);
483 req->reqType = opcode;
484 req->glxCode = X_GLXDestroyContext;
485 req->context = xid;
486 UnlockDisplay(dpy);
487 SyncHandle();
488 }
489
490 /*
491 ** Destroy the named context
492 */
493
494 _GLX_PUBLIC void
495 glXDestroyContext(Display * dpy, GLXContext ctx)
496 {
497 struct glx_context *gc = (struct glx_context *) ctx;
498
499 if (gc == NULL || gc->xid == None)
500 return;
501
502 __glXLock();
503 if (!gc->imported)
504 glx_send_destroy_context(dpy, gc->xid);
505
506 if (gc->currentDpy) {
507 /* This context is bound to some thread. According to the man page,
508 * we should not actually delete the context until it's unbound.
509 * Note that we set gc->xid = None above. In MakeContextCurrent()
510 * we check for that and delete the context there.
511 */
512 gc->xid = None;
513 } else {
514 gc->vtable->destroy(gc);
515 }
516 __glXUnlock();
517 }
518
519 /*
520 ** Return the major and minor version #s for the GLX extension
521 */
522 _GLX_PUBLIC Bool
523 glXQueryVersion(Display * dpy, int *major, int *minor)
524 {
525 struct glx_display *priv;
526
527 /* Init the extension. This fetches the major and minor version. */
528 priv = __glXInitialize(dpy);
529 if (!priv)
530 return False;
531
532 if (major)
533 *major = priv->majorVersion;
534 if (minor)
535 *minor = priv->minorVersion;
536 return True;
537 }
538
539 /*
540 ** Query the existence of the GLX extension
541 */
542 _GLX_PUBLIC Bool
543 glXQueryExtension(Display * dpy, int *errorBase, int *eventBase)
544 {
545 int major_op, erb, evb;
546 Bool rv;
547
548 rv = XQueryExtension(dpy, GLX_EXTENSION_NAME, &major_op, &evb, &erb);
549 if (rv) {
550 if (errorBase)
551 *errorBase = erb;
552 if (eventBase)
553 *eventBase = evb;
554 }
555 return rv;
556 }
557
558 /*
559 ** Put a barrier in the token stream that forces the GL to finish its
560 ** work before X can proceed.
561 */
562 _GLX_PUBLIC void
563 glXWaitGL(void)
564 {
565 struct glx_context *gc = __glXGetCurrentContext();
566
567 if (gc->vtable->wait_gl)
568 gc->vtable->wait_gl(gc);
569 }
570
571 /*
572 ** Put a barrier in the token stream that forces X to finish its
573 ** work before GL can proceed.
574 */
575 _GLX_PUBLIC void
576 glXWaitX(void)
577 {
578 struct glx_context *gc = __glXGetCurrentContext();
579
580 if (gc->vtable->wait_x)
581 gc->vtable->wait_x(gc);
582 }
583
584 _GLX_PUBLIC void
585 glXUseXFont(Font font, int first, int count, int listBase)
586 {
587 struct glx_context *gc = __glXGetCurrentContext();
588
589 if (gc->vtable->use_x_font)
590 gc->vtable->use_x_font(gc, font, first, count, listBase);
591 }
592
593 /************************************************************************/
594
595 /*
596 ** Copy the source context to the destination context using the
597 ** attribute "mask".
598 */
599 _GLX_PUBLIC void
600 glXCopyContext(Display * dpy, GLXContext source_user,
601 GLXContext dest_user, unsigned long mask)
602 {
603 struct glx_context *source = (struct glx_context *) source_user;
604 struct glx_context *dest = (struct glx_context *) dest_user;
605 #ifdef GLX_USE_APPLEGL
606 struct glx_context *gc = __glXGetCurrentContext();
607 int errorcode;
608 bool x11error;
609
610 if(apple_glx_copy_context(gc->driContext, source->driContext, dest->driContext,
611 mask, &errorcode, &x11error)) {
612 __glXSendError(dpy, errorcode, 0, X_GLXCopyContext, x11error);
613 }
614
615 #else
616 xGLXCopyContextReq *req;
617 struct glx_context *gc = __glXGetCurrentContext();
618 GLXContextTag tag;
619 CARD8 opcode;
620
621 opcode = __glXSetupForCommand(dpy);
622 if (!opcode) {
623 return;
624 }
625
626 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
627 if (gc->isDirect) {
628 /* NOT_DONE: This does not work yet */
629 }
630 #endif
631
632 /*
633 ** If the source is the current context, send its tag so that the context
634 ** can be flushed before the copy.
635 */
636 if (source == gc && dpy == gc->currentDpy) {
637 tag = gc->currentContextTag;
638 }
639 else {
640 tag = 0;
641 }
642
643 /* Send the glXCopyContext request */
644 LockDisplay(dpy);
645 GetReq(GLXCopyContext, req);
646 req->reqType = opcode;
647 req->glxCode = X_GLXCopyContext;
648 req->source = source ? source->xid : None;
649 req->dest = dest ? dest->xid : None;
650 req->mask = mask;
651 req->contextTag = tag;
652 UnlockDisplay(dpy);
653 SyncHandle();
654 #endif /* GLX_USE_APPLEGL */
655 }
656
657
658 /**
659 * \todo
660 * Shouldn't this function \b always return \c False when
661 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
662 * the GLX protocol here at all?
663 */
664 _GLX_PUBLIC Bool
665 glXIsDirect(Display * dpy, GLXContext gc_user)
666 {
667 struct glx_context *gc = (struct glx_context *) gc_user;
668
669 if (!gc) {
670 return False;
671 }
672 else if (gc->isDirect) {
673 return True;
674 }
675 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
676 return False;
677 #else
678 return __glXIsDirect(dpy, gc->xid, NULL);
679 #endif
680 }
681
682 _GLX_PUBLIC GLXPixmap
683 glXCreateGLXPixmap(Display * dpy, XVisualInfo * vis, Pixmap pixmap)
684 {
685 #ifdef GLX_USE_APPLEGL
686 int screen = vis->screen;
687 struct glx_screen *const psc = GetGLXScreenConfigs(dpy, screen);
688 const struct glx_config *config;
689
690 config = glx_config_find_visual(psc->visuals, vis->visualid);
691
692 if(apple_glx_pixmap_create(dpy, vis->screen, pixmap, config))
693 return None;
694
695 return pixmap;
696 #else
697 xGLXCreateGLXPixmapReq *req;
698 struct glx_drawable *glxDraw;
699 GLXPixmap xid;
700 CARD8 opcode;
701
702 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
703 struct glx_display *const priv = __glXInitialize(dpy);
704
705 if (priv == NULL)
706 return None;
707 #endif
708
709 opcode = __glXSetupForCommand(dpy);
710 if (!opcode) {
711 return None;
712 }
713
714 glxDraw = malloc(sizeof(*glxDraw));
715 if (!glxDraw)
716 return None;
717
718 /* Send the glXCreateGLXPixmap request */
719 LockDisplay(dpy);
720 GetReq(GLXCreateGLXPixmap, req);
721 req->reqType = opcode;
722 req->glxCode = X_GLXCreateGLXPixmap;
723 req->screen = vis->screen;
724 req->visual = vis->visualid;
725 req->pixmap = pixmap;
726 req->glxpixmap = xid = XAllocID(dpy);
727 UnlockDisplay(dpy);
728 SyncHandle();
729
730 if (InitGLXDrawable(dpy, glxDraw, pixmap, req->glxpixmap)) {
731 free(glxDraw);
732 return None;
733 }
734
735 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
736 do {
737 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
738 * is actually bound to a context... */
739
740 __GLXDRIdrawable *pdraw;
741 struct glx_screen *psc;
742 struct glx_config *config;
743
744 psc = priv->screens[vis->screen];
745 if (psc->driScreen == NULL)
746 return xid;
747
748 config = glx_config_find_visual(psc->visuals, vis->visualid);
749 pdraw = psc->driScreen->createDrawable(psc, pixmap, xid, config);
750 if (pdraw == NULL) {
751 fprintf(stderr, "failed to create pixmap\n");
752 xid = None;
753 break;
754 }
755
756 if (__glxHashInsert(priv->drawHash, xid, pdraw)) {
757 (*pdraw->destroyDrawable) (pdraw);
758 xid = None;
759 break;
760 }
761 } while (0);
762
763 if (xid == None) {
764 xGLXDestroyGLXPixmapReq *dreq;
765 LockDisplay(dpy);
766 GetReq(GLXDestroyGLXPixmap, dreq);
767 dreq->reqType = opcode;
768 dreq->glxCode = X_GLXDestroyGLXPixmap;
769 dreq->glxpixmap = xid;
770 UnlockDisplay(dpy);
771 SyncHandle();
772 }
773 #endif
774
775 return xid;
776 #endif
777 }
778
779 /*
780 ** Destroy the named pixmap
781 */
782 _GLX_PUBLIC void
783 glXDestroyGLXPixmap(Display * dpy, GLXPixmap glxpixmap)
784 {
785 #ifdef GLX_USE_APPLEGL
786 if(apple_glx_pixmap_destroy(dpy, glxpixmap))
787 __glXSendError(dpy, GLXBadPixmap, glxpixmap, X_GLXDestroyPixmap, false);
788 #else
789 xGLXDestroyGLXPixmapReq *req;
790 CARD8 opcode;
791
792 opcode = __glXSetupForCommand(dpy);
793 if (!opcode) {
794 return;
795 }
796
797 /* Send the glXDestroyGLXPixmap request */
798 LockDisplay(dpy);
799 GetReq(GLXDestroyGLXPixmap, req);
800 req->reqType = opcode;
801 req->glxCode = X_GLXDestroyGLXPixmap;
802 req->glxpixmap = glxpixmap;
803 UnlockDisplay(dpy);
804 SyncHandle();
805
806 DestroyGLXDrawable(dpy, glxpixmap);
807
808 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
809 {
810 struct glx_display *const priv = __glXInitialize(dpy);
811 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, glxpixmap);
812
813 if (priv != NULL && pdraw != NULL) {
814 (*pdraw->destroyDrawable) (pdraw);
815 __glxHashDelete(priv->drawHash, glxpixmap);
816 }
817 }
818 #endif
819 #endif /* GLX_USE_APPLEGL */
820 }
821
822 _GLX_PUBLIC void
823 glXSwapBuffers(Display * dpy, GLXDrawable drawable)
824 {
825 #ifdef GLX_USE_APPLEGL
826 struct glx_context * gc = __glXGetCurrentContext();
827 if(gc != &dummyContext && apple_glx_is_current_drawable(dpy, gc->driContext, drawable)) {
828 apple_glx_swap_buffers(gc->driContext);
829 } else {
830 __glXSendError(dpy, GLXBadCurrentWindow, 0, X_GLXSwapBuffers, false);
831 }
832 #else
833 struct glx_context *gc;
834 GLXContextTag tag;
835 CARD8 opcode;
836 xcb_connection_t *c;
837
838 gc = __glXGetCurrentContext();
839
840 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
841 {
842 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
843
844 if (pdraw != NULL) {
845 Bool flush = gc != &dummyContext && drawable == gc->currentDrawable;
846
847 pdraw->psc->driScreen->swapBuffers(pdraw, 0, 0, 0, flush);
848 return;
849 }
850 }
851 #endif
852
853 opcode = __glXSetupForCommand(dpy);
854 if (!opcode) {
855 return;
856 }
857
858 /*
859 ** The calling thread may or may not have a current context. If it
860 ** does, send the context tag so the server can do a flush.
861 */
862 if ((gc != &dummyContext) && (dpy == gc->currentDpy) &&
863 ((drawable == gc->currentDrawable)
864 || (drawable == gc->currentReadable))) {
865 tag = gc->currentContextTag;
866 }
867 else {
868 tag = 0;
869 }
870
871 c = XGetXCBConnection(dpy);
872 xcb_glx_swap_buffers(c, tag, drawable);
873 xcb_flush(c);
874 #endif /* GLX_USE_APPLEGL */
875 }
876
877
878 /*
879 ** Return configuration information for the given display, screen and
880 ** visual combination.
881 */
882 _GLX_PUBLIC int
883 glXGetConfig(Display * dpy, XVisualInfo * vis, int attribute,
884 int *value_return)
885 {
886 struct glx_display *priv;
887 struct glx_screen *psc;
888 struct glx_config *config;
889 int status;
890
891 status = GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc);
892 if (status == Success) {
893 config = glx_config_find_visual(psc->visuals, vis->visualid);
894
895 /* Lookup attribute after first finding a match on the visual */
896 if (config != NULL) {
897 return glx_config_get(config, attribute, value_return);
898 }
899
900 status = GLX_BAD_VISUAL;
901 }
902
903 /*
904 ** If we can't find the config for this visual, this visual is not
905 ** supported by the OpenGL implementation on the server.
906 */
907 if ((status == GLX_BAD_VISUAL) && (attribute == GLX_USE_GL)) {
908 *value_return = False;
909 status = Success;
910 }
911
912 return status;
913 }
914
915 /************************************************************************/
916
917 static void
918 init_fbconfig_for_chooser(struct glx_config * config,
919 GLboolean fbconfig_style_tags)
920 {
921 memset(config, 0, sizeof(struct glx_config));
922 config->visualID = (XID) GLX_DONT_CARE;
923 config->visualType = GLX_DONT_CARE;
924
925 /* glXChooseFBConfig specifies different defaults for these properties than
926 * glXChooseVisual.
927 */
928 if (fbconfig_style_tags) {
929 config->doubleBufferMode = GLX_DONT_CARE;
930 config->renderType = GLX_RGBA_BIT;
931 }
932
933 config->drawableType = GLX_WINDOW_BIT;
934 config->visualRating = GLX_DONT_CARE;
935 config->transparentPixel = GLX_NONE;
936 config->transparentRed = GLX_DONT_CARE;
937 config->transparentGreen = GLX_DONT_CARE;
938 config->transparentBlue = GLX_DONT_CARE;
939 config->transparentAlpha = GLX_DONT_CARE;
940 config->transparentIndex = GLX_DONT_CARE;
941
942 config->xRenderable = GLX_DONT_CARE;
943 config->fbconfigID = (GLXFBConfigID) (GLX_DONT_CARE);
944
945 config->swapMethod = GLX_DONT_CARE;
946 config->sRGBCapable = GLX_DONT_CARE;
947 }
948
949 #define MATCH_DONT_CARE( param ) \
950 do { \
951 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
952 && (a-> param != b-> param) ) { \
953 return False; \
954 } \
955 } while ( 0 )
956
957 #define MATCH_MINIMUM( param ) \
958 do { \
959 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
960 && (a-> param > b-> param) ) { \
961 return False; \
962 } \
963 } while ( 0 )
964
965 #define MATCH_EXACT( param ) \
966 do { \
967 if ( a-> param != b-> param) { \
968 return False; \
969 } \
970 } while ( 0 )
971
972 /* Test that all bits from a are contained in b */
973 #define MATCH_MASK(param) \
974 do { \
975 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
976 && ((a->param & ~b->param) != 0) ) { \
977 return False; \
978 } \
979 } while (0);
980
981 /**
982 * Determine if two GLXFBConfigs are compatible.
983 *
984 * \param a Application specified config to test.
985 * \param b Server specified config to test against \c a.
986 */
987 static Bool
988 fbconfigs_compatible(const struct glx_config * const a,
989 const struct glx_config * const b)
990 {
991 MATCH_DONT_CARE(doubleBufferMode);
992 MATCH_DONT_CARE(visualType);
993 MATCH_DONT_CARE(visualRating);
994 MATCH_DONT_CARE(xRenderable);
995 MATCH_DONT_CARE(fbconfigID);
996 MATCH_DONT_CARE(swapMethod);
997
998 MATCH_MINIMUM(rgbBits);
999 MATCH_MINIMUM(numAuxBuffers);
1000 MATCH_MINIMUM(redBits);
1001 MATCH_MINIMUM(greenBits);
1002 MATCH_MINIMUM(blueBits);
1003 MATCH_MINIMUM(alphaBits);
1004 MATCH_MINIMUM(depthBits);
1005 MATCH_MINIMUM(stencilBits);
1006 MATCH_MINIMUM(accumRedBits);
1007 MATCH_MINIMUM(accumGreenBits);
1008 MATCH_MINIMUM(accumBlueBits);
1009 MATCH_MINIMUM(accumAlphaBits);
1010 MATCH_MINIMUM(sampleBuffers);
1011 MATCH_MINIMUM(maxPbufferWidth);
1012 MATCH_MINIMUM(maxPbufferHeight);
1013 MATCH_MINIMUM(maxPbufferPixels);
1014 MATCH_MINIMUM(samples);
1015
1016 MATCH_DONT_CARE(stereoMode);
1017 MATCH_EXACT(level);
1018
1019 MATCH_MASK(drawableType);
1020 MATCH_MASK(renderType);
1021 MATCH_DONT_CARE(sRGBCapable);
1022
1023 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1024 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1025 * Technically speaking, it is a bug in the DDX driver, but there is
1026 * enough of an installed base to work around the problem here. In any
1027 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1028 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1029 * 0 from the server to be a match to maintain backward compatibility with
1030 * the (broken) drivers.
1031 */
1032
1033 if (a->transparentPixel != (int) GLX_DONT_CARE && a->transparentPixel != 0) {
1034 if (a->transparentPixel == GLX_NONE) {
1035 if (b->transparentPixel != GLX_NONE && b->transparentPixel != 0)
1036 return False;
1037 }
1038 else {
1039 MATCH_EXACT(transparentPixel);
1040 }
1041
1042 switch (a->transparentPixel) {
1043 case GLX_TRANSPARENT_RGB:
1044 MATCH_DONT_CARE(transparentRed);
1045 MATCH_DONT_CARE(transparentGreen);
1046 MATCH_DONT_CARE(transparentBlue);
1047 MATCH_DONT_CARE(transparentAlpha);
1048 break;
1049
1050 case GLX_TRANSPARENT_INDEX:
1051 MATCH_DONT_CARE(transparentIndex);
1052 break;
1053
1054 default:
1055 break;
1056 }
1057 }
1058
1059 return True;
1060 }
1061
1062
1063 /* There's some trickly language in the GLX spec about how this is supposed
1064 * to work. Basically, if a given component size is either not specified
1065 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1066 * Well, that's really hard to do with the code as-is. This behavior is
1067 * closer to correct, but still not technically right.
1068 */
1069 #define PREFER_LARGER_OR_ZERO(comp) \
1070 do { \
1071 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1072 if ( ((*a)-> comp) == 0 ) { \
1073 return -1; \
1074 } \
1075 else if ( ((*b)-> comp) == 0 ) { \
1076 return 1; \
1077 } \
1078 else { \
1079 return ((*b)-> comp) - ((*a)-> comp) ; \
1080 } \
1081 } \
1082 } while( 0 )
1083
1084 #define PREFER_LARGER(comp) \
1085 do { \
1086 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1087 return ((*b)-> comp) - ((*a)-> comp) ; \
1088 } \
1089 } while( 0 )
1090
1091 #define PREFER_SMALLER(comp) \
1092 do { \
1093 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1094 return ((*a)-> comp) - ((*b)-> comp) ; \
1095 } \
1096 } while( 0 )
1097
1098 /**
1099 * Compare two GLXFBConfigs. This function is intended to be used as the
1100 * compare function passed in to qsort.
1101 *
1102 * \returns If \c a is a "better" config, according to the specification of
1103 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1104 * better, then a number greater than zero is return. If both are
1105 * equal, zero is returned.
1106 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1107 */
1108 static int
1109 fbconfig_compare(struct glx_config **a, struct glx_config **b)
1110 {
1111 /* The order of these comparisons must NOT change. It is defined by
1112 * the GLX 1.4 specification.
1113 */
1114
1115 PREFER_SMALLER(visualSelectGroup);
1116
1117 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1118 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1119 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1120 */
1121 PREFER_SMALLER(visualRating);
1122
1123 /* This isn't quite right. It is supposed to compare the sum of the
1124 * components the user specifically set minimums for.
1125 */
1126 PREFER_LARGER_OR_ZERO(redBits);
1127 PREFER_LARGER_OR_ZERO(greenBits);
1128 PREFER_LARGER_OR_ZERO(blueBits);
1129 PREFER_LARGER_OR_ZERO(alphaBits);
1130
1131 PREFER_SMALLER(rgbBits);
1132
1133 if (((*a)->doubleBufferMode != (*b)->doubleBufferMode)) {
1134 /* Prefer single-buffer.
1135 */
1136 return (!(*a)->doubleBufferMode) ? -1 : 1;
1137 }
1138
1139 PREFER_SMALLER(numAuxBuffers);
1140
1141 PREFER_SMALLER(sampleBuffers);
1142 PREFER_SMALLER(samples);
1143
1144 PREFER_LARGER_OR_ZERO(depthBits);
1145 PREFER_SMALLER(stencilBits);
1146
1147 /* This isn't quite right. It is supposed to compare the sum of the
1148 * components the user specifically set minimums for.
1149 */
1150 PREFER_LARGER_OR_ZERO(accumRedBits);
1151 PREFER_LARGER_OR_ZERO(accumGreenBits);
1152 PREFER_LARGER_OR_ZERO(accumBlueBits);
1153 PREFER_LARGER_OR_ZERO(accumAlphaBits);
1154
1155 PREFER_SMALLER(visualType);
1156
1157 /* None of the pbuffer or fbconfig specs say that this comparison needs
1158 * to happen at all, but it seems like it should.
1159 */
1160 PREFER_LARGER(maxPbufferWidth);
1161 PREFER_LARGER(maxPbufferHeight);
1162 PREFER_LARGER(maxPbufferPixels);
1163
1164 return 0;
1165 }
1166
1167
1168 /**
1169 * Selects and sorts a subset of the supplied configs based on the attributes.
1170 * This function forms to basis of \c glXChooseFBConfig and
1171 * \c glXChooseFBConfigSGIX.
1172 *
1173 * \param configs Array of pointers to possible configs. The elements of
1174 * this array that do not meet the criteria will be set to
1175 * NULL. The remaining elements will be sorted according to
1176 * the various visual / FBConfig selection rules.
1177 * \param num_configs Number of elements in the \c configs array.
1178 * \param attribList Attributes used select from \c configs. This array is
1179 * terminated by a \c None tag. The array is of the form
1180 * expected by \c glXChooseFBConfig (where every tag has a
1181 * value).
1182 * \returns The number of valid elements left in \c configs.
1183 *
1184 * \sa glXChooseFBConfig, glXChooseFBConfigSGIX
1185 */
1186 static int
1187 choose_fbconfig(struct glx_config ** configs, int num_configs,
1188 const int *attribList)
1189 {
1190 struct glx_config test_config;
1191 int base;
1192 int i;
1193
1194 /* This is a fairly direct implementation of the selection method
1195 * described by GLX_SGIX_fbconfig. Start by culling out all the
1196 * configs that are not compatible with the selected parameter
1197 * list.
1198 */
1199
1200 init_fbconfig_for_chooser(&test_config, GL_TRUE);
1201 __glXInitializeVisualConfigFromTags(&test_config, 512,
1202 (const INT32 *) attribList,
1203 GL_TRUE, GL_TRUE);
1204
1205 base = 0;
1206 for (i = 0; i < num_configs; i++) {
1207 if (fbconfigs_compatible(&test_config, configs[i])) {
1208 configs[base] = configs[i];
1209 base++;
1210 }
1211 }
1212
1213 if (base == 0) {
1214 return 0;
1215 }
1216
1217 if (base < num_configs) {
1218 (void) memset(&configs[base], 0, sizeof(void *) * (num_configs - base));
1219 }
1220
1221 /* After the incompatible configs are removed, the resulting
1222 * list is sorted according to the rules set out in the various
1223 * specifications.
1224 */
1225
1226 qsort(configs, base, sizeof(struct glx_config *),
1227 (int (*)(const void *, const void *)) fbconfig_compare);
1228 return base;
1229 }
1230
1231
1232
1233
1234 /*
1235 ** Return the visual that best matches the template. Return None if no
1236 ** visual matches the template.
1237 */
1238 _GLX_PUBLIC XVisualInfo *
1239 glXChooseVisual(Display * dpy, int screen, int *attribList)
1240 {
1241 XVisualInfo *visualList = NULL;
1242 struct glx_display *priv;
1243 struct glx_screen *psc;
1244 struct glx_config test_config;
1245 struct glx_config *config;
1246 struct glx_config *best_config = NULL;
1247
1248 /*
1249 ** Get a list of all visuals, return if list is empty
1250 */
1251 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1252 return None;
1253 }
1254
1255
1256 /*
1257 ** Build a template from the defaults and the attribute list
1258 ** Free visual list and return if an unexpected token is encountered
1259 */
1260 init_fbconfig_for_chooser(&test_config, GL_FALSE);
1261 __glXInitializeVisualConfigFromTags(&test_config, 512,
1262 (const INT32 *) attribList,
1263 GL_TRUE, GL_FALSE);
1264
1265 /*
1266 ** Eliminate visuals that don't meet minimum requirements
1267 ** Compute a score for those that do
1268 ** Remember which visual, if any, got the highest score
1269 ** If no visual is acceptable, return None
1270 ** Otherwise, create an XVisualInfo list with just the selected X visual
1271 ** and return this.
1272 */
1273 for (config = psc->visuals; config != NULL; config = config->next) {
1274 if (fbconfigs_compatible(&test_config, config)
1275 && ((best_config == NULL) ||
1276 (fbconfig_compare (&config, &best_config) < 0))) {
1277 XVisualInfo visualTemplate;
1278 XVisualInfo *newList;
1279 int i;
1280
1281 visualTemplate.screen = screen;
1282 visualTemplate.visualid = config->visualID;
1283 newList = XGetVisualInfo(dpy, VisualScreenMask | VisualIDMask,
1284 &visualTemplate, &i);
1285
1286 if (newList) {
1287 free(visualList);
1288 visualList = newList;
1289 best_config = config;
1290 }
1291 }
1292 }
1293
1294 #ifdef GLX_USE_APPLEGL
1295 if(visualList && env_var_as_boolean("LIBGL_DUMP_VISUALID", false)) {
1296 printf("visualid 0x%lx\n", visualList[0].visualid);
1297 }
1298 #endif
1299
1300 return visualList;
1301 }
1302
1303
1304 _GLX_PUBLIC const char *
1305 glXQueryExtensionsString(Display * dpy, int screen)
1306 {
1307 struct glx_screen *psc;
1308 struct glx_display *priv;
1309
1310 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1311 return NULL;
1312 }
1313
1314 if (!psc->effectiveGLXexts) {
1315 if (!psc->serverGLXexts) {
1316 psc->serverGLXexts =
1317 __glXQueryServerString(dpy, priv->majorOpcode, screen,
1318 GLX_EXTENSIONS);
1319 }
1320
1321 __glXCalculateUsableExtensions(psc,
1322 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1323 (psc->driScreen != NULL),
1324 #else
1325 GL_FALSE,
1326 #endif
1327 priv->minorVersion);
1328 }
1329
1330 return psc->effectiveGLXexts;
1331 }
1332
1333 _GLX_PUBLIC const char *
1334 glXGetClientString(Display * dpy, int name)
1335 {
1336 (void) dpy;
1337
1338 switch (name) {
1339 case GLX_VENDOR:
1340 return (__glXGLXClientVendorName);
1341 case GLX_VERSION:
1342 return (__glXGLXClientVersion);
1343 case GLX_EXTENSIONS:
1344 return (__glXGetClientExtensions());
1345 default:
1346 return NULL;
1347 }
1348 }
1349
1350 _GLX_PUBLIC const char *
1351 glXQueryServerString(Display * dpy, int screen, int name)
1352 {
1353 struct glx_screen *psc;
1354 struct glx_display *priv;
1355 const char **str;
1356
1357
1358 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1359 return NULL;
1360 }
1361
1362 switch (name) {
1363 case GLX_VENDOR:
1364 str = &priv->serverGLXvendor;
1365 break;
1366 case GLX_VERSION:
1367 str = &priv->serverGLXversion;
1368 break;
1369 case GLX_EXTENSIONS:
1370 str = &psc->serverGLXexts;
1371 break;
1372 default:
1373 return NULL;
1374 }
1375
1376 if (*str == NULL) {
1377 *str = __glXQueryServerString(dpy, priv->majorOpcode, screen, name);
1378 }
1379
1380 return *str;
1381 }
1382
1383
1384 /*
1385 ** EXT_import_context
1386 */
1387
1388 _GLX_PUBLIC Display *
1389 glXGetCurrentDisplay(void)
1390 {
1391 struct glx_context *gc = __glXGetCurrentContext();
1392 if (gc == &dummyContext)
1393 return NULL;
1394 return gc->currentDpy;
1395 }
1396
1397 _GLX_PUBLIC
1398 GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (),
1399 glXGetCurrentDisplay)
1400
1401 #ifndef GLX_USE_APPLEGL
1402 _GLX_PUBLIC GLXContext
1403 glXImportContextEXT(Display *dpy, GLXContextID contextID)
1404 {
1405 struct glx_display *priv = __glXInitialize(dpy);
1406 struct glx_screen *psc = NULL;
1407 xGLXQueryContextReply reply;
1408 CARD8 opcode;
1409 struct glx_context *ctx;
1410 int i, renderType = GLX_RGBA_TYPE; /* By default, assume RGBA context */
1411 XID share = None;
1412 struct glx_config *mode = NULL;
1413 uint32_t fbconfigID = 0;
1414 uint32_t visualID = 0;
1415 uint32_t screen = 0;
1416 Bool got_screen = False;
1417
1418 if (priv == NULL)
1419 return NULL;
1420
1421 /* The GLX_EXT_import_context spec says:
1422 *
1423 * "If <contextID> does not refer to a valid context, then a BadContext
1424 * error is generated; if <contextID> refers to direct rendering
1425 * context then no error is generated but glXImportContextEXT returns
1426 * NULL."
1427 *
1428 * If contextID is None, generate BadContext on the client-side. Other
1429 * sorts of invalid contexts will be detected by the server in the
1430 * __glXIsDirect call.
1431 */
1432 if (contextID == None) {
1433 __glXSendError(dpy, GLXBadContext, contextID, X_GLXIsDirect, false);
1434 return NULL;
1435 }
1436
1437 if (__glXIsDirect(dpy, contextID, NULL))
1438 return NULL;
1439
1440 opcode = __glXSetupForCommand(dpy);
1441 if (!opcode)
1442 return 0;
1443
1444 /* Send the glXQueryContextInfoEXT request */
1445 LockDisplay(dpy);
1446
1447 if (priv->majorVersion > 1 || priv->minorVersion >= 3) {
1448 xGLXQueryContextReq *req;
1449
1450 GetReq(GLXQueryContext, req);
1451
1452 req->reqType = opcode;
1453 req->glxCode = X_GLXQueryContext;
1454 req->context = contextID;
1455 }
1456 else {
1457 xGLXVendorPrivateReq *vpreq;
1458 xGLXQueryContextInfoEXTReq *req;
1459
1460 GetReqExtra(GLXVendorPrivate,
1461 sz_xGLXQueryContextInfoEXTReq - sz_xGLXVendorPrivateReq,
1462 vpreq);
1463 req = (xGLXQueryContextInfoEXTReq *) vpreq;
1464 req->reqType = opcode;
1465 req->glxCode = X_GLXVendorPrivateWithReply;
1466 req->vendorCode = X_GLXvop_QueryContextInfoEXT;
1467 req->context = contextID;
1468 }
1469
1470 if (_XReply(dpy, (xReply *) & reply, 0, False) &&
1471 reply.n < (INT32_MAX / 2)) {
1472
1473 for (i = 0; i < reply.n; i++) {
1474 int prop[2];
1475
1476 _XRead(dpy, (char *)prop, sizeof(prop));
1477 switch (prop[0]) {
1478 case GLX_SCREEN:
1479 screen = prop[1];
1480 got_screen = True;
1481 break;
1482 case GLX_SHARE_CONTEXT_EXT:
1483 share = prop[1];
1484 break;
1485 case GLX_VISUAL_ID_EXT:
1486 visualID = prop[1];
1487 break;
1488 case GLX_FBCONFIG_ID:
1489 fbconfigID = prop[1];
1490 break;
1491 case GLX_RENDER_TYPE:
1492 renderType = prop[1];
1493 break;
1494 }
1495 }
1496 }
1497 UnlockDisplay(dpy);
1498 SyncHandle();
1499
1500 if (!got_screen)
1501 return NULL;
1502
1503 psc = GetGLXScreenConfigs(dpy, screen);
1504 if (psc == NULL)
1505 return NULL;
1506
1507 if (fbconfigID != 0) {
1508 mode = glx_config_find_fbconfig(psc->configs, fbconfigID);
1509 } else if (visualID != 0) {
1510 mode = glx_config_find_visual(psc->visuals, visualID);
1511 }
1512
1513 if (mode == NULL)
1514 return NULL;
1515
1516 ctx = indirect_create_context(psc, mode, NULL, renderType);
1517 if (ctx == NULL)
1518 return NULL;
1519
1520 ctx->xid = contextID;
1521 ctx->imported = GL_TRUE;
1522 ctx->share_xid = share;
1523
1524 return (GLXContext) ctx;
1525 }
1526
1527 #endif
1528
1529 _GLX_PUBLIC int
1530 glXQueryContext(Display * dpy, GLXContext ctx_user, int attribute, int *value)
1531 {
1532 struct glx_context *ctx = (struct glx_context *) ctx_user;
1533
1534 switch (attribute) {
1535 case GLX_SHARE_CONTEXT_EXT:
1536 *value = ctx->share_xid;
1537 break;
1538 case GLX_VISUAL_ID_EXT:
1539 *value = ctx->config ? ctx->config->visualID : None;
1540 break;
1541 case GLX_SCREEN:
1542 *value = ctx->screen;
1543 break;
1544 case GLX_FBCONFIG_ID:
1545 *value = ctx->config ? ctx->config->fbconfigID : None;
1546 break;
1547 case GLX_RENDER_TYPE:
1548 *value = ctx->renderType;
1549 break;
1550 default:
1551 return GLX_BAD_ATTRIBUTE;
1552 }
1553 return Success;
1554 }
1555
1556 _GLX_PUBLIC
1557 GLX_ALIAS(int, glXQueryContextInfoEXT,
1558 (Display * dpy, GLXContext ctx, int attribute, int *value),
1559 (dpy, ctx, attribute, value), glXQueryContext)
1560
1561 _GLX_PUBLIC GLXContextID glXGetContextIDEXT(const GLXContext ctx_user)
1562 {
1563 struct glx_context *ctx = (struct glx_context *) ctx_user;
1564
1565 return (ctx == NULL) ? None : ctx->xid;
1566 }
1567
1568 _GLX_PUBLIC void
1569 glXFreeContextEXT(Display *dpy, GLXContext ctx)
1570 {
1571 struct glx_context *gc = (struct glx_context *) ctx;
1572
1573 if (gc == NULL || gc->xid == None)
1574 return;
1575
1576 /* The GLX_EXT_import_context spec says:
1577 *
1578 * "glXFreeContext does not free the server-side context information or
1579 * the XID associated with the server-side context."
1580 *
1581 * Don't send any protocol. Just destroy the client-side tracking of the
1582 * context. Also, only release the context structure if it's not current.
1583 */
1584 __glXLock();
1585 if (gc->currentDpy) {
1586 gc->xid = None;
1587 } else {
1588 gc->vtable->destroy(gc);
1589 }
1590 __glXUnlock();
1591 }
1592
1593 _GLX_PUBLIC GLXFBConfig *
1594 glXChooseFBConfig(Display * dpy, int screen,
1595 const int *attribList, int *nitems)
1596 {
1597 struct glx_config **config_list;
1598 int list_size;
1599
1600
1601 config_list = (struct glx_config **)
1602 glXGetFBConfigs(dpy, screen, &list_size);
1603
1604 if ((config_list != NULL) && (list_size > 0) && (attribList != NULL)) {
1605 list_size = choose_fbconfig(config_list, list_size, attribList);
1606 if (list_size == 0) {
1607 free(config_list);
1608 config_list = NULL;
1609 }
1610 }
1611
1612 *nitems = list_size;
1613 return (GLXFBConfig *) config_list;
1614 }
1615
1616
1617 _GLX_PUBLIC GLXContext
1618 glXCreateNewContext(Display * dpy, GLXFBConfig fbconfig,
1619 int renderType, GLXContext shareList, Bool allowDirect)
1620 {
1621 struct glx_config *config = (struct glx_config *) fbconfig;
1622 struct glx_config **config_list;
1623 int list_size;
1624 unsigned i;
1625
1626 if (!config) {
1627 __glXSendError(dpy, GLXBadFBConfig, 0, X_GLXCreateNewContext, false);
1628 return NULL;
1629 }
1630
1631 config_list = (struct glx_config **)
1632 glXGetFBConfigs(dpy, config->screen, &list_size);
1633
1634 for (i = 0; i < list_size; i++) {
1635 if (config_list[i] == config)
1636 break;
1637 }
1638 free(config_list);
1639
1640 if (i == list_size) {
1641 __glXSendError(dpy, GLXBadFBConfig, 0, X_GLXCreateNewContext, false);
1642 return NULL;
1643 }
1644
1645 return CreateContext(dpy, config->fbconfigID, config, shareList,
1646 allowDirect, X_GLXCreateNewContext, renderType,
1647 config->screen);
1648 }
1649
1650
1651 _GLX_PUBLIC GLXDrawable
1652 glXGetCurrentReadDrawable(void)
1653 {
1654 struct glx_context *gc = __glXGetCurrentContext();
1655
1656 return gc->currentReadable;
1657 }
1658
1659
1660 _GLX_PUBLIC GLXFBConfig *
1661 glXGetFBConfigs(Display * dpy, int screen, int *nelements)
1662 {
1663 struct glx_display *priv = __glXInitialize(dpy);
1664 struct glx_config **config_list = NULL;
1665 struct glx_config *config;
1666 unsigned num_configs = 0;
1667 int i;
1668
1669 *nelements = 0;
1670 if (priv && (priv->screens != NULL)
1671 && (screen >= 0) && (screen < ScreenCount(dpy))
1672 && (priv->screens[screen]->configs != NULL)
1673 && (priv->screens[screen]->configs->fbconfigID
1674 != (int) GLX_DONT_CARE)) {
1675
1676 for (config = priv->screens[screen]->configs; config != NULL;
1677 config = config->next) {
1678 if (config->fbconfigID != (int) GLX_DONT_CARE) {
1679 num_configs++;
1680 }
1681 }
1682
1683 config_list = malloc(num_configs * sizeof *config_list);
1684 if (config_list != NULL) {
1685 *nelements = num_configs;
1686 i = 0;
1687 for (config = priv->screens[screen]->configs; config != NULL;
1688 config = config->next) {
1689 if (config->fbconfigID != (int) GLX_DONT_CARE) {
1690 config_list[i] = config;
1691 i++;
1692 }
1693 }
1694 }
1695 }
1696
1697 return (GLXFBConfig *) config_list;
1698 }
1699
1700
1701 _GLX_PUBLIC int
1702 glXGetFBConfigAttrib(Display * dpy, GLXFBConfig fbconfig,
1703 int attribute, int *value)
1704 {
1705 struct glx_config *config = ValidateGLXFBConfig(dpy, fbconfig);
1706
1707 if (config == NULL)
1708 return GLXBadFBConfig;
1709
1710 return glx_config_get(config, attribute, value);
1711 }
1712
1713
1714 _GLX_PUBLIC XVisualInfo *
1715 glXGetVisualFromFBConfig(Display * dpy, GLXFBConfig fbconfig)
1716 {
1717 XVisualInfo visualTemplate;
1718 struct glx_config *config = (struct glx_config *) fbconfig;
1719 int count;
1720
1721 /*
1722 ** Get a list of all visuals, return if list is empty
1723 */
1724 visualTemplate.visualid = config->visualID;
1725 return XGetVisualInfo(dpy, VisualIDMask, &visualTemplate, &count);
1726 }
1727
1728 #ifndef GLX_USE_APPLEGL
1729 /*
1730 ** GLX_SGI_swap_control
1731 */
1732 static int
1733 __glXSwapIntervalSGI(int interval)
1734 {
1735 xGLXVendorPrivateReq *req;
1736 struct glx_context *gc = __glXGetCurrentContext();
1737 struct glx_screen *psc;
1738 Display *dpy;
1739 CARD32 *interval_ptr;
1740 CARD8 opcode;
1741
1742 if (gc == &dummyContext) {
1743 return GLX_BAD_CONTEXT;
1744 }
1745
1746 if (interval <= 0) {
1747 return GLX_BAD_VALUE;
1748 }
1749
1750 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
1751
1752 #ifdef GLX_DIRECT_RENDERING
1753 if (gc->isDirect && psc && psc->driScreen &&
1754 psc->driScreen->setSwapInterval) {
1755 __GLXDRIdrawable *pdraw =
1756 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
1757 /* Simply ignore the command if the GLX drawable has been destroyed but
1758 * the context is still bound.
1759 */
1760 if (pdraw)
1761 psc->driScreen->setSwapInterval(pdraw, interval);
1762 return 0;
1763 }
1764 #endif
1765
1766 dpy = gc->currentDpy;
1767 opcode = __glXSetupForCommand(dpy);
1768 if (!opcode) {
1769 return 0;
1770 }
1771
1772 /* Send the glXSwapIntervalSGI request */
1773 LockDisplay(dpy);
1774 GetReqExtra(GLXVendorPrivate, sizeof(CARD32), req);
1775 req->reqType = opcode;
1776 req->glxCode = X_GLXVendorPrivate;
1777 req->vendorCode = X_GLXvop_SwapIntervalSGI;
1778 req->contextTag = gc->currentContextTag;
1779
1780 interval_ptr = (CARD32 *) (req + 1);
1781 *interval_ptr = interval;
1782
1783 UnlockDisplay(dpy);
1784 SyncHandle();
1785 XFlush(dpy);
1786
1787 return 0;
1788 }
1789
1790
1791 /*
1792 ** GLX_MESA_swap_control
1793 */
1794 static int
1795 __glXSwapIntervalMESA(unsigned int interval)
1796 {
1797 #ifdef GLX_DIRECT_RENDERING
1798 struct glx_context *gc = __glXGetCurrentContext();
1799
1800 if (gc != &dummyContext && gc->isDirect) {
1801 struct glx_screen *psc;
1802
1803 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
1804 if (psc && psc->driScreen && psc->driScreen->setSwapInterval) {
1805 __GLXDRIdrawable *pdraw =
1806 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
1807
1808 /* Simply ignore the command if the GLX drawable has been destroyed but
1809 * the context is still bound.
1810 */
1811 if (!pdraw)
1812 return 0;
1813
1814 return psc->driScreen->setSwapInterval(pdraw, interval);
1815 }
1816 }
1817 #endif
1818
1819 return GLX_BAD_CONTEXT;
1820 }
1821
1822
1823 static int
1824 __glXGetSwapIntervalMESA(void)
1825 {
1826 #ifdef GLX_DIRECT_RENDERING
1827 struct glx_context *gc = __glXGetCurrentContext();
1828
1829 if (gc != &dummyContext && gc->isDirect) {
1830 struct glx_screen *psc;
1831
1832 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
1833 if (psc && psc->driScreen && psc->driScreen->getSwapInterval) {
1834 __GLXDRIdrawable *pdraw =
1835 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
1836 if (pdraw)
1837 return psc->driScreen->getSwapInterval(pdraw);
1838 }
1839 }
1840 #endif
1841
1842 return 0;
1843 }
1844
1845
1846 /*
1847 ** GLX_SGI_video_sync
1848 */
1849 static int
1850 __glXGetVideoSyncSGI(unsigned int *count)
1851 {
1852 int64_t ust, msc, sbc;
1853 int ret;
1854 struct glx_context *gc = __glXGetCurrentContext();
1855 struct glx_screen *psc;
1856 #ifdef GLX_DIRECT_RENDERING
1857 __GLXDRIdrawable *pdraw;
1858 #endif
1859
1860 if (gc == &dummyContext)
1861 return GLX_BAD_CONTEXT;
1862
1863 #ifdef GLX_DIRECT_RENDERING
1864 if (!gc->isDirect)
1865 return GLX_BAD_CONTEXT;
1866 #endif
1867
1868 psc = GetGLXScreenConfigs(gc->currentDpy, gc->screen);
1869 #ifdef GLX_DIRECT_RENDERING
1870 pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
1871 #endif
1872
1873 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1874 * FIXME: there should be a GLX encoding for this call. I can find no
1875 * FIXME: documentation for the GLX encoding.
1876 */
1877 #ifdef GLX_DIRECT_RENDERING
1878 if (psc && psc->driScreen && psc->driScreen->getDrawableMSC) {
1879 ret = psc->driScreen->getDrawableMSC(psc, pdraw, &ust, &msc, &sbc);
1880 *count = (unsigned) msc;
1881 return (ret == True) ? 0 : GLX_BAD_CONTEXT;
1882 }
1883 #endif
1884
1885 return GLX_BAD_CONTEXT;
1886 }
1887
1888 static int
1889 __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
1890 {
1891 struct glx_context *gc = __glXGetCurrentContext();
1892 struct glx_screen *psc;
1893 #ifdef GLX_DIRECT_RENDERING
1894 __GLXDRIdrawable *pdraw;
1895 #endif
1896 int64_t ust, msc, sbc;
1897 int ret;
1898
1899 if (divisor <= 0 || remainder < 0)
1900 return GLX_BAD_VALUE;
1901
1902 if (gc == &dummyContext)
1903 return GLX_BAD_CONTEXT;
1904
1905 #ifdef GLX_DIRECT_RENDERING
1906 if (!gc->isDirect)
1907 return GLX_BAD_CONTEXT;
1908 #endif
1909
1910 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
1911 #ifdef GLX_DIRECT_RENDERING
1912 pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
1913 #endif
1914
1915 #ifdef GLX_DIRECT_RENDERING
1916 if (psc && psc->driScreen && psc->driScreen->waitForMSC) {
1917 ret = psc->driScreen->waitForMSC(pdraw, 0, divisor, remainder, &ust, &msc,
1918 &sbc);
1919 *count = (unsigned) msc;
1920 return (ret == True) ? 0 : GLX_BAD_CONTEXT;
1921 }
1922 #endif
1923
1924 return GLX_BAD_CONTEXT;
1925 }
1926
1927 #endif /* GLX_USE_APPLEGL */
1928
1929 /*
1930 ** GLX_SGIX_fbconfig
1931 ** Many of these functions are aliased to GLX 1.3 entry points in the
1932 ** GLX_functions table.
1933 */
1934
1935 _GLX_PUBLIC
1936 GLX_ALIAS(int, glXGetFBConfigAttribSGIX,
1937 (Display * dpy, GLXFBConfigSGIX config, int attribute, int *value),
1938 (dpy, config, attribute, value), glXGetFBConfigAttrib)
1939
1940 _GLX_PUBLIC GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX,
1941 (Display * dpy, int screen, int *attrib_list,
1942 int *nelements), (dpy, screen, attrib_list, nelements),
1943 glXChooseFBConfig)
1944
1945 _GLX_PUBLIC GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX,
1946 (Display * dpy, GLXFBConfigSGIX config),
1947 (dpy, config), glXGetVisualFromFBConfig)
1948
1949 _GLX_PUBLIC GLXPixmap
1950 glXCreateGLXPixmapWithConfigSGIX(Display * dpy,
1951 GLXFBConfigSGIX fbconfig,
1952 Pixmap pixmap)
1953 {
1954 #ifndef GLX_USE_APPLEGL
1955 xGLXVendorPrivateWithReplyReq *vpreq;
1956 xGLXCreateGLXPixmapWithConfigSGIXReq *req;
1957 GLXPixmap xid = None;
1958 CARD8 opcode;
1959 struct glx_screen *psc;
1960 #endif
1961 struct glx_config *config = (struct glx_config *) fbconfig;
1962
1963
1964 if ((dpy == NULL) || (config == NULL)) {
1965 return None;
1966 }
1967 #ifdef GLX_USE_APPLEGL
1968 if(apple_glx_pixmap_create(dpy, config->screen, pixmap, config))
1969 return None;
1970 return pixmap;
1971 #else
1972
1973 psc = GetGLXScreenConfigs(dpy, config->screen);
1974 if ((psc != NULL)
1975 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) {
1976 opcode = __glXSetupForCommand(dpy);
1977 if (!opcode) {
1978 return None;
1979 }
1980
1981 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
1982 LockDisplay(dpy);
1983 GetReqExtra(GLXVendorPrivateWithReply,
1984 sz_xGLXCreateGLXPixmapWithConfigSGIXReq -
1985 sz_xGLXVendorPrivateWithReplyReq, vpreq);
1986 req = (xGLXCreateGLXPixmapWithConfigSGIXReq *) vpreq;
1987 req->reqType = opcode;
1988 req->glxCode = X_GLXVendorPrivateWithReply;
1989 req->vendorCode = X_GLXvop_CreateGLXPixmapWithConfigSGIX;
1990 req->screen = config->screen;
1991 req->fbconfig = config->fbconfigID;
1992 req->pixmap = pixmap;
1993 req->glxpixmap = xid = XAllocID(dpy);
1994 UnlockDisplay(dpy);
1995 SyncHandle();
1996 }
1997
1998 return xid;
1999 #endif
2000 }
2001
2002 _GLX_PUBLIC GLXContext
2003 glXCreateContextWithConfigSGIX(Display * dpy,
2004 GLXFBConfigSGIX fbconfig, int renderType,
2005 GLXContext shareList, Bool allowDirect)
2006 {
2007 GLXContext gc = NULL;
2008 struct glx_config *config = (struct glx_config *) fbconfig;
2009 struct glx_screen *psc;
2010
2011
2012 if ((dpy == NULL) || (config == NULL)) {
2013 return None;
2014 }
2015
2016 psc = GetGLXScreenConfigs(dpy, config->screen);
2017 if ((psc != NULL)
2018 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) {
2019 gc = CreateContext(dpy, config->fbconfigID, config, shareList,
2020 allowDirect,
2021 X_GLXvop_CreateContextWithConfigSGIX, renderType,
2022 config->screen);
2023 }
2024
2025 return gc;
2026 }
2027
2028
2029 _GLX_PUBLIC GLXFBConfigSGIX
2030 glXGetFBConfigFromVisualSGIX(Display * dpy, XVisualInfo * vis)
2031 {
2032 struct glx_display *priv;
2033 struct glx_screen *psc = NULL;
2034
2035 if ((GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc) == Success)
2036 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)
2037 && (psc->configs->fbconfigID != (int) GLX_DONT_CARE)) {
2038 return (GLXFBConfigSGIX) glx_config_find_visual(psc->configs,
2039 vis->visualid);
2040 }
2041
2042 return NULL;
2043 }
2044
2045 #ifndef GLX_USE_APPLEGL
2046 /*
2047 ** GLX_OML_sync_control
2048 */
2049 static Bool
2050 __glXGetSyncValuesOML(Display * dpy, GLXDrawable drawable,
2051 int64_t * ust, int64_t * msc, int64_t * sbc)
2052 {
2053 struct glx_display * const priv = __glXInitialize(dpy);
2054 int ret;
2055 #ifdef GLX_DIRECT_RENDERING
2056 __GLXDRIdrawable *pdraw;
2057 #endif
2058 struct glx_screen *psc;
2059
2060 if (!priv)
2061 return False;
2062
2063 #ifdef GLX_DIRECT_RENDERING
2064 pdraw = GetGLXDRIDrawable(dpy, drawable);
2065 psc = pdraw ? pdraw->psc : NULL;
2066 if (pdraw && psc->driScreen->getDrawableMSC) {
2067 ret = psc->driScreen->getDrawableMSC(psc, pdraw, ust, msc, sbc);
2068 return ret;
2069 }
2070 #endif
2071
2072 return False;
2073 }
2074
2075 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2076 _X_HIDDEN GLboolean
2077 __glxGetMscRate(struct glx_screen *psc,
2078 int32_t * numerator, int32_t * denominator)
2079 {
2080 #if !defined(GLX_USE_WINDOWSGL)
2081 XF86VidModeModeLine mode_line;
2082 int dot_clock;
2083 int i;
2084
2085 if (XF86VidModeQueryVersion(psc->dpy, &i, &i) &&
2086 XF86VidModeGetModeLine(psc->dpy, psc->scr, &dot_clock, &mode_line)) {
2087 unsigned n = dot_clock * 1000;
2088 unsigned d = mode_line.vtotal * mode_line.htotal;
2089
2090 # define V_INTERLACE 0x010
2091 # define V_DBLSCAN 0x020
2092
2093 if (mode_line.flags & V_INTERLACE)
2094 n *= 2;
2095 else if (mode_line.flags & V_DBLSCAN)
2096 d *= 2;
2097
2098 /* The OML_sync_control spec requires that if the refresh rate is a
2099 * whole number, that the returned numerator be equal to the refresh
2100 * rate and the denominator be 1.
2101 */
2102
2103 if (n % d == 0) {
2104 n /= d;
2105 d = 1;
2106 }
2107 else {
2108 static const unsigned f[] = { 13, 11, 7, 5, 3, 2, 0 };
2109
2110 /* This is a poor man's way to reduce a fraction. It's far from
2111 * perfect, but it will work well enough for this situation.
2112 */
2113
2114 for (i = 0; f[i] != 0; i++) {
2115 while (n % f[i] == 0 && d % f[i] == 0) {
2116 d /= f[i];
2117 n /= f[i];
2118 }
2119 }
2120 }
2121
2122 *numerator = n;
2123 *denominator = d;
2124
2125 return True;
2126 }
2127 #endif
2128
2129 return False;
2130 }
2131 #endif
2132
2133 /**
2134 * Determine the refresh rate of the specified drawable and display.
2135 *
2136 * \param dpy Display whose refresh rate is to be determined.
2137 * \param drawable Drawable whose refresh rate is to be determined.
2138 * \param numerator Numerator of the refresh rate.
2139 * \param demoninator Denominator of the refresh rate.
2140 * \return If the refresh rate for the specified display and drawable could
2141 * be calculated, True is returned. Otherwise False is returned.
2142 *
2143 * \note This function is implemented entirely client-side. A lot of other
2144 * functionality is required to export GLX_OML_sync_control, so on
2145 * XFree86 this function can be called for direct-rendering contexts
2146 * when GLX_OML_sync_control appears in the client extension string.
2147 */
2148
2149 _X_HIDDEN GLboolean
2150 __glXGetMscRateOML(Display * dpy, GLXDrawable drawable,
2151 int32_t * numerator, int32_t * denominator)
2152 {
2153 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) && !defined(GLX_USE_WINDOWSGL)
2154 __GLXDRIdrawable *draw = GetGLXDRIDrawable(dpy, drawable);
2155
2156 if (draw == NULL)
2157 return False;
2158
2159 return __glxGetMscRate(draw->psc, numerator, denominator);
2160 #else
2161 (void) dpy;
2162 (void) drawable;
2163 (void) numerator;
2164 (void) denominator;
2165 #endif
2166 return False;
2167 }
2168
2169
2170 static int64_t
2171 __glXSwapBuffersMscOML(Display * dpy, GLXDrawable drawable,
2172 int64_t target_msc, int64_t divisor, int64_t remainder)
2173 {
2174 struct glx_context *gc = __glXGetCurrentContext();
2175 #ifdef GLX_DIRECT_RENDERING
2176 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2177 struct glx_screen *psc = pdraw ? pdraw->psc : NULL;
2178 #endif
2179
2180 if (gc == &dummyContext) /* no GLX for this */
2181 return -1;
2182
2183 #ifdef GLX_DIRECT_RENDERING
2184 if (!pdraw || !gc->isDirect)
2185 return -1;
2186 #endif
2187
2188 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2189 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2190 * of -1 if the function failed because of errors detected in the input
2191 * parameters"
2192 */
2193 if (divisor < 0 || remainder < 0 || target_msc < 0)
2194 return -1;
2195 if (divisor > 0 && remainder >= divisor)
2196 return -1;
2197
2198 if (target_msc == 0 && divisor == 0 && remainder == 0)
2199 remainder = 1;
2200
2201 #ifdef GLX_DIRECT_RENDERING
2202 if (psc->driScreen && psc->driScreen->swapBuffers)
2203 return (*psc->driScreen->swapBuffers)(pdraw, target_msc, divisor,
2204 remainder, False);
2205 #endif
2206
2207 return -1;
2208 }
2209
2210
2211 static Bool
2212 __glXWaitForMscOML(Display * dpy, GLXDrawable drawable,
2213 int64_t target_msc, int64_t divisor,
2214 int64_t remainder, int64_t * ust,
2215 int64_t * msc, int64_t * sbc)
2216 {
2217 #ifdef GLX_DIRECT_RENDERING
2218 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2219 struct glx_screen *psc = pdraw ? pdraw->psc : NULL;
2220 int ret;
2221 #endif
2222
2223
2224 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2225 * error", but the return type in the spec is Bool.
2226 */
2227 if (divisor < 0 || remainder < 0 || target_msc < 0)
2228 return False;
2229 if (divisor > 0 && remainder >= divisor)
2230 return False;
2231
2232 #ifdef GLX_DIRECT_RENDERING
2233 if (pdraw && psc->driScreen && psc->driScreen->waitForMSC) {
2234 ret = psc->driScreen->waitForMSC(pdraw, target_msc, divisor, remainder,
2235 ust, msc, sbc);
2236 return ret;
2237 }
2238 #endif
2239
2240 return False;
2241 }
2242
2243
2244 static Bool
2245 __glXWaitForSbcOML(Display * dpy, GLXDrawable drawable,
2246 int64_t target_sbc, int64_t * ust,
2247 int64_t * msc, int64_t * sbc)
2248 {
2249 #ifdef GLX_DIRECT_RENDERING
2250 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2251 struct glx_screen *psc = pdraw ? pdraw->psc : NULL;
2252 int ret;
2253 #endif
2254
2255 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2256 * error", but the return type in the spec is Bool.
2257 */
2258 if (target_sbc < 0)
2259 return False;
2260
2261 #ifdef GLX_DIRECT_RENDERING
2262 if (pdraw && psc->driScreen && psc->driScreen->waitForSBC) {
2263 ret = psc->driScreen->waitForSBC(pdraw, target_sbc, ust, msc, sbc);
2264 return ret;
2265 }
2266 #endif
2267
2268 return False;
2269 }
2270
2271 /*@}*/
2272
2273
2274 /**
2275 * Mesa extension stubs. These will help reduce portability problems.
2276 */
2277 /*@{*/
2278
2279 /**
2280 * Release all buffers associated with the specified GLX drawable.
2281 *
2282 * \todo
2283 * This function was intended for stand-alone Mesa. The issue there is that
2284 * the library doesn't get any notification when a window is closed. In
2285 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2286 * supported, there are 3 different functions to destroy a drawable. It
2287 * should be possible to create GLX protocol (or have it determine which
2288 * protocol to use based on the type of the drawable) to have one function
2289 * do the work of 3. For the direct-rendering case, this function could
2290 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2291 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2292 * would need to be used. This really should be done as part of the new DRI
2293 * interface work.
2294 *
2295 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2296 * __driGarbageCollectDrawables
2297 * glXDestroyGLXPixmap
2298 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2299 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2300 */
2301 static Bool
2302 __glXReleaseBuffersMESA(Display * dpy, GLXDrawable d)
2303 {
2304 (void) dpy;
2305 (void) d;
2306 return False;
2307 }
2308
2309
2310 _GLX_PUBLIC GLXPixmap
2311 glXCreateGLXPixmapMESA(Display * dpy, XVisualInfo * visual,
2312 Pixmap pixmap, Colormap cmap)
2313 {
2314 (void) dpy;
2315 (void) visual;
2316 (void) pixmap;
2317 (void) cmap;
2318 return 0;
2319 }
2320
2321 /*@}*/
2322
2323
2324 /**
2325 * GLX_MESA_copy_sub_buffer
2326 */
2327 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2328 static void
2329 __glXCopySubBufferMESA(Display * dpy, GLXDrawable drawable,
2330 int x, int y, int width, int height)
2331 {
2332 xGLXVendorPrivateReq *req;
2333 struct glx_context *gc;
2334 GLXContextTag tag;
2335 CARD32 *drawable_ptr;
2336 INT32 *x_ptr, *y_ptr, *w_ptr, *h_ptr;
2337 CARD8 opcode;
2338
2339 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2340 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2341 if (pdraw != NULL) {
2342 struct glx_screen *psc = pdraw->psc;
2343 if (psc->driScreen->copySubBuffer != NULL) {
2344 (*psc->driScreen->copySubBuffer) (pdraw, x, y, width, height, True);
2345 }
2346
2347 return;
2348 }
2349 #endif
2350
2351 opcode = __glXSetupForCommand(dpy);
2352 if (!opcode)
2353 return;
2354
2355 /*
2356 ** The calling thread may or may not have a current context. If it
2357 ** does, send the context tag so the server can do a flush.
2358 */
2359 gc = __glXGetCurrentContext();
2360 if ((gc != &dummyContext) && (dpy == gc->currentDpy) &&
2361 ((drawable == gc->currentDrawable) ||
2362 (drawable == gc->currentReadable))) {
2363 tag = gc->currentContextTag;
2364 }
2365 else {
2366 tag = 0;
2367 }
2368
2369 LockDisplay(dpy);
2370 GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32) * 4, req);
2371 req->reqType = opcode;
2372 req->glxCode = X_GLXVendorPrivate;
2373 req->vendorCode = X_GLXvop_CopySubBufferMESA;
2374 req->contextTag = tag;
2375
2376 drawable_ptr = (CARD32 *) (req + 1);
2377 x_ptr = (INT32 *) (drawable_ptr + 1);
2378 y_ptr = (INT32 *) (drawable_ptr + 2);
2379 w_ptr = (INT32 *) (drawable_ptr + 3);
2380 h_ptr = (INT32 *) (drawable_ptr + 4);
2381
2382 *drawable_ptr = drawable;
2383 *x_ptr = x;
2384 *y_ptr = y;
2385 *w_ptr = width;
2386 *h_ptr = height;
2387
2388 UnlockDisplay(dpy);
2389 SyncHandle();
2390 }
2391
2392 /*@{*/
2393 static void
2394 __glXBindTexImageEXT(Display * dpy,
2395 GLXDrawable drawable, int buffer, const int *attrib_list)
2396 {
2397 struct glx_context *gc = __glXGetCurrentContext();
2398
2399 if (gc->vtable->bind_tex_image == NULL)
2400 return;
2401
2402 gc->vtable->bind_tex_image(dpy, drawable, buffer, attrib_list);
2403 }
2404
2405 static void
2406 __glXReleaseTexImageEXT(Display * dpy, GLXDrawable drawable, int buffer)
2407 {
2408 struct glx_context *gc = __glXGetCurrentContext();
2409
2410 if (gc->vtable->release_tex_image == NULL)
2411 return;
2412
2413 gc->vtable->release_tex_image(dpy, drawable, buffer);
2414 }
2415
2416 /*@}*/
2417
2418 #endif /* GLX_USE_APPLEGL */
2419
2420 /*
2421 ** glXGetProcAddress support
2422 */
2423
2424 struct name_address_pair
2425 {
2426 const char *Name;
2427 GLvoid *Address;
2428 };
2429
2430 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2431 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2432
2433 static const struct name_address_pair GLX_functions[] = {
2434 /*** GLX_VERSION_1_0 ***/
2435 GLX_FUNCTION(glXChooseVisual),
2436 GLX_FUNCTION(glXCopyContext),
2437 GLX_FUNCTION(glXCreateContext),
2438 GLX_FUNCTION(glXCreateGLXPixmap),
2439 GLX_FUNCTION(glXDestroyContext),
2440 GLX_FUNCTION(glXDestroyGLXPixmap),
2441 GLX_FUNCTION(glXGetConfig),
2442 GLX_FUNCTION(glXGetCurrentContext),
2443 GLX_FUNCTION(glXGetCurrentDrawable),
2444 GLX_FUNCTION(glXIsDirect),
2445 GLX_FUNCTION(glXMakeCurrent),
2446 GLX_FUNCTION(glXQueryExtension),
2447 GLX_FUNCTION(glXQueryVersion),
2448 GLX_FUNCTION(glXSwapBuffers),
2449 GLX_FUNCTION(glXUseXFont),
2450 GLX_FUNCTION(glXWaitGL),
2451 GLX_FUNCTION(glXWaitX),
2452
2453 /*** GLX_VERSION_1_1 ***/
2454 GLX_FUNCTION(glXGetClientString),
2455 GLX_FUNCTION(glXQueryExtensionsString),
2456 GLX_FUNCTION(glXQueryServerString),
2457
2458 /*** GLX_VERSION_1_2 ***/
2459 GLX_FUNCTION(glXGetCurrentDisplay),
2460
2461 /*** GLX_VERSION_1_3 ***/
2462 GLX_FUNCTION(glXChooseFBConfig),
2463 GLX_FUNCTION(glXCreateNewContext),
2464 GLX_FUNCTION(glXCreatePbuffer),
2465 GLX_FUNCTION(glXCreatePixmap),
2466 GLX_FUNCTION(glXCreateWindow),
2467 GLX_FUNCTION(glXDestroyPbuffer),
2468 GLX_FUNCTION(glXDestroyPixmap),
2469 GLX_FUNCTION(glXDestroyWindow),
2470 GLX_FUNCTION(glXGetCurrentReadDrawable),
2471 GLX_FUNCTION(glXGetFBConfigAttrib),
2472 GLX_FUNCTION(glXGetFBConfigs),
2473 GLX_FUNCTION(glXGetSelectedEvent),
2474 GLX_FUNCTION(glXGetVisualFromFBConfig),
2475 GLX_FUNCTION(glXMakeContextCurrent),
2476 GLX_FUNCTION(glXQueryContext),
2477 GLX_FUNCTION(glXQueryDrawable),
2478 GLX_FUNCTION(glXSelectEvent),
2479
2480 #ifndef GLX_USE_APPLEGL
2481 /*** GLX_SGI_swap_control ***/
2482 GLX_FUNCTION2(glXSwapIntervalSGI, __glXSwapIntervalSGI),
2483
2484 /*** GLX_SGI_video_sync ***/
2485 GLX_FUNCTION2(glXGetVideoSyncSGI, __glXGetVideoSyncSGI),
2486 GLX_FUNCTION2(glXWaitVideoSyncSGI, __glXWaitVideoSyncSGI),
2487
2488 /*** GLX_SGI_make_current_read ***/
2489 GLX_FUNCTION2(glXMakeCurrentReadSGI, glXMakeContextCurrent),
2490 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI, glXGetCurrentReadDrawable),
2491
2492 /*** GLX_EXT_import_context ***/
2493 GLX_FUNCTION(glXFreeContextEXT),
2494 GLX_FUNCTION(glXGetContextIDEXT),
2495 GLX_FUNCTION2(glXGetCurrentDisplayEXT, glXGetCurrentDisplay),
2496 GLX_FUNCTION(glXImportContextEXT),
2497 GLX_FUNCTION2(glXQueryContextInfoEXT, glXQueryContext),
2498 #endif
2499
2500 /*** GLX_SGIX_fbconfig ***/
2501 GLX_FUNCTION2(glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib),
2502 GLX_FUNCTION2(glXChooseFBConfigSGIX, glXChooseFBConfig),
2503 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX),
2504 GLX_FUNCTION(glXCreateContextWithConfigSGIX),
2505 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig),
2506 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX),
2507
2508 #ifndef GLX_USE_APPLEGL
2509 /*** GLX_SGIX_pbuffer ***/
2510 GLX_FUNCTION(glXCreateGLXPbufferSGIX),
2511 GLX_FUNCTION(glXDestroyGLXPbufferSGIX),
2512 GLX_FUNCTION(glXQueryGLXPbufferSGIX),
2513 GLX_FUNCTION(glXSelectEventSGIX),
2514 GLX_FUNCTION(glXGetSelectedEventSGIX),
2515
2516 /*** GLX_MESA_copy_sub_buffer ***/
2517 GLX_FUNCTION2(glXCopySubBufferMESA, __glXCopySubBufferMESA),
2518
2519 /*** GLX_MESA_pixmap_colormap ***/
2520 GLX_FUNCTION(glXCreateGLXPixmapMESA),
2521
2522 /*** GLX_MESA_release_buffers ***/
2523 GLX_FUNCTION2(glXReleaseBuffersMESA, __glXReleaseBuffersMESA),
2524
2525 /*** GLX_MESA_swap_control ***/
2526 GLX_FUNCTION2(glXSwapIntervalMESA, __glXSwapIntervalMESA),
2527 GLX_FUNCTION2(glXGetSwapIntervalMESA, __glXGetSwapIntervalMESA),
2528 #endif
2529
2530 /*** GLX_ARB_get_proc_address ***/
2531 GLX_FUNCTION(glXGetProcAddressARB),
2532
2533 /*** GLX 1.4 ***/
2534 GLX_FUNCTION2(glXGetProcAddress, glXGetProcAddressARB),
2535
2536 #ifndef GLX_USE_APPLEGL
2537 /*** GLX_OML_sync_control ***/
2538 GLX_FUNCTION2(glXWaitForSbcOML, __glXWaitForSbcOML),
2539 GLX_FUNCTION2(glXWaitForMscOML, __glXWaitForMscOML),
2540 GLX_FUNCTION2(glXSwapBuffersMscOML, __glXSwapBuffersMscOML),
2541 GLX_FUNCTION2(glXGetMscRateOML, __glXGetMscRateOML),
2542 GLX_FUNCTION2(glXGetSyncValuesOML, __glXGetSyncValuesOML),
2543
2544 /*** GLX_EXT_texture_from_pixmap ***/
2545 GLX_FUNCTION2(glXBindTexImageEXT, __glXBindTexImageEXT),
2546 GLX_FUNCTION2(glXReleaseTexImageEXT, __glXReleaseTexImageEXT),
2547 #endif
2548
2549 #if defined(GLX_DIRECT_RENDERING) && defined(GLX_USE_DRM)
2550 /*** DRI configuration ***/
2551 GLX_FUNCTION(glXGetScreenDriver),
2552 GLX_FUNCTION(glXGetDriverConfig),
2553 #endif
2554
2555 /*** GLX_ARB_create_context and GLX_ARB_create_context_profile ***/
2556 GLX_FUNCTION(glXCreateContextAttribsARB),
2557
2558 /*** GLX_MESA_query_renderer ***/
2559 GLX_FUNCTION(glXQueryRendererIntegerMESA),
2560 GLX_FUNCTION(glXQueryRendererStringMESA),
2561 GLX_FUNCTION(glXQueryCurrentRendererIntegerMESA),
2562 GLX_FUNCTION(glXQueryCurrentRendererStringMESA),
2563
2564 {NULL, NULL} /* end of list */
2565 };
2566
2567 static const GLvoid *
2568 get_glx_proc_address(const char *funcName)
2569 {
2570 GLuint i;
2571
2572 /* try static functions */
2573 for (i = 0; GLX_functions[i].Name; i++) {
2574 if (strcmp(GLX_functions[i].Name, funcName) == 0)
2575 return GLX_functions[i].Address;
2576 }
2577
2578 return NULL;
2579 }
2580
2581 /**
2582 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2583 * \c glXGetProcAddress.
2584 *
2585 * \param procName Name of a GL or GLX function.
2586 * \returns A pointer to the named function
2587 *
2588 * \sa glXGetProcAddress
2589 */
2590 _GLX_PUBLIC void (*glXGetProcAddressARB(const GLubyte * procName)) (void)
2591 {
2592 typedef void (*gl_function) (void);
2593 gl_function f;
2594
2595
2596 /* Search the table of GLX and internal functions first. If that
2597 * fails and the supplied name could be a valid core GL name, try
2598 * searching the core GL function table. This check is done to prevent
2599 * DRI based drivers from searching the core GL function table for
2600 * internal API functions.
2601 */
2602 f = (gl_function) get_glx_proc_address((const char *) procName);
2603 if ((f == NULL) && (procName[0] == 'g') && (procName[1] == 'l')
2604 && (procName[2] != 'X')) {
2605 #ifdef GLX_INDIRECT_RENDERING
2606 f = (gl_function) __indirect_get_proc_address((const char *) procName);
2607 #endif
2608 if (!f)
2609 f = (gl_function) _glapi_get_proc_address((const char *) procName);
2610 if (!f) {
2611 struct glx_context *gc = __glXGetCurrentContext();
2612
2613 if (gc != NULL && gc->vtable->get_proc_address != NULL)
2614 f = gc->vtable->get_proc_address((const char *) procName);
2615 }
2616 }
2617 return f;
2618 }
2619
2620 /**
2621 * Get the address of a named GL function. This is the GLX 1.4 name for
2622 * \c glXGetProcAddressARB.
2623 *
2624 * \param procName Name of a GL or GLX function.
2625 * \returns A pointer to the named function
2626 *
2627 * \sa glXGetProcAddressARB
2628 */
2629 _GLX_PUBLIC
2630 GLX_ALIAS(__GLXextFuncPtr, glXGetProcAddress,
2631 (const GLubyte * procName),
2632 (procName), glXGetProcAddressARB)
2633
2634 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2635 /**
2636 * Get the unadjusted system time (UST). Currently, the UST is measured in
2637 * microseconds since Epoc. The actual resolution of the UST may vary from
2638 * system to system, and the units may vary from release to release.
2639 * Drivers should not call this function directly. They should instead use
2640 * \c glXGetProcAddress to obtain a pointer to the function.
2641 *
2642 * \param ust Location to store the 64-bit UST
2643 * \returns Zero on success or a negative errno value on failure.
2644 *
2645 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2646 *
2647 * \since Internal API version 20030317.
2648 */
2649 _X_HIDDEN int
2650 __glXGetUST(int64_t * ust)
2651 {
2652 struct timeval tv;
2653
2654 if (ust == NULL) {
2655 return -EFAULT;
2656 }
2657
2658 if (gettimeofday(&tv, NULL) == 0) {
2659 ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec;
2660 return 0;
2661 }
2662 else {
2663 return -errno;
2664 }
2665 }
2666 #endif /* GLX_DIRECT_RENDERING */
2667
2668 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2669
2670 PUBLIC int
2671 MesaGLInteropGLXQueryDeviceInfo(Display *dpy, GLXContext context,
2672 struct mesa_glinterop_device_info *out)
2673 {
2674 struct glx_context *gc = (struct glx_context*)context;
2675 int ret;
2676
2677 __glXLock();
2678
2679 if (!gc || gc->xid == None || !gc->isDirect) {
2680 __glXUnlock();
2681 return MESA_GLINTEROP_INVALID_CONTEXT;
2682 }
2683
2684 if (!gc->vtable->interop_query_device_info) {
2685 __glXUnlock();
2686 return MESA_GLINTEROP_UNSUPPORTED;
2687 }
2688
2689 ret = gc->vtable->interop_query_device_info(gc, out);
2690 __glXUnlock();
2691 return ret;
2692 }
2693
2694 PUBLIC int
2695 MesaGLInteropGLXExportObject(Display *dpy, GLXContext context,
2696 struct mesa_glinterop_export_in *in,
2697 struct mesa_glinterop_export_out *out)
2698 {
2699 struct glx_context *gc = (struct glx_context*)context;
2700 int ret;
2701
2702 __glXLock();
2703
2704 if (!gc || gc->xid == None || !gc->isDirect) {
2705 __glXUnlock();
2706 return MESA_GLINTEROP_INVALID_CONTEXT;
2707 }
2708
2709 if (!gc->vtable->interop_export_object) {
2710 __glXUnlock();
2711 return MESA_GLINTEROP_UNSUPPORTED;
2712 }
2713
2714 ret = gc->vtable->interop_export_object(gc, in, out);
2715 __glXUnlock();
2716 return ret;
2717 }
2718
2719 #endif /* defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) */