1cdc920a0Smrg/* 2cdc920a0Smrg * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 3cdc920a0Smrg * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. 4cdc920a0Smrg * 5cdc920a0Smrg * Permission is hereby granted, free of charge, to any person obtaining a 6cdc920a0Smrg * copy of this software and associated documentation files (the "Software"), 7cdc920a0Smrg * to deal in the Software without restriction, including without limitation 8cdc920a0Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9cdc920a0Smrg * and/or sell copies of the Software, and to permit persons to whom the 10cdc920a0Smrg * Software is furnished to do so, subject to the following conditions: 11cdc920a0Smrg * 12cdc920a0Smrg * The above copyright notice including the dates of first publication and 13cdc920a0Smrg * either this permission notice or a reference to 14cdc920a0Smrg * http://oss.sgi.com/projects/FreeB/ 15cdc920a0Smrg * shall be included in all copies or substantial portions of the Software. 16cdc920a0Smrg * 17cdc920a0Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18cdc920a0Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19cdc920a0Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20cdc920a0Smrg * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21cdc920a0Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 22cdc920a0Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23cdc920a0Smrg * SOFTWARE. 24cdc920a0Smrg * 25cdc920a0Smrg * Except as contained in this notice, the name of Silicon Graphics, Inc. 26cdc920a0Smrg * shall not be used in advertising or otherwise to promote the sale, use or 27cdc920a0Smrg * other dealings in this Software without prior written authorization from 28cdc920a0Smrg * Silicon Graphics, Inc. 29cdc920a0Smrg */ 30cdc920a0Smrg 31cdc920a0Smrg/** 32cdc920a0Smrg * \file glxclient.h 33cdc920a0Smrg * Direct rendering support added by Precision Insight, Inc. 34cdc920a0Smrg * 35cdc920a0Smrg * \author Kevin E. Martin <kevin@precisioninsight.com> 36cdc920a0Smrg */ 37cdc920a0Smrg 38cdc920a0Smrg#ifndef _GLX_client_h_ 39cdc920a0Smrg#define _GLX_client_h_ 40cdc920a0Smrg#include <X11/Xproto.h> 41cdc920a0Smrg#include <X11/Xlibint.h> 423464ebd5Sriastradh#include <X11/Xfuncproto.h> 43cdc920a0Smrg#include <X11/extensions/extutil.h> 44cdc920a0Smrg#define GLX_GLXEXT_PROTOTYPES 45cdc920a0Smrg#include <GL/glx.h> 46cdc920a0Smrg#include <GL/glxext.h> 47cdc920a0Smrg#include <string.h> 48cdc920a0Smrg#include <stdlib.h> 49cdc920a0Smrg#include <stdio.h> 50cdc920a0Smrg#include <stdint.h> 5101e04c3fSmrg#include <pthread.h> 52cdc920a0Smrg#include "GL/glxproto.h" 533464ebd5Sriastradh#include "glxconfig.h" 54cdc920a0Smrg#include "glxhash.h" 5501e04c3fSmrg#include "util/macros.h" 561463c08dSmrg#include "util/u_thread.h" 571463c08dSmrg#include "loader.h" 58cdc920a0Smrg#include "glxextensions.h" 59cdc920a0Smrg 6001e04c3fSmrg#if defined(USE_LIBGLVND) 6101e04c3fSmrg#define _GLX_PUBLIC _X_HIDDEN 6201e04c3fSmrg#else 6301e04c3fSmrg#define _GLX_PUBLIC _X_EXPORT 6401e04c3fSmrg#endif 6501e04c3fSmrg 6601e04c3fSmrg#ifdef __cplusplus 6701e04c3fSmrgextern "C" { 6801e04c3fSmrg#endif 6901e04c3fSmrg 701463c08dSmrgextern void glx_message(int level, const char *f, ...) PRINTFLIKE(2, 3); 711463c08dSmrg 721463c08dSmrg#define DebugMessageF(...) glx_message(_LOADER_DEBUG, __VA_ARGS__) 731463c08dSmrg#define InfoMessageF(...) glx_message(_LOADER_INFO, __VA_ARGS__) 741463c08dSmrg#define ErrorMessageF(...) glx_message(_LOADER_WARNING, __VA_ARGS__) 751463c08dSmrg#define CriticalErrorMessageF(...) glx_message(_LOADER_FATAL, __VA_ARGS__) 761463c08dSmrg 77cdc920a0Smrg 78cdc920a0Smrg#define GLX_MAJOR_VERSION 1 /* current version numbers */ 79cdc920a0Smrg#define GLX_MINOR_VERSION 4 80cdc920a0Smrg 813464ebd5Sriastradhstruct glx_display; 823464ebd5Sriastradhstruct glx_context; 83cdc920a0Smrg 84cdc920a0Smrg/************************************************************************/ 85cdc920a0Smrg 86cdc920a0Smrg#ifdef GLX_DIRECT_RENDERING 87cdc920a0Smrg 883464ebd5Sriastradhextern void DRI_glXUseXFont(struct glx_context *ctx, 893464ebd5Sriastradh Font font, int first, int count, int listbase); 90cdc920a0Smrg 91cdc920a0Smrg#endif 92cdc920a0Smrg 93cdc920a0Smrg#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) 94cdc920a0Smrg 95cdc920a0Smrg/** 96cdc920a0Smrg * Display dependent methods. This structure is initialized during the 97cdc920a0Smrg * \c driCreateDisplay call. 98cdc920a0Smrg */ 99cdc920a0Smrgtypedef struct __GLXDRIdisplayRec __GLXDRIdisplay; 100cdc920a0Smrgtypedef struct __GLXDRIscreenRec __GLXDRIscreen; 101cdc920a0Smrgtypedef struct __GLXDRIdrawableRec __GLXDRIdrawable; 102cdc920a0Smrg 103cdc920a0Smrgstruct __GLXDRIdisplayRec 104cdc920a0Smrg{ 105cdc920a0Smrg /** 106cdc920a0Smrg * Method to destroy the private DRI display data. 107cdc920a0Smrg */ 108cdc920a0Smrg void (*destroyDisplay) (__GLXDRIdisplay * display); 109cdc920a0Smrg 1103464ebd5Sriastradh struct glx_screen *(*createScreen)(int screen, struct glx_display * priv); 111cdc920a0Smrg}; 112cdc920a0Smrg 113cdc920a0Smrgstruct __GLXDRIscreenRec { 114cdc920a0Smrg 1153464ebd5Sriastradh void (*destroyScreen)(struct glx_screen *psc); 116cdc920a0Smrg 1173464ebd5Sriastradh __GLXDRIdrawable *(*createDrawable)(struct glx_screen *psc, 118cdc920a0Smrg XID drawable, 119cdc920a0Smrg GLXDrawable glxDrawable, 1203464ebd5Sriastradh struct glx_config *config); 121cdc920a0Smrg 122cdc920a0Smrg int64_t (*swapBuffers)(__GLXDRIdrawable *pdraw, int64_t target_msc, 123af69d88dSmrg int64_t divisor, int64_t remainder, Bool flush); 124cdc920a0Smrg void (*copySubBuffer)(__GLXDRIdrawable *pdraw, 125af69d88dSmrg int x, int y, int width, int height, Bool flush); 1263464ebd5Sriastradh int (*getDrawableMSC)(struct glx_screen *psc, __GLXDRIdrawable *pdraw, 127cdc920a0Smrg int64_t *ust, int64_t *msc, int64_t *sbc); 128cdc920a0Smrg int (*waitForMSC)(__GLXDRIdrawable *pdraw, int64_t target_msc, 129cdc920a0Smrg int64_t divisor, int64_t remainder, int64_t *ust, 130cdc920a0Smrg int64_t *msc, int64_t *sbc); 131cdc920a0Smrg int (*waitForSBC)(__GLXDRIdrawable *pdraw, int64_t target_sbc, int64_t *ust, 132cdc920a0Smrg int64_t *msc, int64_t *sbc); 1333464ebd5Sriastradh int (*setSwapInterval)(__GLXDRIdrawable *pdraw, int interval); 134cdc920a0Smrg int (*getSwapInterval)(__GLXDRIdrawable *pdraw); 135af69d88dSmrg int (*getBufferAge)(__GLXDRIdrawable *pdraw); 1361463c08dSmrg void (*bindTexImage)(__GLXDRIdrawable *pdraw, int buffer, const int *attribs); 1371463c08dSmrg void (*releaseTexImage)(__GLXDRIdrawable *pdraw, int buffer); 138cdc920a0Smrg}; 139cdc920a0Smrg 140cdc920a0Smrgstruct __GLXDRIdrawableRec 141cdc920a0Smrg{ 142cdc920a0Smrg void (*destroyDrawable) (__GLXDRIdrawable * drawable); 143cdc920a0Smrg 144cdc920a0Smrg XID xDrawable; 145cdc920a0Smrg XID drawable; 1463464ebd5Sriastradh struct glx_screen *psc; 147cdc920a0Smrg GLenum textureTarget; 148cdc920a0Smrg GLenum textureFormat; /* EXT_texture_from_pixmap support */ 1493464ebd5Sriastradh unsigned long eventMask; 1503464ebd5Sriastradh int refcount; 151cdc920a0Smrg}; 152cdc920a0Smrg 153cdc920a0Smrg/* 154cdc920a0Smrg** Function to create and DRI display data and initialize the display 155cdc920a0Smrg** dependent methods. 156cdc920a0Smrg*/ 157cdc920a0Smrgextern __GLXDRIdisplay *driswCreateDisplay(Display * dpy); 158cdc920a0Smrgextern __GLXDRIdisplay *dri2CreateDisplay(Display * dpy); 15901e04c3fSmrgextern __GLXDRIdisplay *dri3_create_display(Display * dpy); 16001e04c3fSmrgextern __GLXDRIdisplay *driwindowsCreateDisplay(Display * dpy); 16101e04c3fSmrg 16201e04c3fSmrg/* 16301e04c3fSmrg** 16401e04c3fSmrg*/ 165cdc920a0Smrgextern void dri2InvalidateBuffers(Display *dpy, XID drawable); 1663464ebd5Sriastradhextern unsigned dri2GetSwapEventType(Display *dpy, XID drawable); 167cdc920a0Smrg 168cdc920a0Smrg/* 169cdc920a0Smrg** Functions to obtain driver configuration information from a direct 170cdc920a0Smrg** rendering client application 171cdc920a0Smrg*/ 172cdc920a0Smrgextern const char *glXGetScreenDriver(Display * dpy, int scrNum); 173cdc920a0Smrg 174cdc920a0Smrgextern const char *glXGetDriverConfig(const char *driverName); 175cdc920a0Smrg 176cdc920a0Smrg#endif 177cdc920a0Smrg 178cdc920a0Smrg/************************************************************************/ 179cdc920a0Smrg 180cdc920a0Smrg#define __GL_CLIENT_ATTRIB_STACK_DEPTH 16 181cdc920a0Smrg 182cdc920a0Smrgtypedef struct __GLXpixelStoreModeRec 183cdc920a0Smrg{ 184cdc920a0Smrg GLboolean swapEndian; 185cdc920a0Smrg GLboolean lsbFirst; 186cdc920a0Smrg GLuint rowLength; 187cdc920a0Smrg GLuint imageHeight; 188cdc920a0Smrg GLuint imageDepth; 189cdc920a0Smrg GLuint skipRows; 190cdc920a0Smrg GLuint skipPixels; 191cdc920a0Smrg GLuint skipImages; 192cdc920a0Smrg GLuint alignment; 193cdc920a0Smrg} __GLXpixelStoreMode; 194cdc920a0Smrg 195cdc920a0Smrg 196cdc920a0Smrgtypedef struct __GLXattributeRec 197cdc920a0Smrg{ 198cdc920a0Smrg GLuint mask; 199cdc920a0Smrg 200cdc920a0Smrg /** 201cdc920a0Smrg * Pixel storage state. Most of the pixel store mode state is kept 202cdc920a0Smrg * here and used by the client code to manage the packing and 203cdc920a0Smrg * unpacking of data sent to/received from the server. 204cdc920a0Smrg */ 205cdc920a0Smrg __GLXpixelStoreMode storePack, storeUnpack; 206cdc920a0Smrg 207cdc920a0Smrg /** 208cdc920a0Smrg * Is EXT_vertex_array / GL 1.1 DrawArrays protocol specifically 209cdc920a0Smrg * disabled? 210cdc920a0Smrg */ 211cdc920a0Smrg GLboolean NoDrawArraysProtocol; 212cdc920a0Smrg 213cdc920a0Smrg /** 214cdc920a0Smrg * Vertex Array storage state. The vertex array component 215cdc920a0Smrg * state is stored here and is used to manage the packing of 216cdc920a0Smrg * DrawArrays data sent to the server. 217cdc920a0Smrg */ 218cdc920a0Smrg struct array_state_vector *array_state; 219cdc920a0Smrg} __GLXattribute; 220cdc920a0Smrg 221cdc920a0Smrgtypedef struct __GLXattributeMachineRec 222cdc920a0Smrg{ 223cdc920a0Smrg __GLXattribute *stack[__GL_CLIENT_ATTRIB_STACK_DEPTH]; 224cdc920a0Smrg __GLXattribute **stackPointer; 225cdc920a0Smrg} __GLXattributeMachine; 226cdc920a0Smrg 22701e04c3fSmrgstruct mesa_glinterop_device_info; 22801e04c3fSmrgstruct mesa_glinterop_export_in; 22901e04c3fSmrgstruct mesa_glinterop_export_out; 23001e04c3fSmrg 2313464ebd5Sriastradhstruct glx_context_vtable { 2323464ebd5Sriastradh void (*destroy)(struct glx_context *ctx); 2333464ebd5Sriastradh int (*bind)(struct glx_context *context, struct glx_context *old, 2343464ebd5Sriastradh GLXDrawable draw, GLXDrawable read); 235af69d88dSmrg void (*unbind)(struct glx_context *context, struct glx_context *new_ctx); 2363464ebd5Sriastradh void (*wait_gl)(struct glx_context *ctx); 2373464ebd5Sriastradh void (*wait_x)(struct glx_context *ctx); 23801e04c3fSmrg int (*interop_query_device_info)(struct glx_context *ctx, 23901e04c3fSmrg struct mesa_glinterop_device_info *out); 24001e04c3fSmrg int (*interop_export_object)(struct glx_context *ctx, 24101e04c3fSmrg struct mesa_glinterop_export_in *in, 24201e04c3fSmrg struct mesa_glinterop_export_out *out); 2433464ebd5Sriastradh}; 2443464ebd5Sriastradh 245cdc920a0Smrg/** 246cdc920a0Smrg * GLX state that needs to be kept on the client. One of these records 247cdc920a0Smrg * exist for each context that has been made current by this client. 248cdc920a0Smrg */ 2493464ebd5Sriastradhstruct glx_context 250cdc920a0Smrg{ 251cdc920a0Smrg /** 252cdc920a0Smrg * \name Drawing command buffer. 253cdc920a0Smrg * 254cdc920a0Smrg * Drawing commands are packed into this buffer before being sent as a 255cdc920a0Smrg * single GLX protocol request. The buffer is sent when it overflows or 256cdc920a0Smrg * is flushed by \c __glXFlushRenderBuffer. \c pc is the next location 257cdc920a0Smrg * in the buffer to be filled. \c limit is described above in the buffer 258cdc920a0Smrg * slop discussion. 259cdc920a0Smrg * 260cdc920a0Smrg * Commands that require large amounts of data to be transfered will 261cdc920a0Smrg * also use this buffer to hold a header that describes the large 262cdc920a0Smrg * command. 263cdc920a0Smrg * 264cdc920a0Smrg * These must be the first 6 fields since they are static initialized 265cdc920a0Smrg * in the dummy context in glxext.c 266cdc920a0Smrg */ 267cdc920a0Smrg /*@{ */ 268cdc920a0Smrg GLubyte *buf; 269cdc920a0Smrg GLubyte *pc; 270cdc920a0Smrg GLubyte *limit; 271cdc920a0Smrg GLubyte *bufEnd; 272cdc920a0Smrg GLint bufSize; 273cdc920a0Smrg /*@} */ 274cdc920a0Smrg 2753464ebd5Sriastradh const struct glx_context_vtable *vtable; 2763464ebd5Sriastradh 277cdc920a0Smrg /** 278cdc920a0Smrg * The XID of this rendering context. When the context is created a 279cdc920a0Smrg * new XID is allocated. This is set to None when the context is 280cdc920a0Smrg * destroyed but is still current to some thread. In this case the 281cdc920a0Smrg * context will be freed on next MakeCurrent. 282cdc920a0Smrg */ 283cdc920a0Smrg XID xid; 284cdc920a0Smrg 285cdc920a0Smrg /** 286cdc920a0Smrg * The XID of the \c shareList context. 287cdc920a0Smrg */ 288cdc920a0Smrg XID share_xid; 289cdc920a0Smrg 290cdc920a0Smrg /** 291cdc920a0Smrg * Screen number. 292cdc920a0Smrg */ 293cdc920a0Smrg GLint screen; 2943464ebd5Sriastradh struct glx_screen *psc; 295cdc920a0Smrg 296cdc920a0Smrg /** 297cdc920a0Smrg * \c GL_TRUE if the context was created with ImportContext, which 298cdc920a0Smrg * means the server-side context was created by another X client. 299cdc920a0Smrg */ 300cdc920a0Smrg GLboolean imported; 301cdc920a0Smrg 302cdc920a0Smrg /** 303cdc920a0Smrg * The context tag returned by MakeCurrent when this context is made 304cdc920a0Smrg * current. This tag is used to identify the context that a thread has 305cdc920a0Smrg * current so that proper server context management can be done. It is 306cdc920a0Smrg * used for all context specific commands (i.e., \c Render, \c RenderLarge, 307cdc920a0Smrg * \c WaitX, \c WaitGL, \c UseXFont, and \c MakeCurrent (for the old 308cdc920a0Smrg * context)). 309cdc920a0Smrg */ 310cdc920a0Smrg GLXContextTag currentContextTag; 311cdc920a0Smrg 312cdc920a0Smrg /** 313cdc920a0Smrg * \name Rendering mode 314cdc920a0Smrg * 315cdc920a0Smrg * The rendering mode is kept on the client as well as the server. 316cdc920a0Smrg * When \c glRenderMode is called, the buffer associated with the 317cdc920a0Smrg * previous rendering mode (feedback or select) is filled. 318cdc920a0Smrg */ 319cdc920a0Smrg /*@{ */ 320cdc920a0Smrg GLenum renderMode; 321cdc920a0Smrg GLfloat *feedbackBuf; 322cdc920a0Smrg GLuint *selectBuf; 323cdc920a0Smrg /*@} */ 324cdc920a0Smrg 325cdc920a0Smrg /** 326cdc920a0Smrg * Client side attribs. 327cdc920a0Smrg */ 328cdc920a0Smrg __GLXattributeMachine attributes; 329cdc920a0Smrg 330cdc920a0Smrg /** 331cdc920a0Smrg * Client side error code. This is set when client side gl API 332cdc920a0Smrg * routines need to set an error because of a bad enumerant or 333cdc920a0Smrg * running out of memory, etc. 334cdc920a0Smrg */ 335cdc920a0Smrg GLenum error; 336cdc920a0Smrg 337cdc920a0Smrg /** 338cdc920a0Smrg * Whether this context does direct rendering. 339cdc920a0Smrg */ 340cdc920a0Smrg Bool isDirect; 341cdc920a0Smrg 3423464ebd5Sriastradh#if defined(GLX_DIRECT_RENDERING) && defined(GLX_USE_APPLEGL) 3433464ebd5Sriastradh void *driContext; 3443464ebd5Sriastradh#endif 3453464ebd5Sriastradh 346cdc920a0Smrg /** 347cdc920a0Smrg * \c dpy of current display for this context. Will be \c NULL if not 348cdc920a0Smrg * current to any display, or if this is the "dummy context". 349cdc920a0Smrg */ 350cdc920a0Smrg Display *currentDpy; 351cdc920a0Smrg 352cdc920a0Smrg /** 353cdc920a0Smrg * The current drawable for this context. Will be None if this 354cdc920a0Smrg * context is not current to any drawable. currentReadable is below. 355cdc920a0Smrg */ 356cdc920a0Smrg GLXDrawable currentDrawable; 357cdc920a0Smrg 358cdc920a0Smrg /** 359cdc920a0Smrg * \name GL Constant Strings 360cdc920a0Smrg * 361cdc920a0Smrg * Constant strings that describe the server implementation 362cdc920a0Smrg * These pertain to GL attributes, not to be confused with 363cdc920a0Smrg * GLX versioning attributes. 364cdc920a0Smrg */ 365cdc920a0Smrg /*@{ */ 366cdc920a0Smrg GLubyte *vendor; 367cdc920a0Smrg GLubyte *renderer; 368cdc920a0Smrg GLubyte *version; 369cdc920a0Smrg GLubyte *extensions; 370cdc920a0Smrg /*@} */ 371cdc920a0Smrg 372cdc920a0Smrg /** 373cdc920a0Smrg * Maximum small render command size. This is the smaller of 64k and 374cdc920a0Smrg * the size of the above buffer. 375cdc920a0Smrg */ 376cdc920a0Smrg GLint maxSmallRenderCommandSize; 377cdc920a0Smrg 378cdc920a0Smrg /** 379cdc920a0Smrg * Major opcode for the extension. Copied here so a lookup isn't 380cdc920a0Smrg * needed. 381cdc920a0Smrg */ 382cdc920a0Smrg GLint majorOpcode; 383cdc920a0Smrg 384cdc920a0Smrg /** 3853464ebd5Sriastradh * Pointer to the config used to create this context. 386cdc920a0Smrg */ 3873464ebd5Sriastradh struct glx_config *config; 388cdc920a0Smrg 389cdc920a0Smrg /** 390cdc920a0Smrg * The current read-drawable for this context. Will be None if this 391cdc920a0Smrg * context is not current to any drawable. 392cdc920a0Smrg * 393cdc920a0Smrg * \since Internal API version 20030606. 394cdc920a0Smrg */ 395cdc920a0Smrg GLXDrawable currentReadable; 396cdc920a0Smrg 397cdc920a0Smrg /** 398cdc920a0Smrg * Pointer to client-state data that is private to libGL. This is only 399cdc920a0Smrg * used for indirect rendering contexts. 400cdc920a0Smrg * 401cdc920a0Smrg * No internal API version change was made for this change. Client-side 402cdc920a0Smrg * drivers should NEVER use this data or even care that it exists. 403cdc920a0Smrg */ 404cdc920a0Smrg void *client_state_private; 405cdc920a0Smrg 406cdc920a0Smrg /** 407cdc920a0Smrg * Stored value for \c glXQueryContext attribute \c GLX_RENDER_TYPE. 408cdc920a0Smrg */ 409cdc920a0Smrg int renderType; 410cdc920a0Smrg 411cdc920a0Smrg /** 412cdc920a0Smrg * \name Raw server GL version 413cdc920a0Smrg * 414cdc920a0Smrg * True core GL version supported by the server. This is the raw value 415cdc920a0Smrg * returned by the server, and it may not reflect what is actually 416cdc920a0Smrg * supported (or reported) by the client-side library. 417cdc920a0Smrg */ 418cdc920a0Smrg /*@{ */ 419cdc920a0Smrg int server_major; /**< Major version number. */ 420cdc920a0Smrg int server_minor; /**< Minor version number. */ 421cdc920a0Smrg /*@} */ 422cdc920a0Smrg 423cdc920a0Smrg /** 4243464ebd5Sriastradh * Number of threads we're currently current in. 425cdc920a0Smrg */ 4263464ebd5Sriastradh unsigned long thread_refcount; 427cdc920a0Smrg 428d8407755Smaya /** 429d8407755Smaya * GLX_ARB_create_context_no_error setting for this context. 430d8407755Smaya * This needs to be kept here to enforce shared context rules. 431d8407755Smaya */ 432d8407755Smaya Bool noError; 433d8407755Smaya 434cdc920a0Smrg char gl_extension_bits[__GL_EXT_BYTES]; 435cdc920a0Smrg}; 436cdc920a0Smrg 4373464ebd5Sriastradhextern Bool 4383464ebd5Sriastradhglx_context_init(struct glx_context *gc, 4393464ebd5Sriastradh struct glx_screen *psc, struct glx_config *fbconfig); 4403464ebd5Sriastradh 441cdc920a0Smrg#define __glXSetError(gc,code) \ 442cdc920a0Smrg if (!(gc)->error) { \ 443cdc920a0Smrg (gc)->error = code; \ 444cdc920a0Smrg } 445cdc920a0Smrg 446cdc920a0Smrg/************************************************************************/ 447cdc920a0Smrg 448cdc920a0Smrg/** 449cdc920a0Smrg * The size of the largest drawing command known to the implementation 450cdc920a0Smrg * that will use the GLXRender GLX command. In this case it is 451cdc920a0Smrg * \c glPolygonStipple. 452cdc920a0Smrg */ 453cdc920a0Smrg#define __GLX_MAX_SMALL_RENDER_CMD_SIZE 156 454cdc920a0Smrg 455cdc920a0Smrg/** 456cdc920a0Smrg * To keep the implementation fast, the code uses a "limit" pointer 457cdc920a0Smrg * to determine when the drawing command buffer is too full to hold 458cdc920a0Smrg * another fixed size command. This constant defines the amount of 459cdc920a0Smrg * space that must always be available in the drawing command buffer 460cdc920a0Smrg * at all times for the implementation to work. It is important that 461cdc920a0Smrg * the number be just large enough, but not so large as to reduce the 462cdc920a0Smrg * efficacy of the buffer. The "+32" is just to keep the code working 463cdc920a0Smrg * in case somebody counts wrong. 464cdc920a0Smrg */ 465cdc920a0Smrg#define __GLX_BUFFER_LIMIT_SIZE (__GLX_MAX_SMALL_RENDER_CMD_SIZE + 32) 466cdc920a0Smrg 467cdc920a0Smrg/** 468cdc920a0Smrg * This implementation uses a smaller threshold for switching 469cdc920a0Smrg * to the RenderLarge protocol than the protcol requires so that 470cdc920a0Smrg * large copies don't occur. 471cdc920a0Smrg */ 472cdc920a0Smrg#define __GLX_RENDER_CMD_SIZE_LIMIT 4096 473cdc920a0Smrg 474cdc920a0Smrg/** 475cdc920a0Smrg * One of these records exists per screen of the display. It contains 476cdc920a0Smrg * a pointer to the config data for that screen (if the screen supports GL). 477cdc920a0Smrg */ 4783464ebd5Sriastradhstruct glx_screen_vtable { 4793464ebd5Sriastradh struct glx_context *(*create_context)(struct glx_screen *psc, 4803464ebd5Sriastradh struct glx_config *config, 4813464ebd5Sriastradh struct glx_context *shareList, 4823464ebd5Sriastradh int renderType); 483af69d88dSmrg 484af69d88dSmrg struct glx_context *(*create_context_attribs)(struct glx_screen *psc, 485af69d88dSmrg struct glx_config *config, 486af69d88dSmrg struct glx_context *shareList, 487af69d88dSmrg unsigned num_attrib, 488af69d88dSmrg const uint32_t *attribs, 489af69d88dSmrg unsigned *error); 490af69d88dSmrg int (*query_renderer_integer)(struct glx_screen *psc, 491af69d88dSmrg int attribute, 492af69d88dSmrg unsigned int *value); 493af69d88dSmrg int (*query_renderer_string)(struct glx_screen *psc, 494af69d88dSmrg int attribute, 495af69d88dSmrg const char **value); 4961463c08dSmrg 4971463c08dSmrg char *(*get_driver_name)(struct glx_screen *psc); 4983464ebd5Sriastradh}; 4993464ebd5Sriastradh 5003464ebd5Sriastradhstruct glx_screen 501cdc920a0Smrg{ 5023464ebd5Sriastradh const struct glx_screen_vtable *vtable; 5031463c08dSmrg const struct glx_context_vtable *context_vtable; 5043464ebd5Sriastradh 505cdc920a0Smrg /** 5061463c08dSmrg * \name Storage for the GLX vendor, version, and extension strings 507cdc920a0Smrg */ 5081463c08dSmrg /*@{ */ 509cdc920a0Smrg const char *serverGLXexts; 5101463c08dSmrg const char *serverGLXvendor; 5111463c08dSmrg const char *serverGLXversion; 5121463c08dSmrg /*@} */ 513cdc920a0Smrg 514cdc920a0Smrg /** 515cdc920a0Smrg * GLX extension string to be reported to applications. This is the 516cdc920a0Smrg * set of extensions that the application can actually use. 517cdc920a0Smrg */ 518cdc920a0Smrg char *effectiveGLXexts; 519cdc920a0Smrg 5203464ebd5Sriastradh struct glx_display *display; 5213464ebd5Sriastradh 5223464ebd5Sriastradh Display *dpy; 5233464ebd5Sriastradh int scr; 5243464ebd5Sriastradh 525cdc920a0Smrg#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) 526cdc920a0Smrg /** 527cdc920a0Smrg * Per screen direct rendering interface functions and data. 528cdc920a0Smrg */ 529cdc920a0Smrg __GLXDRIscreen *driScreen; 530cdc920a0Smrg#endif 531cdc920a0Smrg 532cdc920a0Smrg /** 533cdc920a0Smrg * Linked list of glx visuals and fbconfigs for this screen. 534cdc920a0Smrg */ 5353464ebd5Sriastradh struct glx_config *visuals, *configs; 536cdc920a0Smrg 537cdc920a0Smrg /** 538cdc920a0Smrg * Per-screen dynamic GLX extension tracking. The \c direct_support 539cdc920a0Smrg * field only contains enough bits for 64 extensions. Should libGL 540cdc920a0Smrg * ever need to track more than 64 GLX extensions, we can safely grow 5413464ebd5Sriastradh * this field. The \c struct glx_screen structure is not used outside 542cdc920a0Smrg * libGL. 543cdc920a0Smrg */ 544cdc920a0Smrg /*@{ */ 5451463c08dSmrg unsigned char direct_support[__GLX_EXT_BYTES]; 546cdc920a0Smrg GLboolean ext_list_first_time; 5471463c08dSmrg 5481463c08dSmrg unsigned char glx_force_enabled[__GLX_EXT_BYTES]; 5491463c08dSmrg unsigned char glx_force_disabled[__GLX_EXT_BYTES]; 5501463c08dSmrg 5511463c08dSmrg unsigned char gl_force_enabled[__GL_EXT_BYTES]; 5521463c08dSmrg unsigned char gl_force_disabled[__GL_EXT_BYTES]; 553cdc920a0Smrg /*@} */ 554cdc920a0Smrg 555cdc920a0Smrg}; 556cdc920a0Smrg 557cdc920a0Smrg/** 558cdc920a0Smrg * Per display private data. One of these records exists for each display 559cdc920a0Smrg * that is using the OpenGL (GLX) extension. 560cdc920a0Smrg */ 5613464ebd5Sriastradhstruct glx_display 562cdc920a0Smrg{ 5633464ebd5Sriastradh struct glx_display *next; 5643464ebd5Sriastradh 5651463c08dSmrg /* The extension protocol codes */ 5661463c08dSmrg XExtCodes codes; 5671463c08dSmrg 568cdc920a0Smrg /** 569cdc920a0Smrg * Back pointer to the display 570cdc920a0Smrg */ 571cdc920a0Smrg Display *dpy; 572cdc920a0Smrg 573cdc920a0Smrg /** 5741463c08dSmrg * \name Minor Version 575cdc920a0Smrg * 5761463c08dSmrg * Minor version returned by the server during initialization. The major 5771463c08dSmrg * version is asserted to be 1 during extension setup. 578cdc920a0Smrg */ 579cdc920a0Smrg /*@{ */ 5801463c08dSmrg int minorVersion; 581cdc920a0Smrg /*@} */ 582cdc920a0Smrg 583cdc920a0Smrg /** 584cdc920a0Smrg * Configurations of visuals for all screens on this display. 585cdc920a0Smrg * Also, per screen data which now includes the server \c GLX_EXTENSION 586cdc920a0Smrg * string. 587cdc920a0Smrg */ 5883464ebd5Sriastradh struct glx_screen **screens; 589cdc920a0Smrg 590af69d88dSmrg __glxHashTable *glXDrawHash; 591af69d88dSmrg 592cdc920a0Smrg#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) 5933464ebd5Sriastradh __glxHashTable *drawHash; 5943464ebd5Sriastradh 595cdc920a0Smrg /** 596cdc920a0Smrg * Per display direct rendering interface functions and data. 597cdc920a0Smrg */ 598cdc920a0Smrg __GLXDRIdisplay *driswDisplay; 599cdc920a0Smrg __GLXDRIdisplay *dri2Display; 600af69d88dSmrg __GLXDRIdisplay *dri3Display; 601cdc920a0Smrg#endif 60201e04c3fSmrg#ifdef GLX_USE_WINDOWSGL 60301e04c3fSmrg __GLXDRIdisplay *windowsdriDisplay; 60401e04c3fSmrg#endif 605cdc920a0Smrg}; 606cdc920a0Smrg 607af69d88dSmrgstruct glx_drawable { 608af69d88dSmrg XID xDrawable; 609af69d88dSmrg XID drawable; 610af69d88dSmrg 611af69d88dSmrg uint32_t lastEventSbc; 612af69d88dSmrg int64_t eventSbcWrap; 613af69d88dSmrg}; 614af69d88dSmrg 6153464ebd5Sriastradhextern int 6163464ebd5Sriastradhglx_screen_init(struct glx_screen *psc, 6173464ebd5Sriastradh int screen, struct glx_display * priv); 6183464ebd5Sriastradhextern void 6193464ebd5Sriastradhglx_screen_cleanup(struct glx_screen *psc); 620cdc920a0Smrg 6213464ebd5Sriastradh#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) 6223464ebd5Sriastradhextern __GLXDRIdrawable * 6233464ebd5Sriastradhdri2GetGlxDrawableFromXDrawableId(Display *dpy, XID id); 6243464ebd5Sriastradh#endif 625cdc920a0Smrg 6263464ebd5Sriastradhextern GLubyte *__glXFlushRenderBuffer(struct glx_context *, GLubyte *); 6273464ebd5Sriastradh 6283464ebd5Sriastradhextern void __glXSendLargeChunk(struct glx_context * gc, GLint requestNumber, 629cdc920a0Smrg GLint totalRequests, 630cdc920a0Smrg const GLvoid * data, GLint dataLen); 631cdc920a0Smrg 6323464ebd5Sriastradhextern void __glXSendLargeCommand(struct glx_context *, const GLvoid *, GLint, 633cdc920a0Smrg const GLvoid *, GLint); 634cdc920a0Smrg 635cdc920a0Smrg/* Initialize the GLX extension for dpy */ 6363464ebd5Sriastradhextern struct glx_display *__glXInitialize(Display *); 637cdc920a0Smrg 638cdc920a0Smrg/************************************************************************/ 639cdc920a0Smrg 640cdc920a0Smrgextern int __glXDebug; 641cdc920a0Smrg 642cdc920a0Smrg/* This is per-thread storage in an MT environment */ 643cdc920a0Smrg 6443464ebd5Sriastradhextern void __glXSetCurrentContext(struct glx_context * c); 645cdc920a0Smrg 6461463c08dSmrg# if defined( USE_ELF_TLS ) 647cdc920a0Smrg 6481463c08dSmrgextern __THREAD_INITIAL_EXEC void *__glX_tls_Context; 649cdc920a0Smrg 650e81a0f50Smaya#if defined(__NetBSD__) 651e81a0f50Smaya# define __glXGetCurrentContext() (likely(__glX_tls_Context) ? __glX_tls_Context : (void*)&dummyContext) 652e81a0f50Smaya#else 653cdc920a0Smrg# define __glXGetCurrentContext() __glX_tls_Context 654e81a0f50Smaya#endif 655cdc920a0Smrg 656cdc920a0Smrg# else 657cdc920a0Smrg 6583464ebd5Sriastradhextern struct glx_context *__glXGetCurrentContext(void); 659cdc920a0Smrg 6601463c08dSmrg# endif /* defined( USE_ELF_TLS ) */ 661cdc920a0Smrg 662cdc920a0Smrgextern void __glXSetCurrentContextNull(void); 663cdc920a0Smrg 664cdc920a0Smrg 665cdc920a0Smrg/* 666cdc920a0Smrg** Global lock for all threads in this address space using the GLX 667cdc920a0Smrg** extension 668cdc920a0Smrg*/ 669cdc920a0Smrgextern pthread_mutex_t __glXmutex; 670cdc920a0Smrg#define __glXLock() pthread_mutex_lock(&__glXmutex) 671cdc920a0Smrg#define __glXUnlock() pthread_mutex_unlock(&__glXmutex) 672cdc920a0Smrg 673cdc920a0Smrg/* 674cdc920a0Smrg** Setup for a command. Initialize the extension for dpy if necessary. 675cdc920a0Smrg*/ 676cdc920a0Smrgextern CARD8 __glXSetupForCommand(Display * dpy); 677cdc920a0Smrg 678cdc920a0Smrg/************************************************************************/ 679cdc920a0Smrg 680cdc920a0Smrg/* 681cdc920a0Smrg** Data conversion and packing support. 682cdc920a0Smrg*/ 683cdc920a0Smrg 684cdc920a0Smrgextern const GLuint __glXDefaultPixelStore[9]; 685cdc920a0Smrg 686cdc920a0Smrg/* Send an image to the server using RenderLarge. */ 6873464ebd5Sriastradhextern void __glXSendLargeImage(struct glx_context * gc, GLint compsize, GLint dim, 688cdc920a0Smrg GLint width, GLint height, GLint depth, 689cdc920a0Smrg GLenum format, GLenum type, 690cdc920a0Smrg const GLvoid * src, GLubyte * pc, 691cdc920a0Smrg GLubyte * modes); 692cdc920a0Smrg 693cdc920a0Smrg/* Return the size, in bytes, of some pixel data */ 694cdc920a0Smrgextern GLint __glImageSize(GLint, GLint, GLint, GLenum, GLenum, GLenum); 695cdc920a0Smrg 696cdc920a0Smrg/* Return the number of elements per group of a specified format*/ 697cdc920a0Smrgextern GLint __glElementsPerGroup(GLenum format, GLenum type); 698cdc920a0Smrg 699cdc920a0Smrg/* Return the number of bytes per element, based on the element type (other 700cdc920a0Smrg** than GL_BITMAP). 701cdc920a0Smrg*/ 702cdc920a0Smrgextern GLint __glBytesPerElement(GLenum type); 703cdc920a0Smrg 704cdc920a0Smrg/* 705cdc920a0Smrg** Fill the transport buffer with the data from the users buffer, 706cdc920a0Smrg** applying some of the pixel store modes (unpack modes) to the data 707cdc920a0Smrg** first. As a side effect of this call, the "modes" field is 708cdc920a0Smrg** updated to contain the modes needed by the server to decode the 709cdc920a0Smrg** sent data. 710cdc920a0Smrg*/ 7113464ebd5Sriastradhextern void __glFillImage(struct glx_context *, GLint, GLint, GLint, GLint, GLenum, 712cdc920a0Smrg GLenum, const GLvoid *, GLubyte *, GLubyte *); 713cdc920a0Smrg 714cdc920a0Smrg/* Copy map data with a stride into a packed buffer */ 715cdc920a0Smrgextern void __glFillMap1f(GLint, GLint, GLint, const GLfloat *, GLubyte *); 716cdc920a0Smrgextern void __glFillMap1d(GLint, GLint, GLint, const GLdouble *, GLubyte *); 717cdc920a0Smrgextern void __glFillMap2f(GLint, GLint, GLint, GLint, GLint, 718cdc920a0Smrg const GLfloat *, GLfloat *); 719cdc920a0Smrgextern void __glFillMap2d(GLint, GLint, GLint, GLint, GLint, 720cdc920a0Smrg const GLdouble *, GLdouble *); 721cdc920a0Smrg 722cdc920a0Smrg/* 723cdc920a0Smrg** Empty an image out of the reply buffer into the clients memory applying 724cdc920a0Smrg** the pack modes to pack back into the clients requested format. 725cdc920a0Smrg*/ 7263464ebd5Sriastradhextern void __glEmptyImage(struct glx_context *, GLint, GLint, GLint, GLint, GLenum, 727cdc920a0Smrg GLenum, const GLubyte *, GLvoid *); 728cdc920a0Smrg 729cdc920a0Smrg 730cdc920a0Smrg/* 731cdc920a0Smrg** Allocate and Initialize Vertex Array client state, and free. 732cdc920a0Smrg*/ 7333464ebd5Sriastradhextern void __glXInitVertexArrayState(struct glx_context *); 7343464ebd5Sriastradhextern void __glXFreeVertexArrayState(struct glx_context *); 735cdc920a0Smrg 736af69d88dSmrg_X_HIDDEN void 737af69d88dSmrg__glX_send_client_info(struct glx_display *glx_dpy); 738af69d88dSmrg 739cdc920a0Smrg/************************************************************************/ 740cdc920a0Smrg 7413464ebd5Sriastradhextern void __glXInitializeVisualConfigFromTags(struct glx_config * config, 742cdc920a0Smrg int count, const INT32 * bp, 743cdc920a0Smrg Bool tagged_only, 744cdc920a0Smrg Bool fbconfig_style_tags); 745cdc920a0Smrg 7461463c08dSmrgextern char *__glXQueryServerString(Display *dpy, CARD32 screen, CARD32 name); 7471463c08dSmrgextern char *__glXGetString(Display *dpy, CARD32 screen, CARD32 name); 748cdc920a0Smrg 749cdc920a0Smrgextern GLboolean __glXGetMscRateOML(Display * dpy, GLXDrawable drawable, 750cdc920a0Smrg int32_t * numerator, 751cdc920a0Smrg int32_t * denominator); 752cdc920a0Smrg 753cdc920a0Smrg#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) 7543464ebd5Sriastradhextern GLboolean 755af69d88dSmrg__glxGetMscRate(struct glx_screen *psc, 7563464ebd5Sriastradh int32_t * numerator, int32_t * denominator); 757cdc920a0Smrg 758cdc920a0Smrg/* So that dri2.c:DRI2WireToEvent() can access 759cdc920a0Smrg * glx_info->codes->first_event */ 760cdc920a0SmrgXExtDisplayInfo *__glXFindDisplay (Display *dpy); 761cdc920a0Smrg 762cdc920a0Smrgextern __GLXDRIdrawable * 7633464ebd5SriastradhGetGLXDRIDrawable(Display *dpy, GLXDrawable drawable); 7643464ebd5Sriastradh#endif 765cdc920a0Smrg 766af69d88dSmrgextern struct glx_screen *GetGLXScreenConfigs(Display * dpy, int scrn); 767af69d88dSmrg 7683464ebd5Sriastradh#ifdef GLX_USE_APPLEGL 7693464ebd5Sriastradhextern struct glx_screen * 7703464ebd5Sriastradhapplegl_create_screen(int screen, struct glx_display * priv); 7713464ebd5Sriastradh 7723464ebd5Sriastradhextern struct glx_context * 7733464ebd5Sriastradhapplegl_create_context(struct glx_screen *psc, 7743464ebd5Sriastradh struct glx_config *mode, 7753464ebd5Sriastradh struct glx_context *shareList, int renderType); 7763464ebd5Sriastradh 7773464ebd5Sriastradhextern int 7783464ebd5Sriastradhapplegl_create_display(struct glx_display *display); 7791463c08dSmrg 7801463c08dSmrgextern void * 7811463c08dSmrgapplegl_get_proc_address(const char *symbol); 782cdc920a0Smrg#endif 783cdc920a0Smrg 784af69d88dSmrgextern Bool validate_renderType_against_config(const struct glx_config *config, 785af69d88dSmrg int renderType); 786af69d88dSmrg 787af69d88dSmrg 788af69d88dSmrgextern struct glx_drawable *GetGLXDrawable(Display *dpy, GLXDrawable drawable); 789af69d88dSmrgextern int InitGLXDrawable(Display *dpy, struct glx_drawable *glxDraw, 790af69d88dSmrg XID xDrawable, GLXDrawable drawable); 791af69d88dSmrgextern void DestroyGLXDrawable(Display *dpy, GLXDrawable drawable); 792af69d88dSmrg 7933464ebd5Sriastradhextern struct glx_context dummyContext; 7943464ebd5Sriastradh 7953464ebd5Sriastradhextern struct glx_screen * 7963464ebd5Sriastradhindirect_create_screen(int screen, struct glx_display * priv); 7973464ebd5Sriastradhextern struct glx_context * 7983464ebd5Sriastradhindirect_create_context(struct glx_screen *psc, 7993464ebd5Sriastradh struct glx_config *mode, 8003464ebd5Sriastradh struct glx_context *shareList, int renderType); 801af69d88dSmrgextern struct glx_context * 802af69d88dSmrgindirect_create_context_attribs(struct glx_screen *base, 803af69d88dSmrg struct glx_config *config_base, 804af69d88dSmrg struct glx_context *shareList, 805af69d88dSmrg unsigned num_attribs, 806af69d88dSmrg const uint32_t *attribs, 807af69d88dSmrg unsigned *error); 8083464ebd5Sriastradh 80901e04c3fSmrg 81001e04c3fSmrgextern int __glXGetDrawableAttribute(Display * dpy, GLXDrawable drawable, 81101e04c3fSmrg int attribute, unsigned int *value); 81201e04c3fSmrg 81301e04c3fSmrg#ifdef __cplusplus 81401e04c3fSmrg} 81501e04c3fSmrg#endif 81601e04c3fSmrg 817cdc920a0Smrg#endif /* !__GLX_client_h__ */ 818