1
0
Fork 0
mirror of https://github.com/yshui/picom.git synced 2024-11-18 13:55:36 -05:00

Move a couple X related functions to x.c

Also replace remaining Pixmap with xcb_pixmap_t

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2018-09-30 20:53:52 +01:00
parent ddab20176b
commit 03f33ed45c
8 changed files with 51 additions and 54 deletions

View file

@ -438,7 +438,7 @@ typedef struct {
struct _glx_texture { struct _glx_texture {
GLuint texture; GLuint texture;
GLXPixmap glpixmap; GLXPixmap glpixmap;
Pixmap pixmap; xcb_pixmap_t pixmap;
GLenum target; GLenum target;
unsigned width; unsigned width;
unsigned height; unsigned height;
@ -495,7 +495,7 @@ typedef uint32_t glx_prog_main_t;
#endif #endif
typedef struct { typedef struct {
Pixmap pixmap; xcb_pixmap_t pixmap;
xcb_render_picture_t pict; xcb_render_picture_t pict;
glx_texture_t *ptex; glx_texture_t *ptex;
} paint_t; } paint_t;
@ -2311,34 +2311,3 @@ wintype_arr_enable(bool arr[]) {
arr[i] = true; arr[i] = true;
} }
} }
/**
* Destroy a <code>Pixmap</code>.
*/
static inline void
free_pixmap(session_t *ps, Pixmap *p) {
if (*p) {
xcb_connection_t *c = XGetXCBConnection(ps->dpy);
xcb_free_pixmap(c, *p);
*p = None;
}
}
/**
* Create a pixmap and check that creation succeeded.
*/
static inline xcb_pixmap_t
create_pixmap(session_t *ps, uint8_t depth, xcb_drawable_t drawable, uint16_t width, uint16_t height)
{
xcb_connection_t *c = XGetXCBConnection(ps->dpy);
xcb_pixmap_t pix = xcb_generate_id(c);
xcb_void_cookie_t cookie = xcb_create_pixmap_checked(c, depth, pix, drawable, width, height);
xcb_generic_error_t *err = xcb_request_check(c, cookie);
if (err == NULL)
return pix;
printf_err("Failed to create pixmap:");
ev_xcb_error(ps, err);
free(err);
return XCB_NONE;
}

View file

