backend: invert color and dim doesn't need reg_op

We only ever invert color of or dim the entire image, so just remove the
ability to do region based inversion and dimming. Making implementing
image_op easier.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-03-09 13:37:32 +00:00
parent 60c10790d7
commit 6ff0facae6
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
3 changed files with 17 additions and 19 deletions

View File

@ -203,14 +203,12 @@ void paint_all_new(session_t *ps, win *const t, bool ignore_damage) {
&reg_bound_local); &reg_bound_local);
// A region covers the entire window // A region covers the entire window
region_t reg_win;
pixman_region32_init_rect(&reg_win, 0, 0, w->g.width, w->g.height);
auto new_img = ps->backend_data->ops->copy( auto new_img = ps->backend_data->ops->copy(
ps->backend_data, w->win_image, &reg_visible_local); ps->backend_data, w->win_image, &reg_visible_local);
if (w->invert_color) { if (w->invert_color) {
ps->backend_data->ops->image_op( ps->backend_data->ops->image_op(
ps->backend_data, IMAGE_OP_INVERT_COLOR, new_img, ps->backend_data, IMAGE_OP_INVERT_COLOR_ALL, new_img,
&reg_win, &reg_visible_local, NULL); NULL, &reg_visible_local, NULL);
} }
if (w->dim) { if (w->dim) {
double dim_opacity = ps->o.inactive_dim; double dim_opacity = ps->o.inactive_dim;
@ -218,7 +216,7 @@ void paint_all_new(session_t *ps, win *const t, bool ignore_damage) {
dim_opacity *= w->opacity; dim_opacity *= w->opacity;
} }
ps->backend_data->ops->image_op( ps->backend_data->ops->image_op(
ps->backend_data, IMAGE_OP_DIM, new_img, &reg_win, ps->backend_data, IMAGE_OP_DIM_ALL, new_img, NULL,
&reg_visible_local, (double[]){dim_opacity}); &reg_visible_local, (double[]){dim_opacity});
} }
if (w->frame_opacity != 1) { if (w->frame_opacity != 1) {
@ -236,7 +234,6 @@ void paint_all_new(session_t *ps, win *const t, bool ignore_damage) {
ps->backend_data->ops->compose(ps->backend_data, new_img, w->g.x, ps->backend_data->ops->compose(ps->backend_data, new_img, w->g.x,
w->g.y, &reg_paint, &reg_visible); w->g.y, &reg_paint, &reg_visible);
ps->backend_data->ops->release_image(ps->backend_data, new_img); ps->backend_data->ops->release_image(ps->backend_data, new_img);
pixman_region32_fini(&reg_win);
pixman_region32_fini(&reg_visible_local); pixman_region32_fini(&reg_visible_local);
pixman_region32_fini(&reg_bound_local); pixman_region32_fini(&reg_bound_local);
} }

View File

@ -23,10 +23,10 @@ typedef struct backend_base {
} backend_t; } backend_t;
enum image_operations { enum image_operations {
// Invert the color of the image // Invert the color of the entire image, `reg_op` ignored
IMAGE_OP_INVERT_COLOR, IMAGE_OP_INVERT_COLOR_ALL,
// Dim the image, argument is the percentage // Dim the entire image, argument is the percentage. `reg_op` ignored
IMAGE_OP_DIM, IMAGE_OP_DIM_ALL,
// Multiply the alpha channel by the argument // Multiply the alpha channel by the argument
IMAGE_OP_APPLY_ALPHA, IMAGE_OP_APPLY_ALPHA,
// Same as APPLY_ALPHA, but `reg_op` is ignored and the operation applies to the // Same as APPLY_ALPHA, but `reg_op` is ignored and the operation applies to the

View File

@ -351,15 +351,10 @@ static bool image_op(backend_t *base, enum image_operations op, void *image,
} }
pixman_region32_init(&reg); pixman_region32_init(&reg);
pixman_region32_intersect(&reg, (region_t *)reg_op, (region_t *)reg_visible);
if (!pixman_region32_not_empty(&reg)) {
pixman_region32_fini(&reg);
return true;
}
switch (op) { switch (op) {
case IMAGE_OP_INVERT_COLOR: case IMAGE_OP_INVERT_COLOR_ALL:
x_set_picture_clip_region(base->c, img->pict, 0, 0, &reg); x_set_picture_clip_region(base->c, img->pict, 0, 0, reg_visible);
if (img->has_alpha) { if (img->has_alpha) {
auto tmp_pict = auto tmp_pict =
x_create_picture_with_visual(base->c, base->root, img->width, x_create_picture_with_visual(base->c, base->root, img->width,
@ -383,8 +378,8 @@ static bool image_op(backend_t *base, enum image_operations op, void *image,
0, 0, 0, 0, img->width, img->height); 0, 0, 0, 0, img->width, img->height);
} }
break; break;
case IMAGE_OP_DIM: case IMAGE_OP_DIM_ALL:
x_set_picture_clip_region(base->c, img->pict, 0, 0, &reg); x_set_picture_clip_region(base->c, img->pict, 0, 0, reg_visible);
dim_opacity = *(double *)arg; dim_opacity = *(double *)arg;
xcb_render_color_t color = { xcb_render_color_t color = {
@ -402,6 +397,12 @@ static bool image_op(backend_t *base, enum image_operations op, void *image,
color, 1, &rect); color, 1, &rect);
break; break;
case IMAGE_OP_APPLY_ALPHA: case IMAGE_OP_APPLY_ALPHA:
assert(reg_op);
pixman_region32_intersect(&reg, (region_t *)reg_op, (region_t *)reg_visible);
if (!pixman_region32_not_empty(&reg)) {
break;
}
alpha_multiplier = *(double *)arg; alpha_multiplier = *(double *)arg;
if (alpha_multiplier == 1) { if (alpha_multiplier == 1) {
break; break;