summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/vkms/vkms_formats.c
diff options
context:
space:
mode:
authorLouis Chauvet <louis.chauvet@bootlin.com>2024-11-18 19:28:22 +0100
committerLouis Chauvet <louis.chauvet@bootlin.com>2024-11-22 14:00:08 +0100
commitb52fd27356af947f80b0c0855691e42a4c02ee79 (patch)
treecc60ad1905089ed5290894f70f9ebc469831419d /drivers/gpu/drm/vkms/vkms_formats.c
parentcb6de83faa9049bf40e7dc6821d903016bec2337 (diff)
drm/vkms: Introduce pixel_read_direction enum
The pixel_read_direction enum is useful to describe the reading direction in a plane. It avoids using the rotation property of DRM, which not practical to know the direction of reading. This patch also introduce two helpers, one to compute the pixel_read_direction from the DRM rotation property, and one to compute the step, in byte, between two successive pixel in a specific direction. Acked-by: Maíra Canal <mairacanal@riseup.net> Reviewed-by: José Expósito <jose.exposito89@gmail.com> Link: https://patchwork.freedesktop.org/patch/msgid/20241118-yuv-v14-7-2dbc2f1e222c@bootlin.com Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
Diffstat (limited to 'drivers/gpu/drm/vkms/vkms_formats.c')
-rw-r--r--drivers/gpu/drm/vkms/vkms_formats.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c
index f9045a80aceb..5dad7bcec0a6 100644
--- a/drivers/gpu/drm/vkms/vkms_formats.c
+++ b/drivers/gpu/drm/vkms/vkms_formats.c
@@ -80,6 +80,38 @@ static void packed_pixels_addr(const struct vkms_frame_info *frame_info,
}
/**
+ * get_block_step_bytes() - Common helper to compute the correct step value between each pixel block
+ * to read in a certain direction.
+ *
+ * @fb: Framebuffer to iter on
+ * @direction: Direction of the reading
+ * @plane_index: Plane to get the step from
+ *
+ * As the returned count is the number of bytes between two consecutive blocks in a direction,
+ * the caller may have to read multiple pixels before using the next one (for example, to read from
+ * left to right in a DRM_FORMAT_R1 plane, each block contains 8 pixels, so the step must be used
+ * only every 8 pixels).
+ */
+static int get_block_step_bytes(struct drm_framebuffer *fb, enum pixel_read_direction direction,
+ int plane_index)
+{
+ switch (direction) {
+ case READ_LEFT_TO_RIGHT:
+ return fb->format->char_per_block[plane_index];
+ case READ_RIGHT_TO_LEFT:
+ return -fb->format->char_per_block[plane_index];
+ case READ_TOP_TO_BOTTOM:
+ return (int)fb->pitches[plane_index] * drm_format_info_block_width(fb->format,
+ plane_index);
+ case READ_BOTTOM_TO_TOP:
+ return -(int)fb->pitches[plane_index] * drm_format_info_block_width(fb->format,
+ plane_index);
+ }
+
+ return 0;
+}
+
+/**
* packed_pixels_addr_1x1() - Get the pointer to the block containing the pixel at the given
* coordinates
*