glx: added __glXPreferEGL() to tell libGL to prefer "egl_" drivers over regular DRI...
[mesa.git] / src / glx / x11 / glxclient.h
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 * \file glxclient.h
37 * Direct rendering support added by Precision Insight, Inc.
38 *
39 * \author Kevin E. Martin <kevin@precisioninsight.com>
40 */
41
42 #ifndef _GLX_client_h_
43 #define _GLX_client_h_
44 #define NEED_REPLIES
45 #define NEED_EVENTS
46 #include <X11/Xproto.h>
47 #include <X11/Xlibint.h>
48 #define GLX_GLXEXT_PROTOTYPES
49 #include <GL/glx.h>
50 #include <GL/glxext.h>
51 #include <string.h>
52 #include <stdlib.h>
53 #include <stdio.h>
54 #ifdef WIN32
55 #include <stdint.h>
56 #endif
57 #include "GL/glxint.h"
58 #include "GL/glxproto.h"
59 #include "GL/internal/glcore.h"
60 #include "glapitable.h"
61 #include "glxextensions.h"
62 #if defined( USE_XTHREADS )
63 # include <X11/Xthreads.h>
64 #elif defined( PTHREADS )
65 # include <pthread.h>
66 #endif
67
68 #define GLX_MAJOR_VERSION 1 /* current version numbers */
69 #define GLX_MINOR_VERSION 4
70
71 #define __GLX_MAX_TEXTURE_UNITS 32
72
73 typedef struct __GLXcontextRec __GLXcontext;
74 typedef struct __GLXdisplayPrivateRec __GLXdisplayPrivate;
75 typedef struct _glapi_table __GLapi;
76
77 /************************************************************************/
78
79 #ifdef GLX_DIRECT_RENDERING
80
81 #include <GL/internal/dri_interface.h>
82
83
84 /**
85 * Display dependent methods. This structure is initialized during the
86 * \c driCreateDisplay call.
87 */
88 struct __DRIdisplayRec {
89 /**
90 * Method to destroy the private DRI display data.
91 */
92 void (*destroyDisplay)(Display *dpy, void *displayPrivate);
93
94 /**
95 * Opaque pointer to private per display direct rendering data.
96 * \c NULL if direct rendering is not supported on this display.
97 */
98 struct __DRIdisplayPrivateRec *private;
99
100 /**
101 * Array of pointers to methods to create and initialize the private DRI
102 * screen data.
103 */
104 PFNCREATENEWSCREENFUNC * createNewScreen;
105 };
106
107
108 /*
109 ** We keep a linked list of these structures, one per DRI device driver.
110 */
111 struct __DRIdriverRec {
112 const char *name;
113 void *handle;
114 PFNCREATENEWSCREENFUNC createNewScreenFunc;
115 struct __DRIdriverRec *next;
116 };
117
118 /*
119 ** Function to create and DRI display data and initialize the display
120 ** dependent methods.
121 */
122 extern void *driCreateDisplay(Display *dpy, __DRIdisplay *pdisp);
123
124 extern __DRIdriver *driGetDriver(Display *dpy, int scrNum);
125
126 extern void DRI_glXUseXFont( Font font, int first, int count, int listbase );
127
128 /*
129 ** Functions to obtain driver configuration information from a direct
130 ** rendering client application
131 */
132 extern const char *glXGetScreenDriver (Display *dpy, int scrNum);
133
134 extern const char *glXGetDriverConfig (const char *driverName);
135
136 extern Bool __glXWindowExists(Display *dpy, GLXDrawable draw);
137
138 #endif
139
140 /************************************************************************/
141
142 #define __GL_CLIENT_ATTRIB_STACK_DEPTH 16
143
144 typedef struct __GLXpixelStoreModeRec {
145 GLboolean swapEndian;
146 GLboolean lsbFirst;
147 GLuint rowLength;
148 GLuint imageHeight;
149 GLuint imageDepth;
150 GLuint skipRows;
151 GLuint skipPixels;
152 GLuint skipImages;
153 GLuint alignment;
154 } __GLXpixelStoreMode;
155
156
157 typedef struct __GLXattributeRec {
158 GLuint mask;
159
160 /**
161 * Pixel storage state. Most of the pixel store mode state is kept
162 * here and used by the client code to manage the packing and
163 * unpacking of data sent to/received from the server.
164 */
165 __GLXpixelStoreMode storePack, storeUnpack;
166
167 /**
168 * Is EXT_vertex_array / GL 1.1 DrawArrays protocol specifically
169 * disabled?
170 */
171 GLboolean NoDrawArraysProtocol;
172
173 /**
174 * Vertex Array storage state. The vertex array component
175 * state is stored here and is used to manage the packing of
176 * DrawArrays data sent to the server.
177 */
178 struct array_state_vector * array_state;
179 } __GLXattribute;
180
181 typedef struct __GLXattributeMachineRec {
182 __GLXattribute *stack[__GL_CLIENT_ATTRIB_STACK_DEPTH];
183 __GLXattribute **stackPointer;
184 } __GLXattributeMachine;
185
186 /**
187 * GLX state that needs to be kept on the client. One of these records
188 * exist for each context that has been made current by this client.
189 */
190 struct __GLXcontextRec {
191 /**
192 * \name Drawing command buffer.
193 *
194 * Drawing commands are packed into this buffer before being sent as a
195 * single GLX protocol request. The buffer is sent when it overflows or
196 * is flushed by \c __glXFlushRenderBuffer. \c pc is the next location
197 * in the buffer to be filled. \c limit is described above in the buffer
198 * slop discussion.
199 *
200 * Commands that require large amounts of data to be transfered will
201 * also use this buffer to hold a header that describes the large
202 * command.
203 *
204 * These must be the first 6 fields since they are static initialized
205 * in the dummy context in glxext.c
206 */
207 /*@{*/
208 GLubyte *buf;
209 GLubyte *pc;
210 GLubyte *limit;
211 GLubyte *bufEnd;
212 GLint bufSize;
213 /*@}*/
214
215 /**
216 * The XID of this rendering context. When the context is created a
217 * new XID is allocated. This is set to None when the context is
218 * destroyed but is still current to some thread. In this case the
219 * context will be freed on next MakeCurrent.
220 */
221 XID xid;
222
223 /**
224 * The XID of the \c shareList context.
225 */
226 XID share_xid;
227
228 /**
229 * Visual id.
230 *
231 * \deprecated
232 * This filed has been largely been replaced by the \c mode field, but
233 * the work is not quite done.
234 */
235 VisualID vid;
236
237 /**
238 * Screen number.
239 */
240 GLint screen;
241
242 /**
243 * \c GL_TRUE if the context was created with ImportContext, which
244 * means the server-side context was created by another X client.
245 */
246 GLboolean imported;
247
248 /**
249 * The context tag returned by MakeCurrent when this context is made
250 * current. This tag is used to identify the context that a thread has
251 * current so that proper server context management can be done. It is
252 * used for all context specific commands (i.e., \c Render, \c RenderLarge,
253 * \c WaitX, \c WaitGL, \c UseXFont, and \c MakeCurrent (for the old
254 * context)).
255 */
256 GLXContextTag currentContextTag;
257
258 /**
259 * \name Rendering mode
260 *
261 * The rendering mode is kept on the client as well as the server.
262 * When \c glRenderMode is called, the buffer associated with the
263 * previous rendering mode (feedback or select) is filled.
264 */
265 /*@{*/
266 GLenum renderMode;
267 GLfloat *feedbackBuf;
268 GLuint *selectBuf;
269 /*@}*/
270
271 /**
272 * This is \c GL_TRUE if the pixel unpack modes are such that an image
273 * can be unpacked from the clients memory by just copying. It may
274 * still be true that the server will have to do some work. This
275 * just promises that a straight copy will fetch the correct bytes.
276 */
277 GLboolean fastImageUnpack;
278
279 /**
280 * Fill newImage with the unpacked form of \c oldImage getting it
281 * ready for transport to the server.
282 */
283 void (*fillImage)(__GLXcontext*, GLint, GLint, GLint, GLint, GLenum,
284 GLenum, const GLvoid*, GLubyte*, GLubyte*);
285
286 /**
287 * Client side attribs.
288 */
289 __GLXattributeMachine attributes;
290
291 /**
292 * Client side error code. This is set when client side gl API
293 * routines need to set an error because of a bad enumerant or
294 * running out of memory, etc.
295 */
296 GLenum error;
297
298 /**
299 * Whether this context does direct rendering.
300 */
301 Bool isDirect;
302
303 /**
304 * \c dpy of current display for this context. Will be \c NULL if not
305 * current to any display, or if this is the "dummy context".
306 */
307 Display *currentDpy;
308
309 /**
310 * The current drawable for this context. Will be None if this
311 * context is not current to any drawable. currentReadable is below.
312 */
313 GLXDrawable currentDrawable;
314
315 /**
316 * \name GL Constant Strings
317 *
318 * Constant strings that describe the server implementation
319 * These pertain to GL attributes, not to be confused with
320 * GLX versioning attributes.
321 */
322 /*@{*/
323 GLubyte *vendor;
324 GLubyte *renderer;
325 GLubyte *version;
326 GLubyte *extensions;
327 /*@}*/
328
329 /**
330 * Record the dpy this context was created on for later freeing
331 */
332 Display *createDpy;
333
334 /**
335 * Maximum small render command size. This is the smaller of 64k and
336 * the size of the above buffer.
337 */
338 GLint maxSmallRenderCommandSize;
339
340 /**
341 * Major opcode for the extension. Copied here so a lookup isn't
342 * needed.
343 */
344 GLint majorOpcode;
345
346 #ifdef GLX_DIRECT_RENDERING
347 /**
348 * Per context direct rendering interface functions and data.
349 */
350 __DRIcontext driContext;
351 #endif
352
353 /**
354 * \c GLXFBConfigID used to create this context. May be \c None. This
355 * field has been replaced by the \c mode field.
356 *
357 * \since Internal API version 20030317.
358 *
359 * \deprecated
360 * This filed has been largely been replaced by the \c mode field, but
361 * the work is not quite done.
362 */
363 GLXFBConfigID fbconfigID;
364
365 /**
366 * The current read-drawable for this context. Will be None if this
367 * context is not current to any drawable.
368 *
369 * \since Internal API version 20030606.
370 */
371 GLXDrawable currentReadable;
372
373 /**
374 * Pointer to client-state data that is private to libGL. This is only
375 * used for indirect rendering contexts.
376 *
377 * No internal API version change was made for this change. Client-side
378 * drivers should NEVER use this data or even care that it exists.
379 */
380 void * client_state_private;
381
382 /**
383 * Stored value for \c glXQueryContext attribute \c GLX_RENDER_TYPE.
384 */
385 int renderType;
386
387 /**
388 * \name Raw server GL version
389 *
390 * True core GL version supported by the server. This is the raw value
391 * returned by the server, and it may not reflect what is actually
392 * supported (or reported) by the client-side library.
393 */
394 /*@{*/
395 int server_major; /**< Major version number. */
396 int server_minor; /**< Minor version number. */
397 /*@}*/
398
399 char gl_extension_bits[ __GL_EXT_BYTES ];
400 };
401
402 #define __glXSetError(gc,code) \
403 if (!(gc)->error) { \
404 (gc)->error = code; \
405 }
406
407 extern void __glFreeAttributeState(__GLXcontext *);
408
409 /************************************************************************/
410
411 /**
412 * The size of the largest drawing command known to the implementation
413 * that will use the GLXRender GLX command. In this case it is
414 * \c glPolygonStipple.
415 */
416 #define __GLX_MAX_SMALL_RENDER_CMD_SIZE 156
417
418 /**
419 * To keep the implementation fast, the code uses a "limit" pointer
420 * to determine when the drawing command buffer is too full to hold
421 * another fixed size command. This constant defines the amount of
422 * space that must always be available in the drawing command buffer
423 * at all times for the implementation to work. It is important that
424 * the number be just large enough, but not so large as to reduce the
425 * efficacy of the buffer. The "+32" is just to keep the code working
426 * in case somebody counts wrong.
427 */
428 #define __GLX_BUFFER_LIMIT_SIZE (__GLX_MAX_SMALL_RENDER_CMD_SIZE + 32)
429
430 /**
431 * This implementation uses a smaller threshold for switching
432 * to the RenderLarge protocol than the protcol requires so that
433 * large copies don't occur.
434 */
435 #define __GLX_RENDER_CMD_SIZE_LIMIT 4096
436
437 /**
438 * One of these records exists per screen of the display. It contains
439 * a pointer to the config data for that screen (if the screen supports GL).
440 */
441 typedef struct __GLXscreenConfigsRec {
442 /**
443 * GLX extension string reported by the X-server.
444 */
445 const char *serverGLXexts;
446
447 /**
448 * GLX extension string to be reported to applications. This is the
449 * set of extensions that the application can actually use.
450 */
451 char *effectiveGLXexts;
452
453 #ifdef GLX_DIRECT_RENDERING
454 /**
455 * Per screen direct rendering interface functions and data.
456 */
457 __DRIscreen driScreen;
458 #endif
459
460 /**
461 * Linked list of configurations for this screen.
462 */
463 __GLcontextModes *configs;
464
465 /**
466 * Per-screen dynamic GLX extension tracking. The \c direct_support
467 * field only contains enough bits for 64 extensions. Should libGL
468 * ever need to track more than 64 GLX extensions, we can safely grow
469 * this field. The \c __GLXscreenConfigs structure is not used outside
470 * libGL.
471 */
472 /*@{*/
473 unsigned char direct_support[8];
474 GLboolean ext_list_first_time;
475 /*@}*/
476
477 } __GLXscreenConfigs;
478
479 /**
480 * Per display private data. One of these records exists for each display
481 * that is using the OpenGL (GLX) extension.
482 */
483 struct __GLXdisplayPrivateRec {
484 /**
485 * Back pointer to the display
486 */
487 Display *dpy;
488
489 /**
490 * The \c majorOpcode is common to all connections to the same server.
491 * It is also copied into the context structure.
492 */
493 int majorOpcode;
494
495 /**
496 * \name Server Version
497 *
498 * Major and minor version returned by the server during initialization.
499 */
500 /*@{*/
501 int majorVersion, minorVersion;
502 /*@}*/
503
504 /**
505 * \name Storage for the servers GLX vendor and versions strings.
506 *
507 * These are the same for all screens on this display. These fields will
508 * be filled in on demand.
509 */
510 /*@{*/
511 const char *serverGLXvendor;
512 const char *serverGLXversion;
513 /*@}*/
514
515 /**
516 * Configurations of visuals for all screens on this display.
517 * Also, per screen data which now includes the server \c GLX_EXTENSION
518 * string.
519 */
520 __GLXscreenConfigs *screenConfigs;
521
522 #ifdef GLX_DIRECT_RENDERING
523 /**
524 * Per display direct rendering interface functions and data.
525 */
526 __DRIdisplay driDisplay;
527 #endif
528 };
529
530 void __glXFreeContext(__GLXcontext*);
531
532 extern GLubyte *__glXFlushRenderBuffer(__GLXcontext*, GLubyte*);
533
534 extern void __glXSendLargeChunk(__GLXcontext *gc, GLint requestNumber,
535 GLint totalRequests,
536 const GLvoid * data, GLint dataLen);
537
538 extern void __glXSendLargeCommand(__GLXcontext *, const GLvoid *, GLint,
539 const GLvoid *, GLint);
540
541 /* Initialize the GLX extension for dpy */
542 extern __GLXdisplayPrivate *__glXInitialize(Display*);
543
544 extern void __glXPreferEGL(int state);
545
546 /************************************************************************/
547
548 extern int __glXDebug;
549
550 /* This is per-thread storage in an MT environment */
551 #if defined( USE_XTHREADS ) || defined( PTHREADS )
552
553 extern void __glXSetCurrentContext(__GLXcontext *c);
554
555 # if defined( GLX_USE_TLS )
556
557 extern __thread void * __glX_tls_Context
558 __attribute__((tls_model("initial-exec")));
559
560 # define __glXGetCurrentContext() __glX_tls_Context
561
562 # else
563
564 extern __GLXcontext *__glXGetCurrentContext(void);
565
566 # endif /* defined( GLX_USE_TLS ) */
567
568 #else
569
570 extern __GLXcontext *__glXcurrentContext;
571 #define __glXGetCurrentContext() __glXcurrentContext
572 #define __glXSetCurrentContext(gc) __glXcurrentContext = gc
573
574 #endif /* defined( USE_XTHREADS ) || defined( PTHREADS ) */
575
576
577 /*
578 ** Global lock for all threads in this address space using the GLX
579 ** extension
580 */
581 #if defined( USE_XTHREADS )
582 extern xmutex_rec __glXmutex;
583 #define __glXLock() xmutex_lock(&__glXmutex)
584 #define __glXUnlock() xmutex_unlock(&__glXmutex)
585 #elif defined( PTHREADS )
586 extern pthread_mutex_t __glXmutex;
587 #define __glXLock() pthread_mutex_lock(&__glXmutex)
588 #define __glXUnlock() pthread_mutex_unlock(&__glXmutex)
589 #else
590 #define __glXLock()
591 #define __glXUnlock()
592 #endif
593
594 /*
595 ** Setup for a command. Initialize the extension for dpy if necessary.
596 */
597 extern CARD8 __glXSetupForCommand(Display *dpy);
598
599 /************************************************************************/
600
601 /*
602 ** Data conversion and packing support.
603 */
604
605 extern const GLuint __glXDefaultPixelStore[9];
606
607 /* Send an image to the server using RenderLarge. */
608 extern void __glXSendLargeImage(__GLXcontext *gc, GLint compsize, GLint dim,
609 GLint width, GLint height, GLint depth, GLenum format, GLenum type,
610 const GLvoid *src, GLubyte *pc, GLubyte *modes);
611
612 /* Return the size, in bytes, of some pixel data */
613 extern GLint __glImageSize(GLint, GLint, GLint, GLenum, GLenum, GLenum);
614
615 /* Return the number of elements per group of a specified format*/
616 extern GLint __glElementsPerGroup(GLenum format, GLenum type);
617
618 /* Return the number of bytes per element, based on the element type (other
619 ** than GL_BITMAP).
620 */
621 extern GLint __glBytesPerElement(GLenum type);
622
623 /*
624 ** Fill the transport buffer with the data from the users buffer,
625 ** applying some of the pixel store modes (unpack modes) to the data
626 ** first. As a side effect of this call, the "modes" field is
627 ** updated to contain the modes needed by the server to decode the
628 ** sent data.
629 */
630 extern void __glFillImage(__GLXcontext*, GLint, GLint, GLint, GLint, GLenum,
631 GLenum, const GLvoid*, GLubyte*, GLubyte*);
632
633 /* Copy map data with a stride into a packed buffer */
634 extern void __glFillMap1f(GLint, GLint, GLint, const GLfloat *, GLubyte *);
635 extern void __glFillMap1d(GLint, GLint, GLint, const GLdouble *, GLubyte *);
636 extern void __glFillMap2f(GLint, GLint, GLint, GLint, GLint,
637 const GLfloat *, GLfloat *);
638 extern void __glFillMap2d(GLint, GLint, GLint, GLint, GLint,
639 const GLdouble *, GLdouble *);
640
641 /*
642 ** Empty an image out of the reply buffer into the clients memory applying
643 ** the pack modes to pack back into the clients requested format.
644 */
645 extern void __glEmptyImage(__GLXcontext*, GLint, GLint, GLint, GLint, GLenum,
646 GLenum, const GLubyte *, GLvoid *);
647
648
649 /*
650 ** Allocate and Initialize Vertex Array client state
651 */
652 extern void __glXInitVertexArrayState(__GLXcontext*);
653
654 /*
655 ** Inform the Server of the major and minor numbers and of the client
656 ** libraries extension string.
657 */
658 extern void __glXClientInfo ( Display *dpy, int opcode );
659
660 /************************************************************************/
661
662 /*
663 ** Declarations that should be in Xlib
664 */
665 #ifdef __GL_USE_OUR_PROTOTYPES
666 extern void _XFlush(Display*);
667 extern Status _XReply(Display*, xReply*, int, Bool);
668 extern void _XRead(Display*, void*, long);
669 extern void _XSend(Display*, const void*, long);
670 #endif
671
672
673 extern void __glXInitializeVisualConfigFromTags( __GLcontextModes *config,
674 int count, const INT32 *bp, Bool tagged_only, Bool fbconfig_style_tags );
675
676 extern char * __glXGetStringFromServer( Display * dpy, int opcode,
677 CARD32 glxCode, CARD32 for_whom, CARD32 name );
678
679 extern char *__glXstrdup(const char *str);
680
681
682 extern const char __glXGLClientVersion[];
683 extern const char __glXGLClientExtensions[];
684
685 /* Determine the internal API version */
686 extern int __glXGetInternalVersion(void);
687
688 /* Get the unadjusted system time */
689 extern int __glXGetUST( int64_t * ust );
690
691 extern Bool __glXGetMscRateOML(Display * dpy, GLXDrawable drawable,
692 int32_t * numerator, int32_t * denominator);
693
694 #endif /* !__GLX_client_h__ */