1848b8605Smrg/* 2848b8605Smrg * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 3848b8605Smrg * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. 4848b8605Smrg * 5848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 6848b8605Smrg * copy of this software and associated documentation files (the "Software"), 7848b8605Smrg * to deal in the Software without restriction, including without limitation 8848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the 10848b8605Smrg * Software is furnished to do so, subject to the following conditions: 11848b8605Smrg * 12848b8605Smrg * The above copyright notice including the dates of first publication and 13848b8605Smrg * either this permission notice or a reference to 14848b8605Smrg * http://oss.sgi.com/projects/FreeB/ 15848b8605Smrg * shall be included in all copies or substantial portions of the Software. 16848b8605Smrg * 17848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20848b8605Smrg * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21848b8605Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 22848b8605Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23848b8605Smrg * SOFTWARE. 24848b8605Smrg * 25848b8605Smrg * Except as contained in this notice, the name of Silicon Graphics, Inc. 26848b8605Smrg * shall not be used in advertising or otherwise to promote the sale, use or 27848b8605Smrg * other dealings in this Software without prior written authorization from 28848b8605Smrg * Silicon Graphics, Inc. 29848b8605Smrg */ 30848b8605Smrg 31848b8605Smrg/** 32848b8605Smrg * \file glxclient.h 33848b8605Smrg * Direct rendering support added by Precision Insight, Inc. 34848b8605Smrg * 35848b8605Smrg * \author Kevin E. Martin <kevin@precisioninsight.com> 36848b8605Smrg */ 37848b8605Smrg 38848b8605Smrg#ifndef _GLX_client_h_ 39848b8605Smrg#define _GLX_client_h_ 40848b8605Smrg#include <X11/Xproto.h> 41848b8605Smrg#include <X11/Xlibint.h> 42848b8605Smrg#include <X11/Xfuncproto.h> 43848b8605Smrg#include <X11/extensions/extutil.h> 44848b8605Smrg#define GLX_GLXEXT_PROTOTYPES 45848b8605Smrg#include <GL/glx.h> 46848b8605Smrg#include <GL/glxext.h> 47848b8605Smrg#include <string.h> 48848b8605Smrg#include <stdlib.h> 49848b8605Smrg#include <stdio.h> 50848b8605Smrg#include <stdint.h> 51b8e80941Smrg#include <pthread.h> 52848b8605Smrg#include "GL/glxproto.h" 53848b8605Smrg#include "glxconfig.h" 54848b8605Smrg#include "glxhash.h" 55b8e80941Smrg#include "util/macros.h" 56848b8605Smrg 57848b8605Smrg#include "glxextensions.h" 58848b8605Smrg 59b8e80941Smrg#if defined(USE_LIBGLVND) 60b8e80941Smrg#define _GLX_PUBLIC _X_HIDDEN 61b8e80941Smrg#else 62b8e80941Smrg#define _GLX_PUBLIC _X_EXPORT 63b8e80941Smrg#endif 64b8e80941Smrg 65b8e80941Smrg#ifdef __cplusplus 66b8e80941Smrgextern "C" { 67b8e80941Smrg#endif 68b8e80941Smrg 69848b8605Smrg 70848b8605Smrg#define GLX_MAJOR_VERSION 1 /* current version numbers */ 71848b8605Smrg#define GLX_MINOR_VERSION 4 72848b8605Smrg 73848b8605Smrg#define __GLX_MAX_TEXTURE_UNITS 32 74848b8605Smrg 75848b8605Smrgstruct glx_display; 76848b8605Smrgstruct glx_context; 77848b8605Smrg 78848b8605Smrg/************************************************************************/ 79848b8605Smrg 80848b8605Smrg#ifdef GLX_DIRECT_RENDERING 81848b8605Smrg 82848b8605Smrgextern void DRI_glXUseXFont(struct glx_context *ctx, 83848b8605Smrg Font font, int first, int count, int listbase); 84848b8605Smrg 85848b8605Smrg#endif 86848b8605Smrg 87848b8605Smrg#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) 88848b8605Smrg 89848b8605Smrg/** 90848b8605Smrg * Display dependent methods. This structure is initialized during the 91848b8605Smrg * \c driCreateDisplay call. 92848b8605Smrg */ 93848b8605Smrgtypedef struct __GLXDRIdisplayRec __GLXDRIdisplay; 94848b8605Smrgtypedef struct __GLXDRIscreenRec __GLXDRIscreen; 95848b8605Smrgtypedef struct __GLXDRIdrawableRec __GLXDRIdrawable; 96848b8605Smrg 97848b8605Smrgstruct __GLXDRIdisplayRec 98848b8605Smrg{ 99848b8605Smrg /** 100848b8605Smrg * Method to destroy the private DRI display data. 101848b8605Smrg */ 102848b8605Smrg void (*destroyDisplay) (__GLXDRIdisplay * display); 103848b8605Smrg 104848b8605Smrg struct glx_screen *(*createScreen)(int screen, struct glx_display * priv); 105848b8605Smrg}; 106848b8605Smrg 107848b8605Smrgstruct __GLXDRIscreenRec { 108848b8605Smrg 109848b8605Smrg void (*destroyScreen)(struct glx_screen *psc); 110848b8605Smrg 111848b8605Smrg struct glx_context *(*createContext)(struct glx_screen *psc, 112848b8605Smrg struct glx_config *config, 113848b8605Smrg struct glx_context *shareList, 114848b8605Smrg int renderType); 115848b8605Smrg 116848b8605Smrg __GLXDRIdrawable *(*createDrawable)(struct glx_screen *psc, 117848b8605Smrg XID drawable, 118848b8605Smrg GLXDrawable glxDrawable, 119848b8605Smrg struct glx_config *config); 120848b8605Smrg 121848b8605Smrg int64_t (*swapBuffers)(__GLXDRIdrawable *pdraw, int64_t target_msc, 122848b8605Smrg int64_t divisor, int64_t remainder, Bool flush); 123848b8605Smrg void (*copySubBuffer)(__GLXDRIdrawable *pdraw, 124848b8605Smrg int x, int y, int width, int height, Bool flush); 125848b8605Smrg int (*getDrawableMSC)(struct glx_screen *psc, __GLXDRIdrawable *pdraw, 126848b8605Smrg int64_t *ust, int64_t *msc, int64_t *sbc); 127848b8605Smrg int (*waitForMSC)(__GLXDRIdrawable *pdraw, int64_t target_msc, 128848b8605Smrg int64_t divisor, int64_t remainder, int64_t *ust, 129848b8605Smrg int64_t *msc, int64_t *sbc); 130848b8605Smrg int (*waitForSBC)(__GLXDRIdrawable *pdraw, int64_t target_sbc, int64_t *ust, 131848b8605Smrg int64_t *msc, int64_t *sbc); 132848b8605Smrg int (*setSwapInterval)(__GLXDRIdrawable *pdraw, int interval); 133848b8605Smrg int (*getSwapInterval)(__GLXDRIdrawable *pdraw); 134848b8605Smrg int (*getBufferAge)(__GLXDRIdrawable *pdraw); 135848b8605Smrg}; 136848b8605Smrg 137848b8605Smrgstruct __GLXDRIdrawableRec 138848b8605Smrg{ 139848b8605Smrg void (*destroyDrawable) (__GLXDRIdrawable * drawable); 140848b8605Smrg 141848b8605Smrg XID xDrawable; 142848b8605Smrg XID drawable; 143848b8605Smrg struct glx_screen *psc; 144848b8605Smrg GLenum textureTarget; 145848b8605Smrg GLenum textureFormat; /* EXT_texture_from_pixmap support */ 146848b8605Smrg unsigned long eventMask; 147848b8605Smrg int refcount; 148848b8605Smrg}; 149848b8605Smrg 150848b8605Smrg/* 151848b8605Smrg** Function to create and DRI display data and initialize the display 152848b8605Smrg** dependent methods. 153848b8605Smrg*/ 154848b8605Smrgextern __GLXDRIdisplay *driswCreateDisplay(Display * dpy); 155848b8605Smrgextern __GLXDRIdisplay *driCreateDisplay(Display * dpy); 156848b8605Smrgextern __GLXDRIdisplay *dri2CreateDisplay(Display * dpy); 157b8e80941Smrgextern __GLXDRIdisplay *dri3_create_display(Display * dpy); 158b8e80941Smrgextern __GLXDRIdisplay *driwindowsCreateDisplay(Display * dpy); 159b8e80941Smrg 160b8e80941Smrg/* 161b8e80941Smrg** 162b8e80941Smrg*/ 163848b8605Smrgextern void dri2InvalidateBuffers(Display *dpy, XID drawable); 164848b8605Smrgextern unsigned dri2GetSwapEventType(Display *dpy, XID drawable); 165848b8605Smrg 166848b8605Smrg/* 167848b8605Smrg** Functions to obtain driver configuration information from a direct 168848b8605Smrg** rendering client application 169848b8605Smrg*/ 170848b8605Smrgextern const char *glXGetScreenDriver(Display * dpy, int scrNum); 171848b8605Smrg 172848b8605Smrgextern const char *glXGetDriverConfig(const char *driverName); 173848b8605Smrg 174848b8605Smrg#endif 175848b8605Smrg 176848b8605Smrg/************************************************************************/ 177848b8605Smrg 178848b8605Smrg#define __GL_CLIENT_ATTRIB_STACK_DEPTH 16 179848b8605Smrg 180848b8605Smrgtypedef struct __GLXpixelStoreModeRec 181848b8605Smrg{ 182848b8605Smrg GLboolean swapEndian; 183848b8605Smrg GLboolean lsbFirst; 184848b8605Smrg GLuint rowLength; 185848b8605Smrg GLuint imageHeight; 186848b8605Smrg GLuint imageDepth; 187848b8605Smrg GLuint skipRows; 188848b8605Smrg GLuint skipPixels; 189848b8605Smrg GLuint skipImages; 190848b8605Smrg GLuint alignment; 191848b8605Smrg} __GLXpixelStoreMode; 192848b8605Smrg 193848b8605Smrg 194848b8605Smrgtypedef struct __GLXattributeRec 195848b8605Smrg{ 196848b8605Smrg GLuint mask; 197848b8605Smrg 198848b8605Smrg /** 199848b8605Smrg * Pixel storage state. Most of the pixel store mode state is kept 200848b8605Smrg * here and used by the client code to manage the packing and 201848b8605Smrg * unpacking of data sent to/received from the server. 202848b8605Smrg */ 203848b8605Smrg __GLXpixelStoreMode storePack, storeUnpack; 204848b8605Smrg 205848b8605Smrg /** 206848b8605Smrg * Is EXT_vertex_array / GL 1.1 DrawArrays protocol specifically 207848b8605Smrg * disabled? 208848b8605Smrg */ 209848b8605Smrg GLboolean NoDrawArraysProtocol; 210848b8605Smrg 211848b8605Smrg /** 212848b8605Smrg * Vertex Array storage state. The vertex array component 213848b8605Smrg * state is stored here and is used to manage the packing of 214848b8605Smrg * DrawArrays data sent to the server. 215848b8605Smrg */ 216848b8605Smrg struct array_state_vector *array_state; 217848b8605Smrg} __GLXattribute; 218848b8605Smrg 219848b8605Smrgtypedef struct __GLXattributeMachineRec 220848b8605Smrg{ 221848b8605Smrg __GLXattribute *stack[__GL_CLIENT_ATTRIB_STACK_DEPTH]; 222848b8605Smrg __GLXattribute **stackPointer; 223848b8605Smrg} __GLXattributeMachine; 224848b8605Smrg 225b8e80941Smrgstruct mesa_glinterop_device_info; 226b8e80941Smrgstruct mesa_glinterop_export_in; 227b8e80941Smrgstruct mesa_glinterop_export_out; 228b8e80941Smrg 229848b8605Smrgstruct glx_context_vtable { 230848b8605Smrg void (*destroy)(struct glx_context *ctx); 231848b8605Smrg int (*bind)(struct glx_context *context, struct glx_context *old, 232848b8605Smrg GLXDrawable draw, GLXDrawable read); 233848b8605Smrg void (*unbind)(struct glx_context *context, struct glx_context *new_ctx); 234848b8605Smrg void (*wait_gl)(struct glx_context *ctx); 235848b8605Smrg void (*wait_x)(struct glx_context *ctx); 236848b8605Smrg void (*use_x_font)(struct glx_context *ctx, 237848b8605Smrg Font font, int first, int count, int listBase); 238848b8605Smrg void (*bind_tex_image)(Display * dpy, 239848b8605Smrg GLXDrawable drawable, 240848b8605Smrg int buffer, const int *attrib_list); 241848b8605Smrg void (*release_tex_image)(Display * dpy, GLXDrawable drawable, int buffer); 242848b8605Smrg void * (*get_proc_address)(const char *symbol); 243b8e80941Smrg int (*interop_query_device_info)(struct glx_context *ctx, 244b8e80941Smrg struct mesa_glinterop_device_info *out); 245b8e80941Smrg int (*interop_export_object)(struct glx_context *ctx, 246b8e80941Smrg struct mesa_glinterop_export_in *in, 247b8e80941Smrg struct mesa_glinterop_export_out *out); 248848b8605Smrg}; 249848b8605Smrg 250848b8605Smrg/** 251848b8605Smrg * GLX state that needs to be kept on the client. One of these records 252848b8605Smrg * exist for each context that has been made current by this client. 253848b8605Smrg */ 254848b8605Smrgstruct glx_context 255848b8605Smrg{ 256848b8605Smrg /** 257848b8605Smrg * \name Drawing command buffer. 258848b8605Smrg * 259848b8605Smrg * Drawing commands are packed into this buffer before being sent as a 260848b8605Smrg * single GLX protocol request. The buffer is sent when it overflows or 261848b8605Smrg * is flushed by \c __glXFlushRenderBuffer. \c pc is the next location 262848b8605Smrg * in the buffer to be filled. \c limit is described above in the buffer 263848b8605Smrg * slop discussion. 264848b8605Smrg * 265848b8605Smrg * Commands that require large amounts of data to be transfered will 266848b8605Smrg * also use this buffer to hold a header that describes the large 267848b8605Smrg * command. 268848b8605Smrg * 269848b8605Smrg * These must be the first 6 fields since they are static initialized 270848b8605Smrg * in the dummy context in glxext.c 271848b8605Smrg */ 272848b8605Smrg /*@{ */ 273848b8605Smrg GLubyte *buf; 274848b8605Smrg GLubyte *pc; 275848b8605Smrg GLubyte *limit; 276848b8605Smrg GLubyte *bufEnd; 277848b8605Smrg GLint bufSize; 278848b8605Smrg /*@} */ 279848b8605Smrg 280848b8605Smrg const struct glx_context_vtable *vtable; 281848b8605Smrg 282848b8605Smrg /** 283848b8605Smrg * The XID of this rendering context. When the context is created a 284848b8605Smrg * new XID is allocated. This is set to None when the context is 285848b8605Smrg * destroyed but is still current to some thread. In this case the 286848b8605Smrg * context will be freed on next MakeCurrent. 287848b8605Smrg */ 288848b8605Smrg XID xid; 289848b8605Smrg 290848b8605Smrg /** 291848b8605Smrg * The XID of the \c shareList context. 292848b8605Smrg */ 293848b8605Smrg XID share_xid; 294848b8605Smrg 295848b8605Smrg /** 296848b8605Smrg * Screen number. 297848b8605Smrg */ 298848b8605Smrg GLint screen; 299848b8605Smrg struct glx_screen *psc; 300848b8605Smrg 301848b8605Smrg /** 302848b8605Smrg * \c GL_TRUE if the context was created with ImportContext, which 303848b8605Smrg * means the server-side context was created by another X client. 304848b8605Smrg */ 305848b8605Smrg GLboolean imported; 306848b8605Smrg 307848b8605Smrg /** 308848b8605Smrg * The context tag returned by MakeCurrent when this context is made 309848b8605Smrg * current. This tag is used to identify the context that a thread has 310848b8605Smrg * current so that proper server context management can be done. It is 311848b8605Smrg * used for all context specific commands (i.e., \c Render, \c RenderLarge, 312848b8605Smrg * \c WaitX, \c WaitGL, \c UseXFont, and \c MakeCurrent (for the old 313848b8605Smrg * context)). 314848b8605Smrg */ 315848b8605Smrg GLXContextTag currentContextTag; 316848b8605Smrg 317848b8605Smrg /** 318848b8605Smrg * \name Rendering mode 319848b8605Smrg * 320848b8605Smrg * The rendering mode is kept on the client as well as the server. 321848b8605Smrg * When \c glRenderMode is called, the buffer associated with the 322848b8605Smrg * previous rendering mode (feedback or select) is filled. 323848b8605Smrg */ 324848b8605Smrg /*@{ */ 325848b8605Smrg GLenum renderMode; 326848b8605Smrg GLfloat *feedbackBuf; 327848b8605Smrg GLuint *selectBuf; 328848b8605Smrg /*@} */ 329848b8605Smrg 330848b8605Smrg /** 331848b8605Smrg * Fill newImage with the unpacked form of \c oldImage getting it 332848b8605Smrg * ready for transport to the server. 333848b8605Smrg */ 334848b8605Smrg void (*fillImage) (struct glx_context *, GLint, GLint, GLint, GLint, GLenum, 335848b8605Smrg GLenum, const GLvoid *, GLubyte *, GLubyte *); 336848b8605Smrg 337848b8605Smrg /** 338848b8605Smrg * Client side attribs. 339848b8605Smrg */ 340848b8605Smrg __GLXattributeMachine attributes; 341848b8605Smrg 342848b8605Smrg /** 343848b8605Smrg * Client side error code. This is set when client side gl API 344848b8605Smrg * routines need to set an error because of a bad enumerant or 345848b8605Smrg * running out of memory, etc. 346848b8605Smrg */ 347848b8605Smrg GLenum error; 348848b8605Smrg 349848b8605Smrg /** 350848b8605Smrg * Whether this context does direct rendering. 351848b8605Smrg */ 352848b8605Smrg Bool isDirect; 353848b8605Smrg 354848b8605Smrg#if defined(GLX_DIRECT_RENDERING) && defined(GLX_USE_APPLEGL) 355848b8605Smrg void *driContext; 356848b8605Smrg#endif 357848b8605Smrg 358848b8605Smrg /** 359848b8605Smrg * \c dpy of current display for this context. Will be \c NULL if not 360848b8605Smrg * current to any display, or if this is the "dummy context". 361848b8605Smrg */ 362848b8605Smrg Display *currentDpy; 363848b8605Smrg 364848b8605Smrg /** 365848b8605Smrg * The current drawable for this context. Will be None if this 366848b8605Smrg * context is not current to any drawable. currentReadable is below. 367848b8605Smrg */ 368848b8605Smrg GLXDrawable currentDrawable; 369848b8605Smrg 370848b8605Smrg /** 371848b8605Smrg * \name GL Constant Strings 372848b8605Smrg * 373848b8605Smrg * Constant strings that describe the server implementation 374848b8605Smrg * These pertain to GL attributes, not to be confused with 375848b8605Smrg * GLX versioning attributes. 376848b8605Smrg */ 377848b8605Smrg /*@{ */ 378848b8605Smrg GLubyte *vendor; 379848b8605Smrg GLubyte *renderer; 380848b8605Smrg GLubyte *version; 381848b8605Smrg GLubyte *extensions; 382848b8605Smrg /*@} */ 383848b8605Smrg 384848b8605Smrg /** 385848b8605Smrg * Maximum small render command size. This is the smaller of 64k and 386848b8605Smrg * the size of the above buffer. 387848b8605Smrg */ 388848b8605Smrg GLint maxSmallRenderCommandSize; 389848b8605Smrg 390848b8605Smrg /** 391848b8605Smrg * Major opcode for the extension. Copied here so a lookup isn't 392848b8605Smrg * needed. 393848b8605Smrg */ 394848b8605Smrg GLint majorOpcode; 395848b8605Smrg 396848b8605Smrg /** 397848b8605Smrg * Pointer to the config used to create this context. 398848b8605Smrg */ 399848b8605Smrg struct glx_config *config; 400848b8605Smrg 401848b8605Smrg /** 402848b8605Smrg * The current read-drawable for this context. Will be None if this 403848b8605Smrg * context is not current to any drawable. 404848b8605Smrg * 405848b8605Smrg * \since Internal API version 20030606. 406848b8605Smrg */ 407848b8605Smrg GLXDrawable currentReadable; 408848b8605Smrg 409848b8605Smrg /** 410848b8605Smrg * Pointer to client-state data that is private to libGL. This is only 411848b8605Smrg * used for indirect rendering contexts. 412848b8605Smrg * 413848b8605Smrg * No internal API version change was made for this change. Client-side 414848b8605Smrg * drivers should NEVER use this data or even care that it exists. 415848b8605Smrg */ 416848b8605Smrg void *client_state_private; 417848b8605Smrg 418848b8605Smrg /** 419848b8605Smrg * Stored value for \c glXQueryContext attribute \c GLX_RENDER_TYPE. 420848b8605Smrg */ 421848b8605Smrg int renderType; 422848b8605Smrg 423848b8605Smrg /** 424848b8605Smrg * \name Raw server GL version 425848b8605Smrg * 426848b8605Smrg * True core GL version supported by the server. This is the raw value 427848b8605Smrg * returned by the server, and it may not reflect what is actually 428848b8605Smrg * supported (or reported) by the client-side library. 429848b8605Smrg */ 430848b8605Smrg /*@{ */ 431848b8605Smrg int server_major; /**< Major version number. */ 432848b8605Smrg int server_minor; /**< Minor version number. */ 433848b8605Smrg /*@} */ 434848b8605Smrg 435848b8605Smrg /** 436848b8605Smrg * Number of threads we're currently current in. 437848b8605Smrg */ 438848b8605Smrg unsigned long thread_refcount; 439848b8605Smrg 440b8e80941Smrg /** 441b8e80941Smrg * GLX_ARB_create_context_no_error setting for this context. 442b8e80941Smrg * This needs to be kept here to enforce shared context rules. 443b8e80941Smrg */ 444b8e80941Smrg Bool noError; 445b8e80941Smrg 446848b8605Smrg char gl_extension_bits[__GL_EXT_BYTES]; 447848b8605Smrg}; 448848b8605Smrg 449848b8605Smrgextern Bool 450848b8605Smrgglx_context_init(struct glx_context *gc, 451848b8605Smrg struct glx_screen *psc, struct glx_config *fbconfig); 452848b8605Smrg 453848b8605Smrg#define __glXSetError(gc,code) \ 454848b8605Smrg if (!(gc)->error) { \ 455848b8605Smrg (gc)->error = code; \ 456848b8605Smrg } 457848b8605Smrg 458848b8605Smrgextern void __glFreeAttributeState(struct glx_context *); 459848b8605Smrg 460848b8605Smrg/************************************************************************/ 461848b8605Smrg 462848b8605Smrg/** 463848b8605Smrg * The size of the largest drawing command known to the implementation 464848b8605Smrg * that will use the GLXRender GLX command. In this case it is 465848b8605Smrg * \c glPolygonStipple. 466848b8605Smrg */ 467848b8605Smrg#define __GLX_MAX_SMALL_RENDER_CMD_SIZE 156 468848b8605Smrg 469848b8605Smrg/** 470848b8605Smrg * To keep the implementation fast, the code uses a "limit" pointer 471848b8605Smrg * to determine when the drawing command buffer is too full to hold 472848b8605Smrg * another fixed size command. This constant defines the amount of 473848b8605Smrg * space that must always be available in the drawing command buffer 474848b8605Smrg * at all times for the implementation to work. It is important that 475848b8605Smrg * the number be just large enough, but not so large as to reduce the 476848b8605Smrg * efficacy of the buffer. The "+32" is just to keep the code working 477848b8605Smrg * in case somebody counts wrong. 478848b8605Smrg */ 479848b8605Smrg#define __GLX_BUFFER_LIMIT_SIZE (__GLX_MAX_SMALL_RENDER_CMD_SIZE + 32) 480848b8605Smrg 481848b8605Smrg/** 482848b8605Smrg * This implementation uses a smaller threshold for switching 483848b8605Smrg * to the RenderLarge protocol than the protcol requires so that 484848b8605Smrg * large copies don't occur. 485848b8605Smrg */ 486848b8605Smrg#define __GLX_RENDER_CMD_SIZE_LIMIT 4096 487848b8605Smrg 488848b8605Smrg/** 489848b8605Smrg * One of these records exists per screen of the display. It contains 490848b8605Smrg * a pointer to the config data for that screen (if the screen supports GL). 491848b8605Smrg */ 492848b8605Smrgstruct glx_screen_vtable { 493848b8605Smrg struct glx_context *(*create_context)(struct glx_screen *psc, 494848b8605Smrg struct glx_config *config, 495848b8605Smrg struct glx_context *shareList, 496848b8605Smrg int renderType); 497848b8605Smrg 498848b8605Smrg struct glx_context *(*create_context_attribs)(struct glx_screen *psc, 499848b8605Smrg struct glx_config *config, 500848b8605Smrg struct glx_context *shareList, 501848b8605Smrg unsigned num_attrib, 502848b8605Smrg const uint32_t *attribs, 503848b8605Smrg unsigned *error); 504848b8605Smrg int (*query_renderer_integer)(struct glx_screen *psc, 505848b8605Smrg int attribute, 506848b8605Smrg unsigned int *value); 507848b8605Smrg int (*query_renderer_string)(struct glx_screen *psc, 508848b8605Smrg int attribute, 509848b8605Smrg const char **value); 510848b8605Smrg}; 511848b8605Smrg 512848b8605Smrgstruct glx_screen 513848b8605Smrg{ 514848b8605Smrg const struct glx_screen_vtable *vtable; 515848b8605Smrg 516848b8605Smrg /** 517848b8605Smrg * GLX extension string reported by the X-server. 518848b8605Smrg */ 519848b8605Smrg const char *serverGLXexts; 520848b8605Smrg 521848b8605Smrg /** 522848b8605Smrg * GLX extension string to be reported to applications. This is the 523848b8605Smrg * set of extensions that the application can actually use. 524848b8605Smrg */ 525848b8605Smrg char *effectiveGLXexts; 526848b8605Smrg 527848b8605Smrg struct glx_display *display; 528848b8605Smrg 529848b8605Smrg Display *dpy; 530848b8605Smrg int scr; 531848b8605Smrg 532848b8605Smrg#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) 533848b8605Smrg /** 534848b8605Smrg * Per screen direct rendering interface functions and data. 535848b8605Smrg */ 536848b8605Smrg __GLXDRIscreen *driScreen; 537848b8605Smrg#endif 538848b8605Smrg 539848b8605Smrg /** 540848b8605Smrg * Linked list of glx visuals and fbconfigs for this screen. 541848b8605Smrg */ 542848b8605Smrg struct glx_config *visuals, *configs; 543848b8605Smrg 544848b8605Smrg /** 545848b8605Smrg * Per-screen dynamic GLX extension tracking. The \c direct_support 546848b8605Smrg * field only contains enough bits for 64 extensions. Should libGL 547848b8605Smrg * ever need to track more than 64 GLX extensions, we can safely grow 548848b8605Smrg * this field. The \c struct glx_screen structure is not used outside 549848b8605Smrg * libGL. 550848b8605Smrg */ 551848b8605Smrg /*@{ */ 552848b8605Smrg unsigned char direct_support[8]; 553848b8605Smrg GLboolean ext_list_first_time; 554848b8605Smrg /*@} */ 555848b8605Smrg 556848b8605Smrg}; 557848b8605Smrg 558848b8605Smrg/** 559848b8605Smrg * Per display private data. One of these records exists for each display 560848b8605Smrg * that is using the OpenGL (GLX) extension. 561848b8605Smrg */ 562848b8605Smrgstruct glx_display 563848b8605Smrg{ 564848b8605Smrg /* The extension protocol codes */ 565848b8605Smrg XExtCodes *codes; 566848b8605Smrg struct glx_display *next; 567848b8605Smrg 568848b8605Smrg /** 569848b8605Smrg * Back pointer to the display 570848b8605Smrg */ 571848b8605Smrg Display *dpy; 572848b8605Smrg 573848b8605Smrg /** 574848b8605Smrg * The \c majorOpcode is common to all connections to the same server. 575848b8605Smrg * It is also copied into the context structure. 576848b8605Smrg */ 577848b8605Smrg int majorOpcode; 578848b8605Smrg 579848b8605Smrg /** 580848b8605Smrg * \name Server Version 581848b8605Smrg * 582848b8605Smrg * Major and minor version returned by the server during initialization. 583848b8605Smrg */ 584848b8605Smrg /*@{ */ 585848b8605Smrg int majorVersion, minorVersion; 586848b8605Smrg /*@} */ 587848b8605Smrg 588848b8605Smrg /** 589848b8605Smrg * \name Storage for the servers GLX vendor and versions strings. 590848b8605Smrg * 591848b8605Smrg * These are the same for all screens on this display. These fields will 592848b8605Smrg * be filled in on demand. 593848b8605Smrg */ 594848b8605Smrg /*@{ */ 595848b8605Smrg const char *serverGLXvendor; 596848b8605Smrg const char *serverGLXversion; 597848b8605Smrg /*@} */ 598848b8605Smrg 599848b8605Smrg /** 600848b8605Smrg * Configurations of visuals for all screens on this display. 601848b8605Smrg * Also, per screen data which now includes the server \c GLX_EXTENSION 602848b8605Smrg * string. 603848b8605Smrg */ 604848b8605Smrg struct glx_screen **screens; 605848b8605Smrg 606848b8605Smrg __glxHashTable *glXDrawHash; 607848b8605Smrg 608848b8605Smrg#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) 609848b8605Smrg __glxHashTable *drawHash; 610848b8605Smrg 611848b8605Smrg /** 612848b8605Smrg * Per display direct rendering interface functions and data. 613848b8605Smrg */ 614848b8605Smrg __GLXDRIdisplay *driswDisplay; 615848b8605Smrg __GLXDRIdisplay *driDisplay; 616848b8605Smrg __GLXDRIdisplay *dri2Display; 617848b8605Smrg __GLXDRIdisplay *dri3Display; 618848b8605Smrg#endif 619b8e80941Smrg#ifdef GLX_USE_WINDOWSGL 620b8e80941Smrg __GLXDRIdisplay *windowsdriDisplay; 621b8e80941Smrg#endif 622848b8605Smrg}; 623848b8605Smrg 624848b8605Smrgstruct glx_drawable { 625848b8605Smrg XID xDrawable; 626848b8605Smrg XID drawable; 627848b8605Smrg 628848b8605Smrg uint32_t lastEventSbc; 629848b8605Smrg int64_t eventSbcWrap; 630848b8605Smrg}; 631848b8605Smrg 632848b8605Smrgextern int 633848b8605Smrgglx_screen_init(struct glx_screen *psc, 634848b8605Smrg int screen, struct glx_display * priv); 635848b8605Smrgextern void 636848b8605Smrgglx_screen_cleanup(struct glx_screen *psc); 637848b8605Smrg 638848b8605Smrg#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) 639848b8605Smrgextern __GLXDRIdrawable * 640848b8605Smrgdri2GetGlxDrawableFromXDrawableId(Display *dpy, XID id); 641848b8605Smrg#endif 642848b8605Smrg 643848b8605Smrgextern GLubyte *__glXFlushRenderBuffer(struct glx_context *, GLubyte *); 644848b8605Smrg 645848b8605Smrgextern void __glXSendLargeChunk(struct glx_context * gc, GLint requestNumber, 646848b8605Smrg GLint totalRequests, 647848b8605Smrg const GLvoid * data, GLint dataLen); 648848b8605Smrg 649848b8605Smrgextern void __glXSendLargeCommand(struct glx_context *, const GLvoid *, GLint, 650848b8605Smrg const GLvoid *, GLint); 651848b8605Smrg 652848b8605Smrg/* Initialize the GLX extension for dpy */ 653848b8605Smrgextern struct glx_display *__glXInitialize(Display *); 654848b8605Smrg 655848b8605Smrg/************************************************************************/ 656848b8605Smrg 657848b8605Smrgextern int __glXDebug; 658848b8605Smrg 659848b8605Smrg/* This is per-thread storage in an MT environment */ 660848b8605Smrg 661848b8605Smrgextern void __glXSetCurrentContext(struct glx_context * c); 662848b8605Smrg 663848b8605Smrg# if defined( GLX_USE_TLS ) 664848b8605Smrg 665848b8605Smrgextern __thread void *__glX_tls_Context 666848b8605Smrg __attribute__ ((tls_model("initial-exec"))); 667848b8605Smrg 668b8e80941Smrg#if defined(__NetBSD__) 669b8e80941Smrg# define __glXGetCurrentContext() (likely(__glX_tls_Context) ? __glX_tls_Context : (void*)&dummyContext) 670b8e80941Smrg#else 671848b8605Smrg# define __glXGetCurrentContext() __glX_tls_Context 672b8e80941Smrg#endif 673848b8605Smrg 674848b8605Smrg# else 675848b8605Smrg 676848b8605Smrgextern struct glx_context *__glXGetCurrentContext(void); 677848b8605Smrg 678848b8605Smrg# endif /* defined( GLX_USE_TLS ) */ 679848b8605Smrg 680848b8605Smrgextern void __glXSetCurrentContextNull(void); 681848b8605Smrg 682848b8605Smrg 683848b8605Smrg/* 684848b8605Smrg** Global lock for all threads in this address space using the GLX 685848b8605Smrg** extension 686848b8605Smrg*/ 687848b8605Smrgextern pthread_mutex_t __glXmutex; 688848b8605Smrg#define __glXLock() pthread_mutex_lock(&__glXmutex) 689848b8605Smrg#define __glXUnlock() pthread_mutex_unlock(&__glXmutex) 690848b8605Smrg 691848b8605Smrg/* 692848b8605Smrg** Setup for a command. Initialize the extension for dpy if necessary. 693848b8605Smrg*/ 694848b8605Smrgextern CARD8 __glXSetupForCommand(Display * dpy); 695848b8605Smrg 696848b8605Smrg/************************************************************************/ 697848b8605Smrg 698848b8605Smrg/* 699848b8605Smrg** Data conversion and packing support. 700848b8605Smrg*/ 701848b8605Smrg 702848b8605Smrgextern const GLuint __glXDefaultPixelStore[9]; 703848b8605Smrg 704848b8605Smrg/* Send an image to the server using RenderLarge. */ 705848b8605Smrgextern void __glXSendLargeImage(struct glx_context * gc, GLint compsize, GLint dim, 706848b8605Smrg GLint width, GLint height, GLint depth, 707848b8605Smrg GLenum format, GLenum type, 708848b8605Smrg const GLvoid * src, GLubyte * pc, 709848b8605Smrg GLubyte * modes); 710848b8605Smrg 711848b8605Smrg/* Return the size, in bytes, of some pixel data */ 712848b8605Smrgextern GLint __glImageSize(GLint, GLint, GLint, GLenum, GLenum, GLenum); 713848b8605Smrg 714848b8605Smrg/* Return the number of elements per group of a specified format*/ 715848b8605Smrgextern GLint __glElementsPerGroup(GLenum format, GLenum type); 716848b8605Smrg 717848b8605Smrg/* Return the number of bytes per element, based on the element type (other 718848b8605Smrg** than GL_BITMAP). 719848b8605Smrg*/ 720848b8605Smrgextern GLint __glBytesPerElement(GLenum type); 721848b8605Smrg 722848b8605Smrg/* 723848b8605Smrg** Fill the transport buffer with the data from the users buffer, 724848b8605Smrg** applying some of the pixel store modes (unpack modes) to the data 725848b8605Smrg** first. As a side effect of this call, the "modes" field is 726848b8605Smrg** updated to contain the modes needed by the server to decode the 727848b8605Smrg** sent data. 728848b8605Smrg*/ 729848b8605Smrgextern void __glFillImage(struct glx_context *, GLint, GLint, GLint, GLint, GLenum, 730848b8605Smrg GLenum, const GLvoid *, GLubyte *, GLubyte *); 731848b8605Smrg 732848b8605Smrg/* Copy map data with a stride into a packed buffer */ 733848b8605Smrgextern void __glFillMap1f(GLint, GLint, GLint, const GLfloat *, GLubyte *); 734848b8605Smrgextern void __glFillMap1d(GLint, GLint, GLint, const GLdouble *, GLubyte *); 735848b8605Smrgextern void __glFillMap2f(GLint, GLint, GLint, GLint, GLint, 736848b8605Smrg const GLfloat *, GLfloat *); 737848b8605Smrgextern void __glFillMap2d(GLint, GLint, GLint, GLint, GLint, 738848b8605Smrg const GLdouble *, GLdouble *); 739848b8605Smrg 740848b8605Smrg/* 741848b8605Smrg** Empty an image out of the reply buffer into the clients memory applying 742848b8605Smrg** the pack modes to pack back into the clients requested format. 743848b8605Smrg*/ 744848b8605Smrgextern void __glEmptyImage(struct glx_context *, GLint, GLint, GLint, GLint, GLenum, 745848b8605Smrg GLenum, const GLubyte *, GLvoid *); 746848b8605Smrg 747848b8605Smrg 748848b8605Smrg/* 749848b8605Smrg** Allocate and Initialize Vertex Array client state, and free. 750848b8605Smrg*/ 751848b8605Smrgextern void __glXInitVertexArrayState(struct glx_context *); 752848b8605Smrgextern void __glXFreeVertexArrayState(struct glx_context *); 753848b8605Smrg 754848b8605Smrg/* 755848b8605Smrg** Inform the Server of the major and minor numbers and of the client 756848b8605Smrg** libraries extension string. 757848b8605Smrg*/ 758848b8605Smrgextern void __glXClientInfo(Display * dpy, int opcode); 759848b8605Smrg 760848b8605Smrg_X_HIDDEN void 761848b8605Smrg__glX_send_client_info(struct glx_display *glx_dpy); 762848b8605Smrg 763848b8605Smrg/************************************************************************/ 764848b8605Smrg 765848b8605Smrg/* 766848b8605Smrg** Declarations that should be in Xlib 767848b8605Smrg*/ 768848b8605Smrg#ifdef __GL_USE_OUR_PROTOTYPES 769848b8605Smrgextern void _XFlush(Display *); 770848b8605Smrgextern Status _XReply(Display *, xReply *, int, Bool); 771848b8605Smrgextern void _XRead(Display *, void *, long); 772848b8605Smrgextern void _XSend(Display *, const void *, long); 773848b8605Smrg#endif 774848b8605Smrg 775848b8605Smrg 776848b8605Smrgextern void __glXInitializeVisualConfigFromTags(struct glx_config * config, 777848b8605Smrg int count, const INT32 * bp, 778848b8605Smrg Bool tagged_only, 779848b8605Smrg Bool fbconfig_style_tags); 780848b8605Smrg 781848b8605Smrgextern char *__glXQueryServerString(Display * dpy, int opcode, 782848b8605Smrg CARD32 screen, CARD32 name); 783848b8605Smrgextern char *__glXGetString(Display * dpy, int opcode, 784848b8605Smrg CARD32 screen, CARD32 name); 785848b8605Smrg 786848b8605Smrgextern const char __glXGLClientVersion[]; 787848b8605Smrgextern const char __glXGLClientExtensions[]; 788848b8605Smrg 789848b8605Smrg/* Get the unadjusted system time */ 790848b8605Smrgextern int __glXGetUST(int64_t * ust); 791848b8605Smrg 792848b8605Smrgextern GLboolean __glXGetMscRateOML(Display * dpy, GLXDrawable drawable, 793848b8605Smrg int32_t * numerator, 794848b8605Smrg int32_t * denominator); 795848b8605Smrg 796848b8605Smrg#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) 797848b8605Smrgextern GLboolean 798848b8605Smrg__glxGetMscRate(struct glx_screen *psc, 799848b8605Smrg int32_t * numerator, int32_t * denominator); 800848b8605Smrg 801848b8605Smrg/* So that dri2.c:DRI2WireToEvent() can access 802848b8605Smrg * glx_info->codes->first_event */ 803848b8605SmrgXExtDisplayInfo *__glXFindDisplay (Display *dpy); 804848b8605Smrg 805848b8605Smrgextern void 806848b8605SmrgGarbageCollectDRIDrawables(struct glx_screen *psc); 807848b8605Smrg 808848b8605Smrgextern __GLXDRIdrawable * 809848b8605SmrgGetGLXDRIDrawable(Display *dpy, GLXDrawable drawable); 810848b8605Smrg#endif 811848b8605Smrg 812848b8605Smrgextern struct glx_screen *GetGLXScreenConfigs(Display * dpy, int scrn); 813848b8605Smrg 814848b8605Smrg#ifdef GLX_USE_APPLEGL 815848b8605Smrgextern struct glx_screen * 816848b8605Smrgapplegl_create_screen(int screen, struct glx_display * priv); 817848b8605Smrg 818848b8605Smrgextern struct glx_context * 819848b8605Smrgapplegl_create_context(struct glx_screen *psc, 820848b8605Smrg struct glx_config *mode, 821848b8605Smrg struct glx_context *shareList, int renderType); 822848b8605Smrg 823848b8605Smrgextern int 824848b8605Smrgapplegl_create_display(struct glx_display *display); 825848b8605Smrg#endif 826848b8605Smrg 827848b8605Smrgextern Bool validate_renderType_against_config(const struct glx_config *config, 828848b8605Smrg int renderType); 829848b8605Smrg 830848b8605Smrg 831848b8605Smrgextern struct glx_drawable *GetGLXDrawable(Display *dpy, GLXDrawable drawable); 832848b8605Smrgextern int InitGLXDrawable(Display *dpy, struct glx_drawable *glxDraw, 833848b8605Smrg XID xDrawable, GLXDrawable drawable); 834848b8605Smrgextern void DestroyGLXDrawable(Display *dpy, GLXDrawable drawable); 835848b8605Smrg 836848b8605Smrgextern struct glx_context dummyContext; 837848b8605Smrg 838848b8605Smrgextern struct glx_screen * 839848b8605Smrgindirect_create_screen(int screen, struct glx_display * priv); 840848b8605Smrgextern struct glx_context * 841848b8605Smrgindirect_create_context(struct glx_screen *psc, 842848b8605Smrg struct glx_config *mode, 843848b8605Smrg struct glx_context *shareList, int renderType); 844848b8605Smrgextern struct glx_context * 845848b8605Smrgindirect_create_context_attribs(struct glx_screen *base, 846848b8605Smrg struct glx_config *config_base, 847848b8605Smrg struct glx_context *shareList, 848848b8605Smrg unsigned num_attribs, 849848b8605Smrg const uint32_t *attribs, 850848b8605Smrg unsigned *error); 851848b8605Smrg 852b8e80941Smrg 853b8e80941Smrgextern int __glXGetDrawableAttribute(Display * dpy, GLXDrawable drawable, 854b8e80941Smrg int attribute, unsigned int *value); 855b8e80941Smrg 856b8e80941Smrg#ifdef __cplusplus 857b8e80941Smrg} 858b8e80941Smrg#endif 859b8e80941Smrg 860848b8605Smrg#endif /* !__GLX_client_h__ */ 861