Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/vkms: Isolate writeback pixel conversion functions

All convertions from the ARGB16161616 format follow the same structure.
Instead of repeting the same structure for each supported format, create
a function to encapsulate the common logic and isolate the pixel
conversion functions in a callback function.

Suggested-by: Melissa Wen <mwen@igalia.com>
Signed-off-by: Maíra Canal <mcanal@igalia.com>
Reviewed-by: Arthur Grillo <arthurgrillo@riseup.net>
Signed-off-by: Maíra Canal <mairacanal@riseup.net>
Link: https://patchwork.freedesktop.org/patch/msgid/20230515135204.115393-4-mcanal@igalia.com

authored by

Maíra Canal and committed by
Maíra Canal
cc4fd293 e2a47217

+61 -87
+2 -2
drivers/gpu/drm/vkms/vkms_composer.c
··· 133 133 *crc32 = crc32_le(*crc32, (void *)output_buffer->pixels, row_size); 134 134 135 135 if (wb) 136 - wb->wb_write(&wb->wb_frame_info, output_buffer, y_pos); 136 + vkms_writeback_row(wb, output_buffer, y_pos); 137 137 } 138 138 } 139 139 ··· 147 147 if (!planes[i]->pixel_read) 148 148 return -1; 149 149 150 - if (active_wb && !active_wb->wb_write) 150 + if (active_wb && !active_wb->pixel_write) 151 151 return -1; 152 152 153 153 return 0;
+2 -2
drivers/gpu/drm/vkms/vkms_drv.h
··· 46 46 struct vkms_writeback_job { 47 47 struct iosys_map data[DRM_FORMAT_MAX_PLANES]; 48 48 struct vkms_frame_info wb_frame_info; 49 - void (*wb_write)(struct vkms_frame_info *frame_info, 50 - const struct line_buffer *buffer, int y); 49 + void (*pixel_write)(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel); 51 50 }; 52 51 53 52 /** ··· 156 157 void vkms_composer_worker(struct work_struct *work); 157 158 void vkms_set_composer(struct vkms_output *out, bool enabled); 158 159 void vkms_compose_row(struct line_buffer *stage_buffer, struct vkms_plane_state *plane, int y); 160 + void vkms_writeback_row(struct vkms_writeback_job *wb, const struct line_buffer *src_buffer, int y); 159 161 160 162 /* Writeback */ 161 163 int vkms_enable_writeback_connector(struct vkms_device *vkmsdev);
+55 -81
drivers/gpu/drm/vkms/vkms_formats.c
··· 150 150 * They are used in the `compose_active_planes` to convert and store a line 151 151 * from the src_buffer to the writeback buffer. 152 152 */ 153 - static void argb_u16_to_ARGB8888(struct vkms_frame_info *frame_info, 154 - const struct line_buffer *src_buffer, int y) 153 + static void argb_u16_to_ARGB8888(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel) 155 154 { 156 - int x_dst = frame_info->dst.x1; 157 - u8 *dst_pixels = packed_pixels_addr(frame_info, x_dst, y); 158 - struct pixel_argb_u16 *in_pixels = src_buffer->pixels; 159 - int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst), 160 - src_buffer->n_pixels); 161 - 162 - for (size_t x = 0; x < x_limit; x++, dst_pixels += 4) { 163 - /* 164 - * This sequence below is important because the format's byte order is 165 - * in little-endian. In the case of the ARGB8888 the memory is 166 - * organized this way: 167 - * 168 - * | Addr | = blue channel 169 - * | Addr + 1 | = green channel 170 - * | Addr + 2 | = Red channel 171 - * | Addr + 3 | = Alpha channel 172 - */ 173 - dst_pixels[3] = DIV_ROUND_CLOSEST(in_pixels[x].a, 257); 174 - dst_pixels[2] = DIV_ROUND_CLOSEST(in_pixels[x].r, 257); 175 - dst_pixels[1] = DIV_ROUND_CLOSEST(in_pixels[x].g, 257); 176 - dst_pixels[0] = DIV_ROUND_CLOSEST(in_pixels[x].b, 257); 177 - } 155 + /* 156 + * This sequence below is important because the format's byte order is 157 + * in little-endian. In the case of the ARGB8888 the memory is 158 + * organized this way: 159 + * 160 + * | Addr | = blue channel 161 + * | Addr + 1 | = green channel 162 + * | Addr + 2 | = Red channel 163 + * | Addr + 3 | = Alpha channel 164 + */ 165 + dst_pixels[3] = DIV_ROUND_CLOSEST(in_pixel->a, 257); 166 + dst_pixels[2] = DIV_ROUND_CLOSEST(in_pixel->r, 257); 167 + dst_pixels[1] = DIV_ROUND_CLOSEST(in_pixel->g, 257); 168 + dst_pixels[0] = DIV_ROUND_CLOSEST(in_pixel->b, 257); 178 169 } 179 170 180 - static void argb_u16_to_XRGB8888(struct vkms_frame_info *frame_info, 181 - const struct line_buffer *src_buffer, int y) 171 + static void argb_u16_to_XRGB8888(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel) 182 172 { 183 - int x_dst = frame_info->dst.x1; 184 - u8 *dst_pixels = packed_pixels_addr(frame_info, x_dst, y); 185 - struct pixel_argb_u16 *in_pixels = src_buffer->pixels; 186 - int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst), 187 - src_buffer->n_pixels); 188 - 189 - for (size_t x = 0; x < x_limit; x++, dst_pixels += 4) { 190 - dst_pixels[3] = 0xff; 191 - dst_pixels[2] = DIV_ROUND_CLOSEST(in_pixels[x].r, 257); 192 - dst_pixels[1] = DIV_ROUND_CLOSEST(in_pixels[x].g, 257); 193 - dst_pixels[0] = DIV_ROUND_CLOSEST(in_pixels[x].b, 257); 194 - } 173 + dst_pixels[3] = 0xff; 174 + dst_pixels[2] = DIV_ROUND_CLOSEST(in_pixel->r, 257); 175 + dst_pixels[1] = DIV_ROUND_CLOSEST(in_pixel->g, 257); 176 + dst_pixels[0] = DIV_ROUND_CLOSEST(in_pixel->b, 257); 195 177 } 196 178 197 - static void argb_u16_to_ARGB16161616(struct vkms_frame_info *frame_info, 198 - const struct line_buffer *src_buffer, int y) 179 + static void argb_u16_to_ARGB16161616(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel) 199 180 { 200 - int x_dst = frame_info->dst.x1; 201 - u16 *dst_pixels = packed_pixels_addr(frame_info, x_dst, y); 202 - struct pixel_argb_u16 *in_pixels = src_buffer->pixels; 203 - int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst), 204 - src_buffer->n_pixels); 181 + u16 *pixels = (u16 *)dst_pixels; 205 182 206 - for (size_t x = 0; x < x_limit; x++, dst_pixels += 4) { 207 - dst_pixels[3] = cpu_to_le16(in_pixels[x].a); 208 - dst_pixels[2] = cpu_to_le16(in_pixels[x].r); 209 - dst_pixels[1] = cpu_to_le16(in_pixels[x].g); 210 - dst_pixels[0] = cpu_to_le16(in_pixels[x].b); 211 - } 183 + pixels[3] = cpu_to_le16(in_pixel->a); 184 + pixels[2] = cpu_to_le16(in_pixel->r); 185 + pixels[1] = cpu_to_le16(in_pixel->g); 186 + pixels[0] = cpu_to_le16(in_pixel->b); 212 187 } 213 188 214 - static void argb_u16_to_XRGB16161616(struct vkms_frame_info *frame_info, 215 - const struct line_buffer *src_buffer, int y) 189 + static void argb_u16_to_XRGB16161616(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel) 216 190 { 217 - int x_dst = frame_info->dst.x1; 218 - u16 *dst_pixels = packed_pixels_addr(frame_info, x_dst, y); 219 - struct pixel_argb_u16 *in_pixels = src_buffer->pixels; 220 - int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst), 221 - src_buffer->n_pixels); 191 + u16 *pixels = (u16 *)dst_pixels; 222 192 223 - for (size_t x = 0; x < x_limit; x++, dst_pixels += 4) { 224 - dst_pixels[3] = 0xffff; 225 - dst_pixels[2] = cpu_to_le16(in_pixels[x].r); 226 - dst_pixels[1] = cpu_to_le16(in_pixels[x].g); 227 - dst_pixels[0] = cpu_to_le16(in_pixels[x].b); 228 - } 193 + pixels[3] = 0xffff; 194 + pixels[2] = cpu_to_le16(in_pixel->r); 195 + pixels[1] = cpu_to_le16(in_pixel->g); 196 + pixels[0] = cpu_to_le16(in_pixel->b); 229 197 } 230 198 231 - static void argb_u16_to_RGB565(struct vkms_frame_info *frame_info, 232 - const struct line_buffer *src_buffer, int y) 199 + static void argb_u16_to_RGB565(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel) 233 200 { 234 - int x_dst = frame_info->dst.x1; 235 - u16 *dst_pixels = packed_pixels_addr(frame_info, x_dst, y); 236 - struct pixel_argb_u16 *in_pixels = src_buffer->pixels; 237 - int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst), 238 - src_buffer->n_pixels); 201 + u16 *pixels = (u16 *)dst_pixels; 239 202 240 203 s64 fp_rb_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(31)); 241 204 s64 fp_g_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(63)); 242 205 243 - for (size_t x = 0; x < x_limit; x++, dst_pixels++) { 244 - s64 fp_r = drm_int2fixp(in_pixels[x].r); 245 - s64 fp_g = drm_int2fixp(in_pixels[x].g); 246 - s64 fp_b = drm_int2fixp(in_pixels[x].b); 206 + s64 fp_r = drm_int2fixp(in_pixel->r); 207 + s64 fp_g = drm_int2fixp(in_pixel->g); 208 + s64 fp_b = drm_int2fixp(in_pixel->b); 247 209 248 - u16 r = drm_fixp2int_round(drm_fixp_div(fp_r, fp_rb_ratio)); 249 - u16 g = drm_fixp2int_round(drm_fixp_div(fp_g, fp_g_ratio)); 250 - u16 b = drm_fixp2int_round(drm_fixp_div(fp_b, fp_rb_ratio)); 210 + u16 r = drm_fixp2int(drm_fixp_div(fp_r, fp_rb_ratio)); 211 + u16 g = drm_fixp2int(drm_fixp_div(fp_g, fp_g_ratio)); 212 + u16 b = drm_fixp2int(drm_fixp_div(fp_b, fp_rb_ratio)); 251 213 252 - *dst_pixels = cpu_to_le16(r << 11 | g << 5 | b); 253 - } 214 + *pixels = cpu_to_le16(r << 11 | g << 5 | b); 215 + } 216 + 217 + void vkms_writeback_row(struct vkms_writeback_job *wb, 218 + const struct line_buffer *src_buffer, int y) 219 + { 220 + struct vkms_frame_info *frame_info = &wb->wb_frame_info; 221 + int x_dst = frame_info->dst.x1; 222 + u8 *dst_pixels = packed_pixels_addr(frame_info, x_dst, y); 223 + struct pixel_argb_u16 *in_pixels = src_buffer->pixels; 224 + int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst), src_buffer->n_pixels); 225 + 226 + for (size_t x = 0; x < x_limit; x++, dst_pixels += frame_info->cpp) 227 + wb->pixel_write(dst_pixels, &in_pixels[x]); 254 228 } 255 229 256 230 void *get_pixel_conversion_function(u32 format) ··· 245 271 } 246 272 } 247 273 248 - void *get_line_to_frame_function(u32 format) 274 + void *get_pixel_write_function(u32 format) 249 275 { 250 276 switch (format) { 251 277 case DRM_FORMAT_ARGB8888:
+1 -1
drivers/gpu/drm/vkms/vkms_formats.h
··· 7 7 8 8 void *get_pixel_conversion_function(u32 format); 9 9 10 - void *get_line_to_frame_function(u32 format); 10 + void *get_pixel_write_function(u32 format); 11 11 12 12 #endif /* _VKMS_FORMATS_H_ */
+1 -1
drivers/gpu/drm/vkms/vkms_writeback.c
··· 151 151 wb_frame_info->cpp = fb->format->cpp[0]; 152 152 153 153 drm_writeback_queue_job(wb_conn, connector_state); 154 - active_wb->wb_write = get_line_to_frame_function(wb_format); 154 + active_wb->pixel_write = get_pixel_write_function(wb_format); 155 155 drm_rect_init(&wb_frame_info->src, 0, 0, crtc_width, crtc_height); 156 156 drm_rect_init(&wb_frame_info->dst, 0, 0, crtc_width, crtc_height); 157 157 }