DRI2: Drop sarea, implement swap buffers in the X server.
[mesa.git] / src / glx / x11 / glxclient.h
index 7729903f0b95297a6af5f4a745c5987a5f1e3be3..412511247efa4c89365c06dddf230da9f9b007cf 100644 (file)
 #include "GL/glxproto.h"
 #include "GL/internal/glcore.h"
 #include "glapitable.h"
-#ifdef XTHREADS
-#include "Xthreads.h"
-#endif
-#ifdef GLX_BUILT_IN_XMESA
-#include "realglx.h"  /* just silences prototype warnings */
+#include "glxhash.h"
+#if defined( USE_XTHREADS )
+# include <X11/Xthreads.h>
+#elif defined( PTHREADS )
+# include <pthread.h>
 #endif
 
+#include "glxextensions.h"
+
 #define GLX_MAJOR_VERSION      1       /* current version numbers */
 #define GLX_MINOR_VERSION      4
 
 #define __GLX_MAX_TEXTURE_UNITS 32
 
+typedef struct __GLXscreenConfigsRec __GLXscreenConfigs;
 typedef struct __GLXcontextRec __GLXcontext;
+typedef struct __GLXdrawableRec __GLXdrawable;
 typedef struct __GLXdisplayPrivateRec __GLXdisplayPrivate;
 typedef struct _glapi_table __GLapi;
 
@@ -79,73 +83,77 @@ typedef struct _glapi_table __GLapi;
 
 #ifdef GLX_DIRECT_RENDERING
 
-#include <GL/internal/dri_interface.h>
-
-typedef void *(*CreateScreenFunc)(Display *dpy, int scrn, __DRIscreen *psc,
-                                  int numConfigs, __GLXvisualConfig *config);
+#define containerOf(ptr, type, member)                 \
+    (type *)( (char *)ptr - offsetof(type,member) )
 
-typedef void *(*CreateNewScreenFunc)(Display *dpy, int scrn, __DRIscreen *psc,
-    const __GLcontextModes * modes, const __DRIversion * ddx_version,
-    const __DRIversion * dri_version, const __DRIversion * drm_version,
-    const __DRIframebuffer * frame_buffer, void * pSAREA,
-    int fd, int internal_api_version, __GLcontextModes ** driver_modes);
+#include <GL/internal/dri_interface.h>
 
 
 /**
  * Display dependent methods.  This structure is initialized during the
  * \c driCreateDisplay call.
  */
