drm/vkms: add reflect-y and rotate-180 property
authorMaíra Canal <mcanal@igalia.com>
Tue, 18 Apr 2023 13:05:23 +0000 (10:05 -0300)
committerMaíra Canal <mairacanal@riseup.net>
Mon, 8 May 2023 12:46:13 +0000 (09:46 -0300)
Currently, vkms only supports the reflect-x property. Therefore, add the
reflect-y property to vkms through a software implementation of the
operation. This is possible by reverse reading the y axis during the
blending.

Note that, by implementing the reflect-x and reflect-y properties, it is
also possible to add the rotate-180 property, as it is a combination
of those two properties.

Tested with igt@kms_rotation_crc@primary-reflect-y [1],
igt@kms_rotation_crc@sprite-reflect-y [1],
igt@kms_rotation_crc@primary-rotation-180,
igt@kms_rotation_crc@sprite-rotation-180,
and igt@kms_rotation_crc@cursor-rotation-180.

[1] https://patchwork.freedesktop.org/series/116025/

Signed-off-by: Maíra Canal <mcanal@igalia.com>
Reviewed-by: Melissa Wen <mwen@igalia.com>
Signed-off-by: Maíra Canal <mairacanal@riseup.net>
Link: https://patchwork.freedesktop.org/patch/msgid/20230418130525.128733-4-mcanal@igalia.com
drivers/gpu/drm/vkms/vkms_composer.c
drivers/gpu/drm/vkms/vkms_plane.c

index a443698..6c5ef11 100644 (file)
@@ -53,6 +53,13 @@ static void pre_mul_alpha_blend(struct vkms_frame_info *frame_info,
        }
 }
 
+static int get_y_pos(struct vkms_frame_info *frame_info, int y)
+{
+       if (frame_info->rotation & DRM_MODE_REFLECT_Y)
+               return drm_rect_height(&frame_info->rotated) - y - 1;
+       return y;
+}
+
 static bool check_y_limit(struct vkms_frame_info *frame_info, int y)
 {
        if (y >= frame_info->rotated.y1 && y < frame_info->rotated.y2)
@@ -86,6 +93,7 @@ static void blend(struct vkms_writeback_job *wb,
 {
        struct vkms_plane_state **plane = crtc_state->active_planes;
        u32 n_active_planes = crtc_state->num_active_planes;
+       int y_pos;
 
        const struct pixel_argb_u16 background_color = { .a = 0xffff };
 
@@ -96,10 +104,12 @@ static void blend(struct vkms_writeback_job *wb,
 
                /* The active planes are composed associatively in z-order. */
                for (size_t i = 0; i < n_active_planes; i++) {
-                       if (!check_y_limit(plane[i]->frame_info, y))
+                       y_pos = get_y_pos(plane[i]->frame_info, y);
+
+                       if (!check_y_limit(plane[i]->frame_info, y_pos))
                                continue;
 
-                       vkms_compose_row(stage_buffer, plane[i], y);
+                       vkms_compose_row(stage_buffer, plane[i], y_pos);
                        pre_mul_alpha_blend(plane[i]->frame_info, stage_buffer,
                                            output_buffer);
                }
@@ -107,7 +117,7 @@ static void blend(struct vkms_writeback_job *wb,
                *crc32 = crc32_le(*crc32, (void *)output_buffer->pixels, row_size);
 
                if (wb)
-                       wb->wb_write(&wb->wb_frame_info, output_buffer, y);
+                       wb->wb_write(&wb->wb_frame_info, output_buffer, y_pos);
        }
 }
 
index d5392e3..074b9c0 100644 (file)
@@ -117,7 +117,8 @@ static void vkms_plane_atomic_update(struct drm_plane *plane,
        memcpy(&frame_info->map, &shadow_plane_state->data, sizeof(frame_info->map));
        drm_framebuffer_get(frame_info->fb);
        frame_info->rotation = drm_rotation_simplify(new_state->rotation, DRM_MODE_ROTATE_0 |
-                                                    DRM_MODE_REFLECT_X);
+                                                    DRM_MODE_REFLECT_X |
+                                                    DRM_MODE_REFLECT_Y);
 
        drm_rect_rotate(&frame_info->rotated, drm_rect_width(&frame_info->rotated),
                        drm_rect_height(&frame_info->rotated), frame_info->rotation);
@@ -211,7 +212,9 @@ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,
 
        drm_plane_create_rotation_property(&plane->base, DRM_MODE_ROTATE_0,
                                           DRM_MODE_ROTATE_0 |
-                                          DRM_MODE_REFLECT_X);
+                                          DRM_MODE_ROTATE_180 |
+                                          DRM_MODE_REFLECT_X |
+                                          DRM_MODE_REFLECT_Y);
 
        return plane;
 }