diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 95ffc6702..75c313ef2 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; @@ -193,7 +195,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 ad37a048a..2adf0acf5 100644 --- a/types/output/cursor.c +++ b/types/output/cursor.c @@ -286,27 +286,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; } @@ -518,6 +519,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 57b4c87e2..e1ac95ef1 100644 --- a/types/output/output.c +++ b/types/output/output.c @@ -315,8 +315,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) { @@ -469,7 +467,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 a185d8446..c2789bc72 100644 --- a/types/output/render.c +++ b/types/output/render.c @@ -34,9 +34,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 be5e06d43..159212073 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -575,6 +575,11 @@ static void output_cursor_output_handle_output_commit( (event->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) {