From 09c7af0bd4511047f1fed801945336c5315ac010 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 6 Jun 2023 17:11:58 +0200 Subject: [PATCH] backend/wayland: extract layer viewport check to a helper Improves readability, and we'll need to use it from another function. --- backend/wayland/output.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 291e98122..1896e5088 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -247,6 +247,23 @@ static struct wlr_wl_buffer *get_or_create_wl_buffer(struct wlr_wl_backend *wl, return create_wl_buffer(wl, wlr_buffer); } +static bool layer_needs_viewport(struct wlr_output_layer_state *layer_state) { + if (layer_state->buffer == NULL) { + return false; + } + if (layer_state->dst_box.width != layer_state->buffer->width || + layer_state->dst_box.height != layer_state->buffer->height) { + return true; + } + if (layer_state->src_box.x != 0 || + layer_state->src_box.y != 0 || + layer_state->src_box.width != layer_state->dst_box.width || + layer_state->src_box.height != layer_state->dst_box.height) { + return true; + } + return false; +} + static bool test_layer(struct wlr_wl_output *output, struct wlr_output_layer_state *layer_state) { if (layer_state->buffer == NULL) { return true; @@ -265,16 +282,7 @@ static bool test_layer(struct wlr_wl_output *output, struct wlr_output_layer_sta } // We need viewporter for scaling and cropping - bool needs_viewport = width != layer_state->buffer->width || - height != layer_state->buffer->height; - if (!wlr_fbox_empty(&layer_state->src_box)) { - needs_viewport = needs_viewport || - layer_state->src_box.x != 0 || - layer_state->src_box.y != 0 || - layer_state->src_box.width != width || - layer_state->src_box.height != height; - } - if (output->backend->viewporter == NULL && needs_viewport) { + if (output->backend->viewporter == NULL && layer_needs_viewport(layer_state)) { return false; }