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. * Generate a 1x1 <code>Picture</code> of a particular color.
*/ */
xcb_render_picture_t xcb_render_picture_t solid_picture(xcb_connection_t *c, xcb_drawable_t d, bool argb,
solid_picture(session_t *ps, bool argb, double a, double r, double g, double b) { double a, double r, double g, double b) {
xcb_pixmap_t 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;
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) if (!pixmap)
return XCB_NONE; return XCB_NONE;
pa.repeat = 1; pa.repeat = 1;
picture = x_create_picture_with_standard_and_pixmap( 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); XCB_RENDER_CP_REPEAT, &pa);
if (!picture) { if (!picture) {
xcb_free_pixmap(ps->c, pixmap); xcb_free_pixmap(c, pixmap);
return XCB_NONE; 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.width = 1;
rect.height = 1; rect.height = 1;
xcb_render_fill_rectangles(ps->c, XCB_RENDER_PICT_OP_SRC, picture, col, 1, &rect); xcb_render_fill_rectangles(c, XCB_RENDER_PICT_OP_SRC, picture, col, 1, &rect);
xcb_free_pixmap(ps->c, pixmap); xcb_free_pixmap(c, pixmap);
return picture; 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. * Generate shadow <code>Picture</code> for a window.
*/ */
bool build_shadow(session_t *ps, double opacity, const int width, const int height, bool build_shadow(xcb_connection_t *c, xcb_drawable_t d, double opacity, const int width,
const conv *kernel, xcb_render_picture_t shadow_pixel, const int height, const conv *kernel, xcb_render_picture_t shadow_pixel,
xcb_pixmap_t *pixmap, xcb_render_picture_t *pict) { xcb_pixmap_t *pixmap, xcb_render_picture_t *pict) {
xcb_image_t *shadow_image = NULL; xcb_image_t *shadow_image = NULL;
xcb_pixmap_t shadow_pixmap = XCB_NONE, shadow_pixmap_argb = XCB_NONE; 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_render_picture_t shadow_picture = XCB_NONE, shadow_picture_argb = XCB_NONE;
xcb_gcontext_t gc = 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) { if (!shadow_image) {
log_error("Failed to make shadow"); log_error("Failed to make shadow");
return false; return false;
} }
shadow_pixmap = shadow_pixmap = x_create_pixmap(c, 8, d, shadow_image->width, shadow_image->height);
x_create_pixmap(ps->c, 8, ps->root, shadow_image->width, shadow_image->height);
shadow_pixmap_argb = 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) { if (!shadow_pixmap || !shadow_pixmap_argb) {
log_error("Failed to create shadow pixmaps"); 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( 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( shadow_picture_argb = x_create_picture_with_standard_and_pixmap(
ps->c, XCB_PICT_STANDARD_ARGB_32, shadow_pixmap_argb, 0, NULL); c, XCB_PICT_STANDARD_ARGB_32, shadow_pixmap_argb, 0, NULL);
if (!shadow_picture || !shadow_picture_argb) if (!shadow_picture || !shadow_picture_argb) {
goto shadow_picture_err; goto shadow_picture_err;
}
gc = xcb_generate_id(ps->c); gc = xcb_generate_id(c);
xcb_create_gc(ps->c, gc, shadow_pixmap, 0, NULL); xcb_create_gc(c, gc, shadow_pixmap, 0, NULL);
xcb_image_put(ps->c, shadow_pixmap, gc, shadow_image, 0, 0, 0); xcb_image_put(c, shadow_pixmap, gc, shadow_image, 0, 0, 0);
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, shadow_pixel, shadow_picture, 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_picture_argb, 0, 0, 0, 0, 0, 0, shadow_image->width,
shadow_image->height); shadow_image->height);
*pixmap = shadow_pixmap_argb; *pixmap = shadow_pixmap_argb;
*pict = shadow_picture_argb; *pict = shadow_picture_argb;
xcb_free_gc(ps->c, gc); xcb_free_gc(c, gc);
xcb_image_destroy(shadow_image); xcb_image_destroy(shadow_image);
xcb_free_pixmap(ps->c, shadow_pixmap); xcb_free_pixmap(c, shadow_pixmap);
xcb_render_free_picture(ps->c, shadow_picture); xcb_render_free_picture(c, shadow_picture);
return true; return true;
shadow_picture_err: shadow_picture_err:
if (shadow_image) if (shadow_image) {
xcb_image_destroy(shadow_image); xcb_image_destroy(shadow_image);
if (shadow_pixmap) }
xcb_free_pixmap(ps->c, shadow_pixmap); if (shadow_pixmap) {
if (shadow_pixmap_argb) xcb_free_pixmap(c, shadow_pixmap);
xcb_free_pixmap(ps->c, shadow_pixmap_argb); }
if (shadow_picture) if (shadow_pixmap_argb) {
xcb_render_free_picture(ps->c, shadow_picture); xcb_free_pixmap(c, shadow_pixmap_argb);
if (shadow_picture_argb) }
xcb_render_free_picture(ps->c, shadow_picture_argb); if (shadow_picture) {
if (gc) xcb_render_free_picture(c, shadow_picture);
xcb_free_gc(ps->c, gc); }
if (shadow_picture_argb) {
xcb_render_free_picture(c, shadow_picture_argb);
}
if (gc) {
xcb_free_gc(c, gc);
}
return false; return false;
} }

View File

@ -13,12 +13,12 @@ typedef struct session session_t;
typedef struct win win; typedef struct win win;
typedef struct conv conv; typedef struct conv conv;
bool build_shadow(session_t *ps, double opacity, const int width, const int height, bool build_shadow(xcb_connection_t *, xcb_drawable_t, double opacity, const int width,
const conv *kernel, xcb_render_picture_t shadow_pixel, const int height, const conv *kernel, xcb_render_picture_t shadow_pixel,
xcb_pixmap_t *pixmap, xcb_render_picture_t *pict); xcb_pixmap_t *pixmap, xcb_render_picture_t *pict);
xcb_render_picture_t xcb_render_picture_t solid_picture(xcb_connection_t *, xcb_drawable_t, bool argb,
solid_picture(session_t *ps, bool argb, double a, double r, double g, double b); double a, double r, double g, double b);
xcb_image_t * xcb_image_t *
make_shadow(xcb_connection_t *c, const conv *kernel, double opacity, int width, int height); 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 // leave this here until we have chance to re-think the backend API
if (w->shadow) { if (w->shadow) {
xcb_pixmap_t pixmap; 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); xd->shadow_pixel, &pixmap, &wd->shadow_pict);
xcb_free_pixmap(ps->c, pixmap); xcb_free_pixmap(ps->c, pixmap);
} }
@ -425,13 +425,13 @@ static void *init(session_t *ps) {
for (int i = 0; i < 256; ++i) { for (int i = 0; i < 256; ++i) {
double o = (double)i / 255.0; 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); assert(xd->alpha_pict[i] != XCB_NONE);
} }
xd->black_pixel = solid_picture(ps, true, 1, 0, 0, 0); xd->black_pixel = solid_picture(ps->c, ps->root, true, 1, 0, 0, 0);
xd->white_pixel = solid_picture(ps, true, 1, 1, 1, 1); xd->white_pixel = solid_picture(ps->c, ps->root, true, 1, 1, 1, 1);
xd->shadow_pixel = solid_picture(ps, true, 1, ps->o.shadow_red, xd->shadow_pixel = solid_picture(ps->c, ps->root, true, 1, ps->o.shadow_red,
ps->o.shadow_green, ps->o.shadow_blue); ps->o.shadow_green, ps->o.shadow_blue);
xd->shadow_kernel = gaussian_kernel(ps->o.shadow_radius); xd->shadow_kernel = gaussian_kernel(ps->o.shadow_radius);
sum_kernel_preprocess(xd->shadow_kernel); 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); xcb_pixmap_t root_pixmap = x_get_root_back_pixmap(ps);
if (root_pixmap == XCB_NONE) { 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 { } else {
xd->root_pict = x_create_picture_with_visual_and_pixmap( xd->root_pict = x_create_picture_with_visual_and_pixmap(
ps->c, ps->vis, root_pixmap, 0, NULL); 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( auto e = xcb_request_check(
ps->c, xcb_present_pixmap_checked( ps->c, xcb_present_pixmap_checked(
ps->c, xd->target_win, xd->back_pixmap[xd->curr_back], 0, 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, XCB_NONE, XCB_NONE, 0, 0, XCB_NONE, XCB_NONE, XCB_NONE,
0, 0, 0, 0, NULL)); XCB_PRESENT_OPTION_SUBOPTIMAL, 0, 0, 0, 0, NULL));
if (e) { if (e) {
log_error("Failed to present pixmap"); log_error("Failed to present pixmap");
free(e); free(e);

View File

@ -692,7 +692,8 @@ static inline void win_blur_background(session_t *ps, win *w, xcb_render_picture
continue; 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; 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); x_picture_filter_from_conv(kern_src, factor_center, &kern_dst, &size);
ps->blur_kerns_cache[i] = kern_dst; 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) { for (int i = 0; i <= MAX_ALPHA; ++i) {
double o = (double)i / MAX_ALPHA; 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) if (ps->alpha_picts[i] == XCB_NONE)
return false; return false;
} }
@ -1150,8 +1151,8 @@ bool init_render(session_t *ps) {
ps->gaussian_map = gaussian_kernel(ps->o.shadow_radius); ps->gaussian_map = gaussian_kernel(ps->o.shadow_radius);
sum_kernel_preprocess(ps->gaussian_map); sum_kernel_preprocess(ps->gaussian_map);
ps->black_picture = solid_picture(ps, true, 1, 0, 0, 0); ps->black_picture = solid_picture(ps->c, ps->root, true, 1, 0, 0, 0);
ps->white_picture = solid_picture(ps, true, 1, 1, 1, 1); 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) { if (ps->black_picture == XCB_NONE || ps->white_picture == XCB_NONE) {
log_error("Failed to create solid xrender pictures."); 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) { if (!ps->o.shadow_red && !ps->o.shadow_green && !ps->o.shadow_blue) {
ps->cshadow_picture = ps->black_picture; ps->cshadow_picture = ps->black_picture;
} else { } else {
ps->cshadow_picture = solid_picture( ps->cshadow_picture = solid_picture(ps->c, ps->root, true, 1, ps->o.shadow_red,
ps, true, 1, ps->o.shadow_red, ps->o.shadow_green, ps->o.shadow_blue); ps->o.shadow_green, ps->o.shadow_blue);
if (ps->cshadow_picture == XCB_NONE) { if (ps->cshadow_picture == XCB_NONE) {
log_error("Failed to create shadow picture."); log_error("Failed to create shadow picture.");
return false; return false;