From patchwork Mon Aug 6 03:58:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haneen Mohammed X-Patchwork-Id: 10556645 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 AF73214E5 for ; Mon, 6 Aug 2018 08:23:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BBBA202DB for ; Mon, 6 Aug 2018 08:23:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F67829252; Mon, 6 Aug 2018 08:23:52 +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,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,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 03E51202DB for ; Mon, 6 Aug 2018 08:23:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7DD6C6E25F; Mon, 6 Aug 2018 08:20:34 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pl0-x243.google.com (mail-pl0-x243.google.com [IPv6:2607:f8b0:400e:c01::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id E924B6E185 for ; Mon, 6 Aug 2018 04:17:49 +0000 (UTC) Received: by mail-pl0-x243.google.com with SMTP id b90-v6so4291125plb.0 for ; Sun, 05 Aug 2018 21:17:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=umF63rQGu5Fuipa3tVwuoT42KV1RVLFrkp0SSEt4u9A=; b=iwL38RNX1EcmH+tO+n4r95QsyGCptMlRKTQk7oV5WacRL/nfThsEDkjdR7GBfjXwMZ 8Nqq26bIZAA9e00vkQT6F2TQ0fsniuXsXrZZ2OvFuqyfQ/x8DKQiYZMy29bO03V1r53q JPqtKaiEfeNfeG3BNyQOLVHWdF7a2Bt2RURkTt1UK2b5Rfpa49dRS+6sMpbD+r8XQL2S Vpo70Z2dhPm28A3vpXLgZjjLkIiqZABTyion2U54kVqOgTg5Czg11SWPTP8D338AcpXb Z2IHUulsGpLwYMv1cCM+Kd2F025Polg09e9Ny9G2SQEStE+Q+NCGggTrPuukavx8Pjqd 5gDg== X-Gm-Message-State: AOUpUlE4+KeS+VwKAgGNv/4H1rVS1vpp76bsjca+F/NxXMnMaZfL2KZ+ S9F5jk3LkJtcTmw/FLmCUsGCntr7 X-Google-Smtp-Source: AAOMgpc+CW4zLFuxvZyFEEysY5JC4WmSj53rkIR+vQnWX8zdqWOW72jOYYkkmq9RSbXuD3U/bodnLA== X-Received: by 2002:a17:902:290a:: with SMTP id g10-v6mr12420040plb.110.1533529069335; Sun, 05 Aug 2018 21:17:49 -0700 (PDT) Received: from haneenDRM ([64.77.242.50]) by smtp.gmail.com with ESMTPSA id e73-v6sm21819788pfb.153.2018.08.05.21.17.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 05 Aug 2018 21:17:48 -0700 (PDT) Date: Mon, 6 Aug 2018 06:58:29 +0300 From: Haneen Mohammed To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/2] drm/vkms: Compute CRC with Cursor Plane Message-ID: <44b546fedbcf65fd20f7a65d5443fbb50493cf32.1533526327.git.hamohammed.sa@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-Mailman-Approved-At: Mon, 06 Aug 2018 08:20:19 +0000 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: hamohammed.sa@gmail.com, rodrigosiqueiramelo@gmail.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch compute CRC for output frame with cursor and primary plane. Blend cursor with primary plane and compute CRC on the resulted frame. Signed-off-by: Haneen Mohammed --- drivers/gpu/drm/vkms/vkms_crc.c | 149 +++++++++++++++++++++++++----- drivers/gpu/drm/vkms/vkms_drv.h | 5 +- drivers/gpu/drm/vkms/vkms_plane.c | 10 +- 3 files changed, 137 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_crc.c b/drivers/gpu/drm/vkms/vkms_crc.c index 37d717f38e3c..4853a739ae5a 100644 --- a/drivers/gpu/drm/vkms/vkms_crc.c +++ b/drivers/gpu/drm/vkms/vkms_crc.c @@ -1,36 +1,137 @@ // SPDX-License-Identifier: GPL-2.0 #include "vkms_drv.h" #include +#include +#include #include -static uint32_t _vkms_get_crc(struct vkms_crc_data *crc_data) +/** + * compute_crc - Compute CRC value on output frame + * + * @vaddr_out: address to final framebuffer + * @crc_out: framebuffer's metadata + * + * returns CRC value computed using crc32 on the visible portion of + * the final framebuffer at vaddr_out + */ +static uint32_t compute_crc(void *vaddr_out, struct vkms_crc_data *crc_out) { - struct drm_framebuffer *fb = &crc_data->fb; + int i, src_offset; + int x_src = crc_out->src.x1 >> 16; + int y_src = crc_out->src.y1 >> 16; + int h_src = drm_rect_height(&crc_out->src) >> 16; + int w_src = drm_rect_width(&crc_out->src) >> 16; + int size_byte = w_src * crc_out->cpp; + u32 crc = 0; + + for (i = y_src; i < y_src + h_src; i++) { + src_offset = crc_out->offset + + (i * crc_out->pitch) + + (x_src * crc_out->cpp); + crc = crc32_le(crc, vaddr_out + src_offset, size_byte); + } + + return crc; +} + +/** + * blend - belnd value at vaddr_src with value at vaddr_dst + * @vaddr_dst: destination address + * @vaddr_src: source address + * @crc_dst: destination framebuffer's metadata + * @crc_src: source framebuffer's metadata + * + * Blend value at vaddr_src with value at vaddr_dst. + * Currently, this function write value at vaddr_src on value + * at vaddr_dst using buffer's metadata to locate the new values + * from vaddr_src and their distenation at vaddr_dst. + * + * Todo: Use the alpha value to blend vaddr_src with vaddr_dst + * instead of overwriting it. + */ +static void blend(void *vaddr_dst, void *vaddr_src, + struct vkms_crc_data *crc_dst, + struct vkms_crc_data *crc_src) +{ + int i, j, j_dst, i_dst; + int offset_src, offset_dst; + + int x_src = crc_src->src.x1 >> 16; + int y_src = crc_src->src.y1 >> 16; + + int x_dst = crc_src->dst.x1; + int y_dst = crc_src->dst.y1; + int h_dst = drm_rect_height(&crc_src->dst); + int w_dst = drm_rect_width(&crc_src->dst); + + int y_limit = y_src + h_dst; + int x_limit = x_src + w_dst; + + for (i = y_src, i_dst = y_dst; i < y_limit; ++i) { + for (j = x_src, j_dst = x_dst; j < x_limit; ++j) { + offset_dst = crc_dst->offset + + (i_dst * crc_dst->pitch) + + (j_dst++ * crc_dst->cpp); + offset_src = crc_src->offset + + (i * crc_src->pitch) + + (j * crc_src->cpp); + + memcpy(vaddr_dst + offset_dst, + vaddr_src + offset_src, sizeof(u32)); + } + i_dst++; + } +} + +static void compose_cursor(struct vkms_crc_data *cursor_crc, + struct vkms_crc_data *primary_crc, void *vaddr_out) +{ + struct drm_gem_object *cursor_obj; + struct vkms_gem_object *cursor_vkms_obj; + + cursor_obj = drm_gem_fb_get_obj(&cursor_crc->fb, 0); + cursor_vkms_obj = drm_gem_to_vkms_gem(cursor_obj); + + mutex_lock(&cursor_vkms_obj->pages_lock); + if (WARN_ON(!cursor_vkms_obj->vaddr)) + goto out; + + blend(vaddr_out, cursor_vkms_obj->vaddr, primary_crc, cursor_crc); + +out: + mutex_unlock(&cursor_vkms_obj->pages_lock); +} + +static uint32_t _vkms_get_crc(struct vkms_crc_data *primary_crc, + struct vkms_crc_data *cursor_crc) +{ + struct drm_framebuffer *fb = &primary_crc->fb; struct drm_gem_object *gem_obj = drm_gem_fb_get_obj(fb, 0); struct vkms_gem_object *vkms_obj = drm_gem_to_vkms_gem(gem_obj); + void *vaddr_out = kzalloc(vkms_obj->gem.size, GFP_KERNEL); u32 crc = 0; - int i = 0; - unsigned int x = crc_data->src.x1 >> 16; - unsigned int y = crc_data->src.y1 >> 16; - unsigned int height = drm_rect_height(&crc_data->src) >> 16; - unsigned int width = drm_rect_width(&crc_data->src) >> 16; - unsigned int cpp = fb->format->cpp[0]; - unsigned int src_offset; - unsigned int size_byte = width * cpp; - void *vaddr; - mutex_lock(&vkms_obj->pages_lock); - vaddr = vkms_obj->vaddr; - if (WARN_ON(!vaddr)) - goto out; + if (!vaddr_out) { + DRM_ERROR("Failed to allocate memory for output frame."); + return 0; + } - for (i = y; i < y + height; i++) { - src_offset = fb->offsets[0] + (i * fb->pitches[0]) + (x * cpp); - crc = crc32_le(crc, vaddr + src_offset, size_byte); + mutex_lock(&vkms_obj->pages_lock); + if (WARN_ON(!vkms_obj->vaddr)) { + mutex_lock(&vkms_obj->pages_lock); + return crc; } -out: + memcpy(vaddr_out, vkms_obj->vaddr, vkms_obj->gem.size); mutex_unlock(&vkms_obj->pages_lock); + + if (cursor_crc) + compose_cursor(cursor_crc, primary_crc, vaddr_out); + + crc = compute_crc(vaddr_out, primary_crc); + + kfree(vaddr_out); + return crc; } @@ -44,8 +145,8 @@ void vkms_crc_work_handle(struct work_struct *work) struct vkms_device *vdev = container_of(out, struct vkms_device, output); struct vkms_crc_data *primary_crc = NULL; + struct vkms_crc_data *cursor_crc = NULL; struct drm_plane *plane; - u32 crc32 = 0; drm_for_each_plane(plane, &vdev->drm) { @@ -58,14 +159,14 @@ void vkms_crc_work_handle(struct work_struct *work) if (drm_framebuffer_read_refcount(&crc_data->fb) == 0) continue; - if (plane->type == DRM_PLANE_TYPE_PRIMARY) { + if (plane->type == DRM_PLANE_TYPE_PRIMARY) primary_crc = crc_data; - break; - } + else + cursor_crc = crc_data; } if (primary_crc) - crc32 = _vkms_get_crc(primary_crc); + crc32 = _vkms_get_crc(primary_crc, cursor_crc); drm_crtc_add_crc_entry(crtc, true, crtc_state->n_frame, &crc32); } diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index 36e524f791fe..173875dc361e 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -25,8 +25,11 @@ static const u32 vkms_cursor_formats[] = { }; struct vkms_crc_data { - struct drm_rect src; struct drm_framebuffer fb; + struct drm_rect src, dst; + unsigned int offset; + unsigned int pitch; + unsigned int cpp; }; /** diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c index 428247d403dc..7041007396ae 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -85,16 +85,22 @@ static void vkms_plane_atomic_update(struct drm_plane *plane, struct drm_plane_state *old_state) { struct vkms_plane_state *vkms_plane_state; + struct drm_framebuffer *fb = plane->state->fb; struct vkms_crc_data *crc_data; - if (!plane->state->crtc || !plane->state->fb) + if (!plane->state->crtc || !fb) return; vkms_plane_state = to_vkms_plane_state(plane->state); + crc_data = vkms_plane_state->crc_data; memcpy(&crc_data->src, &plane->state->src, sizeof(struct drm_rect)); - memcpy(&crc_data->fb, plane->state->fb, sizeof(struct drm_framebuffer)); + memcpy(&crc_data->dst, &plane->state->dst, sizeof(struct drm_rect)); + memcpy(&crc_data->fb, fb, sizeof(struct drm_framebuffer)); drm_framebuffer_get(&crc_data->fb); + crc_data->offset = fb->offsets[0]; + crc_data->pitch = fb->pitches[0]; + crc_data->cpp = fb->format->cpp[0]; } static int vkms_plane_atomic_check(struct drm_plane *plane,