surface: move INVALID_SIZE check into surface_state_finalize

This fixes some build warnings.

Closes: https://github.com/swaywm/wlroots/issues/2740
References: https://github.com/swaywm/wlroots/pull/2736
This commit is contained in:
Simon Ser 2021-02-15 15:28:04 +01:00
parent 38ec1c0e73
commit 2530235139
1 changed files with 12 additions and 16 deletions

View File

@ -145,22 +145,17 @@ static void surface_set_input_region(struct wl_client *client,
* rectangle) but before applying the viewport scaling (via the viewport's * rectangle) but before applying the viewport scaling (via the viewport's
* destination rectangle). * destination rectangle).
*/ */
static bool surface_state_viewport_src_size(struct wlr_surface_state *state, static void surface_state_viewport_src_size(struct wlr_surface_state *state,
int *out_width, int *out_height) { int *out_width, int *out_height) {
if (state->buffer_width == 0 && state->buffer_height == 0) { if (state->buffer_width == 0 && state->buffer_height == 0) {
*out_width = *out_height = 0; *out_width = *out_height = 0;
return true; return;
} }
if (state->viewport.has_src) { if (state->viewport.has_src) {
*out_width = state->viewport.src.width; *out_width = state->viewport.src.width;
*out_height = state->viewport.src.height; *out_height = state->viewport.src.height;
} else { } else {
if (state->buffer_width % state->scale != 0 ||
state->buffer_height % state->scale != 0) {
return false;
}
int width = state->buffer_width / state->scale; int width = state->buffer_width / state->scale;
int height = state->buffer_height / state->scale; int height = state->buffer_height / state->scale;
if ((state->transform & WL_OUTPUT_TRANSFORM_90) != 0) { if ((state->transform & WL_OUTPUT_TRANSFORM_90) != 0) {
@ -171,8 +166,6 @@ static bool surface_state_viewport_src_size(struct wlr_surface_state *state,
*out_width = width; *out_width = width;
*out_height = height; *out_height = height;
} }
return true;
} }
static bool surface_state_finalize(struct wlr_surface *surface, static bool surface_state_finalize(struct wlr_surface *surface,
@ -186,6 +179,15 @@ static bool surface_state_finalize(struct wlr_surface *surface,
} }
} }
if (!state->viewport.has_src &&
(state->buffer_width % state->scale != 0 ||
state->buffer_height % state->scale != 0)) {
wl_resource_post_error(surface->resource,
WL_SURFACE_ERROR_INVALID_SIZE,
"Buffer size not divisible by scale");
return false;
}
if (state->viewport.has_dst) { if (state->viewport.has_dst) {
if (state->buffer_width == 0 && state->buffer_height == 0) { if (state->buffer_width == 0 && state->buffer_height == 0) {
state->width = state->height = 0; state->width = state->height = 0;
@ -194,13 +196,7 @@ static bool surface_state_finalize(struct wlr_surface *surface,
state->height = state->viewport.dst_height; state->height = state->viewport.dst_height;
} }
} else { } else {
if (!surface_state_viewport_src_size(state, surface_state_viewport_src_size(state, &state->width, &state->height);
&state->width, &state->height)) {
wl_resource_post_error(surface->resource,
WL_SURFACE_ERROR_INVALID_SIZE,
"Buffer size not divisible by scale");
return false;
}
} }
pixman_region32_intersect_rect(&state->surface_damage, pixman_region32_intersect_rect(&state->surface_damage,