Eliminate implicit conversions
Use explicit conversions everywhere. Adding bounds check assertions when necessary. Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
114
src/render.c
114
src/render.c
@ -34,9 +34,8 @@
|
||||
/**
|
||||
* Bind texture in paint_t if we are using GLX backend.
|
||||
*/
|
||||
static inline bool
|
||||
paint_bind_tex(session_t *ps, paint_t *ppaint, unsigned wid, unsigned hei, bool repeat,
|
||||
int depth, xcb_visualid_t visual, bool force) {
|
||||
static inline bool paint_bind_tex(session_t *ps, paint_t *ppaint, int wid, int hei,
|
||||
bool repeat, int depth, xcb_visualid_t visual, bool force) {
|
||||
#ifdef CONFIG_OPENGL
|
||||
// XXX This is a mess. But this will go away after the backend refactor.
|
||||
static thread_local struct glx_fbconfig_info *argb_fbconfig = NULL;
|
||||
@ -174,13 +173,15 @@ void render(session_t *ps, int x, int y, int dx, int dy, int wid, int hei, doubl
|
||||
switch (ps->o.backend) {
|
||||
case BKEND_XRENDER:
|
||||
case BKEND_XR_GLX_HYBRID: {
|
||||
int alpha_step = opacity * MAX_ALPHA;
|
||||
auto alpha_step = (int)(opacity * MAX_ALPHA);
|
||||
xcb_render_picture_t alpha_pict = ps->alpha_picts[alpha_step];
|
||||
if (alpha_step != 0) {
|
||||
int op = ((!argb && !alpha_pict) ? XCB_RENDER_PICT_OP_SRC
|
||||
: XCB_RENDER_PICT_OP_OVER);
|
||||
xcb_render_composite(ps->c, op, pict, alpha_pict, ps->tgt_buffer.pict,
|
||||
x, y, 0, 0, dx, dy, wid, hei);
|
||||
uint8_t op = ((!argb && !alpha_pict) ? XCB_RENDER_PICT_OP_SRC
|
||||
: XCB_RENDER_PICT_OP_OVER);
|
||||
xcb_render_composite(
|
||||
ps->c, op, pict, alpha_pict, ps->tgt_buffer.pict,
|
||||
to_i16_checked(x), to_i16_checked(y), 0, 0, to_i16_checked(dx),
|
||||
to_i16_checked(dy), to_u16_checked(wid), to_u16_checked(hei));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -279,8 +280,8 @@ void paint_one(session_t *ps, win *w, const region_t *reg_paint) {
|
||||
|
||||
const int x = w->g.x;
|
||||
const int y = w->g.y;
|
||||
const int wid = w->widthb;
|
||||
const int hei = w->heightb;
|
||||
const uint16_t wid = to_u16_checked(w->widthb);
|
||||
const uint16_t hei = to_u16_checked(w->heightb);
|
||||
|
||||
xcb_render_picture_t pict = w->paint.pict;
|
||||
|
||||
@ -320,10 +321,10 @@ void paint_one(session_t *ps, win *w, const region_t *reg_paint) {
|
||||
} else {
|
||||
// Painting parameters
|
||||
const margin_t extents = win_calc_frame_extents(w);
|
||||
const int t = extents.top;
|
||||
const int l = extents.left;
|
||||
const int b = extents.bottom;
|
||||
const int r = extents.right;
|
||||
const auto t = (int)extents.top;
|
||||
const auto l = (int)extents.left;
|
||||
const auto b = (int)extents.bottom;
|
||||
const auto r = (int)extents.right;
|
||||
|
||||
#define COMP_BDR(cx, cy, cwid, chei) \
|
||||
paint_region(ps, w, (cx), (cy), (cwid), (chei), w->frame_opacity * w->opacity, \
|
||||
@ -337,7 +338,7 @@ void paint_one(session_t *ps, win *w, const region_t *reg_paint) {
|
||||
int body_height = hei;
|
||||
// ctop = checked top
|
||||
// Make sure top margin is smaller than height
|
||||
int ctop = min_i(body_height, t);
|
||||
int ctop = min2(body_height, t);
|
||||
if (ctop > 0)
|
||||
COMP_BDR(0, 0, wid, ctop);
|
||||
|
||||
@ -348,7 +349,7 @@ void paint_one(session_t *ps, win *w, const region_t *reg_paint) {
|
||||
// bottom
|
||||
// cbot = checked bottom
|
||||
// Make sure bottom margin is not too large
|
||||
int cbot = min_i(body_height, b);
|
||||
int cbot = min2(body_height, b);
|
||||
if (cbot > 0)
|
||||
COMP_BDR(0, hei - cbot, wid, cbot);
|
||||
|
||||
@ -359,7 +360,7 @@ void paint_one(session_t *ps, win *w, const region_t *reg_paint) {
|
||||
|
||||
// left
|
||||
int body_width = wid;
|
||||
int cleft = min_i(body_width, l);
|
||||
int cleft = min2(body_width, l);
|
||||
if (cleft > 0)
|
||||
COMP_BDR(0, ctop, cleft, body_height);
|
||||
|
||||
@ -368,7 +369,7 @@ void paint_one(session_t *ps, win *w, const region_t *reg_paint) {
|
||||
break;
|
||||
|
||||
// right
|
||||
int cright = min_i(body_width, r);
|
||||
int cright = min2(body_width, r);
|
||||
if (cright > 0)
|
||||
COMP_BDR(wid - cright, ctop, cright, body_height);
|
||||
|
||||
@ -396,7 +397,7 @@ void paint_one(session_t *ps, win *w, const region_t *reg_paint) {
|
||||
switch (ps->o.backend) {
|
||||
case BKEND_XRENDER:
|
||||
case BKEND_XR_GLX_HYBRID: {
|
||||
unsigned short cval = 0xffff * dim_opacity;
|
||||
auto cval = (uint16_t)(0xffff * dim_opacity);
|
||||
|
||||
// Premultiply color
|
||||
xcb_render_color_t color = {
|
||||
@ -407,8 +408,8 @@ void paint_one(session_t *ps, win *w, const region_t *reg_paint) {
|
||||
};
|
||||
|
||||
xcb_rectangle_t rect = {
|
||||
.x = x,
|
||||
.y = y,
|
||||
.x = to_i16_checked(x),
|
||||
.y = to_i16_checked(y),
|
||||
.width = wid,
|
||||
.height = hei,
|
||||
};
|
||||
@ -418,8 +419,8 @@ void paint_one(session_t *ps, win *w, const region_t *reg_paint) {
|
||||
} break;
|
||||
#ifdef CONFIG_OPENGL
|
||||
case BKEND_GLX:
|
||||
glx_dim_dst(ps, x, y, wid, hei, ps->psglx->z - 0.7, dim_opacity,
|
||||
reg_paint);
|
||||
glx_dim_dst(ps, x, y, wid, hei, (int)(ps->psglx->z - 0.7),
|
||||
(float)dim_opacity, reg_paint);
|
||||
break;
|
||||
#endif
|
||||
default: assert(false);
|
||||
@ -447,7 +448,7 @@ static bool get_root_tile(session_t *ps) {
|
||||
|
||||
// Create a pixmap if there isn't any
|
||||
if (!pixmap) {
|
||||
pixmap = x_create_pixmap(ps->c, ps->depth, ps->root, 1, 1);
|
||||
pixmap = x_create_pixmap(ps->c, (uint8_t)ps->depth, ps->root, 1, 1);
|
||||
if (pixmap == XCB_NONE) {
|
||||
log_error("Failed to create pixmaps for root tile.");
|
||||
return false;
|
||||
@ -605,8 +606,9 @@ static inline void win_paint_shadow(session_t *ps, win *w, region_t *reg_paint)
|
||||
*
|
||||
* @return true if successful, false otherwise
|
||||
*/
|
||||
static bool xr_blur_dst(session_t *ps, xcb_render_picture_t tgt_buffer, int x, int y, int wid,
|
||||
int hei, xcb_render_fixed_t **blur_kerns, const region_t *reg_clip) {
|
||||
static bool xr_blur_dst(session_t *ps, xcb_render_picture_t tgt_buffer, int16_t x,
|
||||
int16_t y, uint16_t wid, uint16_t hei,
|
||||
xcb_render_fixed_t **blur_kerns, const region_t *reg_clip) {
|
||||
assert(blur_kerns[0]);
|
||||
|
||||
// Directly copying from tgt_buffer to it does not work, so we create a
|
||||
@ -627,16 +629,16 @@ static bool xr_blur_dst(session_t *ps, xcb_render_picture_t tgt_buffer, int x, i
|
||||
assert(i < MAX_BLUR_PASS - 1);
|
||||
xcb_render_fixed_t *convolution_blur = blur_kerns[i];
|
||||
// `x / 65536.0` converts from X fixed point to double
|
||||
int kwid = ((double)convolution_blur[0]) / 65536.0,
|
||||
khei = ((double)convolution_blur[1]) / 65536.0;
|
||||
int kwid = (int)((double)convolution_blur[0] / 65536.0),
|
||||
khei = (int)((double)convolution_blur[1] / 65536.0);
|
||||
bool rd_from_tgt = (tgt_buffer == src_pict);
|
||||
|
||||
// Copy from source picture to destination. The filter must
|
||||
// be applied on source picture, to get the nearby pixels outside the
|
||||
// window.
|
||||
xcb_render_set_picture_filter(ps->c, src_pict, strlen(XRFILTER_CONVOLUTION),
|
||||
XRFILTER_CONVOLUTION, kwid * khei + 2,
|
||||
convolution_blur);
|
||||
xcb_render_set_picture_filter(
|
||||
ps->c, src_pict, strlen(XRFILTER_CONVOLUTION), XRFILTER_CONVOLUTION,
|
||||
(uint32_t)(kwid * khei + 2), convolution_blur);
|
||||
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, src_pict, XCB_NONE,
|
||||
dst_pict, (rd_from_tgt ? x : 0),
|
||||
(rd_from_tgt ? y : 0), 0, 0, (rd_from_tgt ? 0 : x),
|
||||
@ -664,10 +666,10 @@ static bool xr_blur_dst(session_t *ps, xcb_render_picture_t tgt_buffer, int x, i
|
||||
*/
|
||||
static inline void win_blur_background(session_t *ps, win *w, xcb_render_picture_t tgt_buffer,
|
||||
const region_t *reg_paint) {
|
||||
const int x = w->g.x;
|
||||
const int y = w->g.y;
|
||||
const int wid = w->widthb;
|
||||
const int hei = w->heightb;
|
||||
const int16_t x = w->g.x;
|
||||
const int16_t y = w->g.y;
|
||||
const auto wid = to_u16_checked(w->widthb);
|
||||
const auto hei = to_u16_checked(w->heightb);
|
||||
|
||||
double factor_center = 1.0;
|
||||
// Adjust blur strength according to window opacity, to make it appear
|
||||
@ -702,7 +704,7 @@ static inline void win_blur_background(session_t *ps, win *w, xcb_render_picture
|
||||
|
||||
// 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 ? (size_t)(kern_src->w * kern_src->h + 2) : 0;
|
||||
x_picture_filter_from_conv(kern_src, factor_center, &kern_dst, &size);
|
||||
ps->blur_kerns_cache[i] = kern_dst;
|
||||
}
|
||||
@ -726,8 +728,8 @@ static inline void win_blur_background(session_t *ps, win *w, xcb_render_picture
|
||||
#ifdef CONFIG_OPENGL
|
||||
case BKEND_GLX:
|
||||
// TODO: Handle frame opacity
|
||||
glx_blur_dst(ps, x, y, wid, hei, ps->psglx->z - 0.5, factor_center,
|
||||
reg_paint, &w->glx_blur_cache);
|
||||
glx_blur_dst(ps, x, y, wid, hei, (float)ps->psglx->z - 0.5f,
|
||||
(float)factor_center, reg_paint, &w->glx_blur_cache);
|
||||
break;
|
||||
#endif
|
||||
default: assert(0);
|
||||
@ -786,7 +788,7 @@ void paint_all(session_t *ps, win *const t, bool ignore_damage) {
|
||||
pixman_region32_copy(®ion, &ps->screen_reg);
|
||||
} else {
|
||||
for (int i = 0; i < get_buffer_age(ps); i++) {
|
||||
const int curr = ((ps->damage - ps->damage_ring) + i) % ps->ndamage;
|
||||
auto curr = ((ps->damage - ps->damage_ring) + i) % ps->ndamage;
|
||||
pixman_region32_union(®ion, ®ion, &ps->damage_ring[curr]);
|
||||
}
|
||||
}
|
||||
@ -800,7 +802,7 @@ void paint_all(session_t *ps, win *const t, bool ignore_damage) {
|
||||
#endif
|
||||
|
||||
if (ps->o.resize_damage > 0) {
|
||||
resize_region(®ion, ps->o.resize_damage);
|
||||
resize_region(®ion, (short)ps->o.resize_damage);
|
||||
}
|
||||
|
||||
// Remove the damaged area out of screen
|
||||
@ -809,8 +811,9 @@ void paint_all(session_t *ps, win *const t, bool ignore_damage) {
|
||||
if (!paint_isvalid(ps, &ps->tgt_buffer)) {
|
||||
if (!ps->tgt_buffer.pixmap) {
|
||||
free_paint(ps, &ps->tgt_buffer);
|
||||
ps->tgt_buffer.pixmap = x_create_pixmap(
|
||||
ps->c, ps->depth, ps->root, ps->root_width, ps->root_height);
|
||||
ps->tgt_buffer.pixmap =
|
||||
x_create_pixmap(ps->c, (uint8_t)ps->depth, ps->root,
|
||||
ps->root_width, ps->root_height);
|
||||
if (ps->tgt_buffer.pixmap == XCB_NONE) {
|
||||
log_fatal("Failed to allocate a screen-sized pixmap for"
|
||||
"painting");
|
||||
@ -874,9 +877,10 @@ void paint_all(session_t *ps, win *const t, bool ignore_damage) {
|
||||
|
||||
// Might be worth while to crop the region to shadow
|
||||
// border
|
||||
assert(w->shadow_width >= 0 && w->shadow_height >= 0);
|
||||
pixman_region32_intersect_rect(
|
||||
®_tmp, ®_tmp, w->g.x + w->shadow_dx,
|
||||
w->g.y + w->shadow_dy, w->shadow_width, w->shadow_height);
|
||||
®_tmp, ®_tmp, w->g.x + w->shadow_dx, w->g.y + w->shadow_dy,
|
||||
(uint)w->shadow_width, (uint)w->shadow_height);
|
||||
|
||||
// Mask out the body of the window from the shadow if
|
||||
// needed Doing it here instead of in make_shadow() for
|
||||
@ -958,6 +962,8 @@ void paint_all(session_t *ps, win *const t, bool ignore_damage) {
|
||||
ps->vsync_wait(ps);
|
||||
}
|
||||
|
||||
auto rwidth = to_u16_checked(ps->root_width);
|
||||
auto rheight = to_u16_checked(ps->root_height);
|
||||
switch (ps->o.backend) {
|
||||
case BKEND_XRENDER:
|
||||
if (ps->o.monitor_repaint) {
|
||||
@ -969,16 +975,16 @@ 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->c, ps->root, ps->root_width, ps->root_height, pictfmt, 0, NULL);
|
||||
ps->c, ps->root, rwidth, rheight, 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);
|
||||
ps->tgt_buffer.pict, XCB_NONE, new_pict, 0,
|
||||
0, 0, 0, 0, 0, rwidth, rheight);
|
||||
|
||||
// Next, we set the region of paint and highlight it
|
||||
x_set_picture_clip_region(ps->c, new_pict, 0, 0, ®ion);
|
||||
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_OVER, ps->white_picture,
|
||||
ps->alpha_picts[MAX_ALPHA / 2], new_pict, 0, 0,
|
||||
0, 0, 0, 0, ps->root_width, ps->root_height);
|
||||
ps->alpha_picts[MAX_ALPHA / 2], new_pict, 0,
|
||||
0, 0, 0, 0, 0, rwidth, rheight);
|
||||
|
||||
// Finally, clear clip regions of new_pict and the screen, and put
|
||||
// the whole thing on screen
|
||||
@ -986,12 +992,12 @@ void paint_all(session_t *ps, win *const t, bool ignore_damage) {
|
||||
x_set_picture_clip_region(ps->c, ps->tgt_picture, 0, 0, &ps->screen_reg);
|
||||
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, new_pict,
|
||||
XCB_NONE, ps->tgt_picture, 0, 0, 0, 0, 0, 0,
|
||||
ps->root_width, ps->root_height);
|
||||
rwidth, rheight);
|
||||
xcb_render_free_picture(ps->c, new_pict);
|
||||
} else
|
||||
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, ps->tgt_buffer.pict,
|
||||
XCB_NONE, ps->tgt_picture, 0, 0, 0, 0, 0, 0,
|
||||
ps->root_width, ps->root_height);
|
||||
xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC,
|
||||
ps->tgt_buffer.pict, XCB_NONE, ps->tgt_picture,
|
||||
0, 0, 0, 0, 0, 0, rwidth, rheight);
|
||||
break;
|
||||
#ifdef CONFIG_OPENGL
|
||||
case BKEND_XR_GLX_HYBRID:
|
||||
@ -1151,7 +1157,7 @@ bool init_render(session_t *ps) {
|
||||
|
||||
// Generates another Picture for shadows if the color is modified by
|
||||
// user
|
||||
if (!ps->o.shadow_red && !ps->o.shadow_green && !ps->o.shadow_blue) {
|
||||
if (ps->o.shadow_red == 0 && ps->o.shadow_green == 0 && ps->o.shadow_blue == 0) {
|
||||
ps->cshadow_picture = ps->black_picture;
|
||||
} else {
|
||||
ps->cshadow_picture = solid_picture(ps->c, ps->root, true, 1, ps->o.shadow_red,
|
||||
|
Reference in New Issue
Block a user