Fix some problems in new backend integration

Fix several use of uninitialized/unallocated variables when using
--experimental-backends

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-02-20 18:17:16 +00:00
parent 417e12bc62
commit c2f274ca8a
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
7 changed files with 44 additions and 23 deletions

View File

@ -1,17 +1,17 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
// Copyright (c) Yuxuan Shui <yshuiv7@gmail.com> // Copyright (c) Yuxuan Shui <yshuiv7@gmail.com>
#include <string.h> #include <string.h>
#include <xcb/xcb_image.h>
#include <xcb/render.h> #include <xcb/render.h>
#include <xcb/xcb_image.h>
#include <xcb/xcb_renderutil.h> #include <xcb/xcb_renderutil.h>
#include "backend/backend.h" #include "backend/backend.h"
#include "backend/backend_common.h" #include "backend/backend_common.h"
#include "kernel.h"
#include "common.h" #include "common.h"
#include "kernel.h"
#include "log.h" #include "log.h"
#include "x.h"
#include "win.h" #include "win.h"
#include "x.h"
/** /**
* Generate a 1x1 <code>Picture</code> of a particular color. * Generate a 1x1 <code>Picture</code> of a particular color.
@ -54,8 +54,8 @@ solid_picture(session_t *ps, bool argb, double a, double r, double g, double b)
return picture; return picture;
} }
xcb_image_t *make_shadow(xcb_connection_t *c, const conv *kernel, xcb_image_t *
double opacity, int width, int height) { make_shadow(xcb_connection_t *c, const conv *kernel, double opacity, int width, int height) {
/* /*
* We classify shadows into 4 kinds of regions * We classify shadows into 4 kinds of regions
* r = shadow radius * r = shadow radius
@ -71,6 +71,7 @@ xcb_image_t *make_shadow(xcb_connection_t *c, const conv *kernel,
*/ */
xcb_image_t *ximage; xcb_image_t *ximage;
const double *shadow_sum = kernel->rsum; const double *shadow_sum = kernel->rsum;
assert(shadow_sum);
// We only support square kernels for shadow // We only support square kernels for shadow
assert(kernel->w == kernel->h); assert(kernel->w == kernel->h);
int d = kernel->w, r = d / 2; int d = kernel->w, r = d / 2;
@ -184,15 +185,14 @@ xcb_image_t *make_shadow(xcb_connection_t *c, const conv *kernel,
* 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(session_t *ps, double opacity, const int width, const int height,
xcb_render_picture_t shadow_pixel, xcb_pixmap_t *pixmap, const conv *kernel, xcb_render_picture_t shadow_pixel,
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 = shadow_image = make_shadow(ps->c, kernel, opacity, width, height);
make_shadow(ps->c, ps->gaussian_map, 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;

View File

@ -14,8 +14,8 @@ 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(session_t *ps, double opacity, const int width, const int height,
xcb_render_picture_t shadow_pixel, xcb_pixmap_t *pixmap, const conv *kernel, xcb_render_picture_t shadow_pixel,
xcb_render_picture_t *pict); xcb_pixmap_t *pixmap, xcb_render_picture_t *pict);
xcb_render_picture_t xcb_render_picture_t
solid_picture(session_t *ps, bool argb, double a, double r, double g, double b); solid_picture(session_t *ps, bool argb, double a, double r, double g, double b);

View File

@ -20,6 +20,7 @@
#include "utils.h" #include "utils.h"
#include "win.h" #include "win.h"
#include "x.h" #include "x.h"
#include "kernel.h"
#define auto __auto_type #define auto __auto_type
@ -51,6 +52,8 @@ typedef struct _xrender_data {
/// 1x1 picture of the shadow color /// 1x1 picture of the shadow color
xcb_render_picture_t shadow_pixel; xcb_render_picture_t shadow_pixel;
/// convolution kernel for the shadow
conv *shadow_kernel;
/// Blur kernels converted to X format /// Blur kernels converted to X format
xcb_render_fixed_t *x_blur_kern[MAX_BLUR_PASS]; xcb_render_fixed_t *x_blur_kern[MAX_BLUR_PASS];
@ -365,8 +368,8 @@ 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_pixel, &pixmap, build_shadow(ps, 1, w->widthb, w->heightb, xd->shadow_kernel,
&wd->shadow_pict); xd->shadow_pixel, &pixmap, &wd->shadow_pict);
xcb_free_pixmap(ps->c, pixmap); xcb_free_pixmap(ps->c, pixmap);
} }
return wd; return wd;
@ -396,6 +399,8 @@ static void *init(session_t *ps) {
xd->white_pixel = solid_picture(ps, true, 1, 1, 1, 1); xd->white_pixel = solid_picture(ps, true, 1, 1, 1, 1);
xd->shadow_pixel = solid_picture(ps, true, 1, ps->o.shadow_red, xd->shadow_pixel = solid_picture(ps, 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);
sum_kernel_preprocess(xd->shadow_kernel);
if (ps->overlay != XCB_NONE) { if (ps->overlay != XCB_NONE) {
xd->target = x_create_picture_with_visual_and_pixmap( xd->target = x_create_picture_with_visual_and_pixmap(

View File

@ -2645,6 +2645,18 @@ session_init(int argc, char **argv, Display *dpy, const char *config_file,
exit(1); exit(1);
} }
if (ps->o.experimental_backends) {
ps->ndamage = backend_list[ps->o.backend]->max_buffer_age;
} else {
ps->ndamage = maximum_buffer_age(ps);
}
ps->damage_ring = ccalloc(ps->ndamage, region_t);
ps->damage = ps->damage_ring + ps->ndamage - 1;
for (int i = 0; i < ps->ndamage; i++) {
pixman_region32_init(&ps->damage_ring[i]);
}
if (ps->o.print_diagnostics) { if (ps->o.print_diagnostics) {
print_diagnostics(ps, config_file); print_diagnostics(ps, config_file);
free(config_file_to_free); free(config_file_to_free);

View File

@ -1170,14 +1170,6 @@ bool init_render(session_t *ps) {
return false; return false;
} }
} }
ps->ndamage = maximum_buffer_age(ps);
ps->damage_ring = ccalloc(ps->ndamage, region_t);
ps->damage = ps->damage_ring + ps->ndamage - 1;
for (int i = 0; i < ps->ndamage; i++) {
pixman_region32_init(&ps->damage_ring[i]);
}
return true; return true;
} }

View File

@ -42,3 +42,5 @@ void free_root_tile(session_t *ps);
bool init_render(session_t *ps); bool init_render(session_t *ps);
void deinit_render(session_t *ps); void deinit_render(session_t *ps);
int maximum_buffer_age(session_t *);

View File

@ -611,8 +611,18 @@ void calc_win_size(session_t *ps, win *w) {
w->flags |= WFLAG_SIZE_CHANGE; w->flags |= WFLAG_SIZE_CHANGE;
// Invalidate the shadow we built // Invalidate the shadow we built
if (ps->o.experimental_backends) { if (ps->o.experimental_backends) {
if (w->state != WSTATE_UNMAPPED && w->state != WSTATE_MAPPED) {
// wrapping up fading
w->opacity = w->opacity_tgt;
win_check_fade_finished(ps, &w);
}
if (!w) {
return;
}
if (w->state == WSTATE_MAPPED) {
backend_list[ps->o.backend]->release_win(ps->backend_data, ps, w, w->win_data); backend_list[ps->o.backend]->release_win(ps->backend_data, ps, w, w->win_data);
w->win_data = backend_list[ps->o.backend]->prepare_win(ps->backend_data, ps, w); w->win_data = backend_list[ps->o.backend]->prepare_win(ps->backend_data, ps, w);
}
} else { } else {
free_paint(ps, &w->shadow_paint); free_paint(ps, &w->shadow_paint);
} }