From cf15528a19dbb1c5bd7540bf29e663ef62143599 Mon Sep 17 00:00:00 2001
From: Thomas Zimmermann <tzimmermann@suse.de>
Date: Wed, 9 Feb 2022 17:16:15 +0100
Subject: drm/fb-helper: Calculate damaged area in separate helper
Git-commit: 67b723f5b74254d27962b1b59bddfee1584575ff
Patch-mainline: v5.18-rc1
References: jsc#PED-1166 jsc#PED-1168 jsc#PED-1170 jsc#PED-1218 jsc#PED-1220 jsc#PED-1222 jsc#PED-1223 jsc#PED-1225
Add drm_fb_helper_memory_range_to_clip(), a helper function that
accepts an linear range of video memory and converts it into a
rectangle. The computed rectangle describes the damaged area in
terms of scanlines and pixels per scanline.
While at it, make the code more readable by using struct drm_rect
and related helpers.
The code was previously part of the deferred I/O helpers, but is
also useful for damage handling of regular write operations. Update
the deferred I/O code to use the new function.
v2:
* rename helper (Javier)
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220209161617.3553-4-tzimmermann@suse.de
Acked-by: Patrik Jakobsson <pjakobsson@suse.de>
---
drivers/gpu/drm/drm_fb_helper.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
index 8e5ab497d30b..241e68a9658b 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -680,6 +680,19 @@ static void drm_fb_helper_damage(struct fb_info *info, u32 x, u32 y,
schedule_work(&helper->damage_work);
}
+/* Convert memory region into area of scanlines and pixels per scanline */
+static void drm_fb_helper_memory_range_to_clip(struct fb_info *info, off_t off, size_t len,
+ struct drm_rect *clip)
+{
+ off_t end = off + len;
+ u32 x1 = 0;
+ u32 y1 = off / info->fix.line_length;
+ u32 x2 = info->var.xres;
+ u32 y2 = DIV_ROUND_UP(end, info->fix.line_length);
+
+ drm_rect_init(clip, x1, y1, x2 - x1, y2 - y1);
+}
+
/**
* drm_fb_helper_deferred_io() - fbdev deferred_io callback function
* @info: fb_info struct pointer
@@ -693,7 +706,7 @@ void drm_fb_helper_deferred_io(struct fb_info *info,
{
unsigned long start, end, min, max;
struct page *page;
- u32 y1, y2;
+ struct drm_rect damage_area;
min = ULONG_MAX;
max = 0;
@@ -703,12 +716,13 @@ void drm_fb_helper_deferred_io(struct fb_info *info,
min = min(min, start);
max = max(max, end);
}
+ if (min >= max)
+ return;
- if (min < max) {
- y1 = min / info->fix.line_length;
- y2 = DIV_ROUND_UP(max, info->fix.line_length);
- drm_fb_helper_damage(info, 0, y1, info->var.xres, y2 - y1);
- }
+ drm_fb_helper_memory_range_to_clip(info, min, max - min, &damage_area);
+ drm_fb_helper_damage(info, damage_area.x1, damage_area.y1,
+ drm_rect_width(&damage_area),
+ drm_rect_height(&damage_area));
}
EXPORT_SYMBOL(drm_fb_helper_deferred_io);
--
2.38.1