From 30e24cc932ac9045658c779db96642e9be10bc41 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Thu, 10 Jun 2010 10:44:11 -0400 Subject: [PATCH] choose an fbconfig without double buffer, and with smallest stencil/depth buffer possible (to save mem?) also, save the fbconfig's texture format rather than assuming it is RGBA --- openbox/composite.c | 60 +++++++++++++++++++++++++++++++++++---------- openbox/composite.h | 5 +++- 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/openbox/composite.c b/openbox/composite.c index b4613216..e68ac24c 100644 --- a/openbox/composite.c +++ b/openbox/composite.c @@ -54,11 +54,18 @@ static gboolean composite_need_redraw(void) return TRUE; } -static void get_best_fbcon(GLXFBConfig *in, int count, int depth, GLXFBConfig *out) +static void get_best_fbcon(GLXFBConfig *in, int count, int depth, + struct ObCompositeFBConfig *out) { GLXFBConfig best = 0; XVisualInfo *vi; - int i, value, has_alpha; + int i, value, alpha, stencil, depthb; + gboolean rgba, db; + + rgba = FALSE; + db = TRUE; + stencil = G_MAXSHORT; + depthb = G_MAXSHORT; for (i = 0; i < count; i++) { vi = glXGetVisualFromFBConfig(obt_display, in[i]); @@ -71,18 +78,47 @@ static void get_best_fbcon(GLXFBConfig *in, int count, int depth, GLXFBConfig *o if (value != depth) continue; + obcomp.GetFBConfigAttrib(obt_display, in[i], GLX_ALPHA_SIZE, &alpha); + obcomp.GetFBConfigAttrib(obt_display, in[i], GLX_BUFFER_SIZE, &value); + + /* the buffer size should equal the depth or else the buffer size minus + the alpha size should */ + if (value != depth && value - alpha != depth) continue; + value = 0; if (depth == 32) { - obcomp.GetFBConfigAttrib(obt_display, in[i], GLX_BIND_TO_TEXTURE_RGBA_EXT, &value); + obcomp.GetFBConfigAttrib(obt_display, in[i], + GLX_BIND_TO_TEXTURE_RGBA_EXT, &value); + rgba = TRUE; } if (!value) { - obcomp.GetFBConfigAttrib(obt_display, in[i], GLX_BIND_TO_TEXTURE_RGB_EXT, &value); + if (rgba) continue; /* a different one has rgba, prefer that */ + + obcomp.GetFBConfigAttrib(obt_display, in[i], + GLX_BIND_TO_TEXTURE_RGB_EXT, &value); } if (!value) // neither bind to texture? no dice continue; + + /* get no doublebuffer if possible */ + obcomp.GetFBConfigAttrib(obt_display, in[i], GLX_DOUBLEBUFFER, &value); + if (value && !db) continue; + db = value; + + /* get the smallest stencil buffer */ + obcomp.GetFBConfigAttrib(obt_display, in[i], GLX_STENCIL_SIZE, &value); + if (value > stencil) continue; + stencil = value; + + /* get the smallest depth buffer */ + obcomp.GetFBConfigAttrib(obt_display, in[i], GLX_DEPTH_SIZE, &value); + if (value > depthb) continue; + depthb = value; + best = in[i]; } - *out = best; + out->fbc = best; + out->tf = rgba ? GLX_TEXTURE_FORMAT_RGBA_EXT : GLX_TEXTURE_FORMAT_RGB_EXT; } #endif @@ -236,8 +272,10 @@ void composite_startup(gboolean reconfig) if (count) XFree(fbcs); - printf("Best visual for 24bpp was 0x%x\n", obcomp.PixmapConfig[24]); - printf("Best visual for 32bpp was 0x%x\n", obcomp.PixmapConfig[32]); + printf("Best visual for 24bpp was 0x%lx\n", + (gulong)obcomp.PixmapConfig[24].fbc); + printf("Best visual for 32bpp was 0x%lx\n", + (gulong)obcomp.PixmapConfig[32].fbc); g_idle_add(composite, NULL); @@ -282,7 +320,6 @@ static gboolean composite(gpointer data) GList *it; ObWindow *win; ObClient *client; - static int i; // if (!obcomp.need_redraw) // return; @@ -303,10 +340,7 @@ static gboolean composite(gpointer data) continue; } - if (window_depth(win) == 32) - attribs[1] = GLX_TEXTURE_FORMAT_RGBA_EXT; - else - attribs[1] = GLX_TEXTURE_FORMAT_RGB_EXT; + attribs[1] = obcomp.PixmapConfig[window_depth(win)].tf; if (win->pixmap == None) win->pixmap = XCompositeNameWindowPixmap(obt_display, window_top(win)); @@ -314,7 +348,7 @@ static gboolean composite(gpointer data) if (win->gpixmap == None) win->gpixmap = obcomp.CreatePixmap(obt_display, - obcomp.PixmapConfig[window_depth(win)], + obcomp.PixmapConfig[window_depth(win)].fbc, win->pixmap, attribs); glBindTexture(GL_TEXTURE_2D, win->texture); diff --git a/openbox/composite.h b/openbox/composite.h index 01b02d86..26146334 100644 --- a/openbox/composite.h +++ b/openbox/composite.h @@ -62,7 +62,10 @@ struct ObCompositor { Window overlay; GLXContext ctx; - GLXFBConfig PixmapConfig[MAX_DEPTH + 1]; // need a [32] + struct ObCompositeFBConfig { + GLXFBConfig fbc; /* the fbconfig */ + gint tf; /* texture format */ + } PixmapConfig[MAX_DEPTH + 1]; // need a [32] gboolean need_redraw; const Rect *screendims; -- 2.34.1