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

drm/rect: Add drm_rect_overlap()

Check if two rectangles overlap.
It's a bit similar to drm_rect_intersect() but this won't modify
the rectangle.
Simplifies a bit drm_panic.

Signed-off-by: Jocelyn Falempe <jfalempe@redhat.com>
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20240822073852.562286-3-jfalempe@redhat.com

+16 -2
+1 -2
drivers/gpu/drm/drm_panic.c
··· 529 529 /* Fill with the background color, and draw text on top */ 530 530 drm_panic_fill(sb, &r_screen, bg_color); 531 531 532 - if ((r_msg.x1 >= logo_width || r_msg.y1 >= logo_height) && 533 - logo_width <= sb->width && logo_height <= sb->height) { 532 + if (!drm_rect_overlap(&r_logo, &r_msg)) { 534 533 if (logo_mono) 535 534 drm_panic_blit(sb, &r_logo, logo_mono->data, DIV_ROUND_UP(logo_width, 8), 536 535 fg_color);
+15
include/drm/drm_rect.h
··· 238 238 drm_rect_height(src) >> 16); 239 239 } 240 240 241 + /** 242 + * drm_rect_overlap - Check if two rectangles overlap 243 + * @a: first rectangle 244 + * @b: second rectangle 245 + * 246 + * RETURNS: 247 + * %true if the rectangles overlap, %false otherwise. 248 + */ 249 + static inline bool drm_rect_overlap(const struct drm_rect *a, 250 + const struct drm_rect *b) 251 + { 252 + return (a->x2 > b->x1 && b->x2 > a->x1 && 253 + a->y2 > b->y1 && b->y2 > a->y1); 254 + } 255 + 241 256 bool drm_rect_intersect(struct drm_rect *r, const struct drm_rect *clip); 242 257 bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst, 243 258 const struct drm_rect *clip);