cursor, output: apply viewport to cursor

Instead of passing the scale, pass the source and destination
boxes.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3676
This commit is contained in:
Simon Ser 2023-06-27 10:48:24 +02:00 committed by Kirill Primak
parent 657ca2205f
commit 000081db19
4 changed files with 46 additions and 22 deletions

View File

@ -15,7 +15,8 @@ bool output_ensure_buffer(struct wlr_output *output,
struct wlr_output_state *state, bool *new_back_buffer); struct wlr_output_state *state, bool *new_back_buffer);
bool output_cursor_set_texture(struct wlr_output_cursor *cursor, bool output_cursor_set_texture(struct wlr_output_cursor *cursor,
struct wlr_texture *texture, bool own_texture, float scale, struct wlr_texture *texture, bool own_texture, const struct wlr_fbox *src_box,
enum wl_output_transform transform, int32_t hotspot_x, int32_t hotspot_y); int dst_width, int dst_height, enum wl_output_transform transform,
int32_t hotspot_x, int32_t hotspot_y);
#endif #endif

View File

@ -40,7 +40,7 @@ struct wlr_output_cursor {
bool enabled; bool enabled;
bool visible; bool visible;
uint32_t width, height; uint32_t width, height;
float scale; struct wlr_fbox src_box;
enum wl_output_transform transform; enum wl_output_transform transform;
int32_t hotspot_x, hotspot_y; int32_t hotspot_x, hotspot_y;
struct wlr_texture *texture; struct wlr_texture *texture;

View File

@ -195,6 +195,7 @@ void wlr_output_add_software_cursors_to_render_pass(struct wlr_output *output,
wlr_render_pass_add_texture(render_pass, &(struct wlr_render_texture_options) { wlr_render_pass_add_texture(render_pass, &(struct wlr_render_texture_options) {
.texture = texture, .texture = texture,
.src_box = cursor->src_box,
.dst_box = box, .dst_box = box,
.clip = &cursor_damage, .clip = &cursor_damage,
.transform = output->transform, .transform = output->transform,
@ -272,8 +273,8 @@ static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor)
struct wlr_renderer *renderer = output->renderer; struct wlr_renderer *renderer = output->renderer;
assert(allocator != NULL && renderer != NULL); assert(allocator != NULL && renderer != NULL);
int width = texture->width * output->scale / cursor->scale; int width = cursor->width;
int height = texture->height * output->scale / cursor->scale; int height = cursor->height;
if (output->impl->get_cursor_size) { if (output->impl->get_cursor_size) {
// Apply hardware limitations on buffer size // Apply hardware limitations on buffer size
output->impl->get_cursor_size(cursor->output, &width, &height); output->impl->get_cursor_size(cursor->output, &width, &height);
@ -311,10 +312,9 @@ static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor)
} }
struct wlr_box dst_box = { struct wlr_box dst_box = {
.width = texture->width * output->scale / cursor->scale, .width = cursor->width,
.height = texture->height * output->scale / cursor->scale, .height = cursor->height,
}; };
wlr_box_transform(&dst_box, &dst_box, wlr_output_transform_invert(output->transform), wlr_box_transform(&dst_box, &dst_box, wlr_output_transform_invert(output->transform),
buffer->width, buffer->height); buffer->width, buffer->height);
@ -333,6 +333,7 @@ static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor)
}); });
wlr_render_pass_add_texture(pass, &(struct wlr_render_texture_options){ wlr_render_pass_add_texture(pass, &(struct wlr_render_texture_options){
.texture = texture, .texture = texture,
.src_box = cursor->src_box,
.dst_box = dst_box, .dst_box = dst_box,
.transform = transform, .transform = transform,
}); });
@ -398,37 +399,43 @@ bool wlr_output_cursor_set_buffer(struct wlr_output_cursor *cursor,
} }
struct wlr_texture *texture = NULL; struct wlr_texture *texture = NULL;
struct wlr_fbox src_box = {0};
int dst_width = 0, dst_height = 0;
if (buffer != NULL) { if (buffer != NULL) {
texture = wlr_texture_from_buffer(renderer, buffer); texture = wlr_texture_from_buffer(renderer, buffer);
if (texture == NULL) { if (texture == NULL) {
return false; return false;
} }
src_box = (struct wlr_fbox){
.width = texture->width,
.height = texture->height,
};
dst_width = texture->width / cursor->output->scale;
dst_height = texture->height / cursor->output->scale;
} }
hotspot_x /= cursor->output->scale; hotspot_x /= cursor->output->scale;
hotspot_y /= cursor->output->scale; hotspot_y /= cursor->output->scale;
return output_cursor_set_texture(cursor, texture, true, cursor->output->scale, return output_cursor_set_texture(cursor, texture, true, &src_box,
WL_OUTPUT_TRANSFORM_NORMAL, hotspot_x, hotspot_y); dst_width, dst_height, WL_OUTPUT_TRANSFORM_NORMAL, hotspot_x, hotspot_y);
} }
bool output_cursor_set_texture(struct wlr_output_cursor *cursor, bool output_cursor_set_texture(struct wlr_output_cursor *cursor,
struct wlr_texture *texture, bool own_texture, float scale, struct wlr_texture *texture, bool own_texture, const struct wlr_fbox *src_box,
enum wl_output_transform transform, int32_t hotspot_x, int32_t hotspot_y) { int dst_width, int dst_height, enum wl_output_transform transform,
int32_t hotspot_x, int32_t hotspot_y) {
struct wlr_output *output = cursor->output; struct wlr_output *output = cursor->output;
output_cursor_reset(cursor); output_cursor_reset(cursor);
cursor->enabled = texture != NULL; cursor->enabled = texture != NULL;
if (texture != NULL) { if (texture != NULL) {
struct wlr_box box = { cursor->width = (int)roundf(dst_width * output->scale);
.width = texture->width / scale, cursor->height = (int)roundf(dst_height * output->scale);
.height = texture->height / scale, cursor->src_box = *src_box;
};
wlr_box_transform(&box, &box, wlr_output_transform_invert(transform), 0, 0);
cursor->width = (int)roundf(box.width * output->scale);
cursor->height = (int)roundf(box.height * output->scale);
cursor->scale = scale;
cursor->transform = transform; cursor->transform = transform;
} else { } else {
cursor->width = 0; cursor->width = 0;

View File

@ -519,15 +519,26 @@ static void cursor_output_cursor_update(struct wlr_cursor_output_cursor *output_
float scale = cur->state->buffer_scale; float scale = cur->state->buffer_scale;
struct wlr_texture *texture = NULL; struct wlr_texture *texture = NULL;
struct wlr_fbox src_box = {0};
int dst_width = 0, dst_height = 0;
if (buffer != NULL) { if (buffer != NULL) {
texture = wlr_texture_from_buffer(renderer, buffer); texture = wlr_texture_from_buffer(renderer, buffer);
if (texture == NULL) { if (texture == NULL) {
return; return;
} }
src_box = (struct wlr_fbox){
.width = texture->width,
.height = texture->height,
};
dst_width = texture->width / scale;
dst_height = texture->height / scale;
} }
output_cursor_set_texture(output_cursor->output_cursor, texture, true, output_cursor_set_texture(output_cursor->output_cursor, texture, true,
scale, WL_OUTPUT_TRANSFORM_NORMAL, hotspot_x, hotspot_y); &src_box, dst_width, dst_height, WL_OUTPUT_TRANSFORM_NORMAL,
hotspot_x, hotspot_y);
} else if (cur->state->surface != NULL) { } else if (cur->state->surface != NULL) {
struct wlr_surface *surface = cur->state->surface; struct wlr_surface *surface = cur->state->surface;
@ -539,8 +550,13 @@ static void cursor_output_cursor_update(struct wlr_cursor_output_cursor *output_
int32_t hotspot_x = cur->state->surface_hotspot.x; int32_t hotspot_x = cur->state->surface_hotspot.x;
int32_t hotspot_y = cur->state->surface_hotspot.y; int32_t hotspot_y = cur->state->surface_hotspot.y;
struct wlr_fbox src_box;
wlr_surface_get_buffer_source_box(surface, &src_box);
int dst_width = surface->current.width;
int dst_height = surface->current.height;
output_cursor_set_texture(output_cursor->output_cursor, texture, false, output_cursor_set_texture(output_cursor->output_cursor, texture, false,
surface->current.scale, surface->current.transform, &src_box, dst_width, dst_height, surface->current.transform,
hotspot_x, hotspot_y); hotspot_x, hotspot_y);
struct wlr_output *output = output_cursor->output_cursor->output; struct wlr_output *output = output_cursor->output_cursor->output;