summaryrefslogtreecommitdiff
path: root/src/gallium/state_trackers/glx
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/state_trackers/glx')
-rw-r--r--src/gallium/state_trackers/glx/xlib/glx_api.c53
-rw-r--r--src/gallium/state_trackers/glx/xlib/glx_usefont.c2
-rw-r--r--src/gallium/state_trackers/glx/xlib/xm_api.c143
-rw-r--r--src/gallium/state_trackers/glx/xlib/xm_api.h3
4 files changed, 117 insertions, 84 deletions
diff --git a/src/gallium/state_trackers/glx/xlib/glx_api.c b/src/gallium/state_trackers/glx/xlib/glx_api.c
index 3caf56e924..08bf624b5c 100644
--- a/src/gallium/state_trackers/glx/xlib/glx_api.c
+++ b/src/gallium/state_trackers/glx/xlib/glx_api.c
@@ -280,7 +280,7 @@ default_depth_bits(void)
int zBits;
const char *zEnv = _mesa_getenv("MESA_GLX_DEPTH_BITS");
if (zEnv)
- zBits = _mesa_atoi(zEnv);
+ zBits = atoi(zEnv);
else
zBits = DEFAULT_SOFTWARE_DEPTH_BITS;
return zBits;
@@ -292,7 +292,7 @@ default_alpha_bits(void)
int aBits;
const char *aEnv = _mesa_getenv("MESA_GLX_ALPHA_BITS");
if (aEnv)
- aBits = _mesa_atoi(aEnv);
+ aBits = atoi(aEnv);
else
aBits = 0;
return aBits;
@@ -442,17 +442,17 @@ get_env_visual(Display *dpy, int scr, const char *varname)
return NULL;
}
- _mesa_strncpy( value, _mesa_getenv(varname), 100 );
+ strncpy( value, _mesa_getenv(varname), 100 );
value[99] = 0;
sscanf( value, "%s %d", type, &depth );
- if (_mesa_strcmp(type,"TrueColor")==0) xclass = TrueColor;
- else if (_mesa_strcmp(type,"DirectColor")==0) xclass = DirectColor;
- else if (_mesa_strcmp(type,"PseudoColor")==0) xclass = PseudoColor;
- else if (_mesa_strcmp(type,"StaticColor")==0) xclass = StaticColor;
- else if (_mesa_strcmp(type,"GrayScale")==0) xclass = GrayScale;
- else if (_mesa_strcmp(type,"StaticGray")==0) xclass = StaticGray;
+ if (strcmp(type,"TrueColor")==0) xclass = TrueColor;
+ else if (strcmp(type,"DirectColor")==0) xclass = DirectColor;
+ else if (strcmp(type,"PseudoColor")==0) xclass = PseudoColor;
+ else if (strcmp(type,"StaticColor")==0) xclass = StaticColor;
+ else if (strcmp(type,"GrayScale")==0) xclass = GrayScale;
+ else if (strcmp(type,"StaticGray")==0) xclass = StaticGray;
if (xclass>-1 && depth>0) {
vis = get_visual( dpy, scr, depth, xclass );
@@ -689,6 +689,8 @@ choose_visual( Display *dpy, int screen, const int *list, GLboolean fbConfig )
int desiredVisualID = -1;
int numAux = 0;
+ xmesa_init();
+
parselist = list;
while (*parselist) {
@@ -941,9 +943,6 @@ choose_visual( Display *dpy, int screen, const int *list, GLboolean fbConfig )
/* give the visual some useful GLX attributes */
double_flag = GL_TRUE;
rgb_flag = GL_TRUE;
- depth_size = default_depth_bits();
- stencil_size = STENCIL_BITS;
- /* XXX accum??? */
}
}
else if (level==0) {
@@ -1018,9 +1017,9 @@ glXChooseVisual( Display *dpy, int screen, int *list )
xmvis = choose_visual(dpy, screen, list, GL_FALSE);
if (xmvis) {
/* create a new vishandle - the cached one may be stale */
- xmvis->vishandle = (XVisualInfo *) _mesa_malloc(sizeof(XVisualInfo));
+ xmvis->vishandle = (XVisualInfo *) malloc(sizeof(XVisualInfo));
if (xmvis->vishandle) {
- _mesa_memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
+ memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
}
return xmvis->vishandle;
}
@@ -1055,7 +1054,7 @@ glXCreateContext( Display *dpy, XVisualInfo *visinfo,
xmvis = create_glx_visual( dpy, visinfo );
if (!xmvis) {
/* unusable visual */
- _mesa_free(glxCtx);
+ free(glxCtx);
return NULL;
}
}
@@ -1063,7 +1062,7 @@ glXCreateContext( Display *dpy, XVisualInfo *visinfo,
glxCtx->xmesaContext = XMesaCreateContext(xmvis,
shareCtx ? shareCtx->xmesaContext : NULL);
if (!glxCtx->xmesaContext) {
- _mesa_free(glxCtx);
+ free(glxCtx);
return NULL;
}
@@ -1336,7 +1335,7 @@ glXDestroyContext( Display *dpy, GLXContext ctx )
MakeCurrent_PrevReadBuffer = 0;
XMesaDestroyContext( glxCtx->xmesaContext );
XMesaGarbageCollect();
- _mesa_free(glxCtx);
+ free(glxCtx);
}
@@ -1679,8 +1678,8 @@ PUBLIC const char *
glXQueryServerString( Display *dpy, int screen, int name )
{
static char version[1000];
- _mesa_sprintf(version, "%d.%d %s",
- SERVER_MAJOR_VERSION, SERVER_MINOR_VERSION, MESA_GLX_VERSION);
+ sprintf(version, "%d.%d %s",
+ SERVER_MAJOR_VERSION, SERVER_MINOR_VERSION, MESA_GLX_VERSION);
(void) dpy;
(void) screen;
@@ -1704,8 +1703,8 @@ PUBLIC const char *
glXGetClientString( Display *dpy, int name )
{
static char version[1000];
- _mesa_sprintf(version, "%d.%d %s", CLIENT_MAJOR_VERSION,
- CLIENT_MINOR_VERSION, MESA_GLX_VERSION);
+ sprintf(version, "%d.%d %s", CLIENT_MAJOR_VERSION,
+ CLIENT_MINOR_VERSION, MESA_GLX_VERSION);
(void) dpy;
@@ -1755,7 +1754,7 @@ glXGetFBConfigs( Display *dpy, int screen, int *nelements )
visuals = XGetVisualInfo(dpy, visMask, &visTemplate, nelements);
if (*nelements > 0) {
XMesaVisual *results;
- results = (XMesaVisual *) _mesa_malloc(*nelements * sizeof(XMesaVisual));
+ results = (XMesaVisual *) malloc(*nelements * sizeof(XMesaVisual));
if (!results) {
*nelements = 0;
return NULL;
@@ -1782,7 +1781,7 @@ glXChooseFBConfig( Display *dpy, int screen,
xmvis = choose_visual(dpy, screen, attribList, GL_TRUE);
if (xmvis) {
- GLXFBConfig *config = (GLXFBConfig *) _mesa_malloc(sizeof(XMesaVisual));
+ GLXFBConfig *config = (GLXFBConfig *) malloc(sizeof(XMesaVisual));
if (!config) {
*nitems = 0;
return NULL;
@@ -1807,9 +1806,9 @@ glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config )
return xmvis->vishandle;
#else
/* create a new vishandle - the cached one may be stale */
- xmvis->vishandle = (XVisualInfo *) _mesa_malloc(sizeof(XVisualInfo));
+ xmvis->vishandle = (XVisualInfo *) malloc(sizeof(XVisualInfo));
if (xmvis->vishandle) {
- _mesa_memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
+ memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
}
return xmvis->vishandle;
#endif
@@ -2112,7 +2111,7 @@ glXCreateNewContext( Display *dpy, GLXFBConfig config,
glxCtx->xmesaContext = XMesaCreateContext(xmvis,
shareCtx ? shareCtx->xmesaContext : NULL);
if (!glxCtx->xmesaContext) {
- _mesa_free(glxCtx);
+ free(glxCtx);
return NULL;
}
@@ -2332,7 +2331,7 @@ glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, int render_
glxCtx->xmesaContext = XMesaCreateContext(xmvis,
shareCtx ? shareCtx->xmesaContext : NULL);
if (!glxCtx->xmesaContext) {
- _mesa_free(glxCtx);
+ free(glxCtx);
return NULL;
}
diff --git a/src/gallium/state_trackers/glx/xlib/glx_usefont.c b/src/gallium/state_trackers/glx/xlib/glx_usefont.c
index e502198b20..8903b0e6cb 100644
--- a/src/gallium/state_trackers/glx/xlib/glx_usefont.c
+++ b/src/gallium/state_trackers/glx/xlib/glx_usefont.c
@@ -343,7 +343,7 @@ glXUseXFont(Font font, int first, int count, int listbase)
glNewList(list, GL_COMPILE);
if (valid && (bm_width > 0) && (bm_height > 0)) {
- MEMSET(bm, '\0', bm_width * bm_height);
+ memset(bm, '\0', bm_width * bm_height);
fill_bitmap(dpy, win, gc, bm_width, bm_height, x, y, c, bm);
glBitmap(width, height, x0, y0, dx, dy, bm);
diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.c b/src/gallium/state_trackers/glx/xlib/xm_api.c
index fb314f3b52..217bdeff75 100644
--- a/src/gallium/state_trackers/glx/xlib/xm_api.c
+++ b/src/gallium/state_trackers/glx/xlib/xm_api.c
@@ -175,7 +175,7 @@ bits_per_pixel( XMesaVisual xmv )
/* grab the bits/pixel value */
bitsPerPixel = img->bits_per_pixel;
/* free the XImage */
- _mesa_free( img->data );
+ free( img->data );
img->data = NULL;
XDestroyImage( img );
return bitsPerPixel;
@@ -274,10 +274,10 @@ choose_pixel_format(XMesaVisual v)
&& v->BitsPerPixel == 32) {
if (native_byte_order) {
/* no byteswapping needed */
- return 0 /* PIXEL_FORMAT_U_A8_B8_G8_R8 */;
+ return PIPE_FORMAT_R8G8B8A8_UNORM;
}
else {
- return PIPE_FORMAT_R8G8B8A8_UNORM;
+ return PIPE_FORMAT_A8B8G8R8_UNORM;
}
}
else if ( GET_REDMASK(v) == 0xff0000
@@ -286,10 +286,10 @@ choose_pixel_format(XMesaVisual v)
&& v->BitsPerPixel == 32) {
if (native_byte_order) {
/* no byteswapping needed */
- return PIPE_FORMAT_A8R8G8B8_UNORM;
+ return PIPE_FORMAT_B8G8R8A8_UNORM;
}
else {
- return PIPE_FORMAT_B8G8R8A8_UNORM;
+ return PIPE_FORMAT_A8R8G8B8_UNORM;
}
}
else if ( GET_REDMASK(v) == 0x0000ff00
@@ -298,10 +298,10 @@ choose_pixel_format(XMesaVisual v)
&& v->BitsPerPixel == 32) {
if (native_byte_order) {
/* no byteswapping needed */
- return PIPE_FORMAT_B8G8R8A8_UNORM;
+ return PIPE_FORMAT_A8R8G8B8_UNORM;
}
else {
- return PIPE_FORMAT_A8R8G8B8_UNORM;
+ return PIPE_FORMAT_B8G8R8A8_UNORM;
}
}
else if ( GET_REDMASK(v) == 0xf800
@@ -310,7 +310,7 @@ choose_pixel_format(XMesaVisual v)
&& native_byte_order
&& v->BitsPerPixel == 16) {
/* 5-6-5 RGB */
- return PIPE_FORMAT_R5G6B5_UNORM;
+ return PIPE_FORMAT_B5G6R5_UNORM;
}
assert(0);
@@ -319,6 +319,51 @@ choose_pixel_format(XMesaVisual v)
+/**
+ * Query the default gallium screen for a Z/Stencil format that
+ * at least matches the given depthBits and stencilBits.
+ */
+static void
+xmesa_choose_z_stencil_format(int depthBits, int stencilBits,
+ enum pipe_format *depthFormat,
+ enum pipe_format *stencilFormat)
+{
+ const enum pipe_texture_target target = PIPE_TEXTURE_2D;
+ const unsigned tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
+ const unsigned geom_flags = (PIPE_TEXTURE_GEOM_NON_SQUARE |
+ PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO);
+ static enum pipe_format formats[] = {
+ PIPE_FORMAT_S8Z24_UNORM,
+ PIPE_FORMAT_Z24S8_UNORM,
+ PIPE_FORMAT_Z16_UNORM,
+ PIPE_FORMAT_Z32_UNORM
+ };
+ int i;
+
+ assert(screen);
+
+ *depthFormat = *stencilFormat = PIPE_FORMAT_NONE;
+
+ /* search for supported format */
+ for (i = 0; i < Elements(formats); i++) {
+ if (screen->is_format_supported(screen, formats[i],
+ target, tex_usage, geom_flags)) {
+ *depthFormat = formats[i];
+ break;
+ }
+ }
+
+ if (stencilBits) {
+ *stencilFormat = *depthFormat;
+ }
+
+ /* XXX we should check that he chosen format has at least as many bits
+ * as what was requested.
+ */
+}
+
+
+
/**********************************************************************/
/***** Linked list of XMesaBuffers *****/
/**********************************************************************/
@@ -361,34 +406,9 @@ create_xmesa_buffer(Drawable d, BufferType type,
/* determine PIPE_FORMATs for buffers */
colorFormat = choose_pixel_format(vis);
- if (vis->mesa_visual.depthBits == 0)
- depthFormat = PIPE_FORMAT_NONE;
-#ifdef GALLIUM_CELL /* XXX temporary for Cell! */
- else
- depthFormat = PIPE_FORMAT_S8Z24_UNORM;
-#else
- else if (vis->mesa_visual.depthBits <= 16)
- depthFormat = PIPE_FORMAT_Z16_UNORM;
- else if (vis->mesa_visual.depthBits <= 24)
- depthFormat = PIPE_FORMAT_S8Z24_UNORM;
- else
- depthFormat = PIPE_FORMAT_Z32_UNORM;
-#endif
-
- if (vis->mesa_visual.stencilBits == 8) {
- if (depthFormat == PIPE_FORMAT_S8Z24_UNORM)
- stencilFormat = depthFormat;
- else
- stencilFormat = PIPE_FORMAT_S8_UNORM;
- }
- else {
- /* no stencil */
- stencilFormat = PIPE_FORMAT_NONE;
- if (depthFormat == PIPE_FORMAT_S8Z24_UNORM) {
- /* use 24-bit Z, undefined stencil channel */
- depthFormat = PIPE_FORMAT_X8Z24_UNORM;
- }
- }
+ xmesa_choose_z_stencil_format(vis->mesa_visual.depthBits,
+ vis->mesa_visual.stencilBits,
+ &depthFormat, &stencilFormat);
get_drawable_size(vis->display, d, &width, &height);
@@ -550,10 +570,10 @@ initialize_visual_and_buffer(XMesaVisual v, XMesaBuffer b,
* reports bugs.
*/
if (_mesa_getenv("MESA_INFO")) {
- _mesa_printf("X/Mesa visual = %p\n", (void *) v);
- _mesa_printf("X/Mesa level = %d\n", v->mesa_visual.level);
- _mesa_printf("X/Mesa depth = %d\n", v->visinfo->depth);
- _mesa_printf("X/Mesa bits per pixel = %d\n", v->BitsPerPixel);
+ printf("X/Mesa visual = %p\n", (void *) v);
+ printf("X/Mesa level = %d\n", v->mesa_visual.level);
+ printf("X/Mesa depth = %d\n", v->visinfo->depth);
+ printf("X/Mesa bits per pixel = %d\n", v->BitsPerPixel);
}
if (b && window) {
@@ -653,6 +673,8 @@ XMesaVisual XMesaCreateVisual( Display *display,
XMesaVisual v;
GLint red_bits, green_bits, blue_bits, alpha_bits;
+ xmesa_init();
+
/* For debugging only */
if (_mesa_getenv("MESA_XSYNC")) {
/* This makes debugging X easier.
@@ -669,16 +691,16 @@ XMesaVisual XMesaCreateVisual( Display *display,
v->display = display;
- /* Save a copy of the XVisualInfo struct because the user may X_mesa_free()
+ /* Save a copy of the XVisualInfo struct because the user may Xfree()
* the struct but we may need some of the information contained in it
* at a later time.
*/
v->visinfo = (XVisualInfo *) MALLOC(sizeof(*visinfo));
if (!v->visinfo) {
- _mesa_free(v);
+ free(v);
return NULL;
}
- MEMCPY(v->visinfo, visinfo, sizeof(*visinfo));
+ memcpy(v->visinfo, visinfo, sizeof(*visinfo));
v->ximage_flag = ximage_flag;
@@ -724,10 +746,9 @@ XMesaVisual XMesaCreateVisual( Display *display,
}
_mesa_initialize_visual( &v->mesa_visual,
- rgb_flag, db_flag, stereo_flag,
+ db_flag, stereo_flag,
red_bits, green_bits,
blue_bits, alpha_bits,
- v->mesa_visual.indexBits,
depth_size,
stencil_size,
accum_red_size, accum_green_size,
@@ -743,11 +764,26 @@ XMesaVisual XMesaCreateVisual( Display *display,
PUBLIC
void XMesaDestroyVisual( XMesaVisual v )
{
- _mesa_free(v->visinfo);
- _mesa_free(v);
+ free(v->visinfo);
+ free(v);
}
+/**
+ * Do one-time initializations.
+ */
+void
+xmesa_init(void)
+{
+ static GLboolean firstTime = GL_TRUE;
+ if (firstTime) {
+ pipe_mutex_init(_xmesa_lock);
+ _screen = driver.create_pipe_screen();
+ screen = trace_screen_create( _screen );
+ firstTime = GL_FALSE;
+ }
+}
+
/**
* Create a new XMesaContext.
@@ -759,18 +795,12 @@ void XMesaDestroyVisual( XMesaVisual v )
PUBLIC
XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list )
{
- static GLboolean firstTime = GL_TRUE;
struct pipe_context *pipe = NULL;
XMesaContext c;
GLcontext *mesaCtx;
uint pf;
- if (firstTime) {
- pipe_mutex_init(_xmesa_lock);
- _screen = driver.create_pipe_screen();
- screen = trace_screen_create( _screen );
- firstTime = GL_FALSE;
- }
+ xmesa_init();
/* Note: the XMesaContext contains a Mesa GLcontext struct (inheritance) */
c = (XMesaContext) CALLOC_STRUCT(xmesa_context);
@@ -811,7 +841,7 @@ fail:
else if (pipe)
pipe->destroy(pipe);
- _mesa_free(c);
+ free(c);
return NULL;
}
@@ -828,7 +858,7 @@ void XMesaDestroyContext( XMesaContext c )
screen->destroy(screen);
*/
- _mesa_free(c);
+ free(c);
}
@@ -1148,6 +1178,7 @@ void XMesaCopySubBuffer( XMesaBuffer b, int x, int y, int width, int height )
if (!surf_front || !surf_back)
return;
+ assert(pipe);
pipe->surface_copy(pipe,
surf_front, x, y, /* dest */
surf_back, x, y, /* src */
diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.h b/src/gallium/state_trackers/glx/xlib/xm_api.h
index 63a329cbe0..004cb260dc 100644
--- a/src/gallium/state_trackers/glx/xlib/xm_api.h
+++ b/src/gallium/state_trackers/glx/xlib/xm_api.h
@@ -367,6 +367,9 @@ xmesa_buffer(GLframebuffer *fb)
extern void
+xmesa_init(void);
+
+extern void
xmesa_delete_framebuffer(struct gl_framebuffer *fb);
extern XMesaBuffer