-struct __DRIdisplayRec {
+typedef struct __GLXDRIdisplayRec __GLXDRIdisplay;
+typedef struct __GLXDRIscreenRec __GLXDRIscreen;
+typedef struct __GLXDRIdrawableRec __GLXDRIdrawable;
+typedef struct __GLXDRIcontextRec __GLXDRIcontext;
+
+#include "glxextensions.h"
+
+struct __GLXDRIdisplayRec {
     /**
      * Method to destroy the private DRI display data.
      */
-    void (*destroyDisplay)(Display *dpy, void *displayPrivate);
+    void (*destroyDisplay)(__GLXDRIdisplay *display);
 
-    /**
-     * Methods to create the private DRI screen data and initialize the
-     * screen dependent methods.
-     * This is an array [indexed by screen number] of function pointers.
-     * 
-     * \deprecated  This array of function pointers has been replaced by
-     *              \c __DRIdisplayRec::createNewScreen.
-     * \sa __DRIdisplayRec::createNewScreen
-     */
-    CreateScreenFunc * createScreen;
+    __GLXDRIscreen *(*createScreen)(__GLXscreenConfigs *psc, int screen,
+                                   __GLXdisplayPrivate *priv);
+};
 
-    /**
-     * Opaque pointer to private per display direct rendering data.
-     * \c NULL if direct rendering is not supported on this display.
-     */
-    struct __DRIdisplayPrivateRec *private;
+struct __GLXDRIscreenRec {
 
-    /**
-     * Array of pointers to methods to create and initialize the private DRI
-     * screen data.
-     *
-     * \sa __DRIdisplayRec::createScreen
-     */
-    CreateNewScreenFunc * createNewScreen;
+    void (*destroyScreen)(__GLXscreenConfigs *psc);
+
+    __GLXDRIcontext *(*createContext)(__GLXscreenConfigs *psc,
+                                     const __GLcontextModes *mode,
+                                     GLXContext gc,
+                                     GLXContext shareList, int renderType);
+       
+    __GLXDRIdrawable *(*createDrawable)(__GLXscreenConfigs *psc,
+                                       XID drawable,
+                                       GLXDrawable glxDrawable,
+                                       const __GLcontextModes *modes);
+
+    void (*swapBuffers)(__GLXDRIdrawable *pdraw);
 };
 
+struct __GLXDRIcontextRec {
+    void (*destroyContext)(__GLXDRIcontext *context, __GLXscreenConfigs *psc,
+                          Display *dpy);
+    Bool (*bindContext)(__GLXDRIcontext *context,
+                       __GLXDRIdrawable *pdraw,
+                       __GLXDRIdrawable *pread);
+    
+    void (*unbindContext)(__GLXDRIcontext *context);
+};
 
-/*
-** We keep a linked list of these structures, one per DRI device driver.
-*/
-struct __DRIdriverRec {
-   const char *name;
-   void *handle;
-   CreateScreenFunc createScreenFunc;
-   CreateNewScreenFunc createNewScreenFunc;
-   struct __DRIdriverRec *next;
+struct __GLXDRIdrawableRec {
+    void (*destroyDrawable)(__GLXDRIdrawable *drawable);
+
+    XID xDrawable;
+    XID drawable;
+    __GLXscreenConfigs *psc;
+    GLenum textureTarget;
+    __DRIdrawable *driDrawable;
 };
 
 /*
 ** Function to create and DRI display data and initialize the display
 ** dependent methods.
 */
-extern void *driCreateDisplay(Display *dpy, __DRIdisplay *pdisp);
-
-extern  __DRIdriver *driGetDriver(Display *dpy, int scrNum);
+extern __GLXDRIdisplay *driswCreateDisplay(Display *dpy);
+extern __GLXDRIdisplay *driCreateDisplay(Display *dpy);
+extern __GLXDRIdisplay *dri2CreateDisplay(Display *dpy);
 
 extern void DRI_glXUseXFont( Font font, int first, int count, int listbase );
 
@@ -175,155 +183,29 @@ typedef struct __GLXpixelStoreModeRec {
     GLuint alignment;
 } __GLXpixelStoreMode;
 
-/* The next 3 structures are deprecated.  Client state is no longer tracked
- * using them.  They only remain to maintain the layout / structure offset of
- * __GLXcontextRec.  In XFree86 5.0 they will be removed altogether.
- */
-
-typedef struct __GLXvertexArrayPointerStateRecDEPRECATED {
-    GLboolean enable;
-    void (*proc)(const void *);
-    const GLubyte *ptr;
-    GLsizei skip;
-    GLint size;
-    GLenum type;
-    GLsizei stride;
-} __GLXvertexArrayPointerStateDEPRECATED;
-
-typedef struct __GLXvertArrayStateRecDEPRECATED {
-    __GLXvertexArrayPointerStateDEPRECATED vertex;
-    __GLXvertexArrayPointerStateDEPRECATED normal;
-    __GLXvertexArrayPointerStateDEPRECATED color;
-    __GLXvertexArrayPointerStateDEPRECATED index;
-    __GLXvertexArrayPointerStateDEPRECATED texCoord[__GLX_MAX_TEXTURE_UNITS];
-    __GLXvertexArrayPointerStateDEPRECATED edgeFlag;
-    GLint maxElementsVertices;
-    GLint maxElementsIndices;
-    GLint activeTexture;
-} __GLXvertArrayStateDEPRECATED;
-
-typedef struct __GLXattributeRecDEPRECATED {
-       GLuint mask;
-
-       /*
-       ** Pixel storage state.  Most of the pixel store mode state is kept
-       ** here and used by the client code to manage the packing and
-       ** unpacking of data sent to/received from the server.
-       */
-       __GLXpixelStoreMode storePack, storeUnpack;
-
-       /*
-       ** Vertex Array storage state.  The vertex array component
-       ** state is stored here and is used to manage the packing of
-       ** DrawArrays data sent to the server.
-       */
-       __GLXvertArrayStateDEPRECATED vertArray;
-} __GLXattributeDEPRECATED;
-
-typedef struct __GLXvertexArrayPointerStateRec {
-    void (*proc)(const void *);
-    void (*mtex_proc)(GLenum, const void *);
-    const GLubyte *ptr;
-    GLsizei skip;
-    GLint size;
-    GLenum type;
-    GLsizei stride;
-} __GLXvertexArrayPointerState;
 
-/**
- * Define which entries of \c __GLXvertArrayState::arrays match which
- * vertex arrays in the client-state vector.  These are only the one-of
- * arrays.  See the \c __GLXvertArrayState::arrays documentation for more
- * details.
- * 
- * \sa __GLXvertArrayState
- */
-enum {
-    edgeFlag_ARRAY,       /**< \c GL_EDGE_FLAG_ARRAY */
-    index_ARRAY,          /**< \c GL_INDEX_ARRAY */
-    fogCoord_ARRAY,       /**< \c GL_FOG_COORD_ARRAY */
-    secondaryColor_ARRAY, /**< \c GL_SECONDARY_COLOR_ARRAY */
-    color_ARRAY,          /**< \c GL_COLOR_ARRAY */
-    normal_ARRAY,         /**< \c GL_NORMAL_ARRAY */
-       
-    /**
-     * \c GL_VERTEX_ARRAY \b must be last!  All of the code for emitting arrays
-     * and array elements is written based on the assumption that the vertex
-     * array is last.
-     */
-    vertex_ARRAY,
-
-    __GLX_MAX_ARRAYS      /**< Place holder entry. */
-};
-
-#define ENABLE_ARRAY(state,a) \
-    do { (state)->vertArray.enables |=  (1U << (a ## _ARRAY)); } while( 0 )
-#define DISABLE_ARRAY(state,a) \
-    do { (state)->vertArray.enables &= ~(1U << (a ## _ARRAY)); } while( 0 )
-#define IS_ARRAY_ENABLED_BY_INDEX(state, i) \
-    (((state)->vertArray.enables & (1U << (i))) != 0)
-#define IS_ARRAY_ENABLED(state, a) \
-    IS_ARRAY_ENABLED_BY_INDEX(state, a ## _ARRAY)
-
-#define ENABLE_TEXARRAY(state,a) \
-    do { (state)->vertArray.texture_enables |=  (1U << a); } while( 0 )
-#define DISABLE_TEXARRAY(state,a) \
-    do { (state)->vertArray.texture_enables &= ~(1U << a); } while( 0 )
-#define IS_TEXARRAY_ENABLED(state, a) \
-    (((state)->vertArray.texture_enables & (1U << a)) != 0)
+typedef struct __GLXattributeRec {
+    GLuint mask;
 
-/**
- * Client-side vertex array state.
- */
-typedef struct __GLXvertArrayStateRec {
     /**
-     * Which client-side arrays are enabled?  These are the flag bits for
-     * all of the non-texture coordinate arrays.
+     * Pixel storage state.  Most of the pixel store mode state is kept
+     * here and used by the client code to manage the packing and
+     * unpacking of data sent to/received from the server.
      */
-    GLuint enables;
+    __GLXpixelStoreMode storePack, storeUnpack;
 
     /**
-     * Which of the texture coordinate arrays are enabled?
+     * Is EXT_vertex_array / GL 1.1 DrawArrays protocol specifically
+     * disabled?
      */
-    GLuint texture_enables;
-
+    GLboolean NoDrawArraysProtocol;
+    
     /**
-     * State for "one-of" arrays.  These are the arrays, such as
-     * GL_COLOR_ARRAY or GL_FOG_COORD_ARRAY for which there is only one
-     * array.  There are also "many-of" arrays, such as
-     * GL_TEXTURE_COORD_ARRAY.
+     * Vertex Array storage state.  The vertex array component
+     * state is stored here and is used to manage the packing of
+     * DrawArrays data sent to the server.
      */
-    __GLXvertexArrayPointerState arrays[__GLX_MAX_ARRAYS];
-
-    __GLXvertexArrayPointerState texCoord[__GLX_MAX_TEXTURE_UNITS];
-
-    GLint maxElementsVertices;
-    GLint maxElementsIndices;
-    GLint activeTexture;
-} __GLXvertArrayState;
-
-typedef struct __GLXattributeRec {
-       GLuint mask;
-
-       /*
-       ** Pixel storage state.  Most of the pixel store mode state is kept
-       ** here and used by the client code to manage the packing and
-       ** unpacking of data sent to/received from the server.
-       */
-       __GLXpixelStoreMode storePack, storeUnpack;
-
-       /*
-       ** Vertex Array storage state.  The vertex array component
-       ** state is stored here and is used to manage the packing of
-       ** DrawArrays data sent to the server.
-       */
-       __GLXvertArrayState vertArray;
-
-       /**
-        * Is EXT_vertex_array / GL 1.1 DrawArrays protocol specifically
-        * disabled?
-        */
-       GLboolean NoDrawArraysProtocol;
+    struct array_state_vector * array_state;
 } __GLXattribute;
 
 typedef struct __GLXattributeMachineRec {
@@ -373,19 +255,11 @@ struct __GLXcontextRec {
      */
     XID share_xid;
 
-    /**
-     * Visual id.
-     * 
-     * \deprecated
-     * This filed has been largely been replaced by the \c mode field, but
-     * the work is not quite done.
-     */
-    VisualID vid;
-
     /**
      * Screen number.
      */
     GLint screen;
+    __GLXscreenConfigs *psc;
 
     /**
      * \c GL_TRUE if the context was created with ImportContext, which
@@ -432,12 +306,9 @@ struct __GLXcontextRec {
                      GLenum, const GLvoid*, GLubyte*, GLubyte*);
 
     /**
-     * \name Client side attribs.
+     * Client side attribs.
      */
-    /*@{*/
-    __GLXattributeDEPRECATED stateDEPRECATED;
     __GLXattributeMachine attributes;
-    /*@}*/
 
     /**
      * Client side error code.  This is set when client side gl API
@@ -494,24 +365,15 @@ struct __GLXcontextRec {
      */
     GLint majorOpcode;
 
-#ifdef GLX_DIRECT_RENDERING
     /**
-     * Per context direct rendering interface functions and data.
+     * Pointer to the mode used to create this context.
      */
-    __DRIcontext driContext;
+    const __GLcontextModes * mode;
+
+#ifdef GLX_DIRECT_RENDERING
+    __GLXDRIcontext *driContext;
+    __DRIcontext *__driContext;
 #endif
-    
-    /**
-     * \c GLXFBConfigID used to create this context.  May be \c None.  This
-     * field has been replaced by the \c mode field.
-     *
-     * \since Internal API version 20030317.
-     *
-     * \deprecated
-     * This filed has been largely been replaced by the \c mode field, but
-     * the work is not quite done.
-     */
-    GLXFBConfigID  fbconfigID;
 
     /**
      * The current read-drawable for this context.  Will be None if this
@@ -529,7 +391,7 @@ struct __GLXcontextRec {
     * drivers should NEVER use this data or even care that it exists.
     */
    void * client_state_private;
-   
+
    /**
     * Stored value for \c glXQueryContext attribute \c GLX_RENDER_TYPE.
     */
@@ -546,6 +408,8 @@ struct __GLXcontextRec {
    int server_major;        /**< Major version number. */
    int server_minor;        /**< Minor version number. */
     /*@}*/
+
+    char gl_extension_bits[ __GL_EXT_BYTES ];
 };
 
 #define __glXSetError(gc,code) \
@@ -587,15 +451,7 @@ extern void __glFreeAttributeState(__GLXcontext *);
  * One of these records exists per screen of the display.  It contains
  * a pointer to the config data for that screen (if the screen supports GL).
  */
-typedef struct __GLXscreenConfigsRec {
-    /**
-     * GLX visuals formated as \c __GLXvisualConfig structures.
-     */
-    /*@{*/
-    __GLXvisualConfig * old_configs;
-    int numOldConfigs;
-    /*@}*/
-
+struct __GLXscreenConfigsRec {
     /**
      * GLX extension string reported by the X-server.
      */
@@ -611,14 +467,49 @@ typedef struct __GLXscreenConfigsRec {
     /**
      * Per screen direct rendering interface functions and data.
      */
-    __DRIscreen driScreen;
+    __DRIscreen *__driScreen;
+    const __DRIcoreExtension *core;
+    const __DRIlegacyExtension *legacy;
+    const __DRIswrastExtension *swrast;
+    const __DRIdri2Extension *dri2;
+    __glxHashTable *drawHash;
+    Display *dpy;
+    int scr, fd;
+    void *driver;
+
+    __GLXDRIscreen *driScreen;
+
+#ifdef __DRI_COPY_SUB_BUFFER
+    const __DRIcopySubBufferExtension *copySubBuffer;
+#endif
+
+#ifdef __DRI_SWAP_CONTROL
+    const __DRIswapControlExtension *swapControl;
+#endif
+
+#ifdef __DRI_ALLOCATE
+    const __DRIallocateExtension *allocate;
+#endif
+
+#ifdef __DRI_FRAME_TRACKING
+    const __DRIframeTrackingExtension *frameTracking;
+#endif
+
+#ifdef __DRI_MEDIA_STREAM_COUNTER
+    const __DRImediaStreamCounterExtension *msc;
+#endif
+
+#ifdef __DRI_TEX_BUFFER
+    const __DRItexBufferExtension *texBuffer;
+#endif
+
 #endif
 
     /**
-     * Linked list of configurations for this screen.  This is intended to
-     * be a superset of \c old_configs.
+     * Linked list of glx visuals and  fbconfigs for this screen.
      */
-    __GLcontextModes *configs;
+    __GLcontextModes *visuals, *configs;
+
     /**
      * Per-screen dynamic GLX extension tracking.  The \c direct_support
      * field only contains enough bits for 64 extensions.  Should libGL
@@ -631,7 +522,7 @@ typedef struct __GLXscreenConfigsRec {
     GLboolean ext_list_first_time;
     /*@}*/
 
-} __GLXscreenConfigs;
+};
 
 /**
  * Per display private data.  One of these records exists for each display
@@ -680,11 +571,12 @@ struct __GLXdisplayPrivateRec {
     /**
      * Per display direct rendering interface functions and data.
      */
-    __DRIdisplay driDisplay;
+    __GLXDRIdisplay *driswDisplay;
+    __GLXDRIdisplay *driDisplay;
+    __GLXDRIdisplay *dri2Display;
 #endif
 };
 
-void __glXFreeContext(__GLXcontext*);
 
 extern GLubyte *__glXFlushRenderBuffer(__GLXcontext*, GLubyte*);
 
@@ -703,24 +595,48 @@ extern __GLXdisplayPrivate *__glXInitialize(Display*);
 extern int __glXDebug;
 
 /* This is per-thread storage in an MT environment */
-#if defined(GLX_DIRECT_RENDERING) && defined(XTHREADS)
-extern __GLXcontext *__glXGetCurrentContext(void);
+#if defined( USE_XTHREADS ) || defined( PTHREADS )
+
 extern void __glXSetCurrentContext(__GLXcontext *c);
+
+# if defined( GLX_USE_TLS )
+
+extern __thread void * __glX_tls_Context
+    __attribute__((tls_model("initial-exec")));
+
+#  define __glXGetCurrentContext()     __glX_tls_Context
+
+# else
+
+extern __GLXcontext *__glXGetCurrentContext(void);
+
+# endif /* defined( GLX_USE_TLS ) */
+
 #else
+
 extern __GLXcontext *__glXcurrentContext;
 #define __glXGetCurrentContext()       __glXcurrentContext
 #define __glXSetCurrentContext(gc)     __glXcurrentContext = gc
-#endif
+
+#endif /* defined( USE_XTHREADS ) || defined( PTHREADS ) */
+
+extern void __glXSetCurrentContextNull(void);
+
+extern void __glXFreeContext(__GLXcontext*);
 
 
 /*
 ** Global lock for all threads in this address space using the GLX
 ** extension
 */
-#if defined(GLX_DIRECT_RENDERING) && defined(XTHREADS)
+#if defined( USE_XTHREADS )
 extern xmutex_rec __glXmutex;
 #define __glXLock()    xmutex_lock(&__glXmutex)
 #define __glXUnlock()  xmutex_unlock(&__glXmutex)
+#elif defined( PTHREADS )
+extern pthread_mutex_t __glXmutex;
+#define __glXLock()    pthread_mutex_lock(&__glXmutex)
+#define __glXUnlock()  pthread_mutex_unlock(&__glXmutex)
 #else
 #define __glXLock()
 #define __glXUnlock()
@@ -737,8 +653,15 @@ extern CARD8 __glXSetupForCommand(Display *dpy);
 ** Data conversion and packing support.
 */
 
+extern const GLuint __glXDefaultPixelStore[9];
+
+/* Send an image to the server using RenderLarge. */
+extern void __glXSendLargeImage(__GLXcontext *gc, GLint compsize, GLint dim,
+    GLint width, GLint height, GLint depth, GLenum format, GLenum type,
+    const GLvoid *src, GLubyte *pc, GLubyte *modes);
+
 /* Return the size, in bytes, of some pixel data */
-extern GLint __glImageSize(GLint, GLint, GLint, GLenum, GLenum);
+extern GLint __glImageSize(GLint, GLint, GLint, GLenum, GLenum, GLenum);
 
 /* Return the number of elements per group of a specified format*/
 extern GLint __glElementsPerGroup(GLenum format, GLenum type);
@@ -748,9 +671,6 @@ extern GLint __glElementsPerGroup(GLenum format, GLenum type);
 */
 extern GLint __glBytesPerElement(GLenum type);
 
-/* Return the k value for a given map target */
-extern GLint __glEvalComputeK(GLenum);
-
 /*
 ** Fill the transport buffer with the data from the users buffer,
 ** applying some of the pixel store modes (unpack modes) to the data
@@ -778,9 +698,10 @@ extern void __glEmptyImage(__GLXcontext*, GLint, GLint, GLint, GLint, GLenum,
 
 
 /*
-** Allocate and Initialize Vertex Array client state 
+** Allocate and Initialize Vertex Array client state, and free.
 */
-extern void __glXInitVertexArrayState(__GLXcontext*);
+extern void __glXInitVertexArrayState(__GLXcontext *);
+extern void __glXFreeVertexArrayState(__GLXcontext *);
 
 /*
 ** Inform the Server of the major and minor numbers and of the client
@@ -801,17 +722,6 @@ extern void _XSend(Display*, const void*, long);
 #endif
 
 
-/*
-** GLX_BUILT_IN_XMESA controls whether libGL has a built-in verions of
-** Mesa that can render to non-GLX displays.
-*/
-#ifdef GLX_BUILT_IN_XMESA
-#define GLX_PREFIX(function)  _real_##function
-#else
-#define GLX_PREFIX(function)  function
-#endif
-
-
 extern void __glXInitializeVisualConfigFromTags( __GLcontextModes *config,
     int count, const INT32 *bp, Bool tagged_only, Bool fbconfig_style_tags );
 
@@ -824,10 +734,16 @@ extern char *__glXstrdup(const char *str);
 extern const char __glXGLClientVersion[];
 extern const char __glXGLClientExtensions[];
 
-/* Determine the internal API version */
-extern int __glXGetInternalVersion(void);
-
 /* Get the unadjusted system time */
 extern int __glXGetUST( int64_t * ust );
 
+extern GLboolean __glXGetMscRateOML(Display * dpy, GLXDrawable drawable,
+                                   int32_t * numerator, int32_t * denominator);
+
+#ifdef GLX_DIRECT_RENDERING
+GLboolean
+__driGetMscRateOML(__DRIdrawable *draw,
+                  int32_t *numerator, int32_t *denominator, void *private);
+#endif
+
 #endif /* !__GLX_client_h__ */