@ -667,7 +667,7 @@ win_build_shadow(session_t *ps, win *w, double opacity) {
const int height = w->heightb; const int height = w->heightb;
xcb_image_t *shadow_image = NULL; xcb_image_t *shadow_image = NULL;
Pixmap shadow_pixmap = None, shadow_pixmap_argb = None; xcb_pixmap_t shadow_pixmap = None, shadow_pixmap_argb = None;
xcb_render_picture_t shadow_picture = None, shadow_picture_argb = None; xcb_render_picture_t shadow_picture = None, shadow_picture_argb = None;
GC gc = None; GC gc = None;
xcb_connection_t *c = XGetXCBConnection(ps->dpy); xcb_connection_t *c = XGetXCBConnection(ps->dpy);
@ -678,8 +678,8 @@ win_build_shadow(session_t *ps, win *w, double opacity) {
return None; return None;
} }
shadow_pixmap = create_pixmap(ps, 8, ps->root, shadow_image->width, shadow_image->height); shadow_pixmap = x_create_pixmap(ps, 8, ps->root, shadow_image->width, shadow_image->height);
shadow_pixmap_argb = create_pixmap(ps, 32, ps->root, shadow_image->width, shadow_image->height); shadow_pixmap_argb = x_create_pixmap(ps, 32, ps->root, shadow_image->width, shadow_image->height);
if (!shadow_pixmap || !shadow_pixmap_argb) { if (!shadow_pixmap || !shadow_pixmap_argb) {
printf_errf("(): failed to create shadow pixmaps"); printf_errf("(): failed to create shadow pixmaps");
@ -742,14 +742,14 @@ shadow_picture_err:
static xcb_render_picture_t static xcb_render_picture_t
solid_picture(session_t *ps, bool argb, double a, solid_picture(session_t *ps, bool argb, double a,
double r, double g, double b) { double r, double g, double b) {
Pixmap pixmap; xcb_pixmap_t pixmap;
xcb_render_picture_t picture; xcb_render_picture_t picture;
xcb_render_create_picture_value_list_t pa; xcb_render_create_picture_value_list_t pa;
xcb_render_color_t col; xcb_render_color_t col;
xcb_rectangle_t rect; xcb_rectangle_t rect;
xcb_connection_t *c = XGetXCBConnection(ps->dpy); xcb_connection_t *c = XGetXCBConnection(ps->dpy);
pixmap = create_pixmap(ps, argb ? 32 : 8, ps->root, 1, 1); pixmap = x_create_pixmap(ps, argb ? 32 : 8, ps->root, 1, 1);
if (!pixmap) return None; if (!pixmap) return None;
pa.repeat = True; pa.repeat = True;
@ -917,7 +917,7 @@ get_root_tile(session_t *ps) {
ps->root_tile_fill = false; ps->root_tile_fill = false;
bool fill = false; bool fill = false;
Pixmap pixmap = None; xcb_pixmap_t pixmap = None;
// Get the values of background attributes // Get the values of background attributes
for (int p = 0; background_props_str[p]; p++) { for (int p = 0; background_props_str[p]; p++) {
@ -939,7 +939,7 @@ get_root_tile(session_t *ps) {
// Create a pixmap if there isn't any // Create a pixmap if there isn't any
if (!pixmap) { if (!pixmap) {
pixmap = create_pixmap(ps, ps->depth, ps->root, 1, 1); pixmap = x_create_pixmap(ps, ps->depth, ps->root, 1, 1);
if (pixmap == XCB_NONE) { if (pixmap == XCB_NONE) {
fprintf(stderr, "Failed to create some pixmap\n"); fprintf(stderr, "Failed to create some pixmap\n");
exit(1); exit(1);
@ -1719,7 +1719,7 @@ paint_all(session_t *ps, region_t *region, const region_t *region_real, win * co
else { else {
if (!ps->tgt_buffer.pixmap) { if (!ps->tgt_buffer.pixmap) {
free_paint(ps, &ps->tgt_buffer); free_paint(ps, &ps->tgt_buffer);
ps->tgt_buffer.pixmap = create_pixmap(ps, ps->depth, ps->root, ps->root_width, ps->root_height); ps->tgt_buffer.pixmap = x_create_pixmap(ps, ps->depth, ps->root, ps->root_width, ps->root_height);
if (ps->tgt_buffer.pixmap == XCB_NONE) { if (ps->tgt_buffer.pixmap == XCB_NONE) {
fprintf(stderr, "Failed to allocate a screen-sized pixmap\n"); fprintf(stderr, "Failed to allocate a screen-sized pixmap\n");
exit(1); exit(1);

View file

@ -197,9 +197,12 @@ free_texture(session_t *ps, glx_texture_t **t) {
*/ */
static inline void static inline void
free_paint(session_t *ps, paint_t *ppaint) { free_paint(session_t *ps, paint_t *ppaint) {
xcb_connection_t *c = XGetXCBConnection(ps->dpy);
free_paint_glx(ps, ppaint); free_paint_glx(ps, ppaint);
free_picture(ps, &ppaint->pict); free_picture(ps, &ppaint->pict);
free_pixmap(ps, &ppaint->pixmap); if (ppaint->pixmap)
xcb_free_pixmap(c, ppaint->pixmap);
ppaint->pixmap = XCB_NONE;
} }
/** /**
@ -233,10 +236,13 @@ free_win_res(session_t *ps, win *w) {
*/ */
static inline void static inline void
free_root_tile(session_t *ps) { free_root_tile(session_t *ps) {
xcb_connection_t *c = XGetXCBConnection(ps->dpy);
free_picture(ps, &ps->root_tile_paint.pict); free_picture(ps, &ps->root_tile_paint.pict);
free_texture(ps, &ps->root_tile_paint.ptex); free_texture(ps, &ps->root_tile_paint.ptex);
if (ps->root_tile_fill) if (ps->root_tile_fill) {
free_pixmap(ps, &ps->root_tile_paint.pixmap); xcb_free_pixmap(c, ps->root_tile_paint.pixmap);
ps->root_tile_paint.pixmap = XCB_NONE;
}
ps->root_tile_paint.pixmap = None; ps->root_tile_paint.pixmap = None;
ps->root_tile_fill = false; ps->root_tile_fill = false;
} }
@ -392,7 +398,7 @@ dump_drawable(session_t *ps, Drawable drawable) {
* are better ways. * are better ways.
*/ */
static inline bool static inline bool
validate_pixmap(session_t *ps, Pixmap pxmap) { validate_pixmap(session_t *ps, xcb_pixmap_t pxmap) {
if (!pxmap) return false; if (!pxmap) return false;
Window rroot = None; Window rroot = None;

View file

@ -727,14 +727,13 @@ glx_load_prog_main(session_t *ps,
* Bind a X pixmap to an OpenGL texture. * Bind a X pixmap to an OpenGL texture.
*/ */
bool bool
glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, Pixmap pixmap, glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap,
unsigned width, unsigned height, unsigned depth) { unsigned width, unsigned height, unsigned depth) {
if (ps->o.backend != BKEND_GLX) if (ps->o.backend != BKEND_GLX)
return true; return true;
if (!pixmap) { if (!pixmap) {
printf_errf("(%#010lx): Binding to an empty pixmap. This can't work.", printf_errf("(%#010x): Binding to an empty pixmap. This can't work.", pixmap);
pixmap);
return false; return false;
} }
@ -776,7 +775,7 @@ glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, Pixmap pixmap,
unsigned rbdwid = 0; unsigned rbdwid = 0;
if (!XGetGeometry(ps->dpy, pixmap, &rroot, &rx, &ry, if (!XGetGeometry(ps->dpy, pixmap, &rroot, &rx, &ry,
&width, &height, &rbdwid, &depth)) { &width, &height, &rbdwid, &depth)) {
printf_errf("(%#010lx): Failed to query Pixmap info.", pixmap); printf_errf("(%#010x): Failed to query Pixmap info.", pixmap);
return false; return false;
} }
if (depth > OPENGL_MAX_DEPTH) { if (depth > OPENGL_MAX_DEPTH) {

View file

@ -156,7 +156,7 @@ glx_load_prog_main(session_t *ps,
#endif #endif
bool bool
glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, Pixmap pixmap, glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap,
unsigned width, unsigned height, unsigned depth); unsigned width, unsigned height, unsigned depth);
void void
@ -169,7 +169,7 @@ __attribute__((nonnull(1, 2)));
* Check if a texture is binded, or is binded to the given pixmap. * Check if a texture is binded, or is binded to the given pixmap.
*/ */
static inline bool static inline bool
glx_tex_binded(const glx_texture_t *ptex, Pixmap pixmap) { glx_tex_binded(const glx_texture_t *ptex, xcb_pixmap_t pixmap) {
return ptex && ptex->glpixmap && ptex->texture return ptex && ptex->glpixmap && ptex->texture
&& (!pixmap || pixmap == ptex->pixmap); && (!pixmap || pixmap == ptex->pixmap);
} }

24
src/x.c
View file

@ -200,13 +200,15 @@ x_create_picture(session_t *ps, int wid, int hei,
int depth = pictfmt->depth; int depth = pictfmt->depth;
Pixmap tmp_pixmap = create_pixmap(ps, depth, ps->root, wid, hei); xcb_pixmap_t tmp_pixmap = x_create_pixmap(ps, depth, ps->root, wid, hei);
if (!tmp_pixmap) if (!tmp_pixmap)
return None; return None;
xcb_render_picture_t picture = xcb_render_picture_t picture =
x_create_picture_with_pictfmt_and_pixmap(ps, pictfmt, tmp_pixmap, valuemask, attr); x_create_picture_with_pictfmt_and_pixmap(ps, pictfmt, tmp_pixmap, valuemask, attr);
free_pixmap(ps, &tmp_pixmap);
xcb_connection_t *c = XGetXCBConnection(ps->dpy);
xcb_free_pixmap(c, tmp_pixmap);
return picture; return picture;
} }
@ -361,3 +363,21 @@ x_print_error(unsigned long serial, uint8_t major, uint8_t minor, uint8_t error_
// print_backtrace(); // print_backtrace();
} }
/**
* Create a pixmap and check that creation succeeded.
*/
xcb_pixmap_t
x_create_pixmap(session_t *ps, uint8_t depth, xcb_drawable_t drawable, uint16_t width, uint16_t height) {
xcb_connection_t *c = XGetXCBConnection(ps->dpy);
xcb_pixmap_t pix = xcb_generate_id(c);
xcb_void_cookie_t cookie = xcb_create_pixmap_checked(c, depth, pix, drawable, width, height);
xcb_generic_error_t *err = xcb_request_check(c, cookie);
if (err == NULL)
return pix;
printf_err("Failed to create pixmap:");
ev_xcb_error(ps, err);
free(err);
return XCB_NONE;
}

View file

@ -96,3 +96,6 @@ void x_set_picture_clip_region(session_t *ps, xcb_render_picture_t,
*/ */
void void
x_print_error(unsigned long serial, uint8_t major, uint8_t minor, uint8_t error_code); x_print_error(unsigned long serial, uint8_t major, uint8_t minor, uint8_t error_code);
xcb_pixmap_t
x_create_pixmap(session_t *ps, uint8_t depth, xcb_drawable_t drawable, uint16_t width, uint16_t height);

View file

@ -56,7 +56,7 @@ xcb_composite_name_window_pixmap_(xcb_connection_t *c, xcb_window_t window, xcb_
xcb_composite_name_window_pixmap_(dpy, window, pixmap, M_POS_DATA) xcb_composite_name_window_pixmap_(dpy, window, pixmap, M_POS_DATA)
static inline void static inline void
xcb_free_pixmap_(xcb_connection_t *c, Pixmap pixmap, M_POS_DATA_PARAMS) { xcb_free_pixmap_(xcb_connection_t *c, xcb_pixmap_t pixmap, M_POS_DATA_PARAMS) {
xcb_free_pixmap(c, pixmap); xcb_free_pixmap(c, pixmap);
xrc_delete_xid_(pixmap, M_POS_DATA_PASSTHROUGH); xrc_delete_xid_(pixmap, M_POS_DATA_PASSTHROUGH);
} }