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

drm/format-helper: Add blitter functions

The blitter functions copy a framebuffer to I/O memory using one of
the existing conversion functions.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Acked-by: Maxime Ripard <maxime@cerno.tech>
Tested-by: nerdopolis <bluescreen_avenger@verizon.net>
Link: https://patchwork.freedesktop.org/patch/msgid/20210430105840.30515-3-tzimmermann@suse.de

+95
+87
drivers/gpu/drm/drm_format_helper.c
··· 344 344 } 345 345 EXPORT_SYMBOL(drm_fb_xrgb8888_to_gray8); 346 346 347 + /** 348 + * drm_fb_blit_rect_dstclip - Copy parts of a framebuffer to display memory 349 + * @dst: The display memory to copy to 350 + * @dst_pitch: Number of bytes between two consecutive scanlines within dst 351 + * @dst_format: FOURCC code of the display's color format 352 + * @vmap: The framebuffer memory to copy from 353 + * @fb: The framebuffer to copy from 354 + * @clip: Clip rectangle area to copy 355 + * 356 + * This function copies parts of a framebuffer to display memory. If the 357 + * formats of the display and the framebuffer mismatch, the blit function 358 + * will attempt to convert between them. 359 + * 360 + * Use drm_fb_blit_dstclip() to copy the full framebuffer. 361 + * 362 + * Returns: 363 + * 0 on success, or 364 + * -EINVAL if the color-format conversion failed, or 365 + * a negative error code otherwise. 366 + */ 367 + int drm_fb_blit_rect_dstclip(void __iomem *dst, unsigned int dst_pitch, 368 + uint32_t dst_format, void *vmap, 369 + struct drm_framebuffer *fb, 370 + struct drm_rect *clip) 371 + { 372 + uint32_t fb_format = fb->format->format; 373 + 374 + /* treat alpha channel like filler bits */ 375 + if (fb_format == DRM_FORMAT_ARGB8888) 376 + fb_format = DRM_FORMAT_XRGB8888; 377 + if (dst_format == DRM_FORMAT_ARGB8888) 378 + dst_format = DRM_FORMAT_XRGB8888; 379 + 380 + if (dst_format == fb_format) { 381 + drm_fb_memcpy_dstclip(dst, dst_pitch, vmap, fb, clip); 382 + return 0; 383 + 384 + } else if (dst_format == DRM_FORMAT_RGB565) { 385 + if (fb_format == DRM_FORMAT_XRGB8888) { 386 + drm_fb_xrgb8888_to_rgb565_dstclip(dst, dst_pitch, 387 + vmap, fb, clip, 388 + false); 389 + return 0; 390 + } 391 + } else if (dst_format == DRM_FORMAT_RGB888) { 392 + if (fb_format == DRM_FORMAT_XRGB8888) { 393 + drm_fb_xrgb8888_to_rgb888_dstclip(dst, dst_pitch, 394 + vmap, fb, clip); 395 + return 0; 396 + } 397 + } 398 + 399 + return -EINVAL; 400 + } 401 + EXPORT_SYMBOL(drm_fb_blit_rect_dstclip); 402 + 403 + /** 404 + * drm_fb_blit_dstclip - Copy framebuffer to display memory 405 + * @dst: The display memory to copy to 406 + * @dst_pitch: Number of bytes between two consecutive scanlines within dst 407 + * @dst_format: FOURCC code of the display's color format 408 + * @vmap: The framebuffer memory to copy from 409 + * @fb: The framebuffer to copy from 410 + * 411 + * This function copies a full framebuffer to display memory. If the formats 412 + * of the display and the framebuffer mismatch, the copy function will 413 + * attempt to convert between them. 414 + * 415 + * See drm_fb_blit_rect_dstclip() for more inforamtion. 416 + * 417 + * Returns: 418 + * 0 on success, or a negative error code otherwise. 419 + */ 420 + int drm_fb_blit_dstclip(void __iomem *dst, unsigned int dst_pitch, 421 + uint32_t dst_format, void *vmap, 422 + struct drm_framebuffer *fb) 423 + { 424 + struct drm_rect fullscreen = { 425 + .x1 = 0, 426 + .x2 = fb->width, 427 + .y1 = 0, 428 + .y2 = fb->height, 429 + }; 430 + return drm_fb_blit_rect_dstclip(dst, dst_pitch, dst_format, vmap, fb, 431 + &fullscreen); 432 + } 433 + EXPORT_SYMBOL(drm_fb_blit_dstclip);
+8
include/drm/drm_format_helper.h
··· 28 28 void drm_fb_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb, 29 29 struct drm_rect *clip); 30 30 31 + int drm_fb_blit_rect_dstclip(void __iomem *dst, unsigned int dst_pitch, 32 + uint32_t dst_format, void *vmap, 33 + struct drm_framebuffer *fb, 34 + struct drm_rect *rect); 35 + int drm_fb_blit_dstclip(void __iomem *dst, unsigned int dst_pitch, 36 + uint32_t dst_format, void *vmap, 37 + struct drm_framebuffer *fb); 38 + 31 39 #endif /* __LINUX_DRM_FORMAT_HELPER_H */