#ifndef XMESAP_H
#define XMESAP_H
#ifdef XFree86Server
# include "GL/xf86glx.h"
# include "xf86glx_util.h"
#else
# ifdef USE_XSHM
# include <X11/extensions/XShm.h>
# endif
#endif
#include "GL/xmesa.h"
#include "mtypes.h"
#if defined(FX)
#include "GL/fxmesa.h"
#include "FX/fxdrv.h"
#endif
extern _glthread_Mutex _xmesa_lock;
typedef struct {
GLubyte b;
GLubyte g;
GLubyte r;
} bgr_t;
typedef void (*clear_func)( GLcontext *ctx,
GLboolean all, GLint x, GLint y,
GLint width, GLint height );
struct xmesa_visual {
GLvisual mesa_visual;
XMesaDisplay *display;
#ifdef XFree86Server
GLint screen_depth;
#else
XVisualInfo *vishandle;
#endif
XMesaVisualInfo visinfo;
GLint BitsPerPixel;
GLint level;
GLint VisualCaveat;
GLboolean ximage_flag;
GLuint dithered_pf;
GLuint undithered_pf;
GLfloat RedGamma;
GLfloat GreenGamma;
GLfloat BlueGamma;
GLint rmult, gmult, bmult;
GLint index_bits;
GLint rshift, gshift, bshift;
GLubyte Kernel[16];
unsigned long RtoPixel[512];
unsigned long GtoPixel[512];
unsigned long BtoPixel[512];
GLubyte PixelToR[256];
GLubyte PixelToG[256];
GLubyte PixelToB[256];
short hpcr_rgbTbl[3][256];
GLboolean hpcr_clear_flag;
GLubyte hpcr_clear_ximage_pattern[2][16];
XMesaImage *hpcr_clear_ximage;
XMesaPixmap hpcr_clear_pixmap;
int bitFlip;
};
struct xmesa_context {
GLcontext *gl_ctx;
XMesaVisual xm_visual;
XMesaBuffer xm_draw_buffer;
XMesaBuffer xm_read_buffer;
XMesaBuffer xm_buffer;
XMesaDisplay *display;
GLboolean swapbytes;
GLboolean direct;
GLuint pixelformat;
GLubyte clearcolor[4];
unsigned long clearpixel;
};
typedef enum {
WINDOW,
GLXWINDOW,
PIXMAP,
PBUFFER
} BufferType;
struct xmesa_buffer {
GLframebuffer mesa_buffer;
GLboolean wasCurrent;
XMesaVisual xm_visual;
XMesaDisplay *display;
BufferType type;
XMesaDrawable frontbuffer;
XMesaPixmap backpixmap;
XMesaImage *backimage;
XMesaDrawable buffer;
XMesaColormap cmap;
unsigned long selectedEvents;
GLint db_state;
#ifndef XFree86Server
GLuint shm;
#ifdef USE_XSHM
XShmSegmentInfo shminfo;
#endif
#endif
XMesaImage *rowimage;
GLuint width, height;
GLint bottom;
GLubyte *ximage_origin1;
GLint ximage_width1;
GLushort *ximage_origin2;
GLint ximage_width2;
GLubyte *ximage_origin3;
GLint ximage_width3;
GLuint *ximage_origin4;
GLint ximage_width4;
XMesaPixmap stipple_pixmap;
XMesaGC stipple_gc;
XMesaGC gc;
XMesaGC cleargc;
XMesaGC swapgc;
unsigned long color_table[576];
GLubyte pixel_to_r[65536];
GLubyte pixel_to_g[65536];
GLubyte pixel_to_b[65536];
int num_alloced;
#if defined(XFree86Server)
Pixel alloced_colors[256];
#else
unsigned long alloced_colors[256];
#endif
#if defined( FX )
GLboolean FXisHackUsable;
GLboolean FXwindowHack;
fxMesaContext FXctx;
#endif
clear_func front_clear_func;
clear_func back_clear_func;
struct xmesa_buffer *Next;
};
#define FRONT_PIXMAP 1
#define BACK_PIXMAP 2
#define BACK_XIMAGE 4
#define PF_INDEX 1
#define PF_TRUECOLOR 2
#define PF_TRUEDITHER 3
#define PF_8A8B8G8R 4
#define PF_8R8G8B 5
#define PF_5R6G5B 6
#define PF_DITHER 7
#define PF_LOOKUP 8
#define PF_HPCR 9
#define PF_1BIT 10
#define PF_GRAYSCALE 11
#define PF_8R8G8B24 12
#define PF_DITHER_5R6G5B 13
#define PACK_TRUECOLOR( PIXEL, R, G, B ) \
PIXEL = xmesa->xm_visual->RtoPixel[R] \
| xmesa->xm_visual->GtoPixel[G] \
| xmesa->xm_visual->BtoPixel[B]; \
#define PACK_TRUEDITHER( PIXEL, X, Y, R, G, B ) \
{ \
int d = xmesa->xm_visual->Kernel[((X)&3) | (((Y)&3)<<2)]; \
PIXEL = xmesa->xm_visual->RtoPixel[(R)+d] \
| xmesa->xm_visual->GtoPixel[(G)+d] \
| xmesa->xm_visual->BtoPixel[(B)+d]; \
}
#define PACK_8A8B8G8R( R, G, B, A ) \
( ((A) << 24) | ((B) << 16) | ((G) << 8) | (R) )
#define PACK_8B8G8R( R, G, B ) ( ((B) << 16) | ((G) << 8) | (R) )
#define PACK_8R8G8B( R, G, B) ( ((R) << 16) | ((G) << 8) | (B) )
#define PACK_5R6G5B( R, G, B) ( (((R) & 0xf8) << 8) | (((G) & 0xfc) << 3) | ((B) >> 3) )
#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
static int kernel8[DITH_DY * DITH_DX] = {
0 * MAXC, 8 * MAXC, 2 * MAXC, 10 * MAXC,
12 * MAXC, 4 * MAXC, 14 * MAXC, 6 * MAXC,
3 * MAXC, 11 * MAXC, 1 * MAXC, 9 * MAXC,
15 * MAXC, 7 * MAXC, 13 * MAXC, 5 * MAXC,
};
#define DITHER_SETUP \
int __d; \
unsigned long *ctable = xmesa->xm_buffer->color_table;
#define DITHER( X, Y, R, G, B ) \
(__d = kernel8[(((Y)&3)<<2) | ((X)&3)], \
ctable[DITH_MIX(_dither(DITH_R, (R), __d), \
_dither(DITH_G, (G), __d), \
_dither(DITH_B, (B), __d))])
#define XDITHER_SETUP(Y) \
int __d; \
unsigned long *ctable = xmesa->xm_buffer->color_table; \
int *kernel = &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))])
static GLushort DitherValues[16];
#define FLAT_DITHER_SETUP( R, G, B ) \
{ \
unsigned long *ctable = xmesa->xm_buffer->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 = 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]
#define _dither_lookup(C, c) (((unsigned)((DITH_N * (C - 1) + 1) * c)) >> 12)
#define LOOKUP_SETUP \
unsigned long *ctable = xmesa->xm_buffer->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)))]
static const short HPCR_DRGB[3][2][16] = {
{
{ 16, -4, 1,-11, 14, -6, 3, -9, 15, -5, 2,-10, 13, -7, 4, -8},
{-15, 5, 0, 12,-13, 7, -2, 10,-14, 6, -1, 11,-12, 8, -3, 9}
},
{
{-11, 15, -7, 3, -8, 14, -4, 2,-10, 16, -6, 4, -9, 13, -5, 1},
{ 12,-14, 8, -2, 9,-13, 5, -1, 11,-15, 7, -3, 10,-12, 6, 0}
},
{
{ 6,-18, 26,-14, 2,-22, 30,-10, 8,-16, 28,-12, 4,-20, 32, -8},
{ -4, 20,-24, 16, 0, 24,-28, 12, -6, 18,-26, 14, -2, 22,-30, 10}
}
};
#define DITHER_HPCR( X, Y, R, G, B ) \
( ((xmesa->xm_visual->hpcr_rgbTbl[0][R] + HPCR_DRGB[0][(Y)&1][(X)&15]) & 0xE0) \
|(((xmesa->xm_visual->hpcr_rgbTbl[1][G] + HPCR_DRGB[1][(Y)&1][(X)&15]) & 0xE0)>>3) \
| ((xmesa->xm_visual->hpcr_rgbTbl[2][B] + HPCR_DRGB[2][(Y)&1][(X)&15])>>6) \
)
static int const kernel1[16] = {
0*47, 9*47, 4*47, 12*47,
6*47, 2*47, 14*47, 8*47,
10*47, 1*47, 5*47, 11*47,
7*47, 13*47, 3*47, 15*47 };
#define SETUP_1BIT int bitFlip = xmesa->xm_visual->bitFlip
#define DITHER_1BIT( X, Y, R, G, B ) \
(( ((int)(R)+(int)(G)+(int)(B)) > kernel1[(((Y)&3) << 2) | ((X)&3)] ) ^ bitFlip)
#define GRAY_RGB( R, G, B ) xmesa->xm_buffer->color_table[((R) + (G) + (B))/3]
#define XIMAGE None
#define FLIP(BUFFER, Y) ((BUFFER)->bottom-(Y))
#define PIXELADDR1( BUFFER, X, Y ) \
( (BUFFER)->ximage_origin1 - (Y) * (BUFFER)->ximage_width1 + (X) )
#define PIXELADDR2( BUFFER, X, Y ) \
( (BUFFER)->ximage_origin2 - (Y) * (BUFFER)->ximage_width2 + (X) )
#define PIXELADDR3( BUFFER, X, Y ) \
( (bgr_t *) ( (BUFFER)->ximage_origin3 - (Y) * (BUFFER)->ximage_width3 + 3 * (X) ))
#define PIXELADDR4( BUFFER, X, Y ) \
( (BUFFER)->ximage_origin4 - (Y) * (BUFFER)->ximage_width4 + (X) )
extern unsigned long
xmesa_color_to_pixel( XMesaContext xmesa,
GLubyte r, GLubyte g, GLubyte b, GLubyte a,
GLuint pixelFormat );
extern void xmesa_alloc_back_buffer( XMesaBuffer b );
extern void xmesa_init_pointers( GLcontext *ctx );
extern void xmesa_update_state( GLcontext *ctx, GLuint new_state );
extern void xmesa_update_span_funcs( GLcontext *ctx );
extern void xmesa_choose_point( GLcontext *ctx );
extern void xmesa_choose_line( GLcontext *ctx );
extern void xmesa_choose_triangle( GLcontext *ctx );
extern void xmesa_register_swrast_functions( GLcontext *ctx );
extern XMesaBuffer XMesaCreateWindowBuffer2( XMesaVisual v,
XMesaWindow w,
XMesaContext c
);
extern void XMesaSetVisualDisplay( XMesaDisplay *dpy, XMesaVisual v );
extern GLboolean XMesaForceCurrent(XMesaContext c);
extern GLboolean XMesaLoseCurrent(XMesaContext c);
extern void XMesaReset( void );
extern void xmesa_resize_buffers( GLframebuffer *buffer );
#endif