From patchwork Tue Mar 1 06:44:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kshitij Suri X-Patchwork-Id: 12764203 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 CD9DCC433EF for ; Tue, 1 Mar 2022 06:49:29 +0000 (UTC) Received: from localhost ([::1]:60776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nOwK8-0001E0-R5 for qemu-devel@archiver.kernel.org; Tue, 01 Mar 2022 01:49:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58096) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nOwFd-00081Z-G9 for qemu-devel@nongnu.org; Tue, 01 Mar 2022 01:44:49 -0500 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]:43794) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nOwFa-0006V5-QC for qemu-devel@nongnu.org; Tue, 01 Mar 2022 01:44:48 -0500 Received: from pps.filterd (m0127837.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 21SJ6rSc015219; Mon, 28 Feb 2022 22:44:32 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : content-type : mime-version; s=proofpoint20171006; bh=9vARoc5tEfrCv0LNPooRMlevnMa0GTxPsLKqJcDA3Hc=; b=xrGNuokPK7ZBY6W/xW7zxSJJ1S0VYhwGHwHN3lR3iYqDo+sQDxsr3dbpRnsUvpAVRTQs PIgWs7boPUfJXfvvuCRHs3u5G4oLpsdU7BdZBhWjWFoh7aeYo+acf2LqVtpMS1i8HMnB nC58wz/ZO8e1T8pmOMS9GgE8jrPTemQJls5VBbtnwRPkHPYMjG2zfucTH3jz5f4nhx/t OSGgraJcEVpQIfj5NWFYIKR2HuDo2Ibw+VkG1R4MEngxTQTIXom6CCoiqLLF2HoKPjAi YG3MQwXDrRZEBi3cLyAqym9xWhyIDxLEql0OKrMgJcP/h7RFHmLXODATo/agJUD9IoJU Og== Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2106.outbound.protection.outlook.com [104.47.58.106]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3egue3j7b3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Feb 2022 22:44:31 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d79kwoK2/tcPxuhEOPLa4n+enm7kxbqLT+UqlYfWNPyORTAi0mHPIQpxNioee9iN+RbXRXOcZQgLkFO80zzdTucuylKNoPKQn3juofHvMDUnzTIanby1uUYxoTj8M8ovZ1wNpe6eFIJe9J0ApFs1w/pE0r8vz9u9oBBWbhs+m2U4gCzRqy4/GOuam1eTMiq695iKTSj88vT8ZdEKIzO/FsVcWe4cASqzA710PoadAmd43R/Xz9rNTyKA3dqaebIYxc5sxna+cLVs9Y/JVGv8ae7p0Of+KhEM0Up0Zfkcan8HiZGbmXwmjz0x96SrbIkD99fulYmbQuPFbe/wI1VqLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9vARoc5tEfrCv0LNPooRMlevnMa0GTxPsLKqJcDA3Hc=; b=CSk1nNuklNq/+KgPeD0KxdAMBfUM1DNghMiExS5nOPv+OPINiqzPlhMYJFUO43U1IAM8JhOyeYKpkqcjVN4tg1B0ZBnFM3CNl09hqIykMYk2RNCTxaJJgFRupCbb8naLs4zfArVATAuDfd1edQw9GbZrpbPiaxlOkyFZPcMgY/HfmeyNf0oLvdyZbs3WvA31lIWhSJRXVBHZR3eXbOm8pRdikA4L31oC5h+2qRMRh8GQ2CAOKaqUcyZoJUleN05KmCENzWpBtYkGBxvSl+y/1cnCSD8koCPz+Rs+HFuMPB0cvFMJ34xpIgn1ioQFG/zHhYzSE643MATr5AGOredJoQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nutanix.com; dmarc=pass action=none header.from=nutanix.com; dkim=pass header.d=nutanix.com; arc=none Received: from SN6PR02MB4048.namprd02.prod.outlook.com (2603:10b6:805:2c::26) by BY5PR02MB7011.namprd02.prod.outlook.com (2603:10b6:a03:23c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22; Tue, 1 Mar 2022 06:44:30 +0000 Received: from SN6PR02MB4048.namprd02.prod.outlook.com ([fe80::94d7:26e1:9b7a:657f]) by SN6PR02MB4048.namprd02.prod.outlook.com ([fe80::94d7:26e1:9b7a:657f%5]) with mapi id 15.20.5017.027; Tue, 1 Mar 2022 06:44:29 +0000 From: Kshitij Suri To: qemu-devel@nongnu.org Subject: [PATCH v2 1/2] Replacing CONFIG_VNC_PNG with CONFIG_PNG Date: Tue, 1 Mar 2022 06:44:23 +0000 Message-Id: <20220301064424.136234-1-kshitij.suri@nutanix.com> X-Mailer: git-send-email 2.22.3 X-ClientProxiedBy: SJ0PR13CA0208.namprd13.prod.outlook.com (2603:10b6:a03:2c3::33) To SN6PR02MB4048.namprd02.prod.outlook.com (2603:10b6:805:2c::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e6e6981a-f8e7-4303-3458-08d9fb4eefad X-MS-TrafficTypeDiagnostic: BY5PR02MB7011:EE_ X-Microsoft-Antispam-PRVS: x-proofpoint-crosstenant: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bqOFT0Fbw0v8yRAzoG7729PatiQPofIEdOUSOMIxh4a+VZNtDxCJkgRg2pr3imPWe5YllIgAYva5FjAb45wRiZBRnHnH7IZF0UImJ9jKZ2oHf0TNEeDSnt7MFEouhxawt7E0n2Phw+y52iUXS6a8wzo9FWxIFn1pomVbyetGsMComzLFvmovMBRQdM4jnOOJzNcyl1wmWCMazXZwlVSKeL5HytDlx7dRuKcAGdClBFneJaYfaCYwgyjwXj87dSkVWZpK502CNOt+TskBUPEGyYYWgj3F4IMdf6hS2x5CM9XjKPTMvu95Wfj8NJtKQFNnRJo16lJxqdqievsMg+S9D6qD9cvMdWWKpUPY6lcrJgRE2kpZ9X+w4FIcQXPVqmxJhru4DyUxzKuWT+YJJgMY0a8GZrzk1+NcJ6fJquBFKdoBHTwgWjtMljhWbM26VaqdgPZFmUj4wvMtiYYf5+3KNND87I05IQxvTGY0crGjWvxJYRCxRl7yHbQELFbQXBhrKo5enuLP0mtQIYPwtiWPp+jNO90UAstHmLYjJIkRNZm+8aX3senndNlAEZXUD+aiqBj0yPAiPiVDrmccaGW71Gl3uBrmynzHTpUty0TJ7x0KJEIcQl3O278Fe/+/gb3ixSO3PSwQTj2RXLNWzVqmDFF5G0qcLEXEoEHpLMl7m03eg3fY9yexBKHpymad3FLfM+kMjSTjQAZp7+i4uLyKPg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR02MB4048.namprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(107886003)(186003)(6512007)(6666004)(83380400001)(6506007)(6916009)(1076003)(2616005)(26005)(6486002)(316002)(52116002)(8936002)(5660300002)(44832011)(508600001)(2906002)(86362001)(38100700002)(38350700002)(36756003)(4326008)(66946007)(66556008)(66476007)(8676002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZafqwR+hqzY7LLvRp65QN4+nrplF0msOWCe/dvZ6ZMxdn1JQ7Y0KS+aJdIUKq8dmQVjwR+K18kXV4RrsdgUZ1IFjOEJIOiC6we1/jnneVZH7MsjiCm1+7vYSL0GM6LOvQwpek4DjTboePzaELyky5xZLbx6PmaBagltSthk77/AkNYZMPpwZOZlEn2BgBYhmzAHdyCnQvIp0+lQwzGUuPVkFtHLLfvhFrkFUmfJJQZmriGc5S/pGN2cryVhvd6TLAL+MTK2YnUQqzPfxkup6sKVzA/rkYszFo+vUWpZx9Jb4tQAV3nWt5QSFKna84IFq7iD6vuZU61EzoXhMi7AcuKsS2KayUHqNBf+tAZ889GOXWRcOefJPcLqUOrBrtulCod0ldcv7sQ4YqFLMKBiQE9Kvbm/D5GJwWtUfONuTTxwRZdSHQEQM1EmkHcnak8O5UoQSWju0SOunkCrw8wRX7qp93BUeJk4KBtK8ytyBkQrGOoV16odkP8DHnRNKIpygAXEv+Gw7jOGYDHTcNMWHmsDA2tgDzOlpvlkR71pHx1n8cG2lG+1Xfe86ZdwdIo7xg3Zd1IHUbzb1uAoXOknJxNkQVqy8fP6hZ/1FHGR+3sEHvvbPzTFJhDVzHmZzuMT1Vs9/CVy4wOpgan+IAxFM27PB2YIW7uDbP6zomjjAXmCa+qNTdsbQ6FnaX1jf+UVYkO6ZWFAF959UkoPr/v2sMGt0Qx/HF0/93DT+PR5ZHPrmJbQFZHh7/BQ2Tdf/Gan51Q3gT4Ezkw2BVU3kQ5peDxypE2jQDYOn3ljt9uSxrKaOB7ipC1PBlftFvbdohQXdci39VSrEpEClyUHYWfdW5N+tZLVB4b6J92OtMPkU+kyfGxvbV6QJkbsnpDQYjW6xf00gVKIpD+S1xgPdCRKwii9gVklDAMY/9z+BWGEd9iObMT9cHjFRGPlpqOVD/3akGiZdiIkAy7fsq0FnxHRMg2Uxzy8MW6A11vlW1yqsQuWIEl4bjrnMjoO9ct07QPMxLwCuR4OIbKHGd/OwPSoLfv8Yw9XTN1GeIshLWRwZEkQIF2q9b3Tt33v2B03DtrezR8PLy6cJvaPpyUgbrAINH2H6FxJyiidCq9NiEk+A7Jctaw5pLW3Ye3cPuX8s4AKGtCFewJIpNw+wbzHweWqk2k1S+GgT29S0gT4o/N1xaj2X4Rv4gLFSrNhcJcOr7UEU3APeOtVCY5YidWWfAIIjfJ7aNVJh0BveByXB2WgauCUQ+xoedYeBe5vH/86P7e5WKuMw3wc0GDNrLIVY8LGi5UygHvrxFFIP8Q3mZ/FeDAKulkodrH5qu0ideRBFqSlhmiajT6eZC59c4jVtXKeJkIG3X7CSKm6W2oOosVHgq10eaqji6ovRFs6634IF+tmbqA7YwbpakZJGs718naxeOeeXRW+m+Jjc1srPKL2cdVTO1tPsqObhmeI7vdxYG6JBDs7M1LRIgfbQ5Z8ngG41uAHRmY4PDRoGuZt04ag0LPUZF78dQGByFNAmwC2C61673yPR6n+AH/Ao32rOwWITCfQAmvgJGsrJzRR2hQjS0q8yYoLvLhWqMC12thSjkYQ9+XLcSqKeTUxggOpBJqELz63UYc+QK/h0wtluRf54+uIZjq4TfdszsqQ8WiE5gha7h2YKLhKXbvVR/l9B3GGyNIgkEE1VBkuVVcepCDGnrQs= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: e6e6981a-f8e7-4303-3458-08d9fb4eefad X-MS-Exchange-CrossTenant-AuthSource: SN6PR02MB4048.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2022 06:44:29.8324 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: JETee9gTURaxi9VR0Z0pG6c/loYx2j6mpue1RBO3npxXpFWK6GQCUQEPdY6aLO0KPUmvRzLFCso4VhmxhTq0Fm5PDqOTEbJOmx84hM12G5A= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR02MB7011 X-Proofpoint-GUID: F6N7yJIQk8E8QOulZQ9iPGf-w3MRoCRJ X-Proofpoint-ORIG-GUID: F6N7yJIQk8E8QOulZQ9iPGf-w3MRoCRJ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-02-28_10,2022-02-26_01,2022-02-23_01 X-Proofpoint-Spam-Reason: safe Received-SPF: pass client-ip=148.163.151.68; envelope-from=kshitij.suri@nutanix.com; helo=mx0a-002c1b01.pphosted.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: soham.ghosh@nutanix.com, thuth@redhat.com, prerna.saxena@nutanix.com, dgilbert@redhat.com, armbru@redhat.com, Kshitij Suri , kraxel@redhat.com, prachatos.mitra@nutanix.com, eblake@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Libpng is only detected if VNC is enabled currently. This patch adds a generalised png option in the meson build which is aimed to replace use of CONFIG_VNC_PNG with CONFIG_PNG. Signed-off-by: Kshitij Suri --- meson.build | 9 ++++----- meson_options.txt | 4 ++-- ui/vnc-enc-tight.c | 18 +++++++++--------- ui/vnc.c | 4 ++-- ui/vnc.h | 2 +- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/meson.build b/meson.build index 8df40bfac4..3b67f83a2c 100644 --- a/meson.build +++ b/meson.build @@ -1112,14 +1112,13 @@ if gtkx11.found() x11 = dependency('x11', method: 'pkg-config', required: gtkx11.found(), kwargs: static_kwargs) endif +png = dependency('libpng', required: get_option('png'), + method: 'pkg-config', kwargs: static_kwargs) vnc = not_found -png = not_found jpeg = not_found sasl = not_found if get_option('vnc').allowed() and have_system vnc = declare_dependency() # dummy dependency - png = dependency('libpng', required: get_option('vnc_png'), - method: 'pkg-config', kwargs: static_kwargs) jpeg = dependency('libjpeg', required: get_option('vnc_jpeg'), method: 'pkg-config', kwargs: static_kwargs) sasl = cc.find_library('sasl2', has_headers: ['sasl/sasl.h'], @@ -1537,9 +1536,9 @@ config_host_data.set('CONFIG_TPM', have_tpm) config_host_data.set('CONFIG_USB_LIBUSB', libusb.found()) config_host_data.set('CONFIG_VDE', vde.found()) config_host_data.set('CONFIG_VHOST_USER_BLK_SERVER', have_vhost_user_blk_server) +config_host_data.set('CONFIG_PNG', png.found()) config_host_data.set('CONFIG_VNC', vnc.found()) config_host_data.set('CONFIG_VNC_JPEG', jpeg.found()) -config_host_data.set('CONFIG_VNC_PNG', png.found()) config_host_data.set('CONFIG_VNC_SASL', sasl.found()) config_host_data.set('CONFIG_VIRTFS', have_virtfs) config_host_data.set('CONFIG_VTE', vte.found()) @@ -3579,11 +3578,11 @@ summary_info += {'curses support': curses} summary_info += {'virgl support': virgl} summary_info += {'curl support': curl} summary_info += {'Multipath support': mpathpersist} +summary_info += {'PNG support': png} summary_info += {'VNC support': vnc} if vnc.found() summary_info += {'VNC SASL support': sasl} summary_info += {'VNC JPEG support': jpeg} - summary_info += {'VNC PNG support': png} endif if targetos not in ['darwin', 'haiku', 'windows'] summary_info += {'OSS support': oss} diff --git a/meson_options.txt b/meson_options.txt index 52b11cead4..d85734f8e6 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -177,12 +177,12 @@ option('vde', type : 'feature', value : 'auto', description: 'vde network backend support') option('virglrenderer', type : 'feature', value : 'auto', description: 'virgl rendering support') +option('png', type : 'feature', value : 'auto', + description: 'PNG support with libpng') option('vnc', type : 'feature', value : 'auto', description: 'VNC server') option('vnc_jpeg', type : 'feature', value : 'auto', description: 'JPEG lossy compression for VNC server') -option('vnc_png', type : 'feature', value : 'auto', - description: 'PNG compression for VNC server') option('vnc_sasl', type : 'feature', value : 'auto', description: 'SASL authentication for VNC server') option('vte', type : 'feature', value : 'auto', diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c index cebd35841a..a23ad712eb 100644 --- a/ui/vnc-enc-tight.c +++ b/ui/vnc-enc-tight.c @@ -32,7 +32,7 @@ INT32 definitions between jmorecfg.h (included by jpeglib.h) and Win32 basetsd.h (included by windows.h). */ -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG /* The following define is needed by pngconf.h. Otherwise it won't compile, because setjmp.h was already included by qemu-common.h. */ #define PNG_SKIP_SETJMP_CHECK @@ -95,7 +95,7 @@ static const struct { }; #endif -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG static const struct { int png_zlib_level, png_filters; } tight_png_conf[] = { @@ -919,7 +919,7 @@ static int send_full_color_rect(VncState *vs, int x, int y, int w, int h) int stream = 0; ssize_t bytes; -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG if (tight_can_send_png_rect(vs, w, h)) { return send_png_rect(vs, x, y, w, h, NULL); } @@ -966,7 +966,7 @@ static int send_mono_rect(VncState *vs, int x, int y, int stream = 1; int level = tight_conf[vs->tight->compression].mono_zlib_level; -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG if (tight_can_send_png_rect(vs, w, h)) { int ret; int bpp = vs->client_pf.bytes_per_pixel * 8; @@ -1020,7 +1020,7 @@ static int send_mono_rect(VncState *vs, int x, int y, struct palette_cb_priv { VncState *vs; uint8_t *header; -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG png_colorp png_palette; #endif }; @@ -1082,7 +1082,7 @@ static int send_palette_rect(VncState *vs, int x, int y, int colors; ssize_t bytes; -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG if (tight_can_send_png_rect(vs, w, h)) { return send_png_rect(vs, x, y, w, h, palette); } @@ -1233,7 +1233,7 @@ static int send_jpeg_rect(VncState *vs, int x, int y, int w, int h, int quality) /* * PNG compression stuff. */ -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG static void write_png_palette(int idx, uint32_t pix, void *opaque) { struct palette_cb_priv *priv = opaque; @@ -1379,7 +1379,7 @@ static int send_png_rect(VncState *vs, int x, int y, int w, int h, buffer_reset(&vs->tight->png); return 1; } -#endif /* CONFIG_VNC_PNG */ +#endif /* CONFIG_PNG */ static void vnc_tight_start(VncState *vs) { @@ -1706,7 +1706,7 @@ void vnc_tight_clear(VncState *vs) #ifdef CONFIG_VNC_JPEG buffer_free(&vs->tight->jpeg); #endif -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG buffer_free(&vs->tight->png); #endif } diff --git a/ui/vnc.c b/ui/vnc.c index 3ccd33dedc..a588ddff1c 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -2165,7 +2165,7 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings) vs->features |= VNC_FEATURE_TIGHT_MASK; vs->vnc_encoding = enc; break; -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG case VNC_ENCODING_TIGHT_PNG: vs->features |= VNC_FEATURE_TIGHT_PNG_MASK; vs->vnc_encoding = enc; @@ -3248,7 +3248,7 @@ static void vnc_connect(VncDisplay *vd, QIOChannelSocket *sioc, #ifdef CONFIG_VNC_JPEG buffer_init(&vs->tight->jpeg, "vnc-tight-jpeg/%p", sioc); #endif -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG buffer_init(&vs->tight->png, "vnc-tight-png/%p", sioc); #endif buffer_init(&vs->zlib.zlib, "vnc-zlib/%p", sioc); diff --git a/ui/vnc.h b/ui/vnc.h index a7149831f9..a60fb13115 100644 --- a/ui/vnc.h +++ b/ui/vnc.h @@ -201,7 +201,7 @@ typedef struct VncTight { #ifdef CONFIG_VNC_JPEG Buffer jpeg; #endif -#ifdef CONFIG_VNC_PNG +#ifdef CONFIG_PNG Buffer png; #endif int levels[4]; From patchwork Tue Mar 1 06:44:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kshitij Suri X-Patchwork-Id: 12764202 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 0BCECC433EF for ; Tue, 1 Mar 2022 06:49:25 +0000 (UTC) Received: from localhost ([::1]:60720 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nOwK4-0001CC-B0 for qemu-devel@archiver.kernel.org; Tue, 01 Mar 2022 01:49:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58098) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nOwFd-00081a-LR for qemu-devel@nongnu.org; Tue, 01 Mar 2022 01:44:49 -0500 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]:45554) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nOwFa-0006V7-Ji for qemu-devel@nongnu.org; Tue, 01 Mar 2022 01:44:48 -0500 Received: from pps.filterd (m0127837.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 21SJ6rSd015219; Mon, 28 Feb 2022 22:44:32 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=proofpoint20171006; bh=NYCMju0WDUbq3rzKzdyYFCVY2lTv4dpl2JCLkXoRvQE=; b=ngN+vfJWTWmEASZyhHzzgIQAhCoT4G8PzOQANjENBch6LslKVrS6v28q5z/frqsIEycL 7MP1RCWpYyPFfPJoLdjwkdDqcLvORXt1wnxGr8EJFK7KXLP3CwVRzjNzn6TmCIP7grD+ j7tI0KtieNbyA1wv9IMeXjFD8+lO/0GUCONA0xbKpaQv1tjedoFvCWBY8N4otepPBKT7 m4YmMEmwseuwCO5BiTM/98GKUtNSkvd8Fp6RMF4mgXdvEVC0rFQgLdhrt8CRiK8aKA7h MnCIgsI3hohACh1JmLweLWNPI+aEJ2vHY4m2ocTkPSaA635RINJlLTFco+jp4xr/ISqO Mg== Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2106.outbound.protection.outlook.com [104.47.58.106]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3egue3j7b3-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Feb 2022 22:44:32 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XQA7QlSo6I+eiWghhsCu9xVIgRiSGBELqs6l0O3S42Dt2pxz+tsyECsWsBZshutCz4hi4l2/UJqI2ko1zgPCT+OJ15h5iHqmkyb/0ebAFChxwV3JguXpE6oZYKZLNSBIBWc9gzwHqH31aaN+RPRsbCixS6rf8kHgBV/5I3qa3uTxB3gZa2Q2+qzzvhwk1eeFCLyr3Yg4yCwav+LOeOxc19TJuLjTHzhUmXYqTjBO5HKwZ1uACKKE6c8lOv7DMmXg1T5bbhSPJMSpdJhZCMCaZjDepvN5x9OZZ4LKfiJh72c2337z/FcyCU0Gmc17Jnrlhxswrgh84SGG2lZxpGKleg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NYCMju0WDUbq3rzKzdyYFCVY2lTv4dpl2JCLkXoRvQE=; b=JK6VQowkxW0JsKoaE1VbkGKq2xLjTVP+Hkrebiy+/Ds9UdH8UZDmzyNAaBJYVHzrFpDw4Tb1Rkt9qME6EszconmothOIl98+3A0dXsEOf4jN0fL9GCwa4QQ+nSHB1iJNevXFJ8KWnzU3r1zdSY8L9mimMNpgX4ePs28N0YHfiSWh/NUtPXDf+qXTcax4+JXwcmdNmIPv+1fAXvsRKR4V0rTulGHF3yDogrMWom5S05TM9pVxyY7+O3h7QReqCA8Pci8ZvGg/TQhCjSTXg3hUMCFfVRUCYy0/EewiLL7UdzqAwpSfRTqxYDOZUfurtm3q+f34lk2s86IHrZUKQatkcw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nutanix.com; dmarc=pass action=none header.from=nutanix.com; dkim=pass header.d=nutanix.com; arc=none Received: from SN6PR02MB4048.namprd02.prod.outlook.com (2603:10b6:805:2c::26) by BY5PR02MB7011.namprd02.prod.outlook.com (2603:10b6:a03:23c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22; Tue, 1 Mar 2022 06:44:30 +0000 Received: from SN6PR02MB4048.namprd02.prod.outlook.com ([fe80::94d7:26e1:9b7a:657f]) by SN6PR02MB4048.namprd02.prod.outlook.com ([fe80::94d7:26e1:9b7a:657f%5]) with mapi id 15.20.5017.027; Tue, 1 Mar 2022 06:44:30 +0000 From: Kshitij Suri To: qemu-devel@nongnu.org Subject: [PATCH v2 2/2] Added parameter to take screenshot with screendump as PNG. Date: Tue, 1 Mar 2022 06:44:24 +0000 Message-Id: <20220301064424.136234-2-kshitij.suri@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20220301064424.136234-1-kshitij.suri@nutanix.com> References: <20220301064424.136234-1-kshitij.suri@nutanix.com> X-ClientProxiedBy: SJ0PR13CA0208.namprd13.prod.outlook.com (2603:10b6:a03:2c3::33) To SN6PR02MB4048.namprd02.prod.outlook.com (2603:10b6:805:2c::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ff4ca65d-6f75-4e5d-3eb1-08d9fb4ef03c X-MS-TrafficTypeDiagnostic: BY5PR02MB7011:EE_ X-Microsoft-Antispam-PRVS: x-proofpoint-crosstenant: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5eU0ucUMcf8w/pcGoFC9TyZ5/pI8NeLdas/DSj7vklhq5XZdN3fwizWQDIoQFJn9Cwv8QRUjjljP+aoJ/VQquFW7lspy8y2FEFOcH7LdtgP4t61ocnGqPErVJn+qakhD3673M0P6hGwzvmdAQl19q8PPAwFrqQrGkamRRoc2LmY0mUKJA/zZXDfYmnKQdQ9W8pw9QwsfLXHajBr0nOFy48pFYghdm0i6DHVedyDYrponIyZGsltPjnrzI3PJDND3rZXioP058x6w+p0V4hs0Dc4Mj94FjyoK3e6+U6JrS4guvAX3DPe8OqgcS6Q1di99//gwhZgbAtqoWcc/8WzbkbmOQ5Qm1gPb3TnkKDGSdtiOVbgbwAtxb9n5j2iC6mpkqvKEh+eqFp6AFmfK8lpBbvWIQNkIceDKARgd4udGFjHd5S9/8EWnpuhiIEYfinsG4bIswVF9UOHhlYTQRURKpR3e32yI9JxWlh+uQmdBqzXTGo2UUhXLuYDe4EfwDssIgcNnaSi6qnufvDTU8xgc/DeXwEWdiELBbT5ZvoUmNveI2tG1MGTmuxQtVA/5ShIyWABgyH9KaUuMdz9O3KBlfy9j62448jPB6uYRQCJgmh3W9JaFpliWt6lLxr6BJW7G8HmCOJr/RBmBU2d5m0rueIBGYYcAmAzIjigcvWXQk2QPhoBvV4/0Qp2NRIkeLgOZcCAf6EMvSFqSoKN1ZrGf67JnKBTMKinjBAw+Gftfp3TS0ai1xpS+9G3f1nlwW9RQoEpXkN0ZFH0+0N7F3pg5sgfT34VZ7qaAJ9AX1UOphXQ= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR02MB4048.namprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(107886003)(186003)(66574015)(6512007)(6666004)(83380400001)(6506007)(6916009)(1076003)(2616005)(26005)(6486002)(966005)(316002)(52116002)(8936002)(5660300002)(44832011)(508600001)(2906002)(86362001)(38100700002)(38350700002)(36756003)(4326008)(66946007)(66556008)(66476007)(8676002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6Mgly0ISWVBOAAJxyXeVcxOxKnIf8HvouytPluzFP9OELLwgadTxcupZdwbpjGd+adIKSP4x5Iu3Rf4icx3iLXvaOj+yr+fZ1q1xtXo5kfyYV8vcUk2n4yb+VdQj6TRsp6NJJ4Rjpy58gJPYWK4CDTz44NAs4IR3dh4XN1LcTzF0t/CBnxlG6sgZXD0fyrSPoixbyvhNKiZfLSSXUnmzsC43IbouKqZ5ao1IgZF4xc0+hvuBIr6cbI15bjzil9YP05fLL28oBlF4v94G5GzNv9MS7qwdpePRxbpkOrfUFPLGWxe/IIxTb2JG9k2mvopVUzsNOUDc4BcTuBExfazTUSia/XBGr5GPx3MmMuVWSdu+Abio9cOAGy1lameJYm79vdP+Dudqm1jV0/8qfgdBLbIXFIxip8yOv2RbkEEvgrxC8V2t5wnmuGauGVqv3A521S66STcUQU5R4WWgcUy+fThO1YjcVMwD4DeB5bN1PCRgtHEMXtKyYhcIll/+l4WJE4+OG7QuVru3zIP8E+6bMEKRdzmMv0Mb6ed0VCnJUHylf0//7YnNXAathFp02MrO3KQQePkyMAzdErgy4B7pAVbFOpK+6UUvj2WIif1+aGgQ+Sbr6vVrCSTOGMpll1l8DMPOtNbQPYIOMyLxa8mbeXxlBPyVwlghuDb7Yr9g7tZe3PEIEBiDBoarMES/0NSPRfRW8UcwAJ/jTetcwdxNtp9ZDKtISlaL6noXpATHMyOCiAWjGHIK1ci0No9wHxdVrdGD+cLfaZcoDNvhEWxhfpiECf/XSw6FwWm//utPWAN9L3btIsMWhD1rUGhlk0YwQbq3mZn7Z9tbwhXTjxG1LDUnDfiOlkO1Un4yF28Hd/Q1M+Aq18+7YuC9Ai163Y0lgiliTXtZNxZDobPeHFSZZ0HVpufII0kplMck405uqusgT7jXzTzV82o4lmyaL3nwSYBUrA1zTHyJHhC2VdSxu2eq6bX2Jyie4YgoYno4z8ujKndxDI2y6BVRTL5FdNda9aOXJOEch/vQOuB+mKQjXbWCc3Xcn8G5+o7AEFOLhx5ibe6ICjiNk+hOa0PudgIS81qO4VTn94NPeRnSL2kLMtRw2cCGta+nKoGFV68LvJjlGkBk9qLUc6TcgpQeQEKtmqdyIJOyl4D2ZgUWnQMK+0z/eJhvvz1yH++PoRFV/6adlwgBnHBxK7i+GjlLz0+5cJE8xHz4Ss1W9g7xw9C/EVaKuFUrRXJah8h+0Y5u5/8kH4pZMkwKd8/oGJxD+oEroNsGVOIP/bd1BZ1ziL/s5xCmsfAhVSQg/rZn0frlUm48gc4aK6o4N+PirLZQX963HX7JzABCZ/BsJNgRJ4NvXKIpPMTY6qa3PWExJCaNWGtl4/++trVtyAV72LD5zI+bMgmZPm1icWUFJTZJKJ0sdxRkb2TIlpy0y83SMpoNP3iUDcpAplHpiWYSKpluxjHjOLkb/0eDvT5M6kAuZT7/O2ma/Vfxi396ud9gt7yyyykTpmFsVlT7GnQ+8bKAzSDiYQxbT2bj1NrfYbnMgRkf871WYgkblFfucuY94pymui1WTUbdKy4rB9vSDFy0a3AORrXILjbAFtEbAvyo74J/GbCU4gXSia8Sb88+hHsTFMl+Doj2LXEPwUx1oTNDziirgJRjWrQTg9DmvfWE7AYBaxV9qzxOqT+K7WNP0pw75uU= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: ff4ca65d-6f75-4e5d-3eb1-08d9fb4ef03c X-MS-Exchange-CrossTenant-AuthSource: SN6PR02MB4048.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2022 06:44:30.7855 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qZAuS8fveYv4UFOC1aER5bksR4RYqyorh05zOH+LjH/s04Gan1+qRwCiZUfjYAV4OkjflFuv4jVdhICRc+Vz7Xj04ix11I3wIva+LUDI7gs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR02MB7011 X-Proofpoint-GUID: D_rHlupy_GreORQ6pFLGLCTOa3MHpMiK X-Proofpoint-ORIG-GUID: D_rHlupy_GreORQ6pFLGLCTOa3MHpMiK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-02-28_10,2022-02-26_01,2022-02-23_01 X-Proofpoint-Spam-Reason: safe Received-SPF: pass client-ip=148.163.151.68; envelope-from=kshitij.suri@nutanix.com; helo=mx0a-002c1b01.pphosted.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: soham.ghosh@nutanix.com, thuth@redhat.com, prerna.saxena@nutanix.com, dgilbert@redhat.com, armbru@redhat.com, Kshitij Suri , kraxel@redhat.com, prachatos.mitra@nutanix.com, eblake@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Currently screendump only supports PPM format, which is un-compressed and not standard. Added a "format" parameter to qemu monitor screendump capabilites to support PNG image capture using libpng. The param was added in QAPI schema of screendump present in ui.json along with png_save() function which converts pixman_image to PNG. HMP command equivalent was also modified to support the feature. Example usage: { "execute": "screendump", "arguments": { "filename": "/tmp/image", "format":"png" } } Resolves: https://gitlab.com/qemu-project/qemu/-/issues/718 Signed-off-by: Kshitij Suri diff to v1: - Removed repeated alpha conversion operation. - Modified logic to mirror png conversion in vnc-enc-tight.c file. - Added a new CONFIG_PNG parameter for libpng support. - Changed input format to enum instead of string. - Improved error handling. hmp-commands.hx | 11 ++--- monitor/hmp-cmds.c | 19 ++++++++- qapi/ui.json | 25 +++++++++-- ui/console.c | 102 +++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 145 insertions(+), 12 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index 70a9136ac2..5eda4eeb24 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -244,17 +244,18 @@ ERST { .name = "screendump", - .args_type = "filename:F,device:s?,head:i?", - .params = "filename [device [head]]", - .help = "save screen from head 'head' of display device 'device' " - "into PPM image 'filename'", + .args_type = "filename:F,device:s?,head:i?,format:f?", + .params = "filename [device [head]] [format]", + .help = "save screen from head 'head' of display device 'device'" + "in specified format 'format' as image 'filename'." + "Currently only 'png' and 'ppm' formats are supported.", .cmd = hmp_screendump, .coroutine = true, }, SRST ``screendump`` *filename* - Save screen into PPM image *filename*. + Save screen as an image *filename*, with default format of PPM. ERST { diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 8c384dc1b2..9a640146eb 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1677,9 +1677,26 @@ hmp_screendump(Monitor *mon, const QDict *qdict) const char *filename = qdict_get_str(qdict, "filename"); const char *id = qdict_get_try_str(qdict, "device"); int64_t head = qdict_get_try_int(qdict, "head", 0); + const char *input_format = qdict_get_str(qdict, "format"); Error *err = NULL; + ImageFormat format; - qmp_screendump(filename, id != NULL, id, id != NULL, head, &err); + int val = qapi_enum_parse(&ImageFormat_lookup, input_format, -1, &err); + if (val < 0) { + goto end; + } + + switch (val) { + case IMAGE_FORMAT_PNG: + format = IMAGE_FORMAT_PNG; + break; + default: + format = IMAGE_FORMAT_PPM; + } + + qmp_screendump(filename, id != NULL, id, id != NULL, head, + input_format != NULL, format, &err); +end: hmp_handle_error(mon, err); } diff --git a/qapi/ui.json b/qapi/ui.json index 9354f4c467..6aa0dd7c1b 100644 --- a/qapi/ui.json +++ b/qapi/ui.json @@ -73,12 +73,27 @@ ## { 'command': 'expire_password', 'data': {'protocol': 'str', 'time': 'str'} } +## +# @ImageFormat: +# +# Available list of supported types. +# +# @png: PNG format +# +# @ppm: PPM format +# +# Since: 7.0 +# +## +{ 'enum': 'ImageFormat', + 'data': ['ppm', 'png'] } + ## # @screendump: # -# Write a PPM of the VGA screen to a file. +# Write a screenshot of the VGA screen to a file. # -# @filename: the path of a new PPM file to store the image +# @filename: the path of a new file to store the image # # @device: ID of the display device that should be dumped. If this parameter # is missing, the primary display will be used. (Since 2.12) @@ -87,6 +102,9 @@ # parameter is missing, head #0 will be used. Also note that the head # can only be specified in conjunction with the device ID. (Since 2.12) # +# @format: image format for screendump is specified. ppm is the set as the +# default format. (Since 7.0) +# # Returns: Nothing on success # # Since: 0.14 @@ -99,7 +117,8 @@ # ## { 'command': 'screendump', - 'data': {'filename': 'str', '*device': 'str', '*head': 'int'}, + 'data': {'filename': 'str', '*device': 'str', '*head': 'int', + '*format': 'ImageFormat'}, 'coroutine': true } ## diff --git a/ui/console.c b/ui/console.c index 40eebb6d2c..aab561e1ac 100644 --- a/ui/console.c +++ b/ui/console.c @@ -37,6 +37,9 @@ #include "exec/memory.h" #include "io/channel-file.h" #include "qom/object.h" +#ifdef CONFIG_PNG +#include +#endif #define DEFAULT_BACKSCROLL 512 #define CONSOLE_CURSOR_PERIOD 500 @@ -289,6 +292,89 @@ void graphic_hw_invalidate(QemuConsole *con) } } +#ifdef CONFIG_PNG +/** + * png_save: Take a screenshot as PNG + * + * Saves screendump as a PNG file + * + * Returns true for success or false for error. + * + * @fd: File descriptor for PNG file. + * @image: Image data in pixman format. + * @errp: Pointer to an error. + */ +static bool png_save(int fd, pixman_image_t *image, Error **errp) +{ + int width = pixman_image_get_width(image); + int height = pixman_image_get_height(image); + g_autofree png_struct *png_ptr = NULL; + g_autofree png_info *info_ptr = NULL; + g_autoptr(pixman_image_t) linebuf = + qemu_pixman_linebuf_create(PIXMAN_a8r8g8b8, width); + uint8_t *buf = (uint8_t *)pixman_image_get_data(linebuf); + FILE *f = fdopen(fd, "wb"); + int y; + if (!f) { + error_setg_errno(errp, errno, + "Failed to create file from file descriptor"); + return false; + } + + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, + NULL, NULL); + if (!png_ptr) { + error_setg(errp, "PNG creation failed. Unable to write struct"); + fclose(f); + return false; + } + + info_ptr = png_create_info_struct(png_ptr); + + if (!info_ptr) { + error_setg(errp, "PNG creation failed. Unable to write info"); + fclose(f); + png_destroy_write_struct(&png_ptr, &info_ptr); + return false; + } + + png_init_io(png_ptr, f); + + png_set_IHDR(png_ptr, info_ptr, width, height, 8, + PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + + png_write_info(png_ptr, info_ptr); + + for (y = 0; y < height; ++y) { + qemu_pixman_linebuf_fill(linebuf, image, width, 0, y); + png_write_row(png_ptr, buf); + } + qemu_pixman_image_unref(linebuf); + + png_write_end(png_ptr, NULL); + + png_destroy_write_struct(&png_ptr, &info_ptr); + + if (fclose(f) != 0) { + error_setg_errno(errp, errno, + "PNG creation failed. Unable to close file"); + return false; + } + + return true; +} + +#else /* no png support */ + +static bool png_save(int fd, pixman_image_t *image, Error **errp) +{ + error_setg(errp, "Enable PNG support with libpng for screendump"); + return false; +} + +#endif /* CONFIG_PNG */ + static bool ppm_save(int fd, pixman_image_t *image, Error **errp) { int width = pixman_image_get_width(image); @@ -327,7 +413,8 @@ static void graphic_hw_update_bh(void *con) /* Safety: coroutine-only, concurrent-coroutine safe, main thread only */ void coroutine_fn qmp_screendump(const char *filename, bool has_device, const char *device, - bool has_head, int64_t head, Error **errp) + bool has_head, int64_t head, bool has_format, + ImageFormat format, Error **errp) { g_autoptr(pixman_image_t) image = NULL; QemuConsole *con; @@ -383,8 +470,17 @@ qmp_screendump(const char *filename, bool has_device, const char *device, * yields and releases the BQL. It could produce corrupted dump, but * it should be otherwise safe. */ - if (!ppm_save(fd, image, errp)) { - qemu_unlink(filename); + + if (has_format && format == IMAGE_FORMAT_PNG) { + /* PNG format specified for screendump */ + if (!png_save(fd, image, errp)) { + qemu_unlink(filename); + } + } else { + /* PPM format specified/default for screendump */ + if (!ppm_save(fd, image, errp)) { + qemu_unlink(filename); + } } }