[PATCH 2/6] drm/vkms: add rotate-90 property

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently, vkms only supports the rotate-180 property. Therefore,
improve the vkms IGT test coverage by adding the rotate-90 property to
vkms. The rotation was implement by software: rotate the way the
blending occurs by making the source x axis be the destination y axis and
the source y axis be the destination x axis.

Tested with igt@kms_rotation_crc@primary-rotation-90,
igt@kms_rotation_crc@sprite-rotation-90, and
igt@kms_rotation_crc@sprite-rotation-90-pos-100-0.

Signed-off-by: Maíra Canal <mcanal@xxxxxxxxxx>
---
 drivers/gpu/drm/vkms/vkms_composer.c | 29 ++++++++++----
 drivers/gpu/drm/vkms/vkms_formats.c  | 60 ++++++++++++++++------------
 drivers/gpu/drm/vkms/vkms_plane.c    |  2 +
 3 files changed, 58 insertions(+), 33 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c
index b7fba786dc4f..ef4e5181d512 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.c
+++ b/drivers/gpu/drm/vkms/vkms_composer.c
@@ -17,6 +17,9 @@ static struct pixel_argb_u16 *get_out_buffer(const struct vkms_frame_info *frame
 	struct pixel_argb_u16 *out = output_buffer->pixels;
 
 	switch (frame_info->rotation & DRM_MODE_ROTATE_MASK) {
+	case DRM_MODE_ROTATE_90:
+		out -= frame_info->dst.y1;
+		break;
 	case DRM_MODE_ROTATE_180:
 		out -= frame_info->dst.x1;
 		break;
@@ -58,10 +61,12 @@ static void pre_mul_alpha_blend(struct vkms_frame_info *frame_info,
 {
 	struct pixel_argb_u16 *out = get_out_buffer(frame_info, output_buffer);
 	struct pixel_argb_u16 *in = stage_buffer->pixels;
-	int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst),
-			    stage_buffer->n_pixels);
+	int limit = min_t(size_t, drm_rect_width(&frame_info->dst), stage_buffer->n_pixels);
+
+	if (frame_info->rotation & DRM_MODE_ROTATE_90)
+		limit = min_t(size_t, drm_rect_height(&frame_info->dst), stage_buffer->n_pixels);
 
-	for (int x = 0; x < x_limit; x++) {
+	for (int x = 0; x < limit; x++) {
 		out[x].a = (u16)0xffff;
 		out[x].r = pre_mul_blend_channel(in[x].r, out[x].r, in[x].a);
 		out[x].g = pre_mul_blend_channel(in[x].g, out[x].g, in[x].a);
@@ -72,6 +77,10 @@ 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)
 {
 	switch (frame_info->rotation & DRM_MODE_ROTATE_MASK) {
+	case DRM_MODE_ROTATE_90:
+		if (y - frame_info->dst.x1 < 0)
+			return -1;
+		return frame_info->dst.x2 - y - 1;
 	case DRM_MODE_ROTATE_180:
 		return drm_rect_height(&frame_info->dst) - y - 1;
 	default:
@@ -79,11 +88,15 @@ static int get_y_pos(struct vkms_frame_info *frame_info, int y)
 	}
 }
 
-static bool check_y_limit(struct vkms_frame_info *frame_info, int y)
+static bool check_limit(struct vkms_frame_info *frame_info, int pos)
 {
-	if (y >= frame_info->dst.y1 && y < frame_info->dst.y2)
-		return true;
-
+	if (frame_info->rotation & DRM_MODE_ROTATE_90) {
+		if (pos >= 0 && pos < drm_rect_width(&frame_info->dst))
+			return true;
+	} else {
+		if (pos >= frame_info->dst.y1 && pos < frame_info->dst.y2)
+			return true;
+	}
 	return false;
 }
 
@@ -125,7 +138,7 @@ static void blend(struct vkms_writeback_job *wb,
 		for (size_t i = 0; i < n_active_planes; i++) {
 			y_pos = get_y_pos(plane[i]->frame_info, y);
 
-			if (!check_y_limit(plane[i]->frame_info, y_pos))
+			if (!check_limit(plane[i]->frame_info, y_pos))
 				continue;
 
 			plane[i]->plane_read(stage_buffer, plane[i]->frame_info, y_pos);
diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c
index 2f070c505b3b..b874786be6b1 100644
--- a/drivers/gpu/drm/vkms/vkms_formats.c
+++ b/drivers/gpu/drm/vkms/vkms_formats.c
@@ -49,16 +49,30 @@ static int get_x_position(const struct vkms_frame_info *frame_info, int x_limit,
 	return x;
 }
 
+static int get_limit(const struct vkms_frame_info *frame_info, struct line_buffer *stage_buffer)
+{
+	if (frame_info->rotation & DRM_MODE_ROTATE_90)
+		return min_t(size_t, drm_rect_height(&frame_info->dst), stage_buffer->n_pixels);
+	return min_t(size_t, drm_rect_width(&frame_info->dst), stage_buffer->n_pixels);
+}
+
+static u8 *get_src_pixels(const struct vkms_frame_info *frame_info, int x, int y, int pixel_size)
+{
+	if (frame_info->rotation & DRM_MODE_ROTATE_90)
+		return get_packed_src_addr(frame_info, x + frame_info->dst.y1) + pixel_size * y;
+	return get_packed_src_addr(frame_info, y) + pixel_size * x;
+}
+
 static void ARGB8888_to_argb_u16(struct line_buffer *stage_buffer,
 				 const struct vkms_frame_info *frame_info, int y)
 {
 	struct pixel_argb_u16 *out_pixels = stage_buffer->pixels;
-	u8 *src_pixels = get_packed_src_addr(frame_info, y);
-	int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst),
-			    stage_buffer->n_pixels);
+	int limit = get_limit(frame_info, stage_buffer);
+
+	for (size_t x = 0; x < limit; x++) {
+		int x_pos = get_x_position(frame_info, limit, x);
+		u8 *src_pixels = get_src_pixels(frame_info, x, y, 4);
 
-	for (size_t x = 0; x < x_limit; x++, src_pixels += 4) {
-		int x_pos = get_x_position(frame_info, x_limit, x);
 		/*
 		 * The 257 is the "conversion ratio". This number is obtained by the
 		 * (2^16 - 1) / (2^8 - 1) division. Which, in this case, tries to get
@@ -76,12 +90,11 @@ static void XRGB8888_to_argb_u16(struct line_buffer *stage_buffer,
 				 const struct vkms_frame_info *frame_info, int y)
 {
 	struct pixel_argb_u16 *out_pixels = stage_buffer->pixels;
-	u8 *src_pixels = get_packed_src_addr(frame_info, y);
-	int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst),
-			    stage_buffer->n_pixels);
+	int limit = get_limit(frame_info, stage_buffer);
 
-	for (size_t x = 0; x < x_limit; x++, src_pixels += 4) {
-		int x_pos = get_x_position(frame_info, x_limit, x);
+	for (size_t x = 0; x < limit; x++) {
+		int x_pos = get_x_position(frame_info, limit, x);
+		u8 *src_pixels = get_src_pixels(frame_info, x, y, 4);
 
 		out_pixels[x_pos].a = (u16)0xffff;
 		out_pixels[x_pos].r = (u16)src_pixels[2] * 257;
@@ -95,12 +108,11 @@ static void ARGB16161616_to_argb_u16(struct line_buffer *stage_buffer,
 				     int y)
 {
 	struct pixel_argb_u16 *out_pixels = stage_buffer->pixels;
-	u16 *src_pixels = get_packed_src_addr(frame_info, y);
-	int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst),
-			    stage_buffer->n_pixels);
+	int limit = get_limit(frame_info, stage_buffer);
 
-	for (size_t x = 0; x < x_limit; x++, src_pixels += 4) {
-		int x_pos = get_x_position(frame_info, x_limit, x);
+	for (size_t x = 0; x < limit; x++) {
+		int x_pos = get_x_position(frame_info, limit, x);
+		u8 *src_pixels = get_src_pixels(frame_info, x, y, 4);
 
 		out_pixels[x_pos].a = le16_to_cpu(src_pixels[3]);
 		out_pixels[x_pos].r = le16_to_cpu(src_pixels[2]);
@@ -114,12 +126,11 @@ static void XRGB16161616_to_argb_u16(struct line_buffer *stage_buffer,
 				     int y)
 {
 	struct pixel_argb_u16 *out_pixels = stage_buffer->pixels;
-	u16 *src_pixels = get_packed_src_addr(frame_info, y);
-	int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst),
-			    stage_buffer->n_pixels);
+	int limit = get_limit(frame_info, stage_buffer);
 
-	for (size_t x = 0; x < x_limit; x++, src_pixels += 4) {
-		int x_pos = get_x_position(frame_info, x_limit, x);
+	for (size_t x = 0; x < limit; x++) {
+		int x_pos = get_x_position(frame_info, limit, x);
+		u8 *src_pixels = get_src_pixels(frame_info, x, y, 4);
 
 		out_pixels[x_pos].a = (u16)0xffff;
 		out_pixels[x_pos].r = le16_to_cpu(src_pixels[2]);
@@ -132,15 +143,14 @@ static void RGB565_to_argb_u16(struct line_buffer *stage_buffer,
 			       const struct vkms_frame_info *frame_info, int y)
 {
 	struct pixel_argb_u16 *out_pixels = stage_buffer->pixels;
-	u16 *src_pixels = get_packed_src_addr(frame_info, y);
-	int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst),
-			       stage_buffer->n_pixels);
+	int limit = get_limit(frame_info, stage_buffer);
 
 	s64 fp_rb_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(31));
 	s64 fp_g_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(63));
 
-	for (size_t x = 0; x < x_limit; x++, src_pixels++) {
-		int x_pos = get_x_position(frame_info, x_limit, x);
+	for (size_t x = 0; x < limit; x++) {
+		int x_pos = get_x_position(frame_info, limit, x);
+		u8 *src_pixels = get_src_pixels(frame_info, x, y, 1);
 
 		u16 rgb_565 = le16_to_cpu(*src_pixels);
 		s64 fp_r = drm_int2fixp((rgb_565 >> 11) & 0x1f);
diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c
index 1acf715389d6..94c1e5d891cc 100644
--- a/drivers/gpu/drm/vkms/vkms_plane.c
+++ b/drivers/gpu/drm/vkms/vkms_plane.c
@@ -123,6 +123,7 @@ static void vkms_plane_atomic_update(struct drm_plane *plane,
 	drm_framebuffer_get(frame_info->fb);
 	frame_info->rotation = drm_rotation_simplify(new_state->rotation,
 						     DRM_MODE_ROTATE_0 |
+						     DRM_MODE_ROTATE_90 |
 						     DRM_MODE_ROTATE_180);
 
 	drm_rect_rotate(&frame_info->dst, drm_rect_width(&frame_info->dst),
@@ -239,6 +240,7 @@ 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_ROTATE_90 |
 					   DRM_MODE_ROTATE_180);
 
 	return plane;
-- 
2.39.2




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux