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