From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F78619DF76 for ; Tue, 13 Aug 2024 14:34:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723559674; cv=none; b=WnqeZpopOJEyLyMByhDAXQHW7fuRnhwhxmj/gUzKPJ8KePg/5mGBASSiu+fNG3IdaPSiK1+tywsCUs8M5acQugehlaF6Z29vePROnwBf9WBFbeZ3TP/O50MXEMkAIAZ7zsQr3ilgG7jj3dUMhd0cgKOySw2JBcyBJaKNrHTYBUM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723559674; c=relaxed/simple; bh=kvteX7/5/pd+fMe1MAIAeAD4bp2EgbvOCa0PiA9R+cw=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=AxZxBWQmtuAbSzslAucuC43p9yKv/AxIfQ6UfhrOgDJ88bIRqjIuyHNBnk9lqb1ELbflhjU1SGRYi7vdqwx0lLyDvn+NzEDeUd7R5SejFM090twsnWauzPWcoTigH1P6j5tb068JcDRHQLFVtH8K/1I+KfLeF/kqWdxwZnZ0EIw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=cNpbyv8T; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cNpbyv8T" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723559671; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=78IsUJKw9IqeoT5lC9OSKM4PAO7hFbDugoVudFsVevs=; b=cNpbyv8THQzuqaawjFJXG8OgRHlLz9Ce0ODWxwKWP1mWMF573Dh8d75BdcXyJuMidSu4fO vHd9rEKjS5jtnAGFFksCU70iBJyptFMNrJRjnc2MjiYl/VgQHF5R/BSv7k2o7eF6OEBh6I TKczKV/Z7yFaQAtisueK9Aic+UcEReE= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-208-IQTOCT_cOfSs_98rEuRoLw-1; Tue, 13 Aug 2024 10:34:29 -0400 X-MC-Unique: IQTOCT_cOfSs_98rEuRoLw-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-429c224d9edso32822155e9.1 for ; Tue, 13 Aug 2024 07:34:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723559668; x=1724164468; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=78IsUJKw9IqeoT5lC9OSKM4PAO7hFbDugoVudFsVevs=; b=OZ2/481ehGZ3QnHBV8zFgnR+c+9W8uOb/GAzQrmWz0Uk2E408DqrnFI1GqIhfC8H83 P9Pa5H9Hl8fgU9He2YTVudAxltZWvmYHUdi8+eryb9j01MEbWZSbal1VR8kSh1bxHUp/ F/PvKm8kMpx+QTYzccmS15htc/EhfVSux3IfljytC+m7o6lyF+Xr9e3KpM9EyWGzmeTY LcTwOj0Nb4jY4A1yccSU/E6RqIwBPWHlYmztvbtPGmpe+WDSXqRqhY8hiQYUdWIz/999 b07P2NrvBCqSS5/q1EFn/2BMPIHPghHpBbrSGowTi9IdOyWM1jHJtiDEh51I3qWFzfeR MqRg== X-Forwarded-Encrypted: i=1; AJvYcCUJ/XzzRKKpimDQ1r9arc++lEV7uBfYsyS0EpWEhiIpc/Tz0t/g+Soadnrivb2QeiZfki8uYozUL72GejSCdx0hSSZIjQ56vQkwp01lwK0= X-Gm-Message-State: AOJu0Yx6y9XumT7TbUnm3bIj+Qpu115o5eOwuHL8pfGEWsEi0OfyZ9+j z0M4PnPMaq2MGC8SJuiM1zeVhNshSJpBRvKliLwFzOiGncv+VpiVKdmuCfL2NwbAPMGuYJnllIV 0QS3r2xudrAX4N5DCHibsvgddX1/gZ95GUGx4Q96va2zjia6LXqIM+gWkI87/BZwm X-Received: by 2002:a05:600c:548b:b0:427:fa39:b0db with SMTP id 5b1f17b1804b1-429d487347dmr30344025e9.27.1723559668285; Tue, 13 Aug 2024 07:34:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG9S1VIbZLOEd8TYuQEWYafYxx7AV0xbNqaDFtZ2nyxoqmDI3atbQHIXjCKmWBf0/FxeiUD2w== X-Received: by 2002:a05:600c:548b:b0:427:fa39:b0db with SMTP id 5b1f17b1804b1-429d487347dmr30343785e9.27.1723559667737; Tue, 13 Aug 2024 07:34:27 -0700 (PDT) Received: from ?IPV6:2a01:e0a:c:37e0:ced3:55bd:f454:e722? ([2a01:e0a:c:37e0:ced3:55bd:f454:e722]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36e4c938045sm10585470f8f.43.2024.08.13.07.34.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 13 Aug 2024 07:34:27 -0700 (PDT) Message-ID: Date: Tue, 13 Aug 2024 16:34:26 +0200 Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 2/4] drm/rect: Add drm_rect_overlap() To: Jani Nikula , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , Bjorn Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org, Danilo Krummrich References: <20240812123147.81356-1-jfalempe@redhat.com> <20240812123147.81356-3-jfalempe@redhat.com> <87sev926na.fsf@intel.com> <60e55a9d-70bb-45d1-ac97-e4f6f6ffa9a9@redhat.com> <87frr924nj.fsf@intel.com> <87mslgzf52.fsf@intel.com> From: Jocelyn Falempe In-Reply-To: <87mslgzf52.fsf@intel.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US, fr Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 13/08/2024 16:11, Jani Nikula wrote: > On Mon, 12 Aug 2024, Jani Nikula wrote: >> On Mon, 12 Aug 2024, Jocelyn Falempe wrote: >>> On 12/08/2024 15:49, Jani Nikula wrote: >>>> On Mon, 12 Aug 2024, Jocelyn Falempe wrote: >>>>> 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. >>>> >>>> Based on the name, I'd expect drm_rect_overlap() to return true for >>>> *any* overlap, while this one seems to mean if one rectangle is >>>> completely within another, with no adjacent borders. >>> >>> It's what I intended, but I may have messed up the formula. >> >> Hmm, then I may have messed up the review. :) > > Yeah, my bad, sorry for the noise. > > I think I was thrown off by the comparisons mixing r1 and r2 as the > first operand. Something like this might have been easier for *me* to > parse, but not sure if it's worth changing anything: > > return (a->x1 < b->x2 && a->x2 > b->x1 && > a->y1 < b->y2 && a->y2 > b->y1); You're right, I've used r1 and r2 for consistency with other functions, but for this case it's confusing, I prefer the a/b. If I send a v7 I will do this change. I can also rename when pushing, but I was already bitten by doing this. Best regards, -- Jocelyn > > > BR, > Jani. > > >> >> Gotta run now, but I'll get back. >> >> BR, >> Jani. >> >> >> >>>> >>>> I'd expect a drm_rect_overlap() to return true for this: >>>> >>>> +-------+ >>>> | +---+---+ >>>> | | | >>>> +---+ | >>>> | | >>>> +-------+ >>> >>> if r1 is the top left rectangle, you've got: >>> >>> r1->x2 > r2->x1 => true >>> r2->x2 > r1->x1 => true >>> r1->y2 > r2->y1 => true >>> r2->y2 > r1->y1 => true >>> >>> So they count as overlap. >>> >>> Checking in stackoverflow, they use the same formula: >>> https://stackoverflow.com/questions/306316/determine-if-two-rectangles-overlap-each-other >>> >>>> >>>> While this seems to be required instead: >>>> >>>> +-------+ >>>> | +---+ | >>>> | | | | >>>> | +---+ | >>>> +-------+ >>>> >>>> >>>> IOW, I find the name misleading. >>>> >>>> BR, >>>> Jani. >>>> >>>> >>>>> >>>>> Signed-off-by: Jocelyn Falempe >>>>> --- >>>>> drivers/gpu/drm/drm_panic.c | 3 +-- >>>>> include/drm/drm_rect.h | 15 +++++++++++++++ >>>>> 2 files changed, 16 insertions(+), 2 deletions(-) >>>>> >>>>> diff --git a/drivers/gpu/drm/drm_panic.c b/drivers/gpu/drm/drm_panic.c >>>>> index 0a047152f88b8..59fba23e5fd7a 100644 >>>>> --- a/drivers/gpu/drm/drm_panic.c >>>>> +++ b/drivers/gpu/drm/drm_panic.c >>>>> @@ -529,8 +529,7 @@ static void draw_panic_static_user(struct drm_scanout_buffer *sb) >>>>> /* Fill with the background color, and draw text on top */ >>>>> drm_panic_fill(sb, &r_screen, bg_color); >>>>> >>>>> - if ((r_msg.x1 >= logo_width || r_msg.y1 >= logo_height) && >>>>> - logo_width <= sb->width && logo_height <= sb->height) { >>>>> + if (!drm_rect_overlap(&r_logo, &r_msg)) { >>>>> if (logo_mono) >>>>> drm_panic_blit(sb, &r_logo, logo_mono->data, DIV_ROUND_UP(logo_width, 8), >>>>> fg_color); >>>>> diff --git a/include/drm/drm_rect.h b/include/drm/drm_rect.h >>>>> index 73fcb899a01da..7bafde747d560 100644 >>>>> --- a/include/drm/drm_rect.h >>>>> +++ b/include/drm/drm_rect.h >>>>> @@ -238,6 +238,21 @@ static inline void drm_rect_fp_to_int(struct drm_rect *dst, >>>>> drm_rect_height(src) >> 16); >>>>> } >>>>> >>>>> +/** >>>>> + * drm_rect_overlap - Check if two rectangles overlap >>>>> + * @r1: first rectangle >>>>> + * @r2: second rectangle >>>>> + * >>>>> + * RETURNS: >>>>> + * %true if the rectangles overlap, %false otherwise. >>>>> + */ >>>>> +static inline bool drm_rect_overlap(const struct drm_rect *r1, >>>>> + const struct drm_rect *r2) >>>>> +{ >>>>> + return (r1->x2 > r2->x1 && r2->x2 > r1->x1 && >>>>> + r1->y2 > r2->y1 && r2->y2 > r1->y1); >>>>> +} >>>>> + >>>>> bool drm_rect_intersect(struct drm_rect *r, const struct drm_rect *clip); >>>>> bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst, >>>>> const struct drm_rect *clip); >>>> >>> >