Commit 322d716a authored by Maíra Canal's avatar Maíra Canal Committed by Maíra Canal

drm/vkms: isolate pixel conversion functionality

Currently, the pixel conversion functions repeat the same loop to
iterate the rows. Instead of repeating the same code for each pixel
format, create a function to wrap the loop and isolate the pixel
conversion functionality.
Suggested-by: default avatarArthur Grillo <arthurgrillo@riseup.net>
Signed-off-by: default avatarMaíra Canal <mcanal@igalia.com>
Reviewed-by: default avatarArthur Grillo <arthurgrillo@riseup.net>
Signed-off-by: default avatarMaíra Canal <mairacanal@riseup.net>
Link: https://patchwork.freedesktop.org/patch/msgid/20230418130525.128733-2-mcanal@igalia.com
parent 8356b979
...@@ -99,7 +99,7 @@ static void blend(struct vkms_writeback_job *wb, ...@@ -99,7 +99,7 @@ static void blend(struct vkms_writeback_job *wb,
if (!check_y_limit(plane[i]->frame_info, y)) if (!check_y_limit(plane[i]->frame_info, y))
continue; continue;
plane[i]->plane_read(stage_buffer, plane[i]->frame_info, y); vkms_compose_row(stage_buffer, plane[i], y);
pre_mul_alpha_blend(plane[i]->frame_info, stage_buffer, pre_mul_alpha_blend(plane[i]->frame_info, stage_buffer,
output_buffer); output_buffer);
} }
...@@ -118,7 +118,7 @@ static int check_format_funcs(struct vkms_crtc_state *crtc_state, ...@@ -118,7 +118,7 @@ static int check_format_funcs(struct vkms_crtc_state *crtc_state,
u32 n_active_planes = crtc_state->num_active_planes; u32 n_active_planes = crtc_state->num_active_planes;
for (size_t i = 0; i < n_active_planes; i++) for (size_t i = 0; i < n_active_planes; i++)
if (!planes[i]->plane_read) if (!planes[i]->pixel_read)
return -1; return -1;
if (active_wb && !active_wb->wb_write) if (active_wb && !active_wb->wb_write)
......
...@@ -56,8 +56,7 @@ struct vkms_writeback_job { ...@@ -56,8 +56,7 @@ struct vkms_writeback_job {
struct vkms_plane_state { struct vkms_plane_state {
struct drm_shadow_plane_state base; struct drm_shadow_plane_state base;
struct vkms_frame_info *frame_info; struct vkms_frame_info *frame_info;
void (*plane_read)(struct line_buffer *buffer, void (*pixel_read)(u8 *src_buffer, struct pixel_argb_u16 *out_pixel);
const struct vkms_frame_info *frame_info, int y);
}; };
struct vkms_plane { struct vkms_plane {
...@@ -155,6 +154,7 @@ int vkms_verify_crc_source(struct drm_crtc *crtc, const char *source_name, ...@@ -155,6 +154,7 @@ int vkms_verify_crc_source(struct drm_crtc *crtc, const char *source_name,
/* Composer Support */ /* Composer Support */
void vkms_composer_worker(struct work_struct *work); void vkms_composer_worker(struct work_struct *work);
void vkms_set_composer(struct vkms_output *out, bool enabled); void vkms_set_composer(struct vkms_output *out, bool enabled);
void vkms_compose_row(struct line_buffer *stage_buffer, struct vkms_plane_state *plane, int y);
/* Writeback */ /* Writeback */
int vkms_enable_writeback_connector(struct vkms_device *vkmsdev); int vkms_enable_writeback_connector(struct vkms_device *vkmsdev);
......
...@@ -42,100 +42,75 @@ static void *get_packed_src_addr(const struct vkms_frame_info *frame_info, int y ...@@ -42,100 +42,75 @@ static void *get_packed_src_addr(const struct vkms_frame_info *frame_info, int y
return packed_pixels_addr(frame_info, x_src, y_src); return packed_pixels_addr(frame_info, x_src, y_src);
} }
static void ARGB8888_to_argb_u16(struct line_buffer *stage_buffer, static void ARGB8888_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixel)
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);
for (size_t x = 0; x < x_limit; x++, src_pixels += 4) {
/* /*
* The 257 is the "conversion ratio". This number is obtained by the * 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 * (2^16 - 1) / (2^8 - 1) division. Which, in this case, tries to get
* the best color value in a pixel format with more possibilities. * the best color value in a pixel format with more possibilities.
* A similar idea applies to others RGB color conversions. * A similar idea applies to others RGB color conversions.
*/ */
out_pixels[x].a = (u16)src_pixels[3] * 257; out_pixel->a = (u16)src_pixels[3] * 257;
out_pixels[x].r = (u16)src_pixels[2] * 257; out_pixel->r = (u16)src_pixels[2] * 257;
out_pixels[x].g = (u16)src_pixels[1] * 257; out_pixel->g = (u16)src_pixels[1] * 257;
out_pixels[x].b = (u16)src_pixels[0] * 257; out_pixel->b = (u16)src_pixels[0] * 257;
}
} }
static void XRGB8888_to_argb_u16(struct line_buffer *stage_buffer, static void XRGB8888_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixel)
const struct vkms_frame_info *frame_info, int y)
{ {
struct pixel_argb_u16 *out_pixels = stage_buffer->pixels; out_pixel->a = (u16)0xffff;
u8 *src_pixels = get_packed_src_addr(frame_info, y); out_pixel->r = (u16)src_pixels[2] * 257;
int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst), out_pixel->g = (u16)src_pixels[1] * 257;
stage_buffer->n_pixels); out_pixel->b = (u16)src_pixels[0] * 257;
for (size_t x = 0; x < x_limit; x++, src_pixels += 4) {
out_pixels[x].a = (u16)0xffff;
out_pixels[x].r = (u16)src_pixels[2] * 257;
out_pixels[x].g = (u16)src_pixels[1] * 257;
out_pixels[x].b = (u16)src_pixels[0] * 257;
}
} }
static void ARGB16161616_to_argb_u16(struct line_buffer *stage_buffer, static void ARGB16161616_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixel)
const struct vkms_frame_info *frame_info,
int y)
{ {
struct pixel_argb_u16 *out_pixels = stage_buffer->pixels; u16 *pixels = (u16 *)src_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);
for (size_t x = 0; x < x_limit; x++, src_pixels += 4) { out_pixel->a = le16_to_cpu(pixels[3]);
out_pixels[x].a = le16_to_cpu(src_pixels[3]); out_pixel->r = le16_to_cpu(pixels[2]);
out_pixels[x].r = le16_to_cpu(src_pixels[2]); out_pixel->g = le16_to_cpu(pixels[1]);
out_pixels[x].g = le16_to_cpu(src_pixels[1]); out_pixel->b = le16_to_cpu(pixels[0]);
out_pixels[x].b = le16_to_cpu(src_pixels[0]);
}
} }
static void XRGB16161616_to_argb_u16(struct line_buffer *stage_buffer, static void XRGB16161616_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixel)
const struct vkms_frame_info *frame_info,
int y)
{ {
struct pixel_argb_u16 *out_pixels = stage_buffer->pixels; u16 *pixels = (u16 *)src_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);
for (size_t x = 0; x < x_limit; x++, src_pixels += 4) { out_pixel->a = (u16)0xffff;
out_pixels[x].a = (u16)0xffff; out_pixel->r = le16_to_cpu(pixels[2]);
out_pixels[x].r = le16_to_cpu(src_pixels[2]); out_pixel->g = le16_to_cpu(pixels[1]);
out_pixels[x].g = le16_to_cpu(src_pixels[1]); out_pixel->b = le16_to_cpu(pixels[0]);
out_pixels[x].b = le16_to_cpu(src_pixels[0]);
}
} }
static void RGB565_to_argb_u16(struct line_buffer *stage_buffer, static void RGB565_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixel)
const struct vkms_frame_info *frame_info, int y)
{ {
struct pixel_argb_u16 *out_pixels = stage_buffer->pixels; u16 *pixels = (u16 *)src_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);
s64 fp_rb_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(31)); 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)); s64 fp_g_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(63));
for (size_t x = 0; x < x_limit; x++, src_pixels++) { u16 rgb_565 = le16_to_cpu(*pixels);
u16 rgb_565 = le16_to_cpu(*src_pixels);
s64 fp_r = drm_int2fixp((rgb_565 >> 11) & 0x1f); s64 fp_r = drm_int2fixp((rgb_565 >> 11) & 0x1f);
s64 fp_g = drm_int2fixp((rgb_565 >> 5) & 0x3f); s64 fp_g = drm_int2fixp((rgb_565 >> 5) & 0x3f);
s64 fp_b = drm_int2fixp(rgb_565 & 0x1f); s64 fp_b = drm_int2fixp(rgb_565 & 0x1f);
out_pixels[x].a = (u16)0xffff; out_pixel->a = (u16)0xffff;
out_pixels[x].r = drm_fixp2int(drm_fixp_mul(fp_r, fp_rb_ratio)); out_pixel->r = drm_fixp2int(drm_fixp_mul(fp_r, fp_rb_ratio));
out_pixels[x].g = drm_fixp2int(drm_fixp_mul(fp_g, fp_g_ratio)); out_pixel->g = drm_fixp2int(drm_fixp_mul(fp_g, fp_g_ratio));
out_pixels[x].b = drm_fixp2int(drm_fixp_mul(fp_b, fp_rb_ratio)); out_pixel->b = drm_fixp2int(drm_fixp_mul(fp_b, fp_rb_ratio));
} }
void vkms_compose_row(struct line_buffer *stage_buffer, struct vkms_plane_state *plane, int y)
{
struct pixel_argb_u16 *out_pixels = stage_buffer->pixels;
struct vkms_frame_info *frame_info = plane->frame_info;
u8 *src_pixels = get_packed_src_addr(frame_info, y);
int limit = min_t(size_t, drm_rect_width(&frame_info->dst), stage_buffer->n_pixels);
for (size_t x = 0; x < limit; x++, src_pixels += frame_info->cpp)
plane->pixel_read(src_pixels, &out_pixels[x]);
} }
/* /*
...@@ -249,7 +224,7 @@ static void argb_u16_to_RGB565(struct vkms_frame_info *frame_info, ...@@ -249,7 +224,7 @@ static void argb_u16_to_RGB565(struct vkms_frame_info *frame_info,
} }
} }
void *get_frame_to_line_function(u32 format) void *get_pixel_conversion_function(u32 format)
{ {
switch (format) { switch (format) {
case DRM_FORMAT_ARGB8888: case DRM_FORMAT_ARGB8888:
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "vkms_drv.h" #include "vkms_drv.h"
void *get_frame_to_line_function(u32 format); void *get_pixel_conversion_function(u32 format);
void *get_line_to_frame_function(u32 format); void *get_line_to_frame_function(u32 format);
......
...@@ -123,7 +123,7 @@ static void vkms_plane_atomic_update(struct drm_plane *plane, ...@@ -123,7 +123,7 @@ static void vkms_plane_atomic_update(struct drm_plane *plane,
frame_info->offset = fb->offsets[0]; frame_info->offset = fb->offsets[0];
frame_info->pitch = fb->pitches[0]; frame_info->pitch = fb->pitches[0];
frame_info->cpp = fb->format->cpp[0]; frame_info->cpp = fb->format->cpp[0];
vkms_plane_state->plane_read = get_frame_to_line_function(fmt); vkms_plane_state->pixel_read = get_pixel_conversion_function(fmt);
} }
static int vkms_plane_atomic_check(struct drm_plane *plane, static int vkms_plane_atomic_check(struct drm_plane *plane,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment