/*
* Mesa 3-D graphics library
- * Version: 7.1
*
* Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
*/
#define XMESAP_H
-#include "GL/xmesa.h"
-#include "mtypes.h"
-#if defined(FX)
-#include "GL/fxmesa.h"
-#include "xm_glide.h"
-#endif
-#ifdef XFree86Server
-#include "xm_image.h"
-#endif
-#include "state_tracker/st_cb_fbo.h"
-#include "pipe/softpipe/sp_context.h"
-#include "pipe/softpipe/sp_surface.h"
+#include "c11/threads.h"
+#include "xmesa.h"
+#include "main/mtypes.h"
+#include "swrast/s_context.h"
-extern _glthread_Mutex _xmesa_lock;
+extern mtx_t _xmesa_lock;
extern XMesaBuffer XMesaBufferList;
/* Function pointer for clearing color buffers */
-typedef void (*ClearFunc)( GLcontext *ctx, struct xmesa_renderbuffer *xrb,
+typedef void (*ClearFunc)( struct gl_context *ctx, struct xmesa_renderbuffer *xrb,
GLint x, GLint y, GLint width, GLint height );
/** Framebuffer pixel formats */
enum pixel_format {
- PF_Index, /**< Color Index mode */
PF_Truecolor, /**< TrueColor or DirectColor, any depth */
PF_Dither_True, /**< TrueColor with dithering */
PF_8A8R8G8B, /**< 32-bit TrueColor: 8-A, 8-R, 8-G, 8-B 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_Dither_5R6G5B /**< 16-bit dithered TrueColor: 5-R, 6-G, 5-B */
};
/**
- * Visual inforation, derived from GLvisual.
+ * Visual inforation, derived from struct gl_config.
* Basically corresponds to an XVisualInfo.
*/
struct xmesa_visual {
- GLvisual mesa_visual; /* Device independent visual parameters */
+ struct gl_config mesa_visual; /* Device independent visual parameters */
XMesaDisplay *display; /* The X11 display */
-#ifdef XFree86Server
- GLint ColormapEntries;
- GLint nplanes;
-#else
+ int screen, visualID;
+ int visualType;
XMesaVisualInfo visinfo; /* X's visual info (pointer to private copy) */
XVisualInfo *vishandle; /* Only used in fakeglx.c */
-#endif
GLint BitsPerPixel; /* True bits per pixel for XImages */
GLboolean ximage_flag; /* Use XImage for back buffer (not pixmap)? */
GLubyte PixelToR[256]; /* Pixel to RGB conversion */
GLubyte PixelToG[256];
GLubyte PixelToB[256];
-
- /* For PF_HPCR */
- short hpcr_rgbTbl[3][256];
- GLboolean hpcr_clear_flag;
- GLubyte hpcr_clear_ximage_pattern[2][16];
- XMesaImage *hpcr_clear_ximage;
- XMesaPixmap hpcr_clear_pixmap;
-
- /* For PF_1BIT */
- int bitFlip;
};
/**
- * Context info, dDerived from GLcontext.
+ * Context info, derived from struct gl_context.
* Basically corresponds to a GLXContext.
*/
struct xmesa_context {
- GLcontext mesa; /* the core library context (containment) */
+ struct gl_context mesa; /* the core library context (containment) */
XMesaVisual xm_visual; /* Describes the buffers */
XMesaBuffer xm_buffer; /* current span/point/line/triangle buffer */
*/
struct xmesa_renderbuffer
{
-#if 0
- struct gl_renderbuffer Base; /* Base class */
-#else
- struct st_renderbuffer St; /**< Base class */
-#endif
+ struct swrast_renderbuffer Base; /* Base class */
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 */
- GLint width1;
GLushort *origin2; /* used for PIXEL_ADDR2 macro */
GLint width2;
GLubyte *origin3; /* used for PIXEL_ADDR3 macro */
ClearFunc clearFunc;
- void *pSurface; /** pipe surface */
+ GLuint map_x, map_y, map_w, map_h;
+ GLbitfield map_mode;
+ XMesaImage *map_ximage;
};
* Basically corresponds to a GLXDrawable.
*/
struct xmesa_buffer {
- GLframebuffer mesa_buffer; /* depth, stencil, accum, etc buffers */
+ struct gl_framebuffer mesa_buffer; /* depth, stencil, accum, etc buffers */
/* This MUST BE FIRST! */
GLboolean wasCurrent; /* was ever the current buffer? */
XMesaVisual xm_visual; /* the X/Mesa visual */
XMesaDisplay *display;
BufferType type; /* window, pixmap, pbuffer or glxwindow */
+ GLboolean largestPbuffer; /**< for pbuffers */
+ GLboolean preservedContents; /**< for pbuffers */
+
struct xmesa_renderbuffer *frontxrb; /* front color renderbuffer */
struct xmesa_renderbuffer *backxrb; /* back color renderbuffer */
GLint db_mode; /* 0 = single buffered */
/* BACK_PIXMAP = use Pixmap for back buffer */
/* BACK_XIMAGE = use XImage for back buffer */
- GLboolean swAlpha;
-
GLuint shm; /* X Shared Memory extension status: */
/* 0 = not available */
/* 1 = XImage support available */
/* 2 = Pixmap support available too */
-#if defined(USE_XSHM) && !defined(XFree86Server)
+#if defined(USE_XSHM)
XShmSegmentInfo shminfo;
#endif
- XMesaImage *rowimage; /* Used for optimized span writing */
+ // XMesaImage *rowimage; /* Used for optimized span writing */
XMesaPixmap stipple_pixmap; /* For polygon stippling */
XMesaGC stipple_gc; /* For polygon stippling */
/* Used to do XAllocColor/XFreeColors accounting: */
int num_alloced;
-#if defined(XFree86Server)
- Pixel alloced_colors[256];
-#else
unsigned long alloced_colors[256];
-#endif
-
-#if defined( FX )
- /* For 3Dfx Glide only */
- GLboolean FXisHackUsable; /* Can we render into window? */
- GLboolean FXwindowHack; /* Are we rendering into a window? */
- fxMesaContext FXctx;
-#endif
/* GLX_EXT_texture_from_pixmap */
GLint TextureTarget; /** GLX_TEXTURE_1D_EXT, for example */
-/**
- * If pixelformat==PF_DITHER:
- *
- * Improved 8-bit RGB dithering code contributed by Bob Mercier
- * (mercier@hollywood.cinenet.net). Thanks Bob!
- */
-#ifdef DITHER666
-# define DITH_R 6
-# define DITH_G 6
-# define DITH_B 6
-# define DITH_MIX(r,g,b) (((r) * DITH_G + (g)) * DITH_B + (b))
-#else
-# define DITH_R 5
-# define DITH_G 9
-# define DITH_B 5
-# define DITH_MIX(r,g,b) (((g) << 6) | ((b) << 3) | (r))
-#endif
-#define DITH_DX 4
-#define DITH_DY 4
-#define DITH_N (DITH_DX * DITH_DY)
-
-#define _dither(C, c, d) (((unsigned)((DITH_N * (C - 1) + 1) * c + d)) >> 12)
-
-#define MAXC 256
-extern const int xmesa_kernel8[DITH_DY * DITH_DX];
-
-/* Dither for random X,Y */
-#define DITHER_SETUP \
- int __d; \
- unsigned long *ctable = XMESA_BUFFER(ctx->DrawBuffer)->color_table;
-
-#define DITHER( X, Y, R, G, B ) \
- (__d = xmesa_kernel8[(((Y)&3)<<2) | ((X)&3)], \
- ctable[DITH_MIX(_dither(DITH_R, (R), __d), \
- _dither(DITH_G, (G), __d), \
- _dither(DITH_B, (B), __d))])
-
-/* Dither for random X, fixed Y */
-#define XDITHER_SETUP(Y) \
- int __d; \
- unsigned long *ctable = XMESA_BUFFER(ctx->DrawBuffer)->color_table; \
- const int *kernel = &xmesa_kernel8[ ((Y)&3) << 2 ];
-
-#define XDITHER( X, R, G, B ) \
- (__d = kernel[(X)&3], \
- ctable[DITH_MIX(_dither(DITH_R, (R), __d), \
- _dither(DITH_G, (G), __d), \
- _dither(DITH_B, (B), __d))])
-
-
-
-/*
- * Dithering for flat-shaded triangles. Precompute all 16 possible
- * pixel values given the triangle's RGB color. Contributed by Martin Shenk.
- */
-#define FLAT_DITHER_SETUP( R, G, B ) \
- GLushort ditherValues[16]; \
- { \
- unsigned long *ctable = XMESA_BUFFER(ctx->DrawBuffer)->color_table; \
- int msdr = (DITH_N*((DITH_R)-1)+1) * (R); \
- int msdg = (DITH_N*((DITH_G)-1)+1) * (G); \
- int msdb = (DITH_N*((DITH_B)-1)+1) * (B); \
- int i; \
- for (i=0;i<16;i++) { \
- int k = xmesa_kernel8[i]; \
- int j = DITH_MIX( (msdr+k)>>12, (msdg+k)>>12, (msdb+k)>>12 );\
- ditherValues[i] = (GLushort) ctable[j]; \
- } \
- }
-
-#define FLAT_DITHER_ROW_SETUP(Y) \
- GLushort *ditherRow = ditherValues + ( ((Y)&3) << 2);
-
-#define FLAT_DITHER(X) ditherRow[(X)&3]
-
-
-
-/**
- * If pixelformat==PF_LOOKUP:
- */
-#define _dither_lookup(C, c) (((unsigned)((DITH_N * (C - 1) + 1) * c)) >> 12)
-
-#define LOOKUP_SETUP \
- unsigned long *ctable = XMESA_BUFFER(ctx->DrawBuffer)->color_table
-
-#define LOOKUP( R, G, B ) \
- ctable[DITH_MIX(_dither_lookup(DITH_R, (R)), \
- _dither_lookup(DITH_G, (G)), \
- _dither_lookup(DITH_B, (B)))]
-
-
-/**
- * If pixelformat==PF_HPCR:
- *
- * HP Color Recovery dithering (ad@lms.be 30/08/95)
- * HP has on it's 8-bit 700-series computers, a feature called
- * 'Color Recovery'. This allows near 24-bit output (so they say).
- * It is enabled by selecting the 8-bit TrueColor visual AND
- * corresponding colormap (see tkInitWindow) AND doing some special
- * dither.
- */
-extern const short xmesa_HPCR_DRGB[3][2][16];
-
-#define DITHER_HPCR( X, Y, R, G, B ) \
- ( ((xmesa->xm_visual->hpcr_rgbTbl[0][R] + xmesa_HPCR_DRGB[0][(Y)&1][(X)&15]) & 0xE0) \
- |(((xmesa->xm_visual->hpcr_rgbTbl[1][G] + xmesa_HPCR_DRGB[1][(Y)&1][(X)&15]) & 0xE0)>>3) \
- | ((xmesa->xm_visual->hpcr_rgbTbl[2][B] + xmesa_HPCR_DRGB[2][(Y)&1][(X)&15])>>6) \
- )
-
-
-
-/**
- * If pixelformat==PF_1BIT:
- */
-extern const int xmesa_kernel1[16];
-
-#define SETUP_1BIT int bitFlip = xmesa->xm_visual->bitFlip
-#define DITHER_1BIT( X, Y, R, G, B ) \
- (( ((int)(R)+(int)(G)+(int)(B)) > xmesa_kernel1[(((Y)&3) << 2) | ((X)&3)] ) ^ bitFlip)
-
-
-
-/**
- * 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:
/**
- * Return the address of a 1, 2 or 4-byte pixel in the buffer's XImage:
+ * Return the address of a 2, 3 or 4-byte pixel in the buffer's XImage:
* X==0 is left, Y==0 is bottom.
*/
-#define PIXEL_ADDR1(XRB, X, Y) \
- ( (XRB)->origin1 - (Y) * (XRB)->width1 + (X) )
-
#define PIXEL_ADDR2(XRB, X, Y) \
( (XRB)->origin2 - (Y) * (XRB)->width2 + (X) )
*/
extern struct xmesa_renderbuffer *
-xmesa_create_renderbuffer(GLcontext *ctx, GLuint name, const GLvisual *visual,
- GLboolean backBuffer);
+xmesa_new_renderbuffer(struct gl_context *ctx, GLuint name,
+ const struct xmesa_visual *xmvis,
+ GLboolean backBuffer);
extern void
xmesa_delete_framebuffer(struct gl_framebuffer *fb);
xmesa_find_buffer(XMesaDisplay *dpy, XMesaColormap cmap, XMesaBuffer notThis);
extern unsigned long
-xmesa_color_to_pixel( GLcontext *ctx,
+xmesa_color_to_pixel( struct gl_context *ctx,
GLubyte r, GLubyte g, GLubyte b, GLubyte a,
GLuint pixelFormat );
struct dd_function_table *driver );
extern void
-xmesa_update_state( GLcontext *ctx, GLbitfield new_state );
+xmesa_update_state( struct gl_context *ctx, GLbitfield new_state );
+
+
+extern void
+xmesa_MapRenderbuffer(struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint x, GLuint y, GLuint w, GLuint h,
+ GLbitfield mode,
+ GLubyte **mapOut, GLint *rowStrideOut);
extern void
-xmesa_set_renderbuffer_funcs(struct xmesa_renderbuffer *xrb,
- enum pixel_format pixelformat, GLint depth);
+xmesa_UnmapRenderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb);
extern void
xmesa_destroy_buffers_on_display(XMesaDisplay *dpy);
/**
- * Return pointer to XMesaContext corresponding to a Mesa GLcontext.
+ * Return pointer to XMesaContext corresponding to a Mesa struct gl_context.
* 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)
+XMESA_CONTEXT(struct gl_context *ctx)
{
return (XMesaContext) ctx;
}
/**
- * Return pointer to XMesaBuffer corresponding to a Mesa GLframebuffer.
+ * Return pointer to XMesaBuffer corresponding to a Mesa struct gl_framebuffer.
* 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)
+XMESA_BUFFER(struct gl_framebuffer *b)
{
return (XMesaBuffer) b;
}
/* Plugged into the software rasterizer. Try to use internal
* swrast-style point, line and triangle functions.
*/
-extern void xmesa_choose_point( GLcontext *ctx );
-extern void xmesa_choose_line( GLcontext *ctx );
-extern void xmesa_choose_triangle( GLcontext *ctx );
+extern void xmesa_choose_point( struct gl_context *ctx );
+extern void xmesa_choose_line( struct gl_context *ctx );
+extern void xmesa_choose_triangle( struct gl_context *ctx );
-extern void xmesa_register_swrast_functions( GLcontext *ctx );
+extern void xmesa_register_swrast_functions( struct gl_context *ctx );
-#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
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#define ENABLE_EXT_timer_query 1 /* should have 64-bit GLuint64EXT */
#else
#define ENABLE_EXT_timer_query 0 /* may not have 64-bit GLuint64EXT */
#endif
-struct pipe_surface;
-struct pipe_context;
-
-struct xmesa_surface
-{
- struct softpipe_surface surface;
- struct xmesa_renderbuffer *xrb;
-};
-
-
-extern struct pipe_surface *
-xmesa_new_surface(GLcontext *ctx, struct xmesa_renderbuffer *xrb);
-
-extern void
-xmesa_clear(struct pipe_context *pipe, struct pipe_surface *ps, GLuint value);
-
-extern void
-xmesa_clear_buffers(GLcontext *ctx, GLbitfield buffers);
-
-extern struct pipe_context *
-xmesa_create_softpipe(XMesaContext xm);
-
-extern struct pipe_surface *
-xmesa_surface_alloc(struct pipe_context *pipe, GLuint format);
-
-extern const GLuint *
-xmesa_supported_formats(struct pipe_context *pipe, GLuint *numFormats);
+#define TEST_META_FUNCS 0
#endif