fix GLX_USE_TLS breakage, fix a warning
[mesa.git] / src / mesa / drivers / x11 / xmesaP.h
index 7030afaa119a2887a06d56b2b9b1e62a82c3f2d8..e3d7cf381f7c52d2d43faa955ca8ac30df10099e 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.3
+ * Version:  7.1
  *
- * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
 #define XMESAP_H
 
 
-#ifdef XFree86Server
-# include "GL/xf86glx.h"
-# include "xf86glx_util.h"
-#elif defined(USE_XSHM)
-# include <X11/extensions/XShm.h>
-#endif
 #include "GL/xmesa.h"
 #include "mtypes.h"
 #if defined(FX)
 #include "GL/fxmesa.h"
-#include "../glide/fxdrv.h"
+#include "xm_glide.h"
+#endif
+#ifdef XFree86Server
+#include "xm_image.h"
 #endif
 
 
 extern _glthread_Mutex _xmesa_lock;
 
+extern XMesaBuffer XMesaBufferList;
 
 /* for PF_8R8G8B24 pixel format */
 typedef struct {
@@ -57,8 +55,7 @@ struct xmesa_renderbuffer;
 
 /* Function pointer for clearing color buffers */
 typedef void (*ClearFunc)( GLcontext *ctx, struct xmesa_renderbuffer *xrb,
-                            GLboolean all, GLint x, GLint y,
-                            GLint width, GLint height );
+                           GLint x, GLint y, GLint width, GLint height );
 
 
 
@@ -68,22 +65,23 @@ enum pixel_format {
    PF_Index,           /**< Color Index mode */
    PF_Truecolor,       /**< TrueColor or DirectColor, any depth */
    PF_Dither_True,     /**< TrueColor with dithering */
-   PF_8A8B8G8R,                /**< 32-bit TrueColor:  8-A, 8-B, 8-G, 8-R */
+   PF_8A8R8G8B,                /**< 32-bit TrueColor:  8-A, 8-R, 8-G, 8-B bits */
+   PF_8A8B8G8R,                /**< 32-bit TrueColor:  8-A, 8-B, 8-G, 8-R bits */
    PF_8R8G8B,          /**< 32-bit TrueColor:  8-R, 8-G, 8-B bits */
+   PF_8R8G8B24,                /**< 24-bit TrueColor:  8-R, 8-G, 8-B bits */
    PF_5R6G5B,          /**< 16-bit TrueColor:  5-R, 6-G, 5-B bits */
    PF_Dither,          /**< Color-mapped RGB with dither */
    PF_Lookup,          /**< Color-mapped RGB without dither */
    PF_HPCR,            /**< HP Color Recovery (ad@lms.be 30/08/95) */
    PF_1Bit,            /**< monochrome dithering of RGB */
    PF_Grayscale,       /**< Grayscale or StaticGray */
-   PF_8R8G8B24,                /**< 24-bit TrueColor: 8-R, 8-G, 8-B bits */
-   PF_Dither_5R6G5B,   /**< 16-bit dithered TrueColor: 5-R, 6-G, 5-B */
-   PF_8A8R8G8B         /**< 32-bit TrueColor:  8-A, 8-R, 8-G, 8-B */
+   PF_Dither_5R6G5B    /**< 16-bit dithered TrueColor: 5-R, 6-G, 5-B */
 };
 
 
