summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/udl
diff options
context:
space:
mode:
authorThomas Zimmermann <tzimmermann@suse.de>2019-12-06 09:59:51 +0100
committerThomas Zimmermann <tzimmermann@suse.de>2019-12-06 13:51:41 +0100
commitffc90486e320ba68f63de39fe04d757ce0cf49e5 (patch)
treeb908862791027e98291839c5e2399f23696d14c7 /drivers/gpu/drm/udl
parent2d2bebb8332317551ef6fe168396b09337af67df (diff)
drm/udl: Move clip-rectangle code out of udl_handle_damage()
Computing the clip rectable in a separate helper function makes the damage-handler code more readable. Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Reviewed-by: Emil Velikov <emil.velikov@collabora.com> Acked-by: Gerd Hoffmann <kraxel@redhat.com> Link: https://patchwork.freedesktop.org/patch/msgid/20191206085954.9697-5-tzimmermann@suse.de
Diffstat (limited to 'drivers/gpu/drm/udl')
-rw-r--r--drivers/gpu/drm/udl/udl_fb.c48
1 files changed, 32 insertions, 16 deletions
diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
index dd7ba7f63214..cc2a09a995b8 100644
--- a/drivers/gpu/drm/udl/udl_fb.c
+++ b/drivers/gpu/drm/udl/udl_fb.c
@@ -20,9 +20,6 @@
#include "udl_drv.h"
-#define DL_ALIGN_UP(x, a) ALIGN(x, a)
-#define DL_ALIGN_DOWN(x, a) ALIGN_DOWN(x, a)
-
/** Read the red component (0..255) of a 32 bpp colour. */
#define DLO_RGB_GETRED(col) (uint8_t)((col) & 0xFF)
@@ -61,6 +58,28 @@ static uint16_t rgb16(uint32_t col)
}
#endif
+static int udl_aligned_damage_clip(struct drm_rect *clip, int x, int y,
+ int width, int height)
+{
+ int x1, x2;
+
+ if (WARN_ON_ONCE(x < 0) ||
+ WARN_ON_ONCE(y < 0) ||
+ WARN_ON_ONCE(width < 0) ||
+ WARN_ON_ONCE(height < 0))
+ return -EINVAL;
+
+ x1 = ALIGN_DOWN(x, sizeof(unsigned long));
+ x2 = ALIGN(width + (x - x1), sizeof(unsigned long)) + x1;
+
+ clip->x1 = x1;
+ clip->y1 = y;
+ clip->x2 = x2;
+ clip->y2 = y + height;
+
+ return 0;
+}
+
int udl_handle_damage(struct drm_framebuffer *fb, int x, int y,
int width, int height)
{
@@ -69,7 +88,7 @@ int udl_handle_damage(struct drm_framebuffer *fb, int x, int y,
int i, ret;
char *cmd;
struct urb *urb;
- int aligned_x;
+ struct drm_rect clip;
int log_bpp;
void *vaddr;
@@ -85,15 +104,11 @@ int udl_handle_damage(struct drm_framebuffer *fb, int x, int y,
}
spin_unlock(&udl->active_fb_16_lock);
- aligned_x = DL_ALIGN_DOWN(x, sizeof(unsigned long));
- width = DL_ALIGN_UP(width + (x-aligned_x), sizeof(unsigned long));
- x = aligned_x;
-
- if ((width <= 0) ||
- (x + width > fb->width) ||
- (y + height > fb->height)) {
+ ret = udl_aligned_damage_clip(&clip, x, y, width, height);
+ if (ret)
+ return ret;
+ else if ((clip.x2 > fb->width) || (clip.y2 > fb->height))
return -EINVAL;
- }
vaddr = drm_gem_shmem_vmap(fb->obj[0]);
if (IS_ERR(vaddr)) {
@@ -106,13 +121,14 @@ int udl_handle_damage(struct drm_framebuffer *fb, int x, int y,
goto out;
cmd = urb->transfer_buffer;
- for (i = y; i < y + height ; i++) {
+ for (i = clip.y1; i < clip.y2; i++) {
const int line_offset = fb->pitches[0] * i;
- const int byte_offset = line_offset + (x << log_bpp);
- const int dev_byte_offset = (fb->width * i + x) << log_bpp;
+ const int byte_offset = line_offset + (clip.x1 << log_bpp);
+ const int dev_byte_offset = (fb->width * i + clip.x1) << log_bpp;
+ const int byte_width = (clip.x2 - clip.x1) << log_bpp;
if (udl_render_hline(dev, log_bpp, &urb, (char *)vaddr,
&cmd, byte_offset, dev_byte_offset,
- width << log_bpp))
+ byte_width))
goto out;
}