From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 05A5CC48BEF for ; Wed, 14 Feb 2024 06:45:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9A13510E41D; Wed, 14 Feb 2024 06:45:51 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Ji5Dfi8Y"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7936210E41D for ; Wed, 14 Feb 2024 06:45:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707893150; x=1739429150; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UqMzYrtKFM9chdeCSE/xK5HPgASKQdxKu12Bqrdp0eQ=; b=Ji5Dfi8YBmIFUGQDiB9rh24Ow1X6SUp9FRZjn5nMAq8wNmP0VP/Zx/zc eQx8Vtvq/cyg+zYBGQXtQ3skN4sVJ9MP+fAxdDb9wWUFMLKF85YADynP0 NbJSudJD3+DEBpSmdom0yr5SuWFbMSFeGg4a3ojTd2uF+GVQicyocOGXd 03QMw87IYt8Ply+ZTCUDdCGCK3lgMvndoS2qsmMw9JLGEOqJ2Ne83EbKm 9KlIia9m2x7FThArHqKHPbfZWJVYAkoe4M+wYvrV1XtLo61P2p+QW5ZgM l7hcifC0+2v4S7cZcksplOYO1epuR/x2EUWFvpgen7+/CqPBcWqo0tBEW A==; X-IronPort-AV: E=McAfee;i="6600,9927,10982"; a="12645448" X-IronPort-AV: E=Sophos;i="6.06,159,1705392000"; d="scan'208";a="12645448" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2024 22:45:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,159,1705392000"; d="scan'208";a="3427588" Received: from bhanu-nuclab.iind.intel.com ([10.145.169.172]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2024 22:45:49 -0800 From: Bhanuprakash Modem To: igt-dev@lists.freedesktop.org Cc: Harry Wentland Subject: [RFC v4 07/22] lib/igt_fb: Add copy_fb function Date: Wed, 14 Feb 2024 12:09:38 +0530 Message-ID: <20240214063953.1285495-8-bhanuprakash.modem@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214063953.1285495-1-bhanuprakash.modem@intel.com> References: <20240214063953.1285495-1-bhanuprakash.modem@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: igt-dev@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development mailing list for IGT GPU Tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" From: Harry Wentland Signed-off-by: Harry Wentland --- lib/igt_fb.c | 34 ++++++++++++++++++++++++++++++++++ lib/igt_fb.h | 1 + 2 files changed, 35 insertions(+) diff --git a/lib/igt_fb.c b/lib/igt_fb.c index ee9cd1f35..13e9c29b1 100644 --- a/lib/igt_fb.c +++ b/lib/igt_fb.c @@ -2154,6 +2154,40 @@ unsigned int igt_create_fb(int fd, int width, int height, uint32_t format, fb, 0, 0); } +unsigned int igt_copy_fb(int fd, struct igt_fb *src, struct igt_fb *fb) +{ + char *in_ptr, *out_ptr; + int cpp = igt_drm_format_to_bpp(src->drm_format) / 8; + + int fb_id = 0; + igt_assert(src); + + /* TODO allow multiple planes */ + if (src->num_planes != 1) + return -EINVAL; + + /* TODO expand for other formats */ + if (src->drm_format != DRM_FORMAT_XRGB8888) + return -EINVAL; + + fb_id = igt_create_fb(fd, src->width, src->height, src->drm_format, + src->modifier, fb); + + /* copy buffer contents */ + /* TODO simplify :D */ + in_ptr = igt_fb_map_buffer(fb->fd, src); + igt_assert(in_ptr); + out_ptr = igt_fb_map_buffer(fb->fd, fb); + igt_assert(out_ptr); + + igt_memcpy_from_wc(out_ptr, in_ptr, fb->width * fb->height * cpp); + + igt_fb_unmap_buffer(fb, out_ptr); + igt_fb_unmap_buffer(src, in_ptr); + + return fb_id; +} + /** * igt_create_color_fb: * @fd: open drm file descriptor diff --git a/lib/igt_fb.h b/lib/igt_fb.h index d2751c0bb..258a7669e 100644 --- a/lib/igt_fb.h +++ b/lib/igt_fb.h @@ -142,6 +142,7 @@ struct intel_buf *igt_fb_create_intel_buf(int fd, struct buf_ops *bops, const struct igt_fb *fb, const char *name); unsigned int igt_create_fb(int fd, int width, int height, uint32_t format, uint64_t modifier, struct igt_fb *fb); +unsigned int igt_copy_fb(int fd, struct igt_fb *src, struct igt_fb *fb); unsigned int igt_create_color_fb(int fd, int width, int height, uint32_t format, uint64_t modifier, double r, double g, double b, -- 2.43.0