From 304d3aa9cb727eb4cd4797c33f8e13e5ac4285a9 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 19 Feb 2004 00:57:04 +0000 Subject: [PATCH] Refactored several variables out of XMesaVisual in favor of identical fields in __GLcontextModes (the base type). Removed the need to keep the XMesaVisualInfo pointer when building inside the X-server. --- include/GL/xmesa_x.h | 13 ++-- include/GL/xmesa_xf86.h | 11 ++- src/mesa/drivers/x11/fakeglx.c | 14 ++-- src/mesa/drivers/x11/xm_api.c | 127 +++++++++++++++++++++------------ src/mesa/drivers/x11/xm_dd.c | 7 +- src/mesa/drivers/x11/xmesaP.h | 15 ++-- 6 files changed, 109 insertions(+), 78 deletions(-) diff --git a/include/GL/xmesa_x.h b/include/GL/xmesa_x.h index def0447195f..8c4e41e545a 100644 --- a/include/GL/xmesa_x.h +++ b/include/GL/xmesa_x.h @@ -74,16 +74,11 @@ typedef XColor XMesaColor; #define XMesaFreeGC XFreeGC #define GET_COLORMAP_SIZE(__v) __v->visinfo->colormap_size -#define GET_REDMASK(__v) __v->visinfo->red_mask -#define GET_GREENMASK(__v) __v->visinfo->green_mask -#define GET_BLUEMASK(__v) __v->visinfo->blue_mask -#if defined(__cplusplus) || defined(c_plusplus) -#define GET_VISUAL_CLASS(__v) __v->visinfo->c_class -#else -#define GET_VISUAL_CLASS(__v) __v->visinfo->class -#endif +#define GET_REDMASK(__v) __v->mesa_visual.redMask +#define GET_GREENMASK(__v) __v->mesa_visual.greenMask +#define GET_BLUEMASK(__v) __v->mesa_visual.blueMask #define GET_VISUAL_DEPTH(__v) __v->visinfo->depth -#define GET_BLACK_PIXEL(__v) BlackPixel(__v->display, __v->visinfo->screen) +#define GET_BLACK_PIXEL(__v) BlackPixel(__v->display, __v->mesa_visual.screen) #define CHECK_BYTE_ORDER(__v) host_byte_order()==ImageByteOrder(__v->display) #define CHECK_FOR_HPCR(__v) XInternAtom(__v->display, "_HP_RGB_SMOOTH_MAP_LIST", True) diff --git a/include/GL/xmesa_xf86.h b/include/GL/xmesa_xf86.h index 983f234ddd9..88a94dcd765 100644 --- a/include/GL/xmesa_xf86.h +++ b/include/GL/xmesa_xf86.h @@ -174,12 +174,11 @@ do { \ FreeScratchGC(__gc); \ } while (0) -#define GET_COLORMAP_SIZE(__v) __v->visinfo->ColormapEntries -#define GET_REDMASK(__v) __v->visinfo->redMask -#define GET_GREENMASK(__v) __v->visinfo->greenMask -#define GET_BLUEMASK(__v) __v->visinfo->blueMask -#define GET_VISUAL_CLASS(__v) __v->visinfo->class -#define GET_VISUAL_DEPTH(__v) __v->visinfo->nplanes +#define GET_COLORMAP_SIZE(__v) __v->ColormapEntries +#define GET_REDMASK(__v) __v->mesa_visual.redMask +#define GET_GREENMASK(__v) __v->mesa_visual.greenMask +#define GET_BLUEMASK(__v) __v->mesa_visual.blueMask +#define GET_VISUAL_DEPTH(__v) __v->nplanes #define GET_BLACK_PIXEL(__v) __v->display->blackPixel #define CHECK_BYTE_ORDER(__v) GL_TRUE #define CHECK_FOR_HPCR(__v) GL_FALSE diff --git a/src/mesa/drivers/x11/fakeglx.c b/src/mesa/drivers/x11/fakeglx.c index a616915f1d9..063cc9c3575 100644 --- a/src/mesa/drivers/x11/fakeglx.c +++ b/src/mesa/drivers/x11/fakeglx.c @@ -296,7 +296,7 @@ save_glx_visual( Display *dpy, XVisualInfo *vinfo, for (i=0; idisplay == dpy - && v->level == level + && v->mesa_visual.level == level && v->ximage_flag == ximageFlag && v->mesa_visual.rgbMode == rgbFlag && v->mesa_visual.doubleBufferMode == dbFlag @@ -1559,7 +1559,7 @@ get_config( XMesaVisual xmvis, int attrib, int *value, GLboolean fbconfig ) *value = xmvis->visinfo->depth; return 0; case GLX_LEVEL: - *value = xmvis->level; + *value = xmvis->mesa_visual.level; return 0; case GLX_RGBA: if (xmvis->mesa_visual.rgbMode) { @@ -1623,11 +1623,11 @@ get_config( XMesaVisual xmvis, int attrib, int *value, GLboolean fbconfig ) } return 0; case GLX_TRANSPARENT_TYPE_EXT: - if (xmvis->level==0) { + if (xmvis->mesa_visual.level==0) { /* normal planes */ *value = GLX_NONE_EXT; } - else if (xmvis->level>0) { + else if (xmvis->mesa_visual.level>0) { /* overlay */ if (xmvis->mesa_visual.rgbMode) { *value = GLX_TRANSPARENT_RGB_EXT; @@ -1636,7 +1636,7 @@ get_config( XMesaVisual xmvis, int attrib, int *value, GLboolean fbconfig ) *value = GLX_TRANSPARENT_INDEX_EXT; } } - else if (xmvis->level<0) { + else if (xmvis->mesa_visual.level<0) { /* underlay */ *value = GLX_NONE_EXT; } @@ -1668,8 +1668,8 @@ get_config( XMesaVisual xmvis, int attrib, int *value, GLboolean fbconfig ) */ case GLX_VISUAL_CAVEAT_EXT: /* test for zero, just in case */ - if (xmvis->VisualCaveat > 0) - *value = xmvis->VisualCaveat; + if (xmvis->mesa_visual.visualRating > 0) + *value = xmvis->mesa_visual.visualRating; else *value = GLX_NONE_EXT; return 0; diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c index 9a852d9e4cc..16963ab71c7 100644 --- a/src/mesa/drivers/x11/xm_api.c +++ b/src/mesa/drivers/x11/xm_api.c @@ -81,12 +81,10 @@ #include "tnl/t_pipeline.h" #include "drivers/common/driverfuncs.h" - -#ifndef GLX_NONE_EXT -#define GLX_NONE_EXT 0x8000 +#ifdef XFree86Server +#include #endif - /* * Global X driver lock */ @@ -273,8 +271,7 @@ static GLint gamma_adjust( GLfloat gamma, GLint value, GLint max ) static int bits_per_pixel( XMesaVisual xmv ) { - XMesaVisualInfo visinfo = xmv->visinfo; - const int depth = visinfo->nplanes; + const int depth = xmv->nplanes; int i; for (i = 0; i < screenInfo.numPixmapFormats; i++) { if (screenInfo.formats[i].depth == depth) @@ -1200,26 +1197,25 @@ static GLboolean initialize_visual_and_buffer( int client, * being color indexed. This is weird but might be useful to someone. */ v->dithered_pf = v->undithered_pf = PF_Index; - v->index_bits = GET_VISUAL_DEPTH(v); + v->mesa_visual.indexBits = GET_VISUAL_DEPTH(v); } else { /* RGB WINDOW: * We support RGB rendering into almost any kind of visual. */ - int xclass; - xclass = GET_VISUAL_CLASS(v); - if (xclass==TrueColor || xclass==DirectColor) { + const int xclass = v->mesa_visual.visualType; + if (xclass==GLX_TRUE_COLOR || xclass==GLX_DIRECT_COLOR) { setup_truecolor( v, b, cmap ); } - else if (xclass==StaticGray && GET_VISUAL_DEPTH(v)==1) { + else if (xclass==GLX_STATIC_GRAY && GET_VISUAL_DEPTH(v)==1) { setup_monochrome( v, b ); } - else if (xclass==GrayScale || xclass==StaticGray) { + else if (xclass==GLX_GRAY_SCALE || xclass==GLX_STATIC_GRAY) { if (!setup_grayscale( client, v, b, cmap )) { return GL_FALSE; } } - else if ((xclass==PseudoColor || xclass==StaticColor) + else if ((xclass==GLX_PSEUDO_COLOR || xclass==GLX_STATIC_COLOR) && GET_VISUAL_DEPTH(v)>=4 && GET_VISUAL_DEPTH(v)<=16) { if (!setup_dithered_color( client, v, b, cmap )) { return GL_FALSE; @@ -1229,7 +1225,7 @@ static GLboolean initialize_visual_and_buffer( int client, _mesa_warning(NULL, "XMesa: RGB mode rendering not supported in given visual."); return GL_FALSE; } - v->index_bits = 0; + v->mesa_visual.indexBits = 0; if (_mesa_getenv("MESA_NO_DITHER")) { v->dithered_pf = v->undithered_pf; @@ -1246,7 +1242,7 @@ static GLboolean initialize_visual_and_buffer( int client, _mesa_printf("X/Mesa visual = %p\n", (void *) v); _mesa_printf("X/Mesa dithered pf = %u\n", v->dithered_pf); _mesa_printf("X/Mesa undithered pf = %u\n", v->undithered_pf); - _mesa_printf("X/Mesa level = %d\n", v->level); + _mesa_printf("X/Mesa level = %d\n", v->mesa_visual.level); _mesa_printf("X/Mesa depth = %d\n", GET_VISUAL_DEPTH(v)); _mesa_printf("X/Mesa bits per pixel = %d\n", v->BitsPerPixel); } @@ -1410,6 +1406,34 @@ xmesa_color_to_pixel( XMesaContext xmesa, GLubyte r, GLubyte g, GLubyte b, GLuby } +#define NUM_VISUAL_TYPES 6 + +/** + * Convert an X visual type to a GLX visual type. + * + * \param visualType X visual type (i.e., \c TrueColor, \c StaticGray, etc.) + * to be converted. + * \return If \c visualType is a valid X visual type, a GLX visual type will + * be returned. Otherwise \c GLX_NONE will be returned. + * + * \note + * This code was lifted directly from lib/GL/glx/glcontextmodes.c in the + * DRI CVS tree. + */ +static GLint +xmesa_convert_from_x_visual_type( int visualType ) +{ + static const int glx_visual_types[ NUM_VISUAL_TYPES ] = { + GLX_STATIC_GRAY, GLX_GRAY_SCALE, + GLX_STATIC_COLOR, GLX_PSEUDO_COLOR, + GLX_TRUE_COLOR, GLX_DIRECT_COLOR + }; + + return ( (unsigned) visualType < NUM_VISUAL_TYPES ) + ? glx_visual_types[ visualType ] : GLX_NONE; +} + + /**********************************************************************/ /***** Public Functions *****/ /**********************************************************************/ @@ -1435,7 +1459,7 @@ xmesa_color_to_pixel( XMesaContext xmesa, GLubyte r, GLubyte g, GLubyte b, GLuby * accum_alpha_size - requested bits/alpha accum values, or zero * num_samples - number of samples/pixel if multisampling, or zero * level - visual level, usually 0 - * visualCaveat - ala the GLX extension, usually GLX_NONE_EXT + * visualCaveat - ala the GLX extension, usually GLX_NONE * Return; a new XMesaVisual or 0 if error. */ XMesaVisual XMesaCreateVisual( XMesaDisplay *display, @@ -1488,9 +1512,7 @@ XMesaVisual XMesaCreateVisual( XMesaDisplay *display, * the struct but we may need some of the information contained in it * at a later time. */ -#ifdef XFree86Server - v->visinfo = visinfo; -#else +#ifndef XFree86Server v->visinfo = (XVisualInfo *) MALLOC(sizeof(*visinfo)); if(!v->visinfo) { FREE(v); @@ -1499,19 +1521,6 @@ XMesaVisual XMesaCreateVisual( XMesaDisplay *display, MEMCPY(v->visinfo, visinfo, sizeof(*visinfo)); #endif -#ifdef XFree86Server - /* Initialize the depth of the screen */ - { - PixmapFormatRec *format; - - for (format = screenInfo.formats; - format->depth != display->rootDepth; - format++) - ; - v->screen_depth = format->bitsPerPixel; - } -#endif - /* check for MESA_GAMMA environment variable */ gamma = _mesa_getenv("MESA_GAMMA"); if (gamma) { @@ -1526,15 +1535,42 @@ XMesaVisual XMesaCreateVisual( XMesaDisplay *display, } v->ximage_flag = ximage_flag; - v->level = level; - v->VisualCaveat = visualCaveat; + +#ifdef XFree86Server + /* We could calculate these values by ourselves. nplanes is either the sum + * of the red, green, and blue bits or the number index bits. + * ColormapEntries is either (1U << index_bits) or + * (1U << max(redBits, greenBits, blueBits)). + */ + v->nplanes = visinfo->nplanes; + v->ColormapEntries = visinfo->ColormapEntries; + + v->mesa_visual.redMask = visinfo->redMask; + v->mesa_visual.greenMask = visinfo->greenMask; + v->mesa_visual.blueMask = visinfo->blueMask; + v->mesa_visual.visualID = visinfo->vid; + v->mesa_visual.screen = 0; /* FIXME: What should be done here? */ +#else + v->mesa_visual.redMask = visinfo->red_mask; + v->mesa_visual.greenMask = visinfo->green_mask; + v->mesa_visual.blueMask = visinfo->blue_mask; + v->mesa_visual.visualID = visinfo->visualid; + v->mesa_visual.screen = visinfo->screen; +#endif + +#if defined(XFree86Server) || !(defined(__cplusplus) || defined(c_plusplus)) + v->mesa_visual.visualType = xmesa_convert_from_x_visual_type(visinfo->class); +#else + v->mesa_visual.visualType = xmesa_convert_from_x_visual_type(visinfo->c_class); +#endif + + v->mesa_visual.visualRating = visualCaveat; (void) initialize_visual_and_buffer( 0, v, NULL, rgb_flag, 0, 0 ); { - int xclass; - xclass = GET_VISUAL_CLASS(v); - if (xclass==TrueColor || xclass==DirectColor) { + const int xclass = v->mesa_visual.visualType; + if (xclass==GLX_TRUE_COLOR || xclass==GLX_DIRECT_COLOR) { red_bits = bitcount(GET_REDMASK(v)); green_bits = bitcount(GET_GREENMASK(v)); blue_bits = bitcount(GET_BLUEMASK(v)); @@ -1561,12 +1597,14 @@ XMesaVisual XMesaCreateVisual( XMesaDisplay *display, rgb_flag, db_flag, stereo_flag, red_bits, green_bits, blue_bits, alpha_bits, - v->index_bits, + v->mesa_visual.indexBits, depth_size, stencil_size, accum_red_size, accum_green_size, accum_blue_size, accum_alpha_size, 0 ); + + v->mesa_visual.level = level; return v; } @@ -1837,13 +1875,14 @@ XMesaBuffer XMesaCreateWindowBuffer( XMesaVisual v, XMesaWindow w ) } -/* +/** * Create a new XMesaBuffer from an X pixmap. - * Input: v - the XMesaVisual - * p - the pixmap - * cmap - the colormap, may be 0 if using a TrueColor or DirectColor - * visual for the pixmap - * Return: new XMesaBuffer or NULL if error + * + * \param v the XMesaVisual + * \param p the pixmap + * \param cmap the colormap, may be 0 if using a \c GLX_TRUE_COLOR or + * \c GLX_DIRECT_COLOR visual for the pixmap + * \returns new XMesaBuffer or NULL if error */ XMesaBuffer XMesaCreatePixmapBuffer( XMesaVisual v, XMesaPixmap p, XMesaColormap cmap ) diff --git a/src/mesa/drivers/x11/xm_dd.c b/src/mesa/drivers/x11/xm_dd.c index 9f4302b188f..68e56029d24 100644 --- a/src/mesa/drivers/x11/xm_dd.c +++ b/src/mesa/drivers/x11/xm_dd.c @@ -48,6 +48,9 @@ #include "tnl/tnl.h" #include "tnl/t_context.h" +#ifdef XFree86Server +#include +#endif /* * Return the size (width, height) of the X window for the given GLframebuffer. @@ -214,10 +217,10 @@ color_mask(GLcontext *ctx, GLboolean rmask, GLboolean gmask, GLboolean bmask, GLboolean amask) { const XMesaContext xmesa = XMESA_CONTEXT(ctx); - int xclass = GET_VISUAL_CLASS(xmesa->xm_visual); + const int xclass = xmesa->xm_visual->mesa_visual.visualType; (void) amask; - if (xclass == TrueColor || xclass == DirectColor) { + if (xclass == GLX_TRUE_COLOR || xclass == GLX_DIRECT_COLOR) { unsigned long m; if (rmask && gmask && bmask) { m = ((unsigned long)~0L); diff --git a/src/mesa/drivers/x11/xmesaP.h b/src/mesa/drivers/x11/xmesaP.h index ee1f4add1a4..4a1f49799a0 100644 --- a/src/mesa/drivers/x11/xmesaP.h +++ b/src/mesa/drivers/x11/xmesaP.h @@ -86,17 +86,15 @@ enum pixel_format { struct xmesa_visual { GLvisual mesa_visual; /* Device independent visual parameters */ XMesaDisplay *display; /* The X11 display */ -#ifdef XFree86Server - GLint screen_depth; /* The depth of the screen */ -#else +#ifndef XFree86Server XVisualInfo *vishandle; /* Only used in fakeglx.c */ -#endif XMesaVisualInfo visinfo; /* X's visual info (pointer to private copy) */ +#else + GLint ColormapEntries; + GLint nplanes; +#endif GLint BitsPerPixel; /* True bits per pixel for XImages */ - GLint level; /* 0=normal, 1=overlay, etc */ - GLint VisualCaveat; /* for GLX_EXT_visual_rating extension */ - GLboolean ximage_flag; /* Use XImage for back buffer (not pixmap)? */ enum pixel_format dithered_pf; /* Pixel format when dithering */ @@ -106,9 +104,6 @@ struct xmesa_visual { GLfloat GreenGamma; GLfloat BlueGamma; - GLint rmult, gmult, bmult; /* Range of color values */ - GLint index_bits; /* Bits per pixel in CI mode */ - /* For PF_TRUECOLOR */ GLint rshift, gshift, bshift;/* Pixel color component shifts */ GLubyte Kernel[16]; /* Dither kernel */