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