summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/drm_format_helper.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2019-04-05 11:52:16 +0200
committerGerd Hoffmann <kraxel@redhat.com>2019-04-08 06:59:26 +0200
commit26f024f54ab69a1012214755223d6ed61dd7bc98 (patch)
tree14308d3c2318e55a3862534eee8830ee9a3069e6 /drivers/gpu/drm/drm_format_helper.c
parent7415287e1f3675996a4a6919fe500c30d30951f6 (diff)
downloadlinux-26f024f54ab69a1012214755223d6ed61dd7bc98.tar.gz
linux-26f024f54ab69a1012214755223d6ed61dd7bc98.tar.xz
drm: add drm_fb_memcpy_dstclip() helper
It is a drm_fb_memcpy() variant which checks the clip rectangle for the destination too. Common code between drm_fb_memcpy() and drm_fb_memcpy_dstclip() was factored out into the drm_fb_memcpy_lines() helper function. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Noralf Trønnes <noralf@tronnes.org> Link: http://patchwork.freedesktop.org/patch/msgid/20190405095219.9231-3-kraxel@redhat.com
Diffstat (limited to 'drivers/gpu/drm/drm_format_helper.c')
-rw-r--r--drivers/gpu/drm/drm_format_helper.c51
1 files changed, 43 insertions, 8 deletions
diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_format_helper.c
index 62bb4913d6f6..55a2d629a75f 100644
--- a/drivers/gpu/drm/drm_format_helper.c
+++ b/drivers/gpu/drm/drm_format_helper.c
@@ -16,31 +16,66 @@
#include <drm/drm_fourcc.h>
#include <drm/drm_rect.h>
+static void drm_fb_memcpy_lines(void *dst, unsigned int dst_pitch,
+ void *src, unsigned int src_pitch,
+ unsigned int linelength, unsigned int lines)
+{
+ int line;
+
+ for (line = 0; line < lines; line++) {
+ memcpy(dst, src, linelength);
+ src += src_pitch;
+ dst += dst_pitch;
+ }
+}
+
/**
* drm_fb_memcpy - Copy clip buffer
* @dst: Destination buffer
* @vaddr: Source buffer
* @fb: DRM framebuffer
* @clip: Clip rectangle area to copy
+ *
+ * This function does not apply clipping on dst, i.e. the destination
+ * is a small buffer containing the clip rect only.
*/
void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
struct drm_rect *clip)
{
unsigned int cpp = drm_format_plane_cpp(fb->format->format, 0);
- unsigned int pitch = fb->pitches[0];
- void *src = vaddr + (clip->y1 * pitch) + (clip->x1 * cpp);
+ unsigned int offset = (clip->y1 * fb->pitches[0]) + (clip->x1 * cpp);
size_t len = (clip->x2 - clip->x1) * cpp;
- unsigned int y;
- for (y = clip->y1; y < clip->y2; y++) {
- memcpy(dst, src, len);
- src += pitch;
- dst += len;
- }
+ drm_fb_memcpy_lines(dst, len,
+ vaddr + offset, fb->pitches[0],
+ len, clip->y2 - clip->y1);
}
EXPORT_SYMBOL(drm_fb_memcpy);
/**
+ * drm_fb_memcpy_dstclip - Copy clip buffer
+ * @dst: Destination buffer
+ * @vaddr: Source buffer
+ * @fb: DRM framebuffer
+ * @clip: Clip rectangle area to copy
+ *
+ * This function applies clipping on dst, i.e. the destination is a
+ * full framebuffer but only the clip rect content is copied over.
+ */
+void drm_fb_memcpy_dstclip(void *dst, void *vaddr, struct drm_framebuffer *fb,
+ struct drm_rect *clip)
+{
+ unsigned int cpp = drm_format_plane_cpp(fb->format->format, 0);
+ unsigned int offset = (clip->y1 * fb->pitches[0]) + (clip->x1 * cpp);
+ size_t len = (clip->x2 - clip->x1) * cpp;
+
+ drm_fb_memcpy_lines(dst + offset, fb->pitches[0],
+ vaddr + offset, fb->pitches[0],
+ len, clip->y2 - clip->y1);
+}
+EXPORT_SYMBOL(drm_fb_memcpy_dstclip);
+
+/**
* drm_fb_swab16 - Swap bytes into clip buffer
* @dst: RGB565 destination buffer
* @vaddr: RGB565 source buffer