meson: add -Wfloat-conversion

This commit is contained in:
Kirill Primak 2022-09-19 00:16:24 +03:00
parent 2ad25b1460
commit cf857ecf7b
31 changed files with 220 additions and 204 deletions

View file

@ -81,8 +81,8 @@ static void output_scissor(struct wlr_output *output, pixman_box32_t *rect) {
*/
static void output_cursor_get_box(struct wlr_output_cursor *cursor,
struct wlr_box *box) {
box->x = cursor->x - cursor->hotspot_x;
box->y = cursor->y - cursor->hotspot_y;
box->x = (int)(cursor->x - cursor->hotspot_x);
box->y = (int)(cursor->y - cursor->hotspot_y);
box->width = cursor->width;
box->height = cursor->height;
}
@ -287,8 +287,8 @@ static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor)
}
struct wlr_box cursor_box = {
.width = texture->width * output->scale / scale,
.height = texture->height * output->scale / scale,
.width = (int)(texture->width * output->scale / scale),
.height = (int)(texture->height * output->scale / scale),
};
float output_matrix[9];
@ -300,11 +300,11 @@ static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor)
};
wlr_box_transform(&tr_size, &tr_size, output->transform, 0, 0);
wlr_matrix_translate(output_matrix, buffer->width / 2.0,
buffer->height / 2.0);
wlr_matrix_translate(output_matrix, buffer->width / 2.0f,
buffer->height / 2.0f);
wlr_matrix_transform(output_matrix, output->transform);
wlr_matrix_translate(output_matrix, - tr_size.width / 2.0,
- tr_size.height / 2.0);
wlr_matrix_translate(output_matrix, - tr_size.width / 2.0f,
- tr_size.height / 2.0f);
}
float matrix[9];
@ -446,12 +446,12 @@ static void output_cursor_commit(struct wlr_output_cursor *cursor,
// Some clients commit a cursor surface with a NULL buffer to hide it.
cursor->enabled = wlr_surface_has_buffer(surface);
cursor->width = surface->current.width * cursor->output->scale;
cursor->height = surface->current.height * cursor->output->scale;
cursor->width = (int)(surface->current.width * cursor->output->scale);
cursor->height = (int)(surface->current.height * cursor->output->scale);
output_cursor_update_visible(cursor);
if (update_hotspot) {
cursor->hotspot_x -= surface->current.dx * cursor->output->scale;
cursor->hotspot_y -= surface->current.dy * cursor->output->scale;
cursor->hotspot_x -= (int32_t)(surface->current.dx * cursor->output->scale);
cursor->hotspot_y -= (int32_t)(surface->current.dy * cursor->output->scale);
}
if (output_cursor_attempt_hardware(cursor)) {
@ -478,8 +478,8 @@ static void output_cursor_handle_destroy(struct wl_listener *listener,
void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor,
struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y) {
hotspot_x *= cursor->output->scale;
hotspot_y *= cursor->output->scale;
hotspot_x = (int32_t)(hotspot_x * cursor->output->scale);
hotspot_y = (int32_t)(hotspot_y * cursor->output->scale);
if (surface && surface == cursor->surface) {
// Only update the hotspot: surface hasn't changed

View file

@ -197,10 +197,10 @@ static void output_update_matrix(struct wlr_output *output) {
wlr_output_transformed_resolution(output, &tr_width, &tr_height);
wlr_matrix_translate(output->transform_matrix,
output->width / 2.0, output->height / 2.0);
output->width / 2.0f, output->height / 2.0f);
wlr_matrix_transform(output->transform_matrix, output->transform);
wlr_matrix_translate(output->transform_matrix,
- tr_width / 2.0, - tr_height / 2.0);
- tr_width / 2.0f, - tr_height / 2.0f);
}
}
@ -439,8 +439,8 @@ void wlr_output_transformed_resolution(struct wlr_output *output,
void wlr_output_effective_resolution(struct wlr_output *output,
int *width, int *height) {
wlr_output_transformed_resolution(output, width, height);
*width /= output->scale;
*height /= output->scale;
*width = (int)(*width / output->scale);
*height = (int)(*height / output->scale);
}
struct wlr_output_mode *wlr_output_preferred_mode(struct wlr_output *output) {

View file

@ -601,7 +601,8 @@ void wlr_scene_buffer_set_buffer_with_damage(struct wlr_scene_buffer *scene_buff
wlr_region_transform(&trans_damage, damage,
scene_buffer->transform, buffer->width, buffer->height);
pixman_region32_intersect_rect(&trans_damage, &trans_damage,
box.x, box.y, box.width, box.height);
(int)box.x, (int)box.y,
(unsigned int)box.width, (unsigned int)box.height);
struct wlr_scene *scene = scene_node_get_root(&scene_buffer->node);
struct wlr_scene_output *scene_output;
@ -610,18 +611,21 @@ void wlr_scene_buffer_set_buffer_with_damage(struct wlr_scene_buffer *scene_buff
pixman_region32_t output_damage;
pixman_region32_init(&output_damage);
wlr_region_scale_xy(&output_damage, &trans_damage,
output_scale * scale_x, output_scale * scale_y);
(float)(output_scale * scale_x),
(float)(output_scale * scale_y));
pixman_region32_t cull_region;
pixman_region32_init(&cull_region);
wlr_region_scale(&cull_region, &scene_buffer->node.visible, output_scale);
pixman_region32_translate(&cull_region, -lx * output_scale, -ly * output_scale);
pixman_region32_translate(&cull_region,
(int)(-lx * output_scale),
(int)(-ly * output_scale));
pixman_region32_intersect(&output_damage, &output_damage, &cull_region);
pixman_region32_fini(&cull_region);
pixman_region32_translate(&output_damage,
(lx - scene_output->x) * output_scale,
(ly - scene_output->y) * output_scale);
(int)((lx - scene_output->x) * output_scale),
(int)((ly - scene_output->y) * output_scale));
if (wlr_damage_ring_add(&scene_output->damage_ring, &output_damage)) {
wlr_output_schedule_frame(scene_output->output);
}
@ -740,14 +744,14 @@ static void scene_node_get_size(struct wlr_scene_node *node,
}
static int scale_length(int length, int offset, float scale) {
return round((offset + length) * scale) - round(offset * scale);
return (int)(round((offset + length) * scale) - round(offset * scale));
}
static void scale_box(struct wlr_box *box, float scale) {
box->width = scale_length(box->width, box->x, scale);
box->height = scale_length(box->height, box->y, scale);
box->x = round(box->x * scale);
box->y = round(box->y * scale);
box->x = (int)round(box->x * scale);
box->y = (int)round(box->y * scale);
}
void wlr_scene_node_set_enabled(struct wlr_scene_node *node, bool enabled) {
@ -900,8 +904,8 @@ void wlr_scene_node_for_each_buffer(struct wlr_scene_node *node,
}
struct node_at_data {
double lx, ly;
double rx, ry;
int lx, ly;
int rx, ry;
struct wlr_scene_node *node;
};
@ -909,8 +913,8 @@ static bool scene_node_at_iterator(struct wlr_scene_node *node,
int lx, int ly, void *data) {
struct node_at_data *at_data = data;
double rx = at_data->lx - lx;
double ry = at_data->ly - ly;
int rx = at_data->lx - lx;
int ry = at_data->ly - ly;
if (node->type == WLR_SCENE_NODE_BUFFER) {
struct wlr_scene_buffer *scene_buffer = wlr_scene_buffer_from_node(node);
@ -930,15 +934,15 @@ static bool scene_node_at_iterator(struct wlr_scene_node *node,
struct wlr_scene_node *wlr_scene_node_at(struct wlr_scene_node *node,
double lx, double ly, double *nx, double *ny) {
struct wlr_box box = {
.x = floor(lx),
.y = floor(ly),
.x = (int)floor(lx),
.y = (int)floor(ly),
.width = 1,
.height = 1
};
struct node_at_data data = {
.lx = lx,
.ly = ly
.lx = (int)lx,
.ly = (int)ly
};
if (scene_nodes_in_box(node, &box, scene_node_at_iterator, &data)) {
@ -1545,7 +1549,7 @@ bool wlr_scene_output_commit(struct wlr_scene_output *scene_output) {
struct timespec time_diff;
timespec_sub(&time_diff, &now, &damage->when);
int64_t time_diff_ms = timespec_to_msec(&time_diff);
float alpha = 1.0 - (double)time_diff_ms / HIGHLIGHT_DAMAGE_FADEOUT_TIME;
float alpha = 1.0f - (float)time_diff_ms / HIGHLIGHT_DAMAGE_FADEOUT_TIME;
int nrects;
pixman_box32_t *rects = pixman_region32_rectangles(&damage->region, &nrects);
@ -1557,7 +1561,7 @@ bool wlr_scene_output_commit(struct wlr_scene_output *scene_output) {
.height = rects[i].y2 - rects[i].y1,
};
float color[4] = { alpha * .5, 0.0, 0.0, alpha * .5 };
float color[4] = { alpha * 0.5f, 0.0f, 0.0f, alpha * 0.5f };
wlr_render_rect(renderer, &box, color, output->transform_matrix);
}
}

View file

@ -350,8 +350,8 @@ void wlr_seat_pointer_send_axis(struct wlr_seat *wlr_seat, uint32_t time,
if (send_source && version >= WL_POINTER_AXIS_SOURCE_SINCE_VERSION) {
wl_pointer_send_axis_source(resource, source);
}
if (value) {
if (value_discrete) {
if (value != 0.0) {
if (value_discrete != 0) {
if (version >= WL_POINTER_AXIS_VALUE120_SINCE_VERSION) {
// High resolution discrete scrolling
wl_pointer_send_axis_value120(resource, orientation,

View file

@ -505,7 +505,7 @@ void wlr_send_tablet_v2_tablet_pad_strip(struct wlr_tablet_v2_tablet_pad *pad,
if (position < 0) {
zwp_tablet_pad_strip_v2_send_stop(resource);
} else {
zwp_tablet_pad_strip_v2_send_position(resource, position * 65535);
zwp_tablet_pad_strip_v2_send_position(resource, (int)(position * 65535));
}
zwp_tablet_pad_strip_v2_send_frame(resource, time);
}
@ -526,7 +526,8 @@ void wlr_send_tablet_v2_tablet_pad_ring(struct wlr_tablet_v2_tablet_pad *pad,
if (position < 0) {
zwp_tablet_pad_ring_v2_send_stop(resource);
} else {
zwp_tablet_pad_ring_v2_send_angle(resource, position);
zwp_tablet_pad_ring_v2_send_angle(resource,
wl_fixed_from_double(position));
}
zwp_tablet_pad_ring_v2_send_frame(resource, time);
}

View file

@ -415,7 +415,7 @@ void wlr_send_tablet_v2_tablet_tool_pressure(
struct wlr_tablet_v2_tablet_tool *tool, double pressure) {
if (tool->current_client) {
zwp_tablet_tool_v2_send_pressure(tool->current_client->resource,
pressure * 65535);
(uint32_t)(pressure * 65535));
queue_tool_frame(tool->current_client);
}
@ -425,7 +425,7 @@ void wlr_send_tablet_v2_tablet_tool_distance(
struct wlr_tablet_v2_tablet_tool *tool, double distance) {
if (tool->current_client) {
zwp_tablet_tool_v2_send_distance(tool->current_client->resource,
distance * 65535);
(uint32_t)(distance * 65535));
queue_tool_frame(tool->current_client);
}
@ -462,7 +462,7 @@ void wlr_send_tablet_v2_tablet_tool_slider(
}
zwp_tablet_tool_v2_send_slider(tool->current_client->resource,
position * 65535);
(uint32_t)(position * 65535));
queue_tool_frame(tool->current_client);
}
@ -489,7 +489,7 @@ void wlr_send_tablet_v2_tablet_tool_wheel(
struct wlr_tablet_v2_tablet_tool *tool, double degrees, int32_t clicks) {
if (tool->current_client) {
zwp_tablet_tool_v2_send_wheel(tool->current_client->resource,
clicks, degrees);
wl_fixed_from_double(degrees), clicks);
queue_tool_frame(tool->current_client);
}

View file

@ -164,8 +164,8 @@ static void surface_state_viewport_src_size(struct wlr_surface_state *state,
}
if (state->viewport.has_src) {
*out_width = state->viewport.src.width;
*out_height = state->viewport.src.height;
*out_width = (int)state->viewport.src.width;
*out_height = (int)state->viewport.src.height;
} else {
surface_state_transformed_buffer_size(state,
out_width, out_height);
@ -248,13 +248,13 @@ static void surface_update_damage(pixman_region32_t *buffer_damage,
float scale_x = (float)pending->viewport.dst_width / src_width;
float scale_y = (float)pending->viewport.dst_height / src_height;
wlr_region_scale_xy(&surface_damage, &surface_damage,
1.0 / scale_x, 1.0 / scale_y);
1.0f / scale_x, 1.0f / scale_y);
}
if (pending->viewport.has_src) {
// This is lossy: do a best-effort conversion
pixman_region32_translate(&surface_damage,
floor(pending->viewport.src.x),
floor(pending->viewport.src.y));
(int)floor(pending->viewport.src.x),
(int)floor(pending->viewport.src.y));
}
wlr_region_scale(&surface_damage, &surface_damage, pending->scale);
@ -795,7 +795,8 @@ bool wlr_surface_point_accepts_input(struct wlr_surface *surface,
double sx, double sy) {
return sx >= 0 && sx < surface->current.width &&
sy >= 0 && sy < surface->current.height &&
pixman_region32_contains_point(&surface->current.input, floor(sx), floor(sy), NULL);
pixman_region32_contains_point(&surface->current.input,
(int)floor(sx), (int)floor(sy), NULL);
}
struct wlr_surface *wlr_surface_surface_at(struct wlr_surface *surface,
@ -1018,14 +1019,14 @@ void wlr_surface_get_effective_damage(struct wlr_surface *surface,
wlr_region_transform(damage, &surface->buffer_damage,
surface->current.transform, surface->current.buffer_width,
surface->current.buffer_height);
wlr_region_scale(damage, damage, 1.0 / (float)surface->current.scale);
wlr_region_scale(damage, damage, 1.0f / (float)surface->current.scale);
if (surface->current.viewport.has_src) {
struct wlr_box src_box = {
.x = floor(surface->current.viewport.src.x),
.y = floor(surface->current.viewport.src.y),
.width = ceil(surface->current.viewport.src.width),
.height = ceil(surface->current.viewport.src.height),
.x = (int)floor(surface->current.viewport.src.x),
.y = (int)floor(surface->current.viewport.src.y),
.width = (int)ceil(surface->current.viewport.src.width),
.height = (int)ceil(surface->current.viewport.src.height),
};
crop_region(damage, damage, &src_box);
}

View file

@ -280,7 +280,7 @@ bool wlr_cursor_warp(struct wlr_cursor *cur, struct wlr_input_device *dev,
result = wlr_box_contains_point(&mapping, lx, ly);
} else {
result = wlr_output_layout_contains_point(cur->state->layout, NULL,
lx, ly);
(int)lx, (int)ly);
}
if (result) {
@ -818,8 +818,8 @@ static void handle_layout_change(struct wl_listener *listener, void *data) {
wl_container_of(listener, state, layout_change);
struct wlr_output_layout *layout = data;
if (!wlr_output_layout_contains_point(layout, NULL, state->cursor->x,
state->cursor->y)) {
if (!wlr_output_layout_contains_point(layout, NULL,
(int)state->cursor->x, (int)state->cursor->y)) {
// the output we were on has gone away so go to the closest boundary
// point
double x, y;

View file

@ -558,7 +558,7 @@ void wlr_layer_surface_v1_for_each_popup_surface(struct wlr_layer_surface_v1 *su
continue;
}
double popup_sx, popup_sy;
int popup_sx, popup_sy;
popup_sx = popup->current.geometry.x - popup->base->current.geometry.x;
popup_sy = popup->current.geometry.y - popup->base->current.geometry.y;

View file

@ -63,9 +63,9 @@ void wlr_matrix_scale(float mat[static 9], float x, float y) {
void wlr_matrix_rotate(float mat[static 9], float rad) {
float rotate[9] = {
cos(rad), -sin(rad), 0.0f,
sin(rad), cos(rad), 0.0f,
0.0f, 0.0f, 1.0f,
cosf(rad), -sinf(rad), 0.0f,
sinf(rad), cosf(rad), 0.0f,
0.0f, 0.0f, 1.0f,
};
wlr_matrix_multiply(mat, mat, rotate);
}
@ -133,8 +133,8 @@ void matrix_projection(float mat[static 9], int width, int height,
mat[4] = y * -t[4];
// Translation
mat[2] = -copysign(1.0f, mat[0] + mat[1]);
mat[5] = -copysign(1.0f, mat[3] + mat[4]);
mat[2] = -copysignf(1.0f, mat[0] + mat[1]);
mat[5] = -copysignf(1.0f, mat[3] + mat[4]);
// Identity
mat[8] = 1.0f;

View file

@ -247,7 +247,7 @@ static void config_head_handle_set_scale(struct wl_client *client,
return;
}
float scale = wl_fixed_to_double(scale_fixed);
float scale = (float)wl_fixed_to_double(scale_fixed);
if (scale <= 0) {
wl_resource_post_error(config_head_resource,
ZWLR_OUTPUT_CONFIGURATION_HEAD_V1_ERROR_INVALID_SCALE,

View file

@ -570,10 +570,10 @@ static void capture_output(struct wl_client *wl_client,
buffer_box = *box;
wlr_box_transform(&buffer_box, &buffer_box, output->transform, ow, oh);
buffer_box.x *= output->scale;
buffer_box.y *= output->scale;
buffer_box.width *= output->scale;
buffer_box.height *= output->scale;
buffer_box.x = (int)(buffer_box.x * output->scale);
buffer_box.y = (int)(buffer_box.y * output->scale);
buffer_box.width = (int)(buffer_box.width * output->scale);
buffer_box.height = (int)(buffer_box.height * output->scale);
}
frame->box = buffer_box;

View file

@ -46,7 +46,8 @@ bool wlr_xcursor_manager_load(struct wlr_xcursor_manager *manager,
return false;
}
theme->scale = scale;
theme->theme = wlr_xcursor_theme_load(manager->name, manager->size * scale);
theme->theme = wlr_xcursor_theme_load(manager->name,
(int)(manager->size * scale));
if (theme->theme == NULL) {
free(theme);
return false;

View file

@ -528,16 +528,19 @@ static void xdg_surface_for_each_popup_surface(struct wlr_xdg_surface *surface,
double popup_sx, popup_sy;
wlr_xdg_popup_get_position(popup, &popup_sx, &popup_sy);
int sx = x + (int)popup_sx, sy = y + (int)popup_sy;
struct xdg_surface_iterator_data data = {
.user_iterator = iterator,
.user_data = user_data,
.x = x + popup_sx, .y = y + popup_sy,
.x = sx,
.y = sy,
};
wlr_surface_for_each_surface(popup->base->surface,
xdg_surface_iterator, &data);
xdg_surface_for_each_popup_surface(popup->base,
x + popup_sx, y + popup_sy, iterator, user_data);
sx, sy, iterator, user_data);
}
}