diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index ead470396..4ef878e6e 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -36,6 +37,7 @@ struct wlr_output_mode { struct wlr_output_cursor { struct wlr_output *output; + struct wlr_swapchain *swapchain; double x, y; bool enabled; bool visible; @@ -196,7 +198,6 @@ struct wlr_output { struct wl_list cursors; // wlr_output_cursor.link struct wlr_output_cursor *hardware_cursor; - struct wlr_swapchain *cursor_swapchain; struct wlr_buffer *cursor_front_buffer; int software_cursor_locks; // number of locks forcing software cursors diff --git a/types/output/cursor.c b/types/output/cursor.c index 2bf785283..15c687684 100644 --- a/types/output/cursor.c +++ b/types/output/cursor.c @@ -221,27 +221,28 @@ static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor) } } - if (output->cursor_swapchain == NULL || - output->cursor_swapchain->width != width || - output->cursor_swapchain->height != height) { + if (cursor->swapchain == NULL || + cursor->swapchain->allocator != allocator || + cursor->swapchain->width != width || + cursor->swapchain->height != height) { struct wlr_drm_format format = {0}; if (!output_pick_cursor_format(output, &format)) { wlr_log(WLR_DEBUG, "Failed to pick cursor format"); return NULL; } - wlr_swapchain_destroy(output->cursor_swapchain); - output->cursor_swapchain = wlr_swapchain_create(allocator, + wlr_swapchain_destroy(cursor->swapchain); + cursor->swapchain = wlr_swapchain_create(allocator, width, height, &format); wlr_drm_format_finish(&format); - if (output->cursor_swapchain == NULL) { + if (cursor->swapchain == NULL) { wlr_log(WLR_ERROR, "Failed to create cursor swapchain"); return NULL; } } struct wlr_buffer *buffer = - wlr_swapchain_acquire(output->cursor_swapchain, NULL); + wlr_swapchain_acquire(cursor->swapchain, NULL); if (buffer == NULL) { return NULL; } @@ -471,6 +472,7 @@ void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor) { if (cursor->own_texture) { wlr_texture_destroy(cursor->texture); } + wlr_swapchain_destroy(cursor->swapchain); wl_list_remove(&cursor->link); free(cursor); } diff --git a/types/output/output.c b/types/output/output.c index 818f4549e..6df74d7bc 100644 --- a/types/output/output.c +++ b/types/output/output.c @@ -252,8 +252,6 @@ static void output_apply_state(struct wlr_output *output, if ((state->committed & WLR_OUTPUT_STATE_ENABLED) && !state->enabled) { wlr_swapchain_destroy(output->swapchain); output->swapchain = NULL; - wlr_swapchain_destroy(output->cursor_swapchain); - output->cursor_swapchain = NULL; } if (state->committed & WLR_OUTPUT_STATE_LAYERS) { @@ -405,7 +403,6 @@ void wlr_output_destroy(struct wlr_output *output) { wlr_output_layer_destroy(layer); } - wlr_swapchain_destroy(output->cursor_swapchain); wlr_buffer_unlock(output->cursor_front_buffer); wlr_swapchain_destroy(output->swapchain); diff --git a/types/output/render.c b/types/output/render.c index 709646a10..f54b748be 100644 --- a/types/output/render.c +++ b/types/output/render.c @@ -33,9 +33,6 @@ bool wlr_output_init_render(struct wlr_output *output, wlr_swapchain_destroy(output->swapchain); output->swapchain = NULL; - wlr_swapchain_destroy(output->cursor_swapchain); - output->cursor_swapchain = NULL; - output->allocator = allocator; output->renderer = renderer; diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index 77ab2fb70..035b89cfd 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -602,6 +602,11 @@ static void output_cursor_output_handle_output_commit( (event->state->committed & WLR_OUTPUT_STATE_BUFFER)) { wlr_surface_send_frame_done(surface, event->when); } + + if (event->committed & WLR_OUTPUT_STATE_ENABLED) { + wlr_swapchain_destroy(output_cursor->output_cursor->swapchain); + output_cursor->output_cursor->swapchain = NULL; + } } static void cursor_update_outputs(struct wlr_cursor *cur) {