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

drm/format-helper: Add drm_fb_xrgb8888_to_rgb888()

Add XRGB8888 emulation support for devices that can only do RGB888.

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20210929191201.34456-4-noralf@tronnes.org

+40
+38
drivers/gpu/drm/drm_format_helper.c
··· 301 301 } 302 302 303 303 /** 304 + * drm_fb_xrgb8888_to_rgb888 - Convert XRGB8888 to RGB888 clip buffer 305 + * @dst: RGB888 destination buffer 306 + * @src: XRGB8888 source buffer 307 + * @fb: DRM framebuffer 308 + * @clip: Clip rectangle area to copy 309 + * 310 + * Drivers can use this function for RGB888 devices that don't natively 311 + * support XRGB8888. 312 + * 313 + * This function does not apply clipping on dst, i.e. the destination 314 + * is a small buffer containing the clip rect only. 315 + */ 316 + void drm_fb_xrgb8888_to_rgb888(void *dst, void *src, struct drm_framebuffer *fb, 317 + struct drm_rect *clip) 318 + { 319 + size_t width = drm_rect_width(clip); 320 + size_t src_len = width * sizeof(u32); 321 + unsigned int y; 322 + void *sbuf; 323 + 324 + /* Use a buffer to speed up access on buffers with uncached read mapping (i.e. WC) */ 325 + sbuf = kmalloc(src_len, GFP_KERNEL); 326 + if (!sbuf) 327 + return; 328 + 329 + src += clip_offset(clip, fb->pitches[0], sizeof(u32)); 330 + for (y = 0; y < drm_rect_height(clip); y++) { 331 + memcpy(sbuf, src, src_len); 332 + drm_fb_xrgb8888_to_rgb888_line(dst, sbuf, width); 333 + src += fb->pitches[0]; 334 + dst += width * 3; 335 + } 336 + 337 + kfree(sbuf); 338 + } 339 + EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb888); 340 + 341 + /** 304 342 * drm_fb_xrgb8888_to_rgb888_dstclip - Convert XRGB8888 to RGB888 clip buffer 305 343 * @dst: RGB565 destination buffer (iomem) 306 344 * @dst_pitch: destination buffer pitch
+2
include/drm/drm_format_helper.h
··· 24 24 void drm_fb_xrgb8888_to_rgb565_dstclip(void __iomem *dst, unsigned int dst_pitch, 25 25 void *vaddr, struct drm_framebuffer *fb, 26 26 struct drm_rect *clip, bool swab); 27 + void drm_fb_xrgb8888_to_rgb888(void *dst, void *src, struct drm_framebuffer *fb, 28 + struct drm_rect *clip); 27 29 void drm_fb_xrgb8888_to_rgb888_dstclip(void __iomem *dst, unsigned int dst_pitch, 28 30 void *vaddr, struct drm_framebuffer *fb, 29 31 struct drm_rect *clip);