Format changes

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2018-12-16 02:50:39 +00:00
parent 404a6b47ad
commit e7a15ba846
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
1 changed files with 67 additions and 85 deletions

View File

@ -24,8 +24,7 @@ static inline bool paint_bind_tex(session_t *ps, paint_t *ppaint, unsigned wid,
return false; return false;
if (force || !glx_tex_binded(ppaint->ptex, ppaint->pixmap)) if (force || !glx_tex_binded(ppaint->ptex, ppaint->pixmap))
return glx_bind_pixmap(ps, &ppaint->ptex, ppaint->pixmap, wid, hei, return glx_bind_pixmap(ps, &ppaint->ptex, ppaint->pixmap, wid, hei, depth);
depth);
return true; return true;
} }
@ -89,10 +88,9 @@ void free_paint(session_t *ps, paint_t *ppaint) {
ppaint->pixmap = XCB_NONE; ppaint->pixmap = XCB_NONE;
} }
void render(session_t *ps, int x, int y, int dx, int dy, int wid, int hei, void render(session_t *ps, int x, int y, int dx, int dy, int wid, int hei, double opacity,
double opacity, bool argb, bool neg, xcb_render_picture_t pict, bool argb, bool neg, xcb_render_picture_t pict, glx_texture_t *ptex,
glx_texture_t *ptex, const region_t *reg_paint, const region_t *reg_paint, const glx_prog_main_t *pprogram) {
const glx_prog_main_t *pprogram) {
switch (ps->o.backend) { switch (ps->o.backend) {
case BKEND_XRENDER: case BKEND_XRENDER:
case BKEND_XR_GLX_HYBRID: { case BKEND_XR_GLX_HYBRID: {
@ -102,15 +100,15 @@ void render(session_t *ps, int x, int y, int dx, int dy, int wid, int hei,
int op = ((!argb && !alpha_pict) ? XCB_RENDER_PICT_OP_SRC int op = ((!argb && !alpha_pict) ? XCB_RENDER_PICT_OP_SRC
: XCB_RENDER_PICT_OP_OVER); : XCB_RENDER_PICT_OP_OVER);
xcb_render_composite(ps->c, op, pict, alpha_pict, xcb_render_composite(ps->c, op, pict, alpha_pict,
ps->tgt_buffer.pict, x, y, 0, 0, dx, dy, ps->tgt_buffer.pict, x, y, 0, 0, dx, dy, wid,
wid, hei); hei);
} }
break; break;
} }
#ifdef CONFIG_OPENGL #ifdef CONFIG_OPENGL
case BKEND_GLX: case BKEND_GLX:
glx_render(ps, ptex, x, y, dx, dy, wid, hei, ps->psglx->z, opacity, glx_render(ps, ptex, x, y, dx, dy, wid, hei, ps->psglx->z, opacity, argb,
argb, neg, reg_paint, pprogram); neg, reg_paint, pprogram);
ps->psglx->z += 1; ps->psglx->z += 1;
break; break;
#endif #endif
@ -160,8 +158,8 @@ void paint_one(session_t *ps, win *w, const region_t *reg_paint) {
// Fetch Pixmap // Fetch Pixmap
if (!w->paint.pixmap && ps->has_name_pixmap) { if (!w->paint.pixmap && ps->has_name_pixmap) {
w->paint.pixmap = xcb_generate_id(ps->c); w->paint.pixmap = xcb_generate_id(ps->c);
set_ignore_cookie(ps, xcb_composite_name_window_pixmap( set_ignore_cookie(
ps->c, w->id, w->paint.pixmap)); ps, xcb_composite_name_window_pixmap(ps->c, w->id, w->paint.pixmap));
if (w->paint.pixmap) if (w->paint.pixmap)
free_fence(ps, &w->fence); free_fence(ps, &w->fence);
} }
@ -189,14 +187,12 @@ void paint_one(session_t *ps, win *w, const region_t *reg_paint) {
// causing the jittering issue M4he reported in #7. // causing the jittering issue M4he reported in #7.
if (!paint_bind_tex(ps, &w->paint, 0, 0, 0, if (!paint_bind_tex(ps, &w->paint, 0, 0, 0,
(!ps->o.glx_no_rebind_pixmap && w->pixmap_damaged))) { (!ps->o.glx_no_rebind_pixmap && w->pixmap_damaged))) {
printf_errf("(%#010lx): Failed to bind texture. Expect troubles.", printf_errf("(%#010lx): Failed to bind texture. Expect troubles.", w->id);
w->id);
} }
w->pixmap_damaged = false; w->pixmap_damaged = false;
if (!paint_isvalid(ps, &w->paint)) { if (!paint_isvalid(ps, &w->paint)) {
printf_errf("(%#010lx): Missing painting data. This is a bad sign.", printf_errf("(%#010lx): Missing painting data. This is a bad sign.", w->id);
w->id);
return; return;
} }
@ -222,18 +218,17 @@ void paint_one(session_t *ps, win *w, const region_t *reg_paint) {
pixman_region32_fini(&reg); pixman_region32_fini(&reg);
} }
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, pict, xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, pict, None,
None, newpict, 0, 0, 0, 0, 0, 0, wid, newpict, 0, 0, 0, 0, 0, 0, wid, hei);
hei);
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_DIFFERENCE, xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_DIFFERENCE,
ps->white_picture, None, newpict, 0, 0, ps->white_picture, None, newpict, 0, 0, 0, 0,
0, 0, 0, 0, wid, hei); 0, 0, wid, hei);
// We use an extra PictOpInReverse operation to get correct // We use an extra PictOpInReverse operation to get correct
// pixel alpha. There could be a better solution. // pixel alpha. There could be a better solution.
if (win_has_alpha(w)) if (win_has_alpha(w))
xcb_render_composite( xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_IN_REVERSE,
ps->c, XCB_RENDER_PICT_OP_IN_REVERSE, pict, None, pict, None, newpict, 0, 0, 0, 0, 0,
newpict, 0, 0, 0, 0, 0, 0, wid, hei); 0, wid, hei);
pict = newpict; pict = newpict;
} }
} }
@ -273,14 +268,13 @@ void paint_one(session_t *ps, win *w, const region_t *reg_paint) {
// bottom // bottom
// cbot = checked bottom // cbot = checked bottom
int cbot = min_i( int cbot =
body_height, min_i(body_height,
b); // Make sure bottom margin is not too large b); // Make sure bottom margin is not too large
if (cbot > 0) if (cbot > 0)
COMP_BDR(0, hei - cbot, wid, cbot); COMP_BDR(0, hei - cbot, wid, cbot);
body_height -= body_height -= cbot; // Height of window exclude the margin
cbot; // Height of window exclude the margin
if (body_height <= 0) if (body_height <= 0)
break; break;
@ -341,13 +335,12 @@ void paint_one(session_t *ps, win *w, const region_t *reg_paint) {
}; };
xcb_render_fill_rectangles(ps->c, XCB_RENDER_PICT_OP_OVER, xcb_render_fill_rectangles(ps->c, XCB_RENDER_PICT_OP_OVER,
ps->tgt_buffer.pict, color, 1, ps->tgt_buffer.pict, color, 1, &rect);
&rect);
} break; } break;
#ifdef CONFIG_OPENGL #ifdef CONFIG_OPENGL
case BKEND_GLX: case BKEND_GLX:
glx_dim_dst(ps, x, y, wid, hei, ps->psglx->z - 0.7, glx_dim_dst(ps, x, y, wid, hei, ps->psglx->z - 0.7, dim_opacity,
dim_opacity, reg_paint); reg_paint);
break; break;
#endif #endif
default: assert(false); default: assert(false);
@ -374,8 +367,8 @@ static bool get_root_tile(session_t *ps) {
// 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++) {
winprop_t prop = winprop_t prop =
wid_get_prop(ps, ps->root, get_atom(ps, background_props_str[p]), wid_get_prop(ps, ps->root, get_atom(ps, background_props_str[p]), 1L,
1L, XCB_ATOM_PIXMAP, 32); XCB_ATOM_PIXMAP, 32);
if (prop.nitems) { if (prop.nitems) {
pixmap = *prop.p32; pixmap = *prop.p32;
fill = false; fill = false;
@ -481,8 +474,8 @@ static xcb_image_t *make_shadow(session_t *ps, double opacity, int width, int he
if (ps->cgsize > 0) { if (ps->cgsize > 0) {
d = ps->shadow_top[opacity_int * (ps->cgsize + 1) + ps->cgsize]; d = ps->shadow_top[opacity_int * (ps->cgsize + 1) + ps->cgsize];
} else { } else {
d = (unsigned char)(sum_kernel(ps->gaussian_map, center, center, d = (unsigned char)(sum_kernel(ps->gaussian_map, center, center, width,
width, height) * height) *
opacity * 255.0); opacity * 255.0);
} }
memset(data, d, sheight * swidth); memset(data, d, sheight * swidth);
@ -506,9 +499,8 @@ static xcb_image_t *make_shadow(session_t *ps, double opacity, int width, int he
(ps->cgsize + 1) + (ps->cgsize + 1) +
y * (ps->cgsize + 1) + x]; y * (ps->cgsize + 1) + x];
} else { } else {
d = (unsigned char)(sum_kernel(ps->gaussian_map, d = (unsigned char)(sum_kernel(ps->gaussian_map, x - center,
x - center, y - center, y - center, width, height) *
width, height) *
opacity * 255.0); opacity * 255.0);
} }
data[y * sstride + x] = d; data[y * sstride + x] = d;
@ -528,14 +520,12 @@ static xcb_image_t *make_shadow(session_t *ps, double opacity, int width, int he
if (ylimit == ps->cgsize) { if (ylimit == ps->cgsize) {
d = ps->shadow_top[opacity_int * (ps->cgsize + 1) + y]; d = ps->shadow_top[opacity_int * (ps->cgsize + 1) + y];
} else { } else {
d = (unsigned char)(sum_kernel(ps->gaussian_map, d = (unsigned char)(sum_kernel(ps->gaussian_map, center,
center, y - center, y - center, width, height) *
width, height) *
opacity * 255.0); opacity * 255.0);
} }
memset(&data[y * sstride + ps->cgsize], d, x_diff); memset(&data[y * sstride + ps->cgsize], d, x_diff);
memset(&data[(sheight - y - 1) * sstride + ps->cgsize], d, memset(&data[(sheight - y - 1) * sstride + ps->cgsize], d, x_diff);
x_diff);
} }
} }
@ -579,10 +569,10 @@ static bool win_build_shadow(session_t *ps, win *w, double opacity) {
return None; return None;
} }
shadow_pixmap = x_create_pixmap(ps, 8, ps->root, shadow_image->width, shadow_pixmap =
shadow_image->height); x_create_pixmap(ps, 8, ps->root, shadow_image->width, shadow_image->height);
shadow_pixmap_argb = x_create_pixmap(ps, 32, ps->root, shadow_image->width, shadow_pixmap_argb =
shadow_image->height); 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");
@ -648,9 +638,9 @@ static inline void win_paint_shadow(session_t *ps, win *w, region_t *reg_paint)
return; return;
} }
render(ps, 0, 0, w->g.x + w->shadow_dx, w->g.y + w->shadow_dy, render(ps, 0, 0, w->g.x + w->shadow_dx, w->g.y + w->shadow_dy, w->shadow_width,
w->shadow_width, w->shadow_height, w->shadow_opacity, true, false, w->shadow_height, w->shadow_opacity, true, false, w->shadow_paint.pict,
w->shadow_paint.pict, w->shadow_paint.ptex, reg_paint, NULL); w->shadow_paint.ptex, reg_paint, NULL);
} }
/** /**
@ -687,8 +677,7 @@ xr_blur_dst(session_t *ps, xcb_render_picture_t tgt_buffer, int x, int y, int wi
// Directly copying from tgt_buffer to it does not work, so we create a // Directly copying from tgt_buffer to it does not work, so we create a
// Picture in the middle. // Picture in the middle.
xcb_render_picture_t tmp_picture = xcb_render_picture_t tmp_picture = x_create_picture(ps, wid, hei, NULL, 0, NULL);
x_create_picture(ps, wid, hei, NULL, 0, NULL);
if (!tmp_picture) { if (!tmp_picture) {
printf_errf("(): Failed to build intermediate Picture."); printf_errf("(): Failed to build intermediate Picture.");
@ -710,12 +699,12 @@ xr_blur_dst(session_t *ps, xcb_render_picture_t tgt_buffer, int x, int y, int wi
// be applied on source picture, to get the nearby pixels outside the // be applied on source picture, to get the nearby pixels outside the
// window. // window.
xcb_render_set_picture_filter( xcb_render_set_picture_filter(
ps->c, src_pict, strlen(XRFILTER_CONVOLUTION), ps->c, src_pict, strlen(XRFILTER_CONVOLUTION), XRFILTER_CONVOLUTION,
XRFILTER_CONVOLUTION, kwid * khei + 2, convolution_blur); kwid * khei + 2, convolution_blur);
xcb_render_composite( xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, src_pict, None,
ps->c, XCB_RENDER_PICT_OP_SRC, src_pict, None, dst_pict, dst_pict, (rd_from_tgt ? x : 0),
(rd_from_tgt ? x : 0), (rd_from_tgt ? y : 0), 0, 0, (rd_from_tgt ? y : 0), 0, 0, (rd_from_tgt ? 0 : x),
(rd_from_tgt ? 0 : x), (rd_from_tgt ? 0 : y), wid, hei); (rd_from_tgt ? 0 : y), wid, hei);
xrfilter_reset(ps, src_pict); xrfilter_reset(ps, src_pict);
{ {
@ -766,8 +755,8 @@ win_blur_background(session_t *ps, win *w, xcb_render_picture_t tgt_buffer,
break; break;
} }
assert(!kern_dst || (kern_src[0] == kern_dst[0] && assert(!kern_dst ||
kern_src[1] == kern_dst[1])); (kern_src[0] == kern_dst[0] && kern_src[1] == kern_dst[1]));
// Skip for fixed factor_center if the cache exists already // Skip for fixed factor_center if the cache exists already
if (ps->o.blur_background_fixed && kern_dst) if (ps->o.blur_background_fixed && kern_dst)
@ -778,8 +767,7 @@ win_blur_background(session_t *ps, win *w, xcb_render_picture_t tgt_buffer,
// Allocate cache space if needed // Allocate cache space if needed
if (!kern_dst) { if (!kern_dst) {
kern_dst = kern_dst = ccalloc(kwid * khei + 2, xcb_render_fixed_t);
ccalloc(kwid * khei + 2, xcb_render_fixed_t);
if (!kern_dst) { if (!kern_dst) {
printf_errf("(): Failed to allocate memory " printf_errf("(): Failed to allocate memory "
"for blur kernel."); "for blur kernel.");
@ -829,8 +817,7 @@ win_blur_background(session_t *ps, win *w, xcb_render_picture_t tgt_buffer,
/// paint all windows /// paint all windows
/// region = ?? /// region = ??
/// region_real = the damage region /// region_real = the damage region
void paint_all(session_t *ps, region_t *region, const region_t *region_real, void paint_all(session_t *ps, region_t *region, const region_t *region_real, win *const t) {
win *const t) {
if (!region_real) if (!region_real)
region_real = region; region_real = region;
@ -953,8 +940,7 @@ void paint_all(session_t *ps, region_t *region, const region_t *region_real,
if (w->blur_background && if (w->blur_background &&
(!win_is_solid(ps, w) || (!win_is_solid(ps, w) ||
(ps->o.blur_background_frame && w->frame_opacity != 1))) (ps->o.blur_background_frame && w->frame_opacity != 1)))
win_blur_background(ps, w, ps->tgt_buffer.pict, win_blur_background(ps, w, ps->tgt_buffer.pict, &reg_tmp);
&reg_tmp);
// Painting the window // Painting the window
paint_one(ps, w, &reg_tmp); paint_one(ps, w, &reg_tmp);
@ -1006,16 +992,15 @@ void paint_all(session_t *ps, region_t *region, const region_t *region_real,
xcb_render_picture_t new_pict = x_create_picture( xcb_render_picture_t new_pict = x_create_picture(
ps, ps->root_width, ps->root_height, pictfmt, 0, NULL); ps, ps->root_width, ps->root_height, pictfmt, 0, NULL);
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC,
ps->tgt_buffer.pict, None, new_pict, 0, ps->tgt_buffer.pict, None, new_pict, 0, 0, 0,
0, 0, 0, 0, 0, ps->root_width, 0, 0, 0, ps->root_width, ps->root_height);
ps->root_height);
// Next, we set the region of paint and highlight it // Next, we set the region of paint and highlight it
x_set_picture_clip_region(ps, new_pict, 0, 0, region_real); x_set_picture_clip_region(ps, new_pict, 0, 0, region_real);
xcb_render_composite( xcb_render_composite(
ps->c, XCB_RENDER_PICT_OP_OVER, ps->white_picture, ps->c, XCB_RENDER_PICT_OP_OVER, ps->white_picture,
ps->alpha_picts[MAX_ALPHA / 2], new_pict, 0, 0, 0, 0, 0, ps->alpha_picts[MAX_ALPHA / 2], new_pict, 0, 0, 0, 0, 0, 0,
0, ps->root_width, ps->root_height); ps->root_width, ps->root_height);
// Finally, clear clip region and put the whole thing on screen // Finally, clear clip region and put the whole thing on screen
x_set_picture_clip_region(ps, new_pict, 0, 0, &ps->screen_reg); x_set_picture_clip_region(ps, new_pict, 0, 0, &ps->screen_reg);
@ -1025,9 +1010,9 @@ void paint_all(session_t *ps, region_t *region, const region_t *region_real,
xcb_render_free_picture(ps->c, new_pict); xcb_render_free_picture(ps->c, new_pict);
} else } else
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC,
ps->tgt_buffer.pict, None, ps->tgt_buffer.pict, None, ps->tgt_picture,
ps->tgt_picture, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ps->root_width,
ps->root_width, ps->root_height); ps->root_height);
break; break;
#ifdef CONFIG_OPENGL #ifdef CONFIG_OPENGL
case BKEND_XR_GLX_HYBRID: case BKEND_XR_GLX_HYBRID:
@ -1101,8 +1086,7 @@ static bool xr_init_blur(session_t *ps) {
xcb_render_query_filters_reply_t *pf = xcb_render_query_filters_reply( xcb_render_query_filters_reply_t *pf = xcb_render_query_filters_reply(
ps->c, xcb_render_query_filters(ps->c, get_tgt_window(ps)), NULL); ps->c, xcb_render_query_filters(ps->c, get_tgt_window(ps)), NULL);
if (pf) { if (pf) {
xcb_str_iterator_t iter = xcb_str_iterator_t iter = xcb_render_query_filters_filters_iterator(pf);
xcb_render_query_filters_filters_iterator(pf);
for (; iter.rem; xcb_str_next(&iter)) { for (; iter.rem; xcb_str_next(&iter)) {
int len = xcb_str_name_length(iter.data); int len = xcb_str_name_length(iter.data);
char *name = xcb_str_name(iter.data); char *name = xcb_str_name(iter.data);
@ -1161,8 +1145,7 @@ 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, xcb_render_fill_rectangles(ps->c, XCB_RENDER_PICT_OP_SRC, picture, col, 1, &rect);
&rect);
xcb_free_pixmap(ps->c, pixmap); xcb_free_pixmap(ps->c, pixmap);
return picture; return picture;
@ -1292,9 +1275,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 = ps->cshadow_picture = solid_picture(
solid_picture(ps, true, 1, ps->o.shadow_red, ps->o.shadow_green, ps, true, 1, ps->o.shadow_red, ps->o.shadow_green, ps->o.shadow_blue);
ps->o.shadow_blue);
if (ps->cshadow_picture == XCB_NONE) { if (ps->cshadow_picture == XCB_NONE) {
printf_errf("(): Failed to create shadow picture."); printf_errf("(): Failed to create shadow picture.");
return false; return false;