output: add output_cursor_set_texture()

This commit is contained in:
Simon Ser 2023-04-11 17:38:19 +02:00 committed by Alexander Orzechowski
parent b03f71fe5f
commit b64e7e88bf
3 changed files with 35 additions and 16 deletions

View file

@ -13,4 +13,8 @@ void output_clear_back_buffer(struct wlr_output *output);
bool output_ensure_buffer(struct wlr_output *output, bool output_ensure_buffer(struct wlr_output *output,
const struct wlr_output_state *state, bool *new_back_buffer); const struct wlr_output_state *state, bool *new_back_buffer);
bool output_cursor_set_texture(struct wlr_output_cursor *cursor,
struct wlr_texture *texture, bool own_texture, float scale,
enum wl_output_transform transform, int32_t hotspot_x, int32_t hotspot_y);
#endif #endif

View file

@ -44,6 +44,7 @@ struct wlr_output_cursor {
// only when using a software cursor without a surface // only when using a software cursor without a surface
struct wlr_texture *texture; struct wlr_texture *texture;
bool own_texture;
// only when using a cursor surface // only when using a cursor surface
struct wlr_surface *surface; struct wlr_surface *surface;

View file

@ -454,32 +454,44 @@ bool wlr_output_cursor_set_buffer(struct wlr_output_cursor *cursor,
return false; return false;
} }
struct wlr_texture *texture = NULL;
if (buffer != NULL) {
texture = wlr_texture_from_buffer(renderer, buffer);
if (texture == NULL) {
return false;
}
}
return output_cursor_set_texture(cursor, texture, true, 1,
WL_OUTPUT_TRANSFORM_NORMAL, hotspot_x, hotspot_y);
}
bool output_cursor_set_texture(struct wlr_output_cursor *cursor,
struct wlr_texture *texture, bool own_texture, float scale,
enum wl_output_transform transform, int32_t hotspot_x, int32_t hotspot_y) {
output_cursor_reset(cursor); output_cursor_reset(cursor);
if (buffer != NULL) { cursor->enabled = texture != NULL;
cursor->width = buffer->width; if (texture != NULL) {
cursor->height = buffer->height; struct wlr_box box = { .width = texture->width, .height = texture->height };
wlr_box_transform(&box, &box, wlr_output_transform_invert(transform), 0, 0);
cursor->width = (int)roundf(box.width * scale);
cursor->height = (int)roundf(box.height * scale);
} else { } else {
cursor->width = 0; cursor->width = 0;
cursor->height = 0; cursor->height = 0;
} }
cursor->hotspot_x = hotspot_x; cursor->hotspot_x = (int)roundf(hotspot_x * scale);
cursor->hotspot_y = hotspot_y; cursor->hotspot_y = (int)roundf(hotspot_y * scale);
output_cursor_update_visible(cursor); output_cursor_update_visible(cursor);
wlr_texture_destroy(cursor->texture); if (cursor->own_texture) {
cursor->texture = NULL; wlr_texture_destroy(cursor->texture);
cursor->enabled = false;
if (buffer != NULL) {
cursor->texture = wlr_texture_from_buffer(renderer, buffer);
if (cursor->texture == NULL) {
return false;
}
cursor->enabled = true;
} }
cursor->texture = texture;
cursor->own_texture = own_texture;
if (output_cursor_attempt_hardware(cursor)) { if (output_cursor_attempt_hardware(cursor)) {
return true; return true;
@ -646,7 +658,9 @@ void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor) {
output_set_hardware_cursor(cursor->output, NULL, 0, 0); output_set_hardware_cursor(cursor->output, NULL, 0, 0);
cursor->output->hardware_cursor = NULL; cursor->output->hardware_cursor = NULL;
} }
wlr_texture_destroy(cursor->texture); if (cursor->own_texture) {
wlr_texture_destroy(cursor->texture);
}
wl_list_remove(&cursor->link); wl_list_remove(&cursor->link);
free(cursor); free(cursor);
} }