From patchwork Tue Mar 22 10:49:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kshitij Suri X-Patchwork-Id: 12788251 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 A54BFC433F5 for ; Tue, 22 Mar 2022 10:51:40 +0000 (UTC) Received: from localhost ([::1]:41306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nWc71-0001RJ-FK for qemu-devel@archiver.kernel.org; Tue, 22 Mar 2022 06:51:39 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39942) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nWc5V-00080P-Hn for qemu-devel@nongnu.org; Tue, 22 Mar 2022 06:50:05 -0400 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]:48584) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nWc5T-0006Tk-7O for qemu-devel@nongnu.org; Tue, 22 Mar 2022 06:50:05 -0400 Received: from pps.filterd (m0127839.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 22M3775b010595; Tue, 22 Mar 2022 03:50:00 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=proofpoint20171006; bh=aWpq8ynHbMCTC5tG3JF67oR8pzzbwd8Jq4ZPLYpS9lI=; b=RKro7GKFA0YFG5iQ6s6o078Y3IuIw7ZCUr1Ag7jLvcPeZ8kuZSeYgFrVOmjHdtbE3myg UlgJsqq4mvOJPlRqPOqqe9N53yPxDxo50xCn4F8OHnAIvKe6t813j3qENWSX6kRz+Lk6 4kuvHqiMiYTwFlbUAnvADYmciFQ/t2kERFizLgBe/WsIMFGJusWPlgm/Wk9N8INWbIHk NFNWIM9S6B6bRrJe/kRhcTQGkq/6czj2g4v+3NxJzHNaJ6lsJoDn2tqa9v4HezesQp8U jzi9MyHkHziy0TkYuHT2kmoxp7/lSJBS41AXW4TpVGk59/LTwBGhog78Ygw1jjFKRvcO GQ== Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2174.outbound.protection.outlook.com [104.47.59.174]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3ewe8ewjd1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 22 Mar 2022 03:50:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aT5Bnl8ewcEtbxmyP894o4hXb9ABiQGKpFpMVRCCQQt9AOGR5IcSbnroKmuZgyLgA8XT+sjD4487iRJDun6GG3mtUsD7INmZthKp3Mw/utM3NyzChthormTQ2XAyPjOJOHNVZ0NFEpiBMsrZwyD/FyGSpnhUFn68NfEbbtiDPzk/BeDGgOfucj98zEKehLYAOBExIqSQdMhrIKyqFSfIeaKYpfKuEYntQ40eEoqCUNVgH2HyWxrRmElsepvy9EjKfTY11U2sU7ep0fpn+UvfLaiV1gvZ8/tMN52NTXMtTUZjT3tOD+mo8gxdgmfJStoEZFaUnN/yLwNJrmmfYjsZnw== 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=aWpq8ynHbMCTC5tG3JF67oR8pzzbwd8Jq4ZPLYpS9lI=; b=h3cosPOBjBaZ4qm13FAjvddZ8ZyOr4ywKmMnAJ4k/diGI+32EVHB7s4/CXD5JdwhvyEEBwMjihQbPjp6GReUsrK3fQtWxLESuiAchUcqC8UPBGq2cxmnS/3ooOXHa8mlJKUF7rb+G3TfHtsngTNt0H2ufvr+3oGEYsa13cv7I0jCM47bjUit2R6YvT43YaQrE/xPVBbjeNF+F1hcdtrmWhWokwuMkdpSoXnwEFC5ofCW6ezBqsU853EiEYAZx0KfJxn2Lw40j+IgYnsK4tOjUb1Dfwz0jq4ByHhn62ScJKNqD098+VFGK2kR6RXyPiXbPtyWShMIzltzLDZtNzGQ2A== 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 BN7PR02MB4033.namprd02.prod.outlook.com (2603:10b6:406:f9::16) by CY4PR0201MB3556.namprd02.prod.outlook.com (2603:10b6:910:8b::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.19; Tue, 22 Mar 2022 10:49:58 +0000 Received: from BN7PR02MB4033.namprd02.prod.outlook.com ([fe80::5d3d:384c:d914:b12d]) by BN7PR02MB4033.namprd02.prod.outlook.com ([fe80::5d3d:384c:d914:b12d%6]) with mapi id 15.20.5081.023; Tue, 22 Mar 2022 10:49:58 +0000 From: Kshitij Suri To: qemu-devel@nongnu.org Subject: [PATCH v2 1/2] Replacing CONFIG_VNC_PNG with CONFIG_PNG Date: Tue, 22 Mar 2022 10:49:52 +0000 Message-Id: <20220322104953.27731-1-kshitij.suri@nutanix.com> X-Mailer: git-send-email 2.22.3 X-ClientProxiedBy: SJ0PR03CA0253.namprd03.prod.outlook.com (2603:10b6:a03:3a0::18) To BN7PR02MB4033.namprd02.prod.outlook.com (2603:10b6:406:f9::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 36970030-2cf6-446d-1daa-08da0bf1b50b X-MS-TrafficTypeDiagnostic: CY4PR0201MB3556: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: V3vG8bhcORodHiSHh1bNcfu1FGrcmdsW9pCzFfuIi9d1S0MEE4xjN3cAjAZAjRgF58lSla+ul9cVwCcSlk/OuonJVcZQURu2WfrE9BRsssLd+hgyusEDnD7ML+wPhXgM9LAumHVMTWbqbHgoPEiaVMaMwvOqz06AcYRvxsnZNPqbS6DmCWmf3PzjOdtlhB2NKbur8UwiTPRk3CFzyENDs9Pp65NV5wllTUr25yUarY33ttgBP1wfzPO7mAp+kxDSQZj9nuTbZoMlCm41JgtUPrxbfFmC2vSz8FJF09dkaum15gIMz75B6DV61k7K0DXYyImCwdbUaMJWD9aw0bTKeJOVgVz6CwzaY2NDw/KQH5BKF6zAx5fMF1s7otbAwP89ZJK7evw9QJmiy8YQWvRyqoSxGFNLtDmNVVsvMXbCyB8Wuc2sn6iULv7scVj7M0FuQ9RFTaWfY4+wMAi6rN772B3v9DNwNjmNhwzojcAvjcY6MM2OCxTKwqXHZhuzIVhzmsaYfCFTOuePqvhxnC8M34H9TQpJcyePvtqxWwExBUPyK5azIwDbejwUHNhRIUN8cuy4/ghltC0W8HduXXK/6S93aNG/kZ1nND71EkeOEwyAjsspT2jWgW+2GXJNruaxK/xMrnauuecSygcbiFVtlFuE/Oj04PAi8rdwZn1QX5IThbohZuJoPh+tDplXRDIf77nMZLAaFIJI49EpZJxTqg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN7PR02MB4033.namprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(6512007)(6916009)(86362001)(2616005)(26005)(316002)(1076003)(107886003)(186003)(508600001)(6486002)(6506007)(6666004)(52116002)(38100700002)(38350700002)(83380400001)(8936002)(36756003)(5660300002)(2906002)(66556008)(4326008)(66946007)(66476007)(8676002)(44832011); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?bitzDN+WJMbOYdnQjPL5Mx6F2dkH?= =?utf-8?q?3+L8ZpYJ9gitluqfqwXqs9QZbiPCU/xuB5TTIS/NU7U5itYX8F9r7qqWnhSNudTCF?= =?utf-8?q?woLsEbZGMRyiKqwzDJLnQd+83nwOqCQpOe6vf3CGp55ju26ZBUmQCkmc758NG5Ooh?= =?utf-8?q?KaoTEzic9ljF40gE6UWeWJ8UOAwsifywZtQtR5mgB9Wi7AqGB3304u3+OB3cIL7G+?= =?utf-8?q?pjuYlYHRC61UNoN/HLeE4fDVOcOv6ey2CKzCaQRl1xykmjPl8ao17KxhJGbv7nfRL?= =?utf-8?q?194VTW0F0iOKH/74sCYTy21zgU7fjMdgA/gKspIuzq6Ucw1VfUjtLjbzpKKpYBTgy?= =?utf-8?q?zskUV4k4JDf/63bnL09N8w6Cu/S3euSalZtUHVQN2AFpB5RUvEU3zAcldjvgfwizr?= =?utf-8?q?x6y5LOi0UZxzkoP/oQXTxgqYOz4ZUis5pdvFdFkYJ3tiBgvSlkk8Ix/oT1H8nf3Uk?= =?utf-8?q?Shv+T7WOyV7px/q7XuWLJ54nb5/hQHHe/ljNit4s+ESdwc/NS2FW9i+4rk106q/bT?= =?utf-8?q?Pg9T7qPgKbKP97raEUoVXsZjpejy7vGCP/jwGHM8OYv1wskTjfoBLohz2AL08APaS?= =?utf-8?q?fQpLtRVhf4wLWVLZq9A+dNXx/QHkkoVP92pu8cZrPfxuDOQqgeYI933YnmrUnk/3V?= =?utf-8?q?ytMOF9FOD+og8bJH6GYnc6TT2F7uDSiZ84BwoL8fWmNUO02ii8yK/0e8nFqEi9Sbb?= =?utf-8?q?PnDDuClF3Ft+l9WmgK0rdGnethVo5kG4h9w+ENcvOa5Yci/1yeL8z122GJ9uUvcge?= =?utf-8?q?SNI+N94RZUQNK6sZYGQQ3LYsqvnW2jBdbSojGH6zWf8nTrWJqlG66+yxMMGr2ZU5K?= =?utf-8?q?rMHKz6IQ6CY8IPJhcqF8VkLq7FomNi5WvZgXNh/UwMeAlXMtbISacGlXgAhWy4R+B?= =?utf-8?q?fmtbRE6p3te30jC+cIFdSZZv0aQVmNzvnkZ7cV+KgdESez3Sd/kVdjrYIoPZ+CTMw?= =?utf-8?q?RZtWGIIcXAb/64CckzxsWaFG4vjauDTQfRjO6akQBKbe4qeUEKnAmucN5gzrXB2mm?= =?utf-8?q?MoK+L/bitoMTT5u11j4GLje1oIIphGwmgABbtK3tZQnm0zxLzLCwjDVhjtUxbfAlK?= =?utf-8?q?a3+jANZwv9PDzLlWcXINjbOTG61HvNY0P13wYyAunZRMgP6nfu/30YkTjk9uQ2kXy?= =?utf-8?q?0lapctUzp3bs/pztvTNOOxNld4cB1CSkMJaZ62UEG4muJer6mBbutbw+ThCuoxsXr?= =?utf-8?q?J+hfmp6iGfVdLIGVhLNN9CjWiR+PaQaFqWW4D4a6dr+Q0l1vTCK5v6IPMXEIftK02?= =?utf-8?q?V+2x0u7Rbl66vUtmdgms6/Ceck4bjxpmdH3uAFwI5tc2XA5eGVPpRCvVzBOJAVgFx?= =?utf-8?q?L+QJ5BqiEbI0CViWoWk25dfRevLxkaFRVxRtcw8UPzIJGl+Op96jZeP4lI34SGOye?= =?utf-8?q?Xgl1tabeeNLOKYjKqkYjQo6Sxgdwfxi8BiQw=3D=3D?= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 36970030-2cf6-446d-1daa-08da0bf1b50b X-MS-Exchange-CrossTenant-AuthSource: BN7PR02MB4033.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2022 10:49:58.0337 (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: 8rT2/lqTwGp1WhTUPRpZFIitR4VRKBIxEDdT66DvTUN22YFSi6HLx8kQ0F2TwXUtxJmLX2RMtsLQXM27UAJBJHLexWXQu64IUe46LWkaX/U= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR0201MB3556 X-Proofpoint-ORIG-GUID: prHrdkcacyTxcYta2JU52r1yHNJF9sci X-Proofpoint-GUID: prHrdkcacyTxcYta2JU52r1yHNJF9sci X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-22_03,2022-03-22_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, berrange@redhat.com, prerna.saxena@nutanix.com, dgilbert@redhat.com, armbru@redhat.com, Kshitij Suri , philippe.mathieu.daude@gmail.com, 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 Reviewed-by: Daniel P. Berrangé --- 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 282e7c4650..ccb6840a49 100644 --- a/meson.build +++ b/meson.build @@ -1115,14 +1115,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'], @@ -1554,9 +1553,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()) @@ -3638,11 +3637,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 7b86a4713d..e879cca7f5 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 310a873c21..8376291b47 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; @@ -3256,7 +3256,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 22 10:49:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kshitij Suri X-Patchwork-Id: 12788252 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 7A733C433F5 for ; Tue, 22 Mar 2022 10:51:50 +0000 (UTC) Received: from localhost ([::1]:41982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nWc7B-0001tk-B1 for qemu-devel@archiver.kernel.org; Tue, 22 Mar 2022 06:51:49 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40042) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nWc5d-000859-Fc for qemu-devel@nongnu.org; Tue, 22 Mar 2022 06:50:13 -0400 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]:5024) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nWc5Z-0006VF-7r for qemu-devel@nongnu.org; Tue, 22 Mar 2022 06:50:12 -0400 Received: from pps.filterd (m0127839.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 22M67b4f026511; Tue, 22 Mar 2022 03:50:02 -0700 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=7lmGXgU3EhR0vQR3nmbwsoPHlV5OekJ/GP9k6YHsuE4=; b=VttmVWHllg1uUkT93g7BRwoaWrd43dzNt+NF9V8g5w9KPi/FdX712PXGsrnfiVX+eNIc 9HUNt69ThsoKGL+mSSSwm/FGXHcaIHKT03Z/p1D4lWGU9oEDAl1VnNC9JqoH5qBjGWPL k46/cnfEyFsyLIBYodnE1SND35tF6xX62q1wIG7QeFqMGEFM6U5or62FjiZwNvdJeOj3 cuxS01AY0GXCjvf54ForgHdPM8dUKGkUnXtd/ZNEbMhEkcU8kewLp2Inow8Tds0gRGOd 7qRcV6eUX5JMTCl8FOSAhaNWAaQEXXOodM+ZJWW1AFBBw0n7zSy0Ezt9DJoEtTXQw5Mx 0A== Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2175.outbound.protection.outlook.com [104.47.59.175]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3ewe8ewjd5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 22 Mar 2022 03:50:02 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MtI08AW+GjmdWwH+TWE1KOmRLrqyVA7jJA2yzL1PCyFwIxUFubHrIt0sMwdogPWvFpScE2tmoumCWbmLwIARHHaCGaLZDRwwvT2v3lyG2l/6nNjhotce6zgSkg49OID+N+uBysvxsqqphawdQO9OJbsT/y24DBtMdSiifeApij2/SUkdespDpC14okwWmNjZWWHhnzCDuefe/5DRiPJF2UJPt58+fI6PMeR7DRM05Td7WioO5PZt8wbdtG0qMQfLvUUokssP0qr0LvDWZnUY7nGGl/SHGv2CNoOZS3v1PaXGNnaM7mdhqZPxgRFWJzMJw598i2zPaIxc1yJ/V5tPig== 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=7lmGXgU3EhR0vQR3nmbwsoPHlV5OekJ/GP9k6YHsuE4=; b=BpAYE71pzXDop3s+gQwVmdE+jrl3tBl/z1U051m/ZZYDtSmjim/L2Zh9YhsNmHICwKz0oPhZLBxKvBMz0ukZpd0/z4Cj39fS87ASAV/KWie39KtqkolwK1bB/U/jqKySlJjOE8sO9Errcnrw5PKDYBygclG6IWKxVVzXdUo19t6ehwo2jfiZ6C1rbW5XYgI3OS/0ZY2qWP+AnfQDnVxIOwL19xeLlES4sm71RlvKRUAHALyVv1xj89o9mJw40VIXbyGg6e09fHlcsn9QnnxjONtNR8qbT6ibqoFlRHYG8A2PfkU2o1ncluV8pRWdHLON6gdaSklJOJPwVh4wqbiOvw== 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 BN7PR02MB4033.namprd02.prod.outlook.com (2603:10b6:406:f9::16) by CY4PR0201MB3556.namprd02.prod.outlook.com (2603:10b6:910:8b::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.19; Tue, 22 Mar 2022 10:50:00 +0000 Received: from BN7PR02MB4033.namprd02.prod.outlook.com ([fe80::5d3d:384c:d914:b12d]) by BN7PR02MB4033.namprd02.prod.outlook.com ([fe80::5d3d:384c:d914:b12d%6]) with mapi id 15.20.5081.023; Tue, 22 Mar 2022 10:50:00 +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, 22 Mar 2022 10:49:53 +0000 Message-Id: <20220322104953.27731-2-kshitij.suri@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20220322104953.27731-1-kshitij.suri@nutanix.com> References: <20220322104953.27731-1-kshitij.suri@nutanix.com> X-ClientProxiedBy: SJ0PR03CA0253.namprd03.prod.outlook.com (2603:10b6:a03:3a0::18) To BN7PR02MB4033.namprd02.prod.outlook.com (2603:10b6:406:f9::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7f440b9c-4f5b-4480-179d-08da0bf1b692 X-MS-TrafficTypeDiagnostic: CY4PR0201MB3556: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: J3QCAVjOOMUerFOPl+wMsgI3YDpMd95mjaz+z4ACCRVct10psiECSg1wekbk0IAtvLtvJbf4RCiWo6qa5DgVF3qogZS7J8yjW2AFZjbZulU4DZ26V1FEEmZJnZDOoVHA7Kxkp/CmRfsbCtAzrdtnGDCwXnNEdvD3YazfLVsgBAcG3RGP7Xa5mEDxLTDDZKW6rcrRJRkP0kNzxzrxus5ghceqGtx5QK3L5GYdENiDpvxTjdLJBzSze//rPGOTkVw0MYfebNGpoc90WiVHBLovhNtmpWGbsIhosMpfAbiVRBO+wScS5kvJc9ypco98jYNxHxHPrsTS5FvyMdROjX+H+1YYkgp/CHcg5PXhh5HS2SBtyp2mzrc0WHn2gvVum0yjFnETSc4VqBapjWz/riYWbmxDySGU6R4THabrqg+TDqhpm5Erxm5SGa6sJECIH1kRAs5amzL7bDwaQuOAcm0/b0N8Klyne1Dj4kGbjd3UmGCe+RgOD2SVLSSwCGnzTlL3e1amElLejqP8JqFJDNO3UaRI5JGT0Sln1r6j9gTQ79llpc4NeiHc/K4f7jZGfWqexFr/M/sjE5dOZ4QsFY+sjH2raNmmzcWh3d2yblufmuFVThTJyPVP3wRixLds+DBtGD3RNxBCnnBl96bm2spFS1O5gKfq2APJ9aK00xaY6uVMdFm7H/tLYTAdAcz56Nz+AGxXnu0ajUQpBdFAP1X7O8HEAX25apsM2YJWUuXSv8mxnMcfhR208v7iQUoyegVlgE1Y0uDiJxqZDUB1AwY8l65zxC2v+wLISDL9wnoesw4= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN7PR02MB4033.namprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(6512007)(6916009)(86362001)(2616005)(26005)(316002)(1076003)(107886003)(186003)(508600001)(6486002)(966005)(6506007)(6666004)(52116002)(38100700002)(38350700002)(83380400001)(66574015)(8936002)(36756003)(5660300002)(2906002)(66556008)(4326008)(66946007)(66476007)(8676002)(44832011); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7T1mnrnZqYx2JJSToP7OR1ju5Y+qmY3hluID5UhcP7nFa67pqVnU91PubNqHmgnXVBTqXv3u9gtPM9KksEBeeYLaQqnJH3am3R70cotYeE2QSEdF5rNUioBtiE/q19NmGKkRJC460/b4e7yJ5K3YvXQetGJ0Z1MeH/VaGPO+cYpYTB9Vk8CP1gNrAmF2R1SfHI7H4VXf3bI+zMXOM+kMDUYSvIklMlFScJug+8hZFLzNVKrAz3g7AtYa0ULnavhVsabCwQNcan/rAwLKhzsIlldpBCTovSoePPpw9hAnvolEhAAtkVtw1lyptJspkGQ/8yZKb0MLRJkfQ2hY6xtDLKf+jNo9yyqa0sSbgSNkDO7B7ZsrANzZZopoS69zjaaqaNAv2JVWK0zjJQPe0xiH85UEf5Mgk5pGc+wBFbFUQw/B2jazz3N3OQ3WEia7iTOL0igj+6I/e93dXpBWybU0asd1nwVksY3jHoy3g2V41eYIGDAFWigeyJey6LgGjMNC7w7J61W1RF77XBuEE3O/1Hql9fwHoIOYX2LKMU78N9SPvd24RzPl6oQ9CpN661yJzwxRdcWPa64xvicV3s68v43EqXafHDaDt3eAsQHb6MWCVWcFHzHr0K1usDh9uR06/nMxN+88GDjo+sJEe/Wh2ajrjaFi1gSPHk04WiVWt5n00b4T09QSicyq0SE9PivlquOxK1lq7OHxud3MzzJHFMVOz7AO+VymyIGqcqBy6vK5FYO1i2WEjCjndg6SePy3SFhTjZPO1iwnY/lBsqc98B7xMmGuMxQ4KTeFGKD2nZibCMmYrSErQCptvs/MixzCEMFLL4ZMmUjaURlcbUfBBzKrjcwIc4pHQP5U72zs0zhvJ4QCEkMstuxhaIp+inEfb1Q2/IswfdWqEo5S+r/9VOu7KgZvST7hIxyjkkdsLBU68/zsLgUUTFQ7592wSYZmy0pRStvOrZ73VkRsNc6bPaH1ZWF2xonCnKLxgQbcZfFX3GLMHt+DHFPt/U6Gu5Kf+3FGBZXeA1vEKrrS2D5chUHd3ELJvdxPTxvDYdv9N9BjTHDUgaxCQn+gI/TmCuyfvZpLJEQNHsCkHSFBaTzWFLtDHESUMZ7TNtP9nLXx7zW74C3pJdDG5kWjzg7PkVIyQlB99KGqEixSYca9pFA0UCpvy5EcaO5oFLVFEZKb+V5lwttAm1qRmFpnesMDch4GcFyJyqsLREyGw4MsXlQpDTnTwk48U2bxNz9bVK90rAOAa3UOgccO5W0+hmsoFTPsj9GUG21iS05mj4c9jJhhK96qkEGDpuyXvxpH5AjfwJ0JBNJ7l80yRTdZe63KdE7ZH1Bzq/PgPuVnDtVrOBsjFKr+0uwG+A/UskWK4uCvDUefzDCZSotL4mAjoniUbitquCZ5Vr/PuptyMVcFBEV0aRgU0/e9QHFSGHNEAjadxpCvxcSUkNdcTYgOGLFrhcL93KbWEWK/cwnqECsf+phvtQ== X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7f440b9c-4f5b-4480-179d-08da0bf1b692 X-MS-Exchange-CrossTenant-AuthSource: BN7PR02MB4033.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2022 10:50:00.5804 (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: teESM0Gjc4QiP/xYUZzs+5cXZcV98f0PDjm23d2Rt1B0nMwv/8cZulJhcBmKDuFcdqfh/tK9ghKEQC80Ugfotua50JCKthBRwQTvRYC1Xfg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR0201MB3556 X-Proofpoint-ORIG-GUID: DfJyi05T6-ubsIC482mNuA7r8R8slGs6 X-Proofpoint-GUID: DfJyi05T6-ubsIC482mNuA7r8R8slGs6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-22_03,2022-03-22_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, berrange@redhat.com, prerna.saxena@nutanix.com, dgilbert@redhat.com, armbru@redhat.com, Kshitij Suri , philippe.mathieu.daude@gmail.com, 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 | 12 +++++- qapi/ui.json | 24 +++++++++-- ui/console.c | 101 +++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 136 insertions(+), 12 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index 8476277aa9..19b7cab595 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -244,11 +244,12 @@ 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'", - .cmd = hmp_screendump, + .args_type = "filename:F,format:s?,device:s?,head:i?", + .params = "filename [format] [device [head]]", + .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, }, diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 634968498b..2442bfa989 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1720,9 +1720,19 @@ 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_try_str(qdict, "format"); Error *err = NULL; + ImageFormat format; - qmp_screendump(filename, id != NULL, id, id != NULL, head, &err); + format = qapi_enum_parse(&ImageFormat_lookup, input_format, + IMAGE_FORMAT_PPM, &err); + if (err) { + goto end; + } + + 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 664da9e462..e8060d6b3c 100644 --- a/qapi/ui.json +++ b/qapi/ui.json @@ -157,12 +157,27 @@ ## { 'command': 'expire_password', 'boxed': true, 'data': 'ExpirePasswordOptions' } +## +# @ImageFormat: +# +# Supported image format 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. +# Capture the contents of a screen and write it 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) @@ -171,6 +186,8 @@ # 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. (default: ppm) (Since 7.0) +# # Returns: Nothing on success # # Since: 0.14 @@ -183,7 +200,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 da434ce1b2..f42f64d556 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 @@ -291,6 +294,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); @@ -329,7 +415,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; @@ -385,8 +472,16 @@ 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); + } } }