render/pass: accept fractional destination coordinates

Signed-off-by: Loukas Agorgianitis <loukas@agorgianitis.com>
This commit is contained in:
Loukas Agorgianitis 2025-12-08 11:47:15 +02:00
parent 91c08d5a53
commit 5a49f2ae14
No known key found for this signature in database
GPG key ID: DDC6FA7D5BB332E6
13 changed files with 79 additions and 47 deletions

View file

@ -75,9 +75,9 @@ out:
return ok;
}
static void render(const struct wlr_box *box, const pixman_region32_t *clip, GLint attrib) {
static void render(const struct wlr_fbox *box, const pixman_region32_t *clip, GLint attrib) {
pixman_region32_t region;
pixman_region32_init_rect(&region, box->x, box->y, box->width, box->height);
pixman_region32_init_rect(&region, round(box->x), round(box->y), round(box->width), round(box->height));
if (clip) {
pixman_region32_intersect(&region, &region, clip);
@ -124,7 +124,7 @@ static void render(const struct wlr_box *box, const pixman_region32_t *clip, GLi
pixman_region32_fini(&region);
}
static void set_proj_matrix(GLint loc, float proj[9], const struct wlr_box *box) {
static void set_proj_matrix(GLint loc, float proj[9], const struct wlr_fbox *box) {
float gl_matrix[9];
wlr_matrix_identity(gl_matrix);
wlr_matrix_translate(gl_matrix, box->x, box->y);
@ -190,16 +190,16 @@ static void render_pass_add_texture(struct wlr_render_pass *wlr_pass,
abort();
}
struct wlr_box dst_box;
struct wlr_fbox src_fbox;
wlr_render_texture_options_get_src_box(options, &src_fbox);
struct wlr_fbox dst_box;
struct wlr_fbox src_box;
wlr_render_texture_options_get_src_box(options, &src_box);
wlr_render_texture_options_get_dst_box(options, &dst_box);
float alpha = wlr_render_texture_options_get_alpha(options);
src_fbox.x /= options->texture->width;
src_fbox.y /= options->texture->height;
src_fbox.width /= options->texture->width;
src_fbox.height /= options->texture->height;
src_box.x /= options->texture->width;
src_box.y /= options->texture->height;
src_box.width /= options->texture->width;
src_box.height /= options->texture->height;
push_gles2_debug(renderer);
@ -245,7 +245,7 @@ static void render_pass_add_texture(struct wlr_render_pass *wlr_pass,
glUniform1i(shader->tex, 0);
glUniform1f(shader->alpha, alpha);
set_proj_matrix(shader->proj, pass->projection_matrix, &dst_box);
set_tex_matrix(shader->tex_proj, options->transform, &src_fbox);
set_tex_matrix(shader->tex_proj, options->transform, &src_box);
render(&dst_box, options->clip, shader->pos_attrib);
@ -259,7 +259,7 @@ static void render_pass_add_rect(struct wlr_render_pass *wlr_pass,
struct wlr_gles2_renderer *renderer = pass->buffer->renderer;
const struct wlr_render_color *color = &options->color;
struct wlr_box box;
struct wlr_fbox box;
wlr_render_rect_options_get_box(options, pass->buffer->buffer, &box);
push_gles2_debug(renderer);

View file

@ -46,9 +46,9 @@ void wlr_render_texture_options_get_src_box(const struct wlr_render_texture_opti
}
void wlr_render_texture_options_get_dst_box(const struct wlr_render_texture_options *options,
struct wlr_box *box) {
struct wlr_fbox *box) {
*box = options->dst_box;
if (wlr_box_empty(box)) {
if (wlr_fbox_empty(box)) {
box->width = options->texture->width;
box->height = options->texture->height;
}
@ -62,9 +62,9 @@ float wlr_render_texture_options_get_alpha(const struct wlr_render_texture_optio
}
void wlr_render_rect_options_get_box(const struct wlr_render_rect_options *options,
const struct wlr_buffer *buffer, struct wlr_box *box) {
if (wlr_box_empty(&options->box)) {
*box = (struct wlr_box){
const struct wlr_buffer *buffer, struct wlr_fbox *box) {
if (wlr_fbox_empty(&options->box)) {
*box = (struct wlr_fbox){
.width = buffer->width,
.height = buffer->height,
};

View file

@ -59,7 +59,7 @@ static void render_pass_add_texture(struct wlr_render_pass *wlr_pass,
.height = roundf(src_fbox.height),
};
struct wlr_box dst_box;
struct wlr_fbox dst_box;
wlr_render_texture_options_get_dst_box(options, &dst_box);
pixman_image_t *mask = NULL;
@ -125,8 +125,8 @@ static void render_pass_add_texture(struct wlr_render_pass *wlr_pass,
// it depends on the whether the rotation swapped width and height, which is why
// we use src_box_transformed instead of src_box.
pixman_transform_scale(&transform, NULL,
pixman_double_to_fixed(src_box_transformed.width / (double)dst_box.width),
pixman_double_to_fixed(src_box_transformed.height / (double)dst_box.height));
pixman_double_to_fixed(src_box_transformed.width / dst_box.width),
pixman_double_to_fixed(src_box_transformed.height / dst_box.height));
// pixman rotates about the origin which again leaves everything outside of the
// viewport. Translate the result so that its new top-left corner is back at the
@ -174,8 +174,8 @@ static void render_pass_add_texture(struct wlr_render_pass *wlr_pass,
pixman_image_composite32(op, texture->image, mask, buffer->image,
0, 0, // source x,y
0, 0, // mask x,y
dst_box.x, dst_box.y, // dest x,y
dst_box.width, dst_box.height // composite width,height
round(dst_box.x), round(dst_box.y), // dest x,y
round(dst_box.width), round(dst_box.height) // composite width,height
);
pixman_image_set_transform(texture->image, NULL);
@ -183,7 +183,7 @@ static void render_pass_add_texture(struct wlr_render_pass *wlr_pass,
// No transforms or crop needed, just a straight blit from the source
pixman_image_set_transform(texture->image, NULL);
pixman_image_composite32(op, texture->image, mask, buffer->image,
src_box.x, src_box.y, 0, 0, dst_box.x, dst_box.y,
src_box.x, src_box.y, 0, 0, round(dst_box.x), round(dst_box.y),
src_box.width, src_box.height);
}
@ -202,7 +202,7 @@ static void render_pass_add_rect(struct wlr_render_pass *wlr_pass,
const struct wlr_render_rect_options *options) {
struct wlr_pixman_render_pass *pass = get_render_pass(wlr_pass);
struct wlr_pixman_buffer *buffer = pass->buffer;
struct wlr_box box;
struct wlr_fbox box;
wlr_render_rect_options_get_box(options, pass->buffer->buffer, &box);
pixman_op_t op = get_pixman_blending(options->color.a == 1 ?

View file

@ -686,14 +686,20 @@ static void render_pass_add_rect(struct wlr_render_pass *wlr_pass,
.width = clip_rects[i].x2 - clip_rects[i].x1,
.height = clip_rects[i].y2 - clip_rects[i].y1,
};
struct wlr_box rect_box = {
.x = round(options->box.x),
.y = round(options->box.y),
.width = round(options->box.width),
.height = round(options->box.height),
};
struct wlr_box intersection;
if (!wlr_box_intersection(&intersection, &options->box, &clip_box)) {
if (!wlr_box_intersection(&intersection, &rect_box, &clip_box)) {
continue;
}
render_pass_mark_box_updated(pass, &intersection);
}
struct wlr_box box;
struct wlr_fbox box;
wlr_render_rect_options_get_box(options, pass->render_buffer->wlr_buffer, &box);
switch (options->blend_mode) {
@ -782,7 +788,7 @@ static void render_pass_add_texture(struct wlr_render_pass *wlr_pass,
struct wlr_fbox src_box;
wlr_render_texture_options_get_src_box(options, &src_box);
struct wlr_box dst_box;
struct wlr_fbox dst_box;
wlr_render_texture_options_get_dst_box(options, &dst_box);
float alpha = wlr_render_texture_options_get_alpha(options);
@ -926,8 +932,14 @@ static void render_pass_add_texture(struct wlr_render_pass *wlr_pass,
.width = clip_rects[i].x2 - clip_rects[i].x1,
.height = clip_rects[i].y2 - clip_rects[i].y1,
};
struct wlr_box texture_box = {
.x = round(dst_box.x),
.y = round(dst_box.y),
.width = round(dst_box.width),
.height = round(dst_box.height),
};
struct wlr_box intersection;
if (!wlr_box_intersection(&intersection, &dst_box, &clip_box)) {
if (!wlr_box_intersection(&intersection, &texture_box, &clip_box)) {
continue;
}
render_pass_mark_box_updated(pass, &intersection);