From patchwork Wed Sep 5 23:38:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Singh Rawat X-Patchwork-Id: 10589627 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2652D174C for ; Wed, 5 Sep 2018 23:39:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1508A2AA6B for ; Wed, 5 Sep 2018 23:39:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 095D62AA71; Wed, 5 Sep 2018 23:39:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 98DA22AA6B for ; Wed, 5 Sep 2018 23:39:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 70B066E442; Wed, 5 Sep 2018 23:39:31 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from EX13-EDG-OU-002.vmware.com (ex13-edg-ou-002.vmware.com [208.91.0.190]) by gabe.freedesktop.org (Postfix) with ESMTPS id BF3826E442 for ; Wed, 5 Sep 2018 23:39:29 +0000 (UTC) Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Wed, 5 Sep 2018 16:39:22 -0700 Received: from ubuntu.localdomain (promb-2n-dhcp79.eng.vmware.com [10.20.88.79]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 57A4FB0749; Wed, 5 Sep 2018 19:39:29 -0400 (EDT) From: Deepak Rawat To: , , , Subject: [PATCH 02/14] drm: add helper iterator functions for plane fb_damage_clips blob Date: Wed, 5 Sep 2018 16:38:49 -0700 Message-ID: <20180905233901.2321-3-drawat@vmware.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180905233901.2321-1-drawat@vmware.com> References: <20180905233901.2321-1-drawat@vmware.com> MIME-Version: 1.0 Received-SPF: None (EX13-EDG-OU-002.vmware.com: drawat@vmware.com does not designate permitted sender hosts) X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Deepak Rawat , lukasz.spintzyk@displaylink.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP With fb_damage_clips blob property in drm_plane_state, this patch adds helper iterator to traverse the damage clips that lie inside plane src. Iterator will return full plane src as damage in case need full plane update or damage is not specified. Signed-off-by: Deepak Rawat --- drivers/gpu/drm/drm_damage_helper.c | 93 +++++++++++++++++++++++++++++ include/drm/drm_damage_helper.h | 20 +++++++ 2 files changed, 113 insertions(+) diff --git a/drivers/gpu/drm/drm_damage_helper.c b/drivers/gpu/drm/drm_damage_helper.c index 3e7de5afe7f6..7d70f6001889 100644 --- a/drivers/gpu/drm/drm_damage_helper.c +++ b/drivers/gpu/drm/drm_damage_helper.c @@ -30,6 +30,7 @@ **************************************************************************/ #include +#include #include /** @@ -75,6 +76,11 @@ * While kernel does not error for overlapped damage clips, it is discouraged. */ +static int convert_fixed_to_32(int fixed) +{ + return ((fixed >> 15) & 1) + (fixed >> 16); +} + /** * drm_plane_enable_fb_damage_clips - enables plane fb damage clips property * @plane: plane on which to enable damage clips property @@ -90,3 +96,90 @@ void drm_plane_enable_fb_damage_clips(struct drm_plane *plane) 0); } EXPORT_SYMBOL(drm_plane_enable_fb_damage_clips); + +/** + * drm_atomic_helper_damage_iter_init - initialize the damage iterator + * @iter: The iterator to initialize. + * @old_state: old plane state for validation. + * @new_state: plane state from which to iterate the damage clips. + * + * Initialize an iterator that clip framebuffer damage in plane fb_damage_clips + * blob to plane src clip. The iterator returns full plane src in case needing + * full update e.g. during full modeset. + * + * With this helper iterator, drivers which enabled fb_damage_clips property can + * iterate over the damage clips that falls inside plane src during plane + * update. + * + * Returns: 0 on success and negative error code on error. If an error code is + * returned then it means the plane state shouldn't update with attached fb. + */ +int +drm_atomic_helper_damage_iter_init(struct drm_atomic_helper_damage_iter *iter, + const struct drm_plane_state *old_state, + const struct drm_plane_state *new_state) +{ + if (!new_state || !new_state->crtc || !new_state->fb) + return -EINVAL; + + if (!new_state->visible) + return -EINVAL; + + memset(iter, 0, sizeof(*iter)); + iter->clips = drm_plane_get_damage_clips(new_state); + iter->num_clips = drm_plane_get_damage_clips_count(new_state); + + if (!iter->clips) + iter->full_update = true; + + if (!drm_rect_equals(&new_state->src, &old_state->src)) + iter->full_update = true; + + iter->plane_src.x1 = convert_fixed_to_32(new_state->src.x1); + iter->plane_src.y1 = convert_fixed_to_32(new_state->src.y1); + iter->plane_src.x2 = convert_fixed_to_32(new_state->src.x2); + iter->plane_src.y2 = convert_fixed_to_32(new_state->src.y2); + + if (iter->full_update) { + iter->clips = 0; + iter->curr_clip = 0; + iter->num_clips = 0; + } + + return 0; +} +EXPORT_SYMBOL(drm_atomic_helper_damage_iter_init); + +/** + * drm_atomic_helper_damage_iter_next - advance the damage iterator + * @iter: The iterator to advance. + * @rect: Return a rectangle in fb coordinate clipped to plane src. + * + * Returns: true if the output is valid, false if we've reached the end of the + * rectangle list. + */ +bool +drm_atomic_helper_damage_iter_next(struct drm_atomic_helper_damage_iter *iter, + struct drm_rect *rect) +{ + bool ret = false; + + if (iter->full_update) { + *rect = iter->plane_src; + iter->full_update = false; + return true; + } + + while (iter->curr_clip < iter->num_clips) { + *rect = iter->clips[iter->curr_clip]; + iter->curr_clip++; + + if (drm_rect_intersect(rect, &iter->plane_src)) { + ret = true; + break; + } + } + + return ret; +} +EXPORT_SYMBOL(drm_atomic_helper_damage_iter_next); diff --git a/include/drm/drm_damage_helper.h b/include/drm/drm_damage_helper.h index 217694e9168c..f1282b459a4f 100644 --- a/include/drm/drm_damage_helper.h +++ b/include/drm/drm_damage_helper.h @@ -32,6 +32,19 @@ #ifndef DRM_DAMAGE_HELPER_H_ #define DRM_DAMAGE_HELPER_H_ +/** + * struct drm_atomic_helper_damage_iter - damage clip iterator + * + * This iterator tracks state needed to walk the list of damage clips. + */ +struct drm_atomic_helper_damage_iter { + const struct drm_rect *clips; + struct drm_rect plane_src; + uint32_t num_clips; + uint32_t curr_clip; + bool full_update; +}; + /** * drm_plane_get_damage_clips_count - returns damage clips count * @state: Plane state @@ -59,5 +72,12 @@ drm_plane_get_damage_clips(const struct drm_plane_state *state) } void drm_plane_enable_fb_damage_clips(struct drm_plane *plane); +int +drm_atomic_helper_damage_iter_init(struct drm_atomic_helper_damage_iter *iter, + const struct drm_plane_state *old_state, + const struct drm_plane_state *new_state); +bool +drm_atomic_helper_damage_iter_next(struct drm_atomic_helper_damage_iter *iter, + struct drm_rect *rect); #endif