mirror of https://github.com/yshui/picom.git
backend: gl: don't force fbconfig info on to heap
It's fairly small, so it's reasonable to put it on the stack. Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
parent
e948b74363
commit
e8d42885fa
|
@ -54,10 +54,13 @@ struct _glx_data {
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
struct glx_fbconfig_info *glx_find_fbconfig(struct x_connection *c, struct xvisual_info m) {
|
||||
bool glx_find_fbconfig(struct x_connection *c, struct xvisual_info m,
|
||||
struct glx_fbconfig_info *info) {
|
||||
log_debug("Looking for FBConfig for RGBA%d%d%d%d, depth %d", m.red_size,
|
||||
m.blue_size, m.green_size, m.alpha_size, m.visual_depth);
|
||||
|
||||
info->cfg = NULL;
|
||||
|
||||
int ncfg;
|
||||
// clang-format off
|
||||
GLXFBConfig *cfg =
|
||||
|
@ -143,16 +146,13 @@ struct glx_fbconfig_info *glx_find_fbconfig(struct x_connection *c, struct xvisu
|
|||
min_cost = depthbuf + stencil + bufsize * (doublebuf + 1);
|
||||
}
|
||||
free(cfg);
|
||||
if (!found) {
|
||||
return NULL;
|
||||
if (found) {
|
||||
info->cfg = ret;
|
||||
info->texture_tgts = texture_tgts;
|
||||
info->texture_fmt = texture_fmt;
|
||||
info->y_inverted = y_inverted;
|
||||
}
|
||||
|
||||
auto info = cmalloc(struct glx_fbconfig_info);
|
||||
info->cfg = ret;
|
||||
info->texture_tgts = texture_tgts;
|
||||
info->texture_fmt = texture_fmt;
|
||||
info->y_inverted = y_inverted;
|
||||
return info;
|
||||
return found;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -394,8 +394,8 @@ glx_bind_pixmap(backend_t *base, xcb_pixmap_t pixmap, struct xvisual_info fmt, b
|
|||
wd->inner = (struct backend_image_inner_base *)inner;
|
||||
free(r);
|
||||
|
||||
auto fbcfg = glx_find_fbconfig(base->c, fmt);
|
||||
if (!fbcfg) {
|
||||
struct glx_fbconfig_info fbcfg;
|
||||
if (!glx_find_fbconfig(base->c, fmt, &fbcfg)) {
|
||||
log_error("Couldn't find FBConfig with requested visual %x", fmt.visual);
|
||||
goto err;
|
||||
}
|
||||
|
@ -403,29 +403,28 @@ glx_bind_pixmap(backend_t *base, xcb_pixmap_t pixmap, struct xvisual_info fmt, b
|
|||
// Choose a suitable texture target for our pixmap.
|
||||
// Refer to GLX_EXT_texture_om_pixmap spec to see what are the mean
|
||||
// of the bits in texture_tgts
|
||||
if (!(fbcfg->texture_tgts & GLX_TEXTURE_2D_BIT_EXT)) {
|
||||
if (!(fbcfg.texture_tgts & GLX_TEXTURE_2D_BIT_EXT)) {
|
||||
log_error("Cannot bind pixmap to GL_TEXTURE_2D, giving up");
|
||||
goto err;
|
||||
}
|
||||
|
||||
log_debug("depth %d, rgba %d", fmt.visual_depth,
|
||||
(fbcfg->texture_fmt == GLX_TEXTURE_FORMAT_RGBA_EXT));
|
||||
(fbcfg.texture_fmt == GLX_TEXTURE_FORMAT_RGBA_EXT));
|
||||
|
||||
GLint attrs[] = {
|
||||
GLX_TEXTURE_FORMAT_EXT,
|
||||
fbcfg->texture_fmt,
|
||||
fbcfg.texture_fmt,
|
||||
GLX_TEXTURE_TARGET_EXT,
|
||||
GLX_TEXTURE_2D_EXT,
|
||||
0,
|
||||
};
|
||||
|
||||
inner->y_inverted = fbcfg->y_inverted;
|
||||
inner->y_inverted = fbcfg.y_inverted;
|
||||
|
||||
glxpixmap = cmalloc(struct _glx_pixmap);
|
||||
glxpixmap->pixmap = pixmap;
|
||||
glxpixmap->glpixmap = glXCreatePixmap(base->c->dpy, fbcfg->cfg, pixmap, attrs);
|
||||
glxpixmap->glpixmap = glXCreatePixmap(base->c->dpy, fbcfg.cfg, pixmap, attrs);
|
||||
glxpixmap->owned = owned;
|
||||
free(fbcfg);
|
||||
|
||||
if (!glxpixmap->glpixmap) {
|
||||
log_error("Failed to create glpixmap for pixmap %#010x", pixmap);
|
||||
|
|
|
@ -19,7 +19,8 @@ struct glx_fbconfig_info {
|
|||
int y_inverted;
|
||||
};
|
||||
|
||||
struct glx_fbconfig_info *glx_find_fbconfig(struct x_connection *, struct xvisual_info);
|
||||
bool glx_find_fbconfig(struct x_connection *c, struct xvisual_info m,
|
||||
struct glx_fbconfig_info *info);
|
||||
|
||||
struct glxext_info {
|
||||
bool initialized;
|
||||
|
|
|
@ -204,7 +204,7 @@ typedef struct session {
|
|||
/// Custom GLX program used for painting window.
|
||||
// XXX should be in struct glx_session
|
||||
glx_prog_main_t glx_prog_win;
|
||||
struct glx_fbconfig_info *argb_fbconfig;
|
||||
struct glx_fbconfig_info argb_fbconfig;
|
||||
#endif
|
||||
/// Sync fence to sync draw operations
|
||||
xcb_sync_fence_t sync_fence;
|
||||
|
|
|
@ -279,7 +279,7 @@ void glx_destroy(session_t *ps) {
|
|||
|
||||
free(ps->psglx);
|
||||
ps->psglx = NULL;
|
||||
ps->argb_fbconfig = NULL;
|
||||
ps->argb_fbconfig = (struct glx_fbconfig_info){0};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -228,10 +228,7 @@ static inline void free_texture(session_t *ps, glx_texture_t **pptex) {
|
|||
*/
|
||||
static inline void free_paint_glx(session_t *ps, paint_t *ppaint) {
|
||||
free_texture(ps, &ppaint->ptex);
|
||||
#ifdef CONFIG_OPENGL
|
||||
free(ppaint->fbcfg);
|
||||
#endif
|
||||
ppaint->fbcfg = NULL;
|
||||
ppaint->fbcfg = (struct glx_fbconfig_info){0};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2640,11 +2640,6 @@ static void session_destroy(session_t *ps) {
|
|||
unredirect(ps);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
free(ps->argb_fbconfig);
|
||||
ps->argb_fbconfig = NULL;
|
||||
#endif
|
||||
|
||||
file_watch_destroy(ps->loop, ps->file_watch_handle);
|
||||
ps->file_watch_handle = NULL;
|
||||
|
||||
|
|
29
src/render.c
29
src/render.c
|
@ -55,19 +55,20 @@ static inline bool paint_bind_tex(session_t *ps, paint_t *ppaint, int wid, int h
|
|||
struct glx_fbconfig_info *fbcfg;
|
||||
if (!visual) {
|
||||
assert(depth == 32);
|
||||
if (!ps->argb_fbconfig) {
|
||||
ps->argb_fbconfig = glx_find_fbconfig(
|
||||
&ps->c, (struct xvisual_info){.red_size = 8,
|
||||
.green_size = 8,
|
||||
.blue_size = 8,
|
||||
.alpha_size = 8,
|
||||
.visual_depth = 32});
|
||||
if (!ps->argb_fbconfig.cfg) {
|
||||
glx_find_fbconfig(&ps->c,
|
||||
(struct xvisual_info){.red_size = 8,
|
||||
.green_size = 8,
|
||||
.blue_size = 8,
|
||||
.alpha_size = 8,
|
||||
.visual_depth = 32},
|
||||
&ps->argb_fbconfig);
|
||||
}
|
||||
if (!ps->argb_fbconfig) {
|
||||
if (!ps->argb_fbconfig.cfg) {
|
||||
log_error("Failed to find appropriate FBConfig for 32 bit depth");
|
||||
return false;
|
||||
}
|
||||
fbcfg = ps->argb_fbconfig;
|
||||
fbcfg = &ps->argb_fbconfig;
|
||||
} else {
|
||||
auto m = x_get_visual_info(&ps->c, visual);
|
||||
if (m.visual_depth < 0) {
|
||||
|
@ -79,14 +80,14 @@ static inline bool paint_bind_tex(session_t *ps, paint_t *ppaint, int wid, int h
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!ppaint->fbcfg) {
|
||||
ppaint->fbcfg = glx_find_fbconfig(&ps->c, m);
|
||||
if (!ppaint->fbcfg.cfg) {
|
||||
glx_find_fbconfig(&ps->c, m, &ppaint->fbcfg);
|
||||
}
|
||||
if (!ppaint->fbcfg) {
|
||||
if (!ppaint->fbcfg.cfg) {
|
||||
log_error("Failed to find appropriate FBConfig for X pixmap");
|
||||
return false;
|
||||
}
|
||||
fbcfg = ppaint->fbcfg;
|
||||
fbcfg = &ppaint->fbcfg;
|
||||
}
|
||||
|
||||
if (force || !glx_tex_bound(ppaint->ptex, ppaint->pixmap)) {
|
||||
|
@ -1528,7 +1529,7 @@ void deinit_render(session_t *ps) {
|
|||
free_root_tile(ps);
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
free(ps->root_tile_paint.fbcfg);
|
||||
ps->root_tile_paint.fbcfg = (struct glx_fbconfig_info){0};
|
||||
if (bkend_use_glx(ps)) {
|
||||
glx_destroy(ps);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ typedef struct paint {
|
|||
xcb_render_picture_t pict;
|
||||
glx_texture_t *ptex;
|
||||
#ifdef CONFIG_OPENGL
|
||||
struct glx_fbconfig_info *fbcfg;
|
||||
struct glx_fbconfig_info fbcfg;
|
||||
#endif
|
||||
} paint_t;
|
||||
|
||||
|
|
Loading…
Reference in New Issue