summaryrefslogtreecommitdiff
path: root/src/mesa/drivers/x11/xm_api.c
diff options
context:
space:
mode:
authorIan Romanick <idr@us.ibm.com>2004-02-19 00:57:04 +0000
committerIan Romanick <idr@us.ibm.com>2004-02-19 00:57:04 +0000
commit304d3aa9cb727eb4cd4797c33f8e13e5ac4285a9 (patch)
treedbd971e7bfa0355e40db0ccd4efceebd2dcb68b1 /src/mesa/drivers/x11/xm_api.c
parente01370271eebb6cf86d8119c3c37b3f6f9db1d8b (diff)
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.
Diffstat (limited to 'src/mesa/drivers/x11/xm_api.c')
-rw-r--r--src/mesa/drivers/x11/xm_api.c127
1 files changed, 83 insertions, 44 deletions
diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c
index 9a852d9e4c..16963ab71c 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 <GL/glxtokens.h>
#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 )