x: create_picture_with_{visual, pictfmt} don't need session_t

Take xcb_connection_t and xcb_drawable_t instead.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-02-27 00:30:27 +00:00
parent 0ceee9aad1
commit 26214f312f
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
4 changed files with 42 additions and 42 deletions

View File

@ -184,8 +184,8 @@ blur(void *backend_data, session_t *ps, double opacity, const region_t *reg_pain
// Create a buffer for storing blurred picture, make it just big enough
// for the blur region
xcb_render_picture_t tmp_picture[2] = {
x_create_picture_with_visual(ps, width, height, ps->vis, 0, NULL),
x_create_picture_with_visual(ps, width, height, ps->vis, 0, NULL)};
x_create_picture_with_visual(ps->c, ps->root, width, height, ps->vis, 0, NULL),
x_create_picture_with_visual(ps->c, ps->root, width, height, ps->vis, 0, NULL)};
region_t clip;
pixman_region32_init(&clip);
@ -279,7 +279,7 @@ static void render_win(void *backend_data, session_t *ps, win *w, void *win_data
// We don't want to modify the content of the original window when we process
// it, so we create a buffer.
if (wd->buffer == XCB_NONE) {
wd->buffer = x_create_picture_with_pictfmt(ps, w->widthb, w->heightb,
wd->buffer = x_create_picture_with_pictfmt(ps->c, ps->root, w->widthb, w->heightb,
w->pictfmt, 0, NULL);
}

View File

@ -279,7 +279,7 @@ void paint_one(session_t *ps, win *w, const region_t *reg_paint) {
// Invert window color, if required
if (bkend_use_xrender(ps) && w->invert_color) {
xcb_render_picture_t newpict =
x_create_picture_with_pictfmt(ps, wid, hei, w->pictfmt, 0, NULL);
x_create_picture_with_pictfmt(ps->c, ps->root, wid, hei, w->pictfmt, 0, NULL);
if (newpict) {
// Apply clipping region to save some CPU
if (reg_paint) {
@ -604,7 +604,7 @@ static bool xr_blur_dst(session_t *ps, xcb_render_picture_t tgt_buffer, int x, i
// Directly copying from tgt_buffer to it does not work, so we create a
// Picture in the middle.
xcb_render_picture_t tmp_picture =
x_create_picture_with_pictfmt(ps, wid, hei, NULL, 0, NULL);
x_create_picture_with_visual(ps->c, ps->root, wid, hei, ps->vis, 0, NULL);
if (!tmp_picture) {
log_error("Failed to build intermediate Picture.");
@ -964,7 +964,7 @@ void paint_all(session_t *ps, win *const t, bool ignore_damage) {
// to it
auto pictfmt = x_get_pictform_for_visual(ps->c, ps->vis);
xcb_render_picture_t new_pict = x_create_picture_with_pictfmt(
ps, ps->root_width, ps->root_height, pictfmt, 0, NULL);
ps->c, ps->root, ps->root_width, ps->root_height, pictfmt, 0, NULL);
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC,
ps->tgt_buffer.pict, XCB_NONE, new_pict, 0, 0,
0, 0, 0, 0, ps->root_width, ps->root_height);

23
src/x.c
View File

@ -182,6 +182,7 @@ x_create_picture_with_pictfmt_and_pixmap(
pixmap, pictfmt->id, valuemask, buf));
free(buf);
if (e) {
x_print_error(e->full_sequence, e->major_code, e->minor_code, e->error_code);
log_error("failed to create picture");
return XCB_NONE;
}
@ -216,39 +217,31 @@ x_create_picture_with_standard_and_pixmap(
* Create an picture.
*/
xcb_render_picture_t
x_create_picture_with_pictfmt(session_t *ps, int wid, int hei,
x_create_picture_with_pictfmt(xcb_connection_t *c, xcb_drawable_t d, int wid, int hei,
const xcb_render_pictforminfo_t *pictfmt, unsigned long valuemask,
const xcb_render_create_picture_value_list_t *attr)
{
if (!pictfmt)
pictfmt = x_get_pictform_for_visual(ps->c, ps->vis);
if (!pictfmt) {
log_fatal("Default visual is invalid");
abort();
}
int depth = pictfmt->depth;
xcb_pixmap_t tmp_pixmap = x_create_pixmap(ps->c, depth, ps->root, wid, hei);
xcb_pixmap_t tmp_pixmap = x_create_pixmap(c, depth, d, wid, hei);
if (!tmp_pixmap)
return XCB_NONE;
xcb_render_picture_t picture =
x_create_picture_with_pictfmt_and_pixmap(ps->c, pictfmt, tmp_pixmap, valuemask, attr);
x_create_picture_with_pictfmt_and_pixmap(c, pictfmt, tmp_pixmap, valuemask, attr);
xcb_free_pixmap(ps->c, tmp_pixmap);
xcb_free_pixmap(c, tmp_pixmap);
return picture;
}
xcb_render_picture_t
x_create_picture_with_visual(session_t *ps, int w, int h,
x_create_picture_with_visual(xcb_connection_t *c, xcb_drawable_t d, int w, int h,
xcb_visualid_t visual, unsigned long valuemask,
const xcb_render_create_picture_value_list_t *attr)
{
auto pictfmt = x_get_pictform_for_visual(ps->c, visual);
return x_create_picture_with_pictfmt(ps, w, h, pictfmt, valuemask, attr);
auto pictfmt = x_get_pictform_for_visual(c, visual);
return x_create_picture_with_pictfmt(c, d, w, h, pictfmt, valuemask, attr);
}
bool x_fetch_region(xcb_connection_t *c, xcb_xfixes_region_t r, pixman_region32_t *res) {

29
src/x.h
View File

@ -11,8 +11,8 @@
#include <xcb/xfixes.h>
#include "compiler.h"
#include "region.h"
#include "kernel.h"
#include "region.h"
typedef struct session session_t;
@ -39,7 +39,8 @@ typedef struct winprop {
xcb_generic_error_t *e = NULL; \
__auto_type r = func##_reply(c, func(c, __VA_ARGS__), &e); \
if (e) { \
x_print_error(e->sequence, e->major_code, e->minor_code, e->error_code); \
x_print_error(e->sequence, e->major_code, e->minor_code, \
e->error_code); \
free(e); \
} \
r; \
@ -92,13 +93,16 @@ xcb_window_t wid_get_prop_window(session_t *ps, xcb_window_t wid, xcb_atom_t apr
/**
* Get the value of a text property of a window.
*/
bool wid_get_text_prop(session_t *ps, xcb_window_t wid, xcb_atom_t prop, char ***pstrlst, int *pnstr);
bool wid_get_text_prop(session_t *ps, xcb_window_t wid, xcb_atom_t prop, char ***pstrlst,
int *pnstr);
const xcb_render_pictforminfo_t *x_get_pictform_for_visual(xcb_connection_t *, xcb_visualid_t);
const xcb_render_pictforminfo_t *
x_get_pictform_for_visual(xcb_connection_t *, xcb_visualid_t);
int x_get_visual_depth(xcb_connection_t *, xcb_visualid_t);
xcb_render_picture_t
x_create_picture_with_pictfmt_and_pixmap(xcb_connection_t *, const xcb_render_pictforminfo_t *pictfmt,
x_create_picture_with_pictfmt_and_pixmap(xcb_connection_t *,
const xcb_render_pictforminfo_t *pictfmt,
xcb_pixmap_t pixmap, unsigned long valuemask,
const xcb_render_create_picture_value_list_t *attr)
attr_nonnull(1, 2);
@ -118,13 +122,15 @@ x_create_picture_with_standard_and_pixmap(xcb_connection_t *, xcb_pict_standard_
/**
* Create an picture.
*/
xcb_render_picture_t
x_create_picture_with_pictfmt(session_t *ps, int wid, int hei,
const xcb_render_pictforminfo_t *pictfmt, unsigned long valuemask,
xcb_render_picture_t attr_nonnull(1, 4)
x_create_picture_with_pictfmt(xcb_connection_t *, xcb_drawable_t, int wid, int hei,
const xcb_render_pictforminfo_t *pictfmt,
unsigned long valuemask,
const xcb_render_create_picture_value_list_t *attr);
xcb_render_picture_t
x_create_picture_with_visual(session_t *ps, int w, int h, xcb_visualid_t visual, unsigned long valuemask,
xcb_render_picture_t attr_nonnull(1)
x_create_picture_with_visual(xcb_connection_t *, xcb_drawable_t, int w, int h,
xcb_visualid_t visual, unsigned long valuemask,
const xcb_render_create_picture_value_list_t *attr);
/// Fetch a X region and store it in a pixman region
@ -180,4 +186,5 @@ bool x_fence_sync(xcb_connection_t *, xcb_sync_fence_t);
* will be allocated, and `*ret` will be updated.
* @param[inout] size size of the array pointed to by `ret`.
*/
size_t x_picture_filter_from_conv(const conv *kernel, double center, xcb_render_fixed_t **ret, size_t *size);
size_t x_picture_filter_from_conv(const conv *kernel, double center,
xcb_render_fixed_t **ret, size_t *size);