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