From: Ayan Kumar Halder Subject: [PATCH] drm: Use horizontal and vertical chroma subsampling factor while calculating offsets in the physical address of framebuffer Date: Fri, 17 Aug 2018 18:33:04 +0100 Message-ID: <1534527184-24552-1-git-send-email-ayan.halder@arm.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Sender: linux-kernel-owner@vger.kernel.org To: ayan.halder@arm.com, liviu.dudau@arm.com, brian.starkey@arm.com, gustavo@padovan.org, maarten.lankhorst@linux.intel.com, seanpaul@chromium.org, airlied@linux.ie, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: nd@arm.com List-Id: dri-devel@lists.freedesktop.org For multi-planar formats, while calculating offsets in planes with index greater than 0 (ie second plane, third plane, etc), one needs to divide (src_x * cpp) with horizontal chroma subsampling factor and (src_y * pitch) with vertical chroma subsampling factor. The reason being that the planes contain subsampled (ie reduced) data (by a factor of 2) and thus the while calculating the byte position coresponding to the x and y co-ordinates, one needs to be divide it with the sampling factor. Signed-off-by: Ayan Kumar halder --- drivers/gpu/drm/drm_fb_cma_helper.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_fb_cma_helper.c b/drivers/gpu/drm/drm_fb_cma_helper.c index b127061..47e0e2f 100644 --- a/drivers/gpu/drm/drm_fb_cma_helper.c +++ b/drivers/gpu/drm/drm_fb_cma_helper.c @@ -86,14 +86,21 @@ dma_addr_t drm_fb_cma_get_gem_addr(struct drm_framebuffer *fb, { struct drm_gem_cma_object *obj; dma_addr_t paddr; + u8 h_div = 1, v_div = 1; obj = drm_fb_cma_get_gem_obj(fb, plane); if (!obj) return 0; paddr = obj->paddr + fb->offsets[plane]; - paddr += fb->format->cpp[plane] * (state->src_x >> 16); - paddr += fb->pitches[plane] * (state->src_y >> 16); + + if (plane > 0) { + h_div = fb->format->hsub; + v_div = fb->format->vsub; + } + + paddr += (fb->format->cpp[plane] * (state->src_x >> 16)) / h_div; + paddr += (fb->pitches[plane] * (state->src_y >> 16)) / v_div; return paddr; } -- 2.7.4