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