-/*
- * "Derived" from GLvisual.  Basically corresponds to an XVisualInfo.
+/**
+ * Visual inforation, derived from GLvisual.
+ * Basically corresponds to an XVisualInfo.
  */
 struct xmesa_visual {
    GLvisual mesa_visual;       /* Device independent visual parameters */
@@ -128,8 +126,9 @@ struct xmesa_visual {
 };
 
 
-/*
- * "Derived" from __GLcontextRec.  Basically corresponds to a GLXContext.
+/**
+ * Context info, dDerived from GLcontext.
+ * Basically corresponds to a GLXContext.
  */
 struct xmesa_context {
    GLcontext mesa;             /* the core library context (containment) */
@@ -147,7 +146,9 @@ struct xmesa_context {
 };
 
 
-
+/**
+ * Types of X/GLX drawables we might render into.
+ */
 typedef enum {
    WINDOW,          /* An X window */
    GLXWINDOW,       /* GLX window */
@@ -156,13 +157,31 @@ typedef enum {
 } BufferType;
 
 
+/** Values for db_mode: */
+/*@{*/
+#define BACK_PIXMAP    1
+#define BACK_XIMAGE    2
+/*@}*/
+
+
+/**
+ * An xmesa_renderbuffer represents the back or front color buffer.
+ * For the front color buffer:
+ *    <drawable> is the X window
+ * For the back color buffer:
+ *    Either <ximage> or <pixmap> will be used, never both.
+ * In any case, <drawable> always equals <pixmap>.
+ * For stand-alone Mesa, we could merge <drawable> and <pixmap> into one
+ * field.  We don't do that for the server-side GLcore module because
+ * pixmaps and drawables are different and we'd need a bunch of casts.
+ */
 struct xmesa_renderbuffer
 {
    struct gl_renderbuffer Base;  /* Base class */
 
-   XMesaDrawable pixmap;       /* Either an X Window ID (front color buf) */
-                                /* or X Pixmap ID (back color buf) */
-
+   XMesaBuffer Parent;  /**< The XMesaBuffer this renderbuffer belongs to */
+   XMesaDrawable drawable;     /* Usually the X window ID */
+   XMesaPixmap pixmap; /* Back color buffer */
    XMesaImage *ximage; /* The back buffer, if not using a Pixmap */
 
    GLubyte *origin1;   /* used for PIXEL_ADDR1 macro */
@@ -174,14 +193,15 @@ struct xmesa_renderbuffer
    GLuint *origin4;    /* used for PIXEL_ADDR4 macro */
    GLint width4;
 
-   GLint bottom;       /* used for FLIP macro */
+   GLint bottom;       /* used for FLIP macro, equals height - 1 */
 
    ClearFunc clearFunc;
 };
 
 
-/*
- * "Derived" from GLframebuffer.  Basically corresponds to a GLXDrawable.
+/**
+ * Framebuffer information, derived from.
+ * Basically corresponds to a GLXDrawable.
  */
 struct xmesa_buffer {
    GLframebuffer mesa_buffer;  /* depth, stencil, accum, etc buffers */
@@ -199,18 +219,17 @@ struct xmesa_buffer {
 
    unsigned long selectedEvents;/* for pbuffers only */
 
-   GLint db_state;             /* 0 = single buffered */
+   GLint db_mode;              /* 0 = single buffered */
                                /* BACK_PIXMAP = use Pixmap for back buffer */
                                /* BACK_XIMAGE = use XImage for back buffer */
+   GLboolean swAlpha;
 
-#ifndef XFree86Server
    GLuint shm;                 /* X Shared Memory extension status:    */
                                /*    0 = not available                 */
                                /*    1 = XImage support available      */
                                /*    2 = Pixmap support available too  */
-#ifdef USE_XSHM
+#if defined(USE_XSHM) && !defined(XFree86Server)
    XShmSegmentInfo shminfo;
-#endif
 #endif
 
    XMesaImage *rowimage;       /* Used for optimized span writing */
@@ -248,17 +267,16 @@ struct xmesa_buffer {
    fxMesaContext FXctx;
 #endif
 
+   /* GLX_EXT_texture_from_pixmap */
+   GLint TextureTarget; /** GLX_TEXTURE_1D_EXT, for example */
+   GLint TextureFormat; /** GLX_TEXTURE_FORMAT_RGB_EXT, for example */
+   GLint TextureMipmap; /** 0 or 1 */
+
    struct xmesa_buffer *Next;  /* Linked list pointer: */
 };
 
 
-/* Values for xmesa->db_state: */
-#define FRONT_PIXMAP   1
-#define BACK_PIXMAP    2
-#define BACK_XIMAGE    4
-
-
-/*
+/**
  * If pixelformat==PF_TRUECOLOR:
  */
 #define PACK_TRUECOLOR( PIXEL, R, G, B )       \
@@ -267,7 +285,7 @@ struct xmesa_buffer {
          | xmesa->xm_visual->BtoPixel[B];      \
 
 
-/*
+/**
  * If pixelformat==PF_TRUEDITHER:
  */
 #define PACK_TRUEDITHER( PIXEL, X, Y, R, G, B )                        \
@@ -280,14 +298,14 @@ struct xmesa_buffer {
 
 
 
-/*
+/**
  * If pixelformat==PF_8A8B8G8R:
  */
 #define PACK_8A8B8G8R( R, G, B, A )    \
        ( ((A) << 24) | ((B) << 16) | ((G) << 8) | (R) )
 
 
-/*
+/**
  * Like PACK_8A8B8G8R() but don't use alpha.  This is usually an acceptable
  * shortcut.
  */
@@ -295,19 +313,19 @@ struct xmesa_buffer {
 
 
 
-/*
+/**
  * If pixelformat==PF_8R8G8B:
  */
 #define PACK_8R8G8B( R, G, B)   ( ((R) << 16) | ((G) << 8) | (B) )
 
 
-/*
+/**
  * If pixelformat==PF_5R6G5B:
  */
 #define PACK_5R6G5B( R, G, B)   ( (((R) & 0xf8) << 8) | (((G) & 0xfc) << 3) | ((B) >> 3) )
 
 
-/*
+/**
  * If pixelformat==PF_8A8R8G8B:
  */
 #define PACK_8A8R8G8B( R, G, B, A )    \
@@ -315,7 +333,7 @@ struct xmesa_buffer {
 
 
 
-/*
+/**
  * If pixelformat==PF_DITHER:
  *
  * Improved 8-bit RGB dithering code contributed by Bob Mercier
@@ -392,7 +410,7 @@ extern const int xmesa_kernel8[DITH_DY * DITH_DX];
 
 
 
-/*
+/**
  * If pixelformat==PF_LOOKUP:
  */
 #define _dither_lookup(C, c)   (((unsigned)((DITH_N * (C - 1) + 1) * c)) >> 12)
@@ -406,8 +424,7 @@ extern const int xmesa_kernel8[DITH_DY * DITH_DX];
                        _dither_lookup(DITH_B, (B)))]
 
 
-
-/*
+/**
  * If pixelformat==PF_HPCR:
  *
  *      HP Color Recovery dithering               (ad@lms.be 30/08/95)
@@ -427,7 +444,7 @@ extern const short xmesa_HPCR_DRGB[3][2][16];
 
 
 
-/*
+/**
  * If pixelformat==PF_1BIT:
  */
 extern const int xmesa_kernel1[16];
@@ -438,20 +455,20 @@ extern const int xmesa_kernel1[16];
 
 
 
-/*
+/**
  * If pixelformat==PF_GRAYSCALE:
  */
 #define GRAY_RGB( R, G, B )   XMESA_BUFFER(ctx->DrawBuffer)->color_table[((R) + (G) + (B))/3]
 
 
 
-/*
+/**
  * Converts a GL window Y coord to an X window Y coord:
  */
 #define YFLIP(XRB, Y)  ((XRB)->bottom - (Y))
 
 
-/*
+/**
  * Return the address of a 1, 2 or 4-byte pixel in the buffer's XImage:
  * X==0 is left, Y==0 is bottom.
  */
@@ -469,27 +486,19 @@ extern const int xmesa_kernel1[16];
 
 
 
-
-/*
- * Return pointer to XMesaContext corresponding to a Mesa GLcontext.
- * Since we're using structure containment, it's just a cast!.
- */
-#define XMESA_CONTEXT(MESACTX)  ((XMesaContext) (MESACTX))
-
-/*
- * Return pointer to XMesaBuffer corresponding to a Mesa GLframebuffer.
- * Since we're using structure containment, it's just a cast!.
- */
-#define XMESA_BUFFER(MESABUFF)  ((XMesaBuffer) (MESABUFF))
-
-
-
 /*
  * External functions:
  */
 
 extern struct xmesa_renderbuffer *
-xmesa_new_renderbuffer(GLcontext *ctx, GLuint name, GLboolean rgbMode);
+xmesa_new_renderbuffer(GLcontext *ctx, GLuint name, const GLvisual *visual,
+                       GLboolean backBuffer);
+
+extern void
+xmesa_delete_framebuffer(struct gl_framebuffer *fb);
+
+extern XMesaBuffer
+xmesa_find_buffer(XMesaDisplay *dpy, XMesaColormap cmap, XMesaBuffer notThis);
 
 extern unsigned long
 xmesa_color_to_pixel( GLcontext *ctx,
@@ -497,20 +506,60 @@ xmesa_color_to_pixel( GLcontext *ctx,
                       GLuint pixelFormat );
 
 extern void
-xmesa_alloc_back_buffer(XMesaBuffer b, GLuint width, GLuint height);
+xmesa_get_window_size(XMesaDisplay *dpy, XMesaBuffer b,
+                      GLuint *width, GLuint *height);
 
-extern void xmesa_resize_buffers(GLcontext *ctx, GLframebuffer *buffer,
-                                 GLuint width, GLuint height);
+extern void
+xmesa_check_and_update_buffer_size(XMesaContext xmctx, XMesaBuffer drawBuffer);
 
-extern void xmesa_init_driver_functions( XMesaVisual xmvisual,
-                                         struct dd_function_table *driver );
+extern void
+xmesa_init_driver_functions( XMesaVisual xmvisual,
+                             struct dd_function_table *driver );
 
-extern void xmesa_update_state( GLcontext *ctx, GLuint new_state );
+extern void
+xmesa_update_state( GLcontext *ctx, GLbitfield new_state );
 
 extern void
 xmesa_set_renderbuffer_funcs(struct xmesa_renderbuffer *xrb,
                              enum pixel_format pixelformat, GLint depth);
 
+extern void
+xmesa_destroy_buffers_on_display(XMesaDisplay *dpy);
+
+
+/**
+ * Using a function instead of an ordinary cast is safer.
+ */
+static INLINE struct xmesa_renderbuffer *
+xmesa_renderbuffer(struct gl_renderbuffer *rb)
+{
+   return (struct xmesa_renderbuffer *) rb;
+}
+
+
+/**
+ * Return pointer to XMesaContext corresponding to a Mesa GLcontext.
+ * Since we're using structure containment, it's just a cast!.
+ * XXX should use inlined function for better type safety.
+ */
+static INLINE XMesaContext
+XMESA_CONTEXT(GLcontext *ctx)
+{
+   return (XMesaContext) ctx;
+}
+
+
+/**
+ * Return pointer to XMesaBuffer corresponding to a Mesa GLframebuffer.
+ * Since we're using structure containment, it's just a cast!.
+ * XXX should use inlined function for better type safety.
+ */
+static INLINE XMesaBuffer
+XMESA_BUFFER(GLframebuffer *b)
+{
+   return (XMesaBuffer) b;
+}
+
 
 /* Plugged into the software rasterizer.  Try to use internal
  * swrast-style point, line and triangle functions.
@@ -524,27 +573,14 @@ extern void xmesa_register_swrast_functions( GLcontext *ctx );
 
 
 
-/* XXX this is a hack to implement shared display lists with 3Dfx */
-extern XMesaBuffer XMesaCreateWindowBuffer2( XMesaVisual v,
-                                            XMesaWindow w,
-                                            XMesaContext c );
-
-/*
- * These are the extra routines required for integration with XFree86.
- * None of these routines should be user visible. -KEM
- */
-extern void XMesaSetVisualDisplay( XMesaDisplay *dpy, XMesaVisual v );
-extern GLboolean XMesaForceCurrent(XMesaContext c);
-extern GLboolean XMesaLoseCurrent(XMesaContext c);
-extern void XMesaReset( void );
-
-
 #define ENABLE_EXT_texure_compression_s3tc 0 /* SW texture compression */
 
 #ifdef XFree86Server
 #define ENABLE_EXT_timer_query 0
+#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+#define ENABLE_EXT_timer_query 1 /* should have 64-bit GLuint64EXT */
 #else
-#define ENABLE_EXT_timer_query 1
+#define ENABLE_EXT_timer_query 0 /* may not have 64-bit GLuint64EXT */
 #endif
 
 #endif