solid_picture and build_shadow shouldn't take session_t

Pass xcb_connection_t and xcb_drawable_t instead, which is what these
functions need.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-02-26 23:21:11 +00:00
parent 7e7c54761e
commit 0ceee9aad1
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
4 changed files with 59 additions and 52 deletions

View File

@ -16,25 +16,25 @@
/**
* Generate a 1x1 <code>Picture</code> of a particular color.
*/
xcb_render_picture_t
solid_picture(session_t *ps, bool argb, double a, double r, double g, double b) {
xcb_render_picture_t solid_picture(xcb_connection_t *c, xcb_drawable_t d, bool argb,
double a, double r, double g, double b) {
xcb_pixmap_t pixmap;
xcb_render_picture_t picture;
xcb_render_create_picture_value_list_t pa;
xcb_render_color_t col;
xcb_rectangle_t rect;
pixmap = x_create_pixmap(ps->c, argb ? 32 : 8, ps->root, 1, 1);
pixmap = x_create_pixmap(c, argb ? 32 : 8, d, 1, 1);
if (!pixmap)
return XCB_NONE;
pa.repeat = 1;
picture = x_create_picture_with_standard_and_pixmap(
ps->c, argb ? XCB_PICT_STANDARD_ARGB_32 : XCB_PICT_STANDARD_A_8, pixmap,
c, argb ? XCB_PICT_STANDARD_ARGB_32 : XCB_PICT_STANDARD_A_8, pixmap,
XCB_RENDER_CP_REPEAT, &pa);
if (!picture) {
xcb_free_pixmap(ps->c, pixmap);
xcb_free_pixmap(c, pixmap);
return XCB_NONE;
}
@ -48,8 +48,8 @@ solid_picture(session_t *ps, bool argb, double a, double r, double g, double b)
rect.width = 1;
rect.height = 1;
xcb_render_fill_rectangles(ps->c, XCB_RENDER_PICT_OP_SRC, picture, col, 1, &rect);
xcb_free_pixmap(ps->c, pixmap);
xcb_render_fill_rectangles(c, XCB_RENDER_PICT_OP_SRC, picture, col, 1, &rect);
xcb_free_pixmap(c, pixmap);
return picture;
}
@ -184,24 +184,23 @@ make_shadow(xcb_connection_t *c, const conv *kernel, double opacity, int width,
/**
* Generate shadow <code>Picture</code> for a window.
*/
bool build_shadow(session_t *ps, double opacity, const int width, const int height,
const conv *kernel, xcb_render_picture_t shadow_pixel,
bool build_shadow(xcb_connection_t *c, xcb_drawable_t d, double opacity, const int width,
const int height, const conv *kernel, xcb_render_picture_t shadow_pixel,
xcb_pixmap_t *pixmap, xcb_render_picture_t *pict) {
xcb_image_t *shadow_image = NULL;
xcb_pixmap_t shadow_pixmap = XCB_NONE, shadow_pixmap_argb = XCB_NONE;
xcb_render_picture_t shadow_picture = XCB_NONE, shadow_picture_argb = XCB_NONE;
xcb_gcontext_t gc = XCB_NONE;
shadow_image = make_shadow(ps->c, kernel, opacity, width, height);
shadow_image = make_shadow(c, kernel, opacity, width, height);
if (!shadow_image) {
log_error("Failed to make shadow");
return false;
}
shadow_pixmap =
x_create_pixmap(ps->c, 8, ps->root, shadow_image->width, shadow_image->height);
shadow_pixmap = x_create_pixmap(c, 8, d, shadow_image->width, shadow_image->height);
shadow_pixmap_argb =
x_create_pixmap(ps->c, 32, ps->root, shadow_image->width, shadow_image->height);
x_create_pixmap(c, 32, d, shadow_image->width, shadow_image->height);
if (!shadow_pixmap || !shadow_pixmap_argb) {
log_error("Failed to create shadow pixmaps");
@ -209,43 +208,50 @@ bool build_shadow(session_t *ps, double opacity, const int width, const int heig
}
shadow_picture = x_create_picture_with_standard_and_pixmap(
ps->c, XCB_PICT_STANDARD_A_8, shadow_pixmap, 0, NULL);
c, XCB_PICT_STANDARD_A_8, shadow_pixmap, 0, NULL);
shadow_picture_argb = x_create_picture_with_standard_and_pixmap(
ps->c, XCB_PICT_STANDARD_ARGB_32, shadow_pixmap_argb, 0, NULL);
if (!shadow_picture || !shadow_picture_argb)
c, XCB_PICT_STANDARD_ARGB_32, shadow_pixmap_argb, 0, NULL);
if (!shadow_picture || !shadow_picture_argb) {
goto shadow_picture_err;
}
gc = xcb_generate_id(ps->c);
xcb_create_gc(ps->c, gc, shadow_pixmap, 0, NULL);
gc = xcb_generate_id(c);
xcb_create_gc(c, gc, shadow_pixmap, 0, NULL);
xcb_image_put(ps->c, shadow_pixmap, gc, shadow_image, 0, 0, 0);
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, shadow_pixel, shadow_picture,
xcb_image_put(c, shadow_pixmap, gc, shadow_image, 0, 0, 0);
xcb_render_composite(c, XCB_RENDER_PICT_OP_SRC, shadow_pixel, shadow_picture,
shadow_picture_argb, 0, 0, 0, 0, 0, 0, shadow_image->width,
shadow_image->height);
*pixmap = shadow_pixmap_argb;
*pict = shadow_picture_argb;
xcb_free_gc(ps->c, gc);
xcb_free_gc(c, gc);
xcb_image_destroy(shadow_image);
xcb_free_pixmap(ps->c, shadow_pixmap);
xcb_render_free_picture(ps->c, shadow_picture);
xcb_free_pixmap(c, shadow_pixmap);
xcb_render_free_picture(c, shadow_picture);
return true;
shadow_picture_err:
if (shadow_image)
if (shadow_image) {
xcb_image_destroy(shadow_image);
if (shadow_pixmap)
xcb_free_pixmap(ps->c, shadow_pixmap);
if (shadow_pixmap_argb)
xcb_free_pixmap(ps->c, shadow_pixmap_argb);
if (shadow_picture)
xcb_render_free_picture(ps->c, shadow_picture);
if (shadow_picture_argb)
xcb_render_free_picture(ps->c, shadow_picture_argb);
if (gc)
xcb_free_gc(ps->c, gc);
}
if (shadow_pixmap) {
xcb_free_pixmap(c, shadow_pixmap);
}
if (shadow_pixmap_argb) {
xcb_free_pixmap(c, shadow_pixmap_argb);
}
if (shadow_picture) {
xcb_render_free_picture(c, shadow_picture);
}
if (shadow_picture_argb) {
xcb_render_free_picture(c, shadow_picture_argb);
}
if (gc) {
xcb_free_gc(c, gc);
}
return false;
}

View File

@ -13,12 +13,12 @@ typedef struct session session_t;
typedef struct win win;
typedef struct conv conv;
bool build_shadow(session_t *ps, double opacity, const int width, const int height,
const conv *kernel, xcb_render_picture_t shadow_pixel,
bool build_shadow(xcb_connection_t *, xcb_drawable_t, double opacity, const int width,
const int height, const conv *kernel, xcb_render_picture_t shadow_pixel,
xcb_pixmap_t *pixmap, xcb_render_picture_t *pict);
xcb_render_picture_t
solid_picture(session_t *ps, bool argb, double a, double r, double g, double b);
xcb_render_picture_t solid_picture(xcb_connection_t *, xcb_drawable_t, bool argb,
double a, double r, double g, double b);
xcb_image_t *
make_shadow(xcb_connection_t *c, const conv *kernel, double opacity, int width, int height);

View File

@ -378,7 +378,7 @@ static void *prepare_win(void *backend_data, session_t *ps, win *w) {
// leave this here until we have chance to re-think the backend API
if (w->shadow) {
xcb_pixmap_t pixmap;
build_shadow(ps, 1, w->widthb, w->heightb, xd->shadow_kernel,
build_shadow(ps->c, ps->root, 1, w->widthb, w->heightb, xd->shadow_kernel,
xd->shadow_pixel, &pixmap, &wd->shadow_pict);
xcb_free_pixmap(ps->c, pixmap);
}
@ -425,13 +425,13 @@ static void *init(session_t *ps) {
for (int i = 0; i < 256; ++i) {
double o = (double)i / 255.0;
xd->alpha_pict[i] = solid_picture(ps, false, o, 0, 0, 0);
xd->alpha_pict[i] = solid_picture(ps->c, ps->root, false, o, 0, 0, 0);
assert(xd->alpha_pict[i] != XCB_NONE);
}
xd->black_pixel = solid_picture(ps, true, 1, 0, 0, 0);
xd->white_pixel = solid_picture(ps, true, 1, 1, 1, 1);
xd->shadow_pixel = solid_picture(ps, true, 1, ps->o.shadow_red,
xd->black_pixel = solid_picture(ps->c, ps->root, true, 1, 0, 0, 0);
xd->white_pixel = solid_picture(ps->c, ps->root, true, 1, 1, 1, 1);
xd->shadow_pixel = solid_picture(ps->c, ps->root, true, 1, ps->o.shadow_red,
ps->o.shadow_green, ps->o.shadow_blue);
xd->shadow_kernel = gaussian_kernel(ps->o.shadow_radius);
sum_kernel_preprocess(xd->shadow_kernel);
@ -496,7 +496,7 @@ static void *init(session_t *ps) {
xcb_pixmap_t root_pixmap = x_get_root_back_pixmap(ps);
if (root_pixmap == XCB_NONE) {
xd->root_pict = solid_picture(ps, false, 1, 0.5, 0.5, 0.5);
xd->root_pict = solid_picture(ps->c, ps->root, false, 1, 0.5, 0.5, 0.5);
} else {
xd->root_pict = x_create_picture_with_visual_and_pixmap(
ps->c, ps->vis, root_pixmap, 0, NULL);
@ -538,8 +538,8 @@ static void present(void *backend_data, session_t *ps) {
auto e = xcb_request_check(
ps->c, xcb_present_pixmap_checked(
ps->c, xd->target_win, xd->back_pixmap[xd->curr_back], 0,
XCB_NONE, XCB_NONE, 0, 0, XCB_NONE, XCB_NONE, XCB_NONE, 0,
0, 0, 0, 0, NULL));
XCB_NONE, XCB_NONE, 0, 0, XCB_NONE, XCB_NONE, XCB_NONE,
XCB_PRESENT_OPTION_SUBOPTIMAL, 0, 0, 0, 0, NULL));
if (e) {
log_error("Failed to present pixmap");
free(e);

View File

@ -692,7 +692,8 @@ static inline void win_blur_background(session_t *ps, win *w, xcb_render_picture
continue;
}
// If kern_dst is allocated, it's always allocated to the right size
// If kern_dst is allocated, it's always allocated to the right
// size
size_t size = kern_dst ? kern_src->w * kern_src->h + 2 : 0;
x_picture_filter_from_conv(kern_src, factor_center, &kern_dst, &size);
ps->blur_kerns_cache[i] = kern_dst;
@ -1086,7 +1087,7 @@ static bool init_alpha_picts(session_t *ps) {
for (int i = 0; i <= MAX_ALPHA; ++i) {
double o = (double)i / MAX_ALPHA;
ps->alpha_picts[i] = solid_picture(ps, false, o, 0, 0, 0);
ps->alpha_picts[i] = solid_picture(ps->c, ps->root, false, o, 0, 0, 0);
if (ps->alpha_picts[i] == XCB_NONE)
return false;
}
@ -1150,8 +1151,8 @@ bool init_render(session_t *ps) {
ps->gaussian_map = gaussian_kernel(ps->o.shadow_radius);
sum_kernel_preprocess(ps->gaussian_map);
ps->black_picture = solid_picture(ps, true, 1, 0, 0, 0);
ps->white_picture = solid_picture(ps, true, 1, 1, 1, 1);
ps->black_picture = solid_picture(ps->c, ps->root, true, 1, 0, 0, 0);
ps->white_picture = solid_picture(ps->c, ps->root, true, 1, 1, 1, 1);
if (ps->black_picture == XCB_NONE || ps->white_picture == XCB_NONE) {
log_error("Failed to create solid xrender pictures.");
@ -1163,8 +1164,8 @@ bool init_render(session_t *ps) {
if (!ps->o.shadow_red && !ps->o.shadow_green && !ps->o.shadow_blue) {
ps->cshadow_picture = ps->black_picture;
} else {
ps->cshadow_picture = solid_picture(
ps, true, 1, ps->o.shadow_red, ps->o.shadow_green, ps->o.shadow_blue);
ps->cshadow_picture = solid_picture(ps->c, ps->root, true, 1, ps->o.shadow_red,
ps->o.shadow_green, ps->o.shadow_blue);
if (ps->cshadow_picture == XCB_NONE) {
log_error("Failed to create shadow picture.");
return false;