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