From patchwork Fri Apr 8 07:13:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kshitij Suri X-Patchwork-Id: 12806190 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 6E61AC433EF for ; Fri, 8 Apr 2022 07:26:20 +0000 (UTC) Received: from localhost ([::1]:52298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncj0d-0000OL-1d for qemu-devel@archiver.kernel.org; Fri, 08 Apr 2022 03:26:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41088) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nciom-0000wm-Ar for qemu-devel@nongnu.org; Fri, 08 Apr 2022 03:14:04 -0400 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]:56006) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncioj-0004oZ-AZ for qemu-devel@nongnu.org; Fri, 08 Apr 2022 03:14:03 -0400 Received: from pps.filterd (m0127840.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 237KhbVZ032017; Fri, 8 Apr 2022 00:13:58 -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-type : content-transfer-encoding : mime-version; s=proofpoint20171006; bh=T+c2Gkx/I6NktWlHyo2jhS+uRIPji2xT0zo0lGeRnd4=; b=Sh7q0AC6BEG7NyrnxM9K42qXDbq1e/MYO+8elSe5qY1Nq8/kMHGri2CdQLaLGVfG3CkJ M77gi56yJrJ2o+gF8cbKI84/HwTcFxXWi4npC6c73H+QRD3qovinx4NTDKj+/0adEM0k t3jff6Ra/+0Ni/S4epSDBUCoF1DOu1MMwzFzKt/wrnT8r7jLR6x1m5Vw7mw2ACPgq2pI y6/kkhTcL03M+dH8jFYXly7VDiqu0xTUVmF04aCayBCrzfYXVe/MsJD6sH00I2avvbYU RHF+eEfL7UPSyk0TkAX57A7s8CtW7KfwiqpV1YZHnEVWextTeZZj2y4Ss/k6ZCcTIbA3 ZQ== Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2177.outbound.protection.outlook.com [104.47.55.177]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3f6jttw02y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 08 Apr 2022 00:13:57 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MXKTZhhgQP5FTNe7Vj4IxZ5ZD2K3JAWJJlaeYO+GNu7U9DP812o+czdNknjcqIK7DsYh3mkj7gHJWDrVYerP9U48LPTALKbz/ux7vQzkw3gz1n/uXab8JrVDWrPsYrBttL3kP1denKq5cmmizcFeWGOZgjyqOYnxLX4kP2Y2cLFUDYN6UJdDb6zQY1Poxt/Xxq5Wma1mqfj2XNA+2T1+xhxxULK195LrgkqtFTwcwG1dc+HlOqONymsZOiLzcjGGnd/7daawS+KCbK33/7KFr1VTrau7W+zVAZ3Z885uyLAWcJ83XLscQ9dNpL5XL3Z2vezwa1VEZWuw/iU4OoRwew== 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=T+c2Gkx/I6NktWlHyo2jhS+uRIPji2xT0zo0lGeRnd4=; b=Uf0WZL7KqPmDb8ro2B9OWXjvIW0o6ffMvJFwwYg4UJ5UD2EDteBBe1bZO5klHpj1t7777fxx4JMLqFkFr6tyemZI9Pt9AywZeW4uydDAIao4IoKTwxzw917pWfAUcStvuBxNfn6c77dDJ3PCcjIaKvMLfxSw9Gv1SZuVmayYZDOsabIRl/npwAFiXyfa1RrJrF+Mqqj5wHJPoYaoTIdS2lLlKnqH9KldECrxuwm3HHLcvTMLt9G2oJDII5soSZDm4gufLLjcPPFOtLBVD+W2C1v0srX1ucY+uRsGNSA8XY7QBdUFdUBoJ6KvtRvf6ZMRnXr+jW/VDIzlaUXCupNBSg== 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 BN6PR02MB3281.namprd02.prod.outlook.com (2603:10b6:405:6c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.25; Fri, 8 Apr 2022 07:13:56 +0000 Received: from BN7PR02MB4033.namprd02.prod.outlook.com ([fe80::df1:1d4d:e30c:55e6]) by BN7PR02MB4033.namprd02.prod.outlook.com ([fe80::df1:1d4d:e30c:55e6%3]) with mapi id 15.20.5144.021; Fri, 8 Apr 2022 07:13:56 +0000 From: Kshitij Suri To: qemu-devel@nongnu.org Subject: [PATCH v5 1/2] Replacing CONFIG_VNC_PNG with CONFIG_PNG Date: Fri, 8 Apr 2022 07:13:34 +0000 Message-Id: <20220408071336.99839-2-kshitij.suri@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20220408071336.99839-1-kshitij.suri@nutanix.com> References: <20220408071336.99839-1-kshitij.suri@nutanix.com> X-ClientProxiedBy: PH0P220CA0024.NAMP220.PROD.OUTLOOK.COM (2603:10b6:510:d3::29) 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: 1e23a79e-57ad-4c23-deca-08da192f5816 X-MS-TrafficTypeDiagnostic: BN6PR02MB3281: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: v399/exBdx2gStjbMBAoet5IKZYEcSDutCXKs+mBqacY1iWw4Lq/Ucce1CasOPNoYyG0lNY98sBZCMV96b+qHH2nVw5YdtGj+bcDVh7s5FFjqr6+t13zWJtFzVVt3cUBVeL6zywmEmc7kwG3glX6dRlJWcWcoWaacmYO4i3Iy4xo11EG+bQpJCO9BjC8+ZahxqYh+OPyOc8UAa46gV3Kl4zMEq0D50su8NsGV5QghrcmLcVsH+iWtQDZr/t0zvac5aDQFcf0PaRenZlkko9pKF9Q0EOO99s2ct4fmOkPmFWAMBLOYRV2N9h7lPzpUfQcX0zWxSHBNX9G9X0Wp4Dsoj7BAV/ze7iNOw/wBuxNukrXJkhYc55cw5B237659tG/Gz1/0HxxGm1PYHA9IphL/ej/pT6WEv7ZTda2BsoaALWkJsNdypsPpHFfObLBp5geIUSKdMDow4DQoFF7kOm15mH6ekTy14xAHh4qjNHMGxuu3oQTr8CCIyQTus4ghXGUs1f+c9g47rdTkDi6E4Tuj7qVF2Va/tmLGDGcFeGPRMuO2rkzXZaKL5ECOcJb4lL30eEIGFrbyGrvv9bv4EYilRKYnCgkaD5J4q9Oz/nJDEPYAWYt0IgRr9lrS271YVdXrNZVJk0W6htNLuC0aTrkD3mISIMcD7fMYPTsnJYTuYqyasbvFyMKIW0uMTpcfd3WoaTXUU9oMTU7mLuR2HANjA== 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)(6916009)(316002)(1076003)(66946007)(66556008)(66476007)(38350700002)(38100700002)(8676002)(4326008)(36756003)(6486002)(2906002)(6506007)(44832011)(6512007)(7416002)(508600001)(86362001)(52116002)(6666004)(5660300002)(2616005)(107886003)(83380400001)(8936002)(26005)(186003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?USMHkBervxYrQsRxGWTaXgrEpsNi?= =?utf-8?q?XbNaTytIHlO4qzVsOanvgIbafSCZdWnTwR+gbocBU72+c2qpj+Gv8YOYRscTJRidD?= =?utf-8?q?Iru0yliOLucsy+/f6dUgOguY/r9SHHbbZ9zEEP+PotCmO1jExCEY36uai4YnHV2x7?= =?utf-8?q?BoEqHWO+BeWTgPiyoFFqu8C55QU7wf3OqIRvVFGgJIz8IHELfAq9PYihtaWUjcfym?= =?utf-8?q?BzrJYBS/1CJoHHBro/icnpTTux0enYVlCHzQwUtrjrbot53ikpciQH6+kn7rpixrz?= =?utf-8?q?tmDHD+0B1D9dA+El0liJYP2eZ+r0t7ASVCpah+HpH9DUSEzai1A3tzb/nldGEbHHp?= =?utf-8?q?g2VPguAfCD6PZsNC4E7X3hOVIQiDE+02bJx0ydnyhf/5seKOl8fnfgWWiBY1a6Mnt?= =?utf-8?q?g6MUwPGEmP7KMSz2HITSBA+INvncH6CYhP29XGin7DWIdopEnXWTSfxweQpAzOKgs?= =?utf-8?q?InrFLfR1nw6i2sP+Y2BTI5FS9Un+Pf4GTdShjPkqOZOwqG0d9o8yf5iia9kM2xf08?= =?utf-8?q?vEJkdcjIYtn9pdeobLMakq5myHON7aAdEe/eA2MRxepMtGeTUlAl3sUmW6zAdglBp?= =?utf-8?q?X4Jvh9bOTvKIAdra664YbfIhGLd5WprMMgQDjET1yt2seKcWuJZWOUtrKqEE+CZpT?= =?utf-8?q?/Oh9glqDUewZGAFKdvEx761aZ7h9nc8x7VsdTAQ3tnnGGid7UePZcy5CnTEkWg3E1?= =?utf-8?q?M2Dk3f7/imM8jcY/U4kPDWhViTmCfqg8RsfzLZd/PKZSEAymIgGRlqHWgQsIcevjf?= =?utf-8?q?ZSQuMz8cZQCkAptnowTA92Wu2yXI5MOKmfUbCXsQ/uJb6JWdV8iJKMFYi6//J61Fm?= =?utf-8?q?ukKqhmb8aTU42MonqxRaHD7ViLTZ2yVbBCrhBBn1a22PhpzzLln5twO/9ZPfN5o8v?= =?utf-8?q?sxC8mkyiydmayt9lcaLfI+VjILy9ZYh2nrqLaUWAs7/qYSxUq38jJTsSyWoNCI6P5?= =?utf-8?q?K5eX/rqJ9aiMFB/2tNOk2rtBC8JWMeZn4hHeavTM5gQMfSArsQO6v7owRCv3BHMFl?= =?utf-8?q?9stk+nyHeQgF7oR9zPiK9BWxr/zk8m5UbbkMsiul13V+sguh8hYeW1s8YAXxhTeIS?= =?utf-8?q?4E9afFF7kqL0Tjn4Q+mOk5EvOtx8GEIgFOYArKbpN3YZ6hJl15Vp9D8cvZBaucB12?= =?utf-8?q?88VLsu2IqjNK/TAC/KrQ8Otcs98uzZH2KaZWUwPdLngi6yuPD5KZlsDnYbXkNivBr?= =?utf-8?q?wwyjtYJ1C99sQmd+0Qb3I9MAqchVjjkXmVS/iW/gVSI6T1thivhGk9kkhTpdJ9m5w?= =?utf-8?q?eh2DMwQ8+Rnb03OzeoEQovtGEAa7Rtc1XsxTgpEoOf41CQ/hd0ZJwWH2R2Ybi/L9L?= =?utf-8?q?Jx2bGtfF14HI3yWwSkdgvAcSylauUoxCynQEi97fNZ+pE5l7Eg+RpTrXVoTJVbdMd?= =?utf-8?q?UanMGD9r01ZcXf850sbsOgNg+3jp3fHVEXx0JSO/ELahStyexSobyRGJL4PPQwXSz?= =?utf-8?q?pJnwVcCcuLAihIzabTVw3+1UwL4eIzSKcZVjrGnOlXF5JhPLSvsvPKV55zlB9JRav?= =?utf-8?q?UbPEPur8wgHjyBv5eQ/QeOBbzqCkGyGmi7MC65HB+/ZR1pTAWeXEWbRczOZ+bLkO/?= =?utf-8?q?Sa0dONKa+a/d7+B4SDqAnDE8kt9CI+eXqffYOzy0jN8EOzkWmsOdauZpQQ2glHmpx?= =?utf-8?q?3DLXGx7nulJCL5pRq/fRLyPzyBZaMqGLs71YqLUE85D+ziKR58aAc=3D?= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1e23a79e-57ad-4c23-deca-08da192f5816 X-MS-Exchange-CrossTenant-AuthSource: BN7PR02MB4033.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2022 07:13:55.9178 (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: ReXAPuTHC6UnZJ0y0XE2N0dOzXBXq5J0in0Fncs2hvxLtNUGcldEksz+PsACa9y2t6SEpB8U4yJT8cLqenPgTt/LrCok05JrhbTcwvOcuYk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR02MB3281 X-Proofpoint-GUID: pVbjNYGIFz_Fm5IZhMARuyqDVW00W3W0 X-Proofpoint-ORIG-GUID: pVbjNYGIFz_Fm5IZhMARuyqDVW00W3W0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-04-08_02,2022-04-07_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, peter.maydell@linaro.org, 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, pbonzini@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 | 12 +++++++----- meson_options.txt | 4 ++-- ui/vnc-enc-tight.c | 18 +++++++++--------- ui/vnc.c | 4 ++-- ui/vnc.h | 2 +- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/meson.build b/meson.build index 282e7c4650..0790ccef99 100644 --- a/meson.build +++ b/meson.build @@ -1115,14 +1115,16 @@ if gtkx11.found() x11 = dependency('x11', method: 'pkg-config', required: gtkx11.found(), kwargs: static_kwargs) endif -vnc = not_found png = not_found +if get_option('png').allowed() and have_system + png = dependency('libpng', required: get_option('png'), + method: 'pkg-config', kwargs: static_kwargs) +endif +vnc = 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 +1556,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 +3640,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 Fri Apr 8 07:13:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kshitij Suri X-Patchwork-Id: 12806206 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 0B53EC433F5 for ; Fri, 8 Apr 2022 07:29:46 +0000 (UTC) Received: from localhost ([::1]:56882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncj3w-0003d1-RM for qemu-devel@archiver.kernel.org; Fri, 08 Apr 2022 03:29:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41106) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncioo-0000yD-7g for qemu-devel@nongnu.org; Fri, 08 Apr 2022 03:14:06 -0400 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]:33736) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nciol-0004pt-RD for qemu-devel@nongnu.org; Fri, 08 Apr 2022 03:14: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 2387AHBo023969; Fri, 8 Apr 2022 00:14:01 -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-type : content-transfer-encoding : mime-version; s=proofpoint20171006; bh=DLr087wiwgqVF2LkWuQviXKfRSS5CR5TFv+Ef3Tr1Ig=; b=I/aLUEpc9OcKZaUHqXfpQ7dCXRasZTSeRNau97dLtE2RH8g49Rl+gK3jhj6W0uDZjMfT J07e3QNlqWovgOu3MsrhajUQ+QlMy3rkI6HZheXn7js4lor07vhVuevZorGllpDyv5xZ Q56qtx2xfsuiv1kTkhQ8uhee97e9hSmasHqTkA92grIxRAnIIGw1NAIFGKdxjqqd0+/f 6BgKN0z9QynPXYJjrDamX74SPa9l1NJnWAJ1zz9EbelYXDR5VetwKoDMgms6fYkbDrNB u0DN7c2D9whttsYMWRCOKOclwDzS5L2xmmnWlkTPn4YRxeXSUmkvrMgP/k5y/NWwlILK sg== Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2174.outbound.protection.outlook.com [104.47.55.174]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3f6njfvs19-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 08 Apr 2022 00:14:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jyHEM5kiso4kf6y0wiSdeXII1mcIiuuOi5bg0yAaG0iMztbQydoMLcXzx3qBVSwjeu/LfMIqSNeuEgIJN5OotnMKHmHDNWSdJMbZdLFzLb6rt1KP4zctAJRNBLFSEHoafKi3WDaMHb6CgrIkHgWc7U88NetVEH9C1gwQjzlV55vRvCRSYo3A5EYMbK66/yphLAD7asi8OZcRTHV7NgDcvgvFrR8rnfKUSnZoaHcYIa44ZPQRqdIrlOJ12FNtkSL/6RE5x3tZKupDoBkRZKy2AY4Cumexm0hCU814y0CLMdP7IZpuW4rFwEcTjDsJTp+HNQksVWxmMAFwin1jep3KWQ== 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=DLr087wiwgqVF2LkWuQviXKfRSS5CR5TFv+Ef3Tr1Ig=; b=Ro5FkBOZhcc5qA62JjL4bcSfWRACpjOEFTjFrtnDBsgJ8zaAuY7pdrpjl8INMX5h8vol79kZxZLdAR+p5r0CAY03A55UTYVVFab6r9EOkDiwOoN+5sf/tnNFiLRZCpvRj03S5TDaKy4kSkcvex40IKCH6SFivt6wgjSl7A/uOpcIHU0ATMazc59Xj5pNsvEktgaT3vLC1vKDzeNWmlz6g2G9N25yDrDIt5b3kpBrOVYTSi8dsZ3mWwEdBAX5HoaPv+2r4AnPARz43WaaPXV3rndNAC78yona1SbOC97kNlbC1cEI11HJdEwwLihC8dndYMiBOytdxB5ceE/l9+3F8w== 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 BN6PR02MB3281.namprd02.prod.outlook.com (2603:10b6:405:6c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.25; Fri, 8 Apr 2022 07:13:59 +0000 Received: from BN7PR02MB4033.namprd02.prod.outlook.com ([fe80::df1:1d4d:e30c:55e6]) by BN7PR02MB4033.namprd02.prod.outlook.com ([fe80::df1:1d4d:e30c:55e6%3]) with mapi id 15.20.5144.021; Fri, 8 Apr 2022 07:13:59 +0000 From: Kshitij Suri To: qemu-devel@nongnu.org Subject: [PATCH v5 2/2] Added parameter to take screenshot with screendump as PNG Date: Fri, 8 Apr 2022 07:13:35 +0000 Message-Id: <20220408071336.99839-3-kshitij.suri@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20220408071336.99839-1-kshitij.suri@nutanix.com> References: <20220408071336.99839-1-kshitij.suri@nutanix.com> X-ClientProxiedBy: PH0P220CA0024.NAMP220.PROD.OUTLOOK.COM (2603:10b6:510:d3::29) 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: 98d2667b-7863-44cd-abdd-08da192f59f3 X-MS-TrafficTypeDiagnostic: BN6PR02MB3281: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: Tr5xiTKMsd4frIdKDSbofb6D4EMgxu6ORUhZXs6RMaKMJOwphwXQxQOPy2TlVlqKptPev9pBDR+VrbTXWuxsHOdfQkKCHmXkAvvdp7NzFIUi/uXV/k7NYGhJMBNT/2F0a79ZZrMWm4/4xN4wwqAhp7FF00f1GNvNtV5IRviwOGD0pJ7VJaRHpauSiuSsigj8b0XCFabTs7uTSXOL1Lw4yS59OmjtYtL84CJhRU4JhUWjR2hNLH/jil8/tv6MUkhfgxjekRrt2j3R88sz/NPJuJawYX+T9HyNTqd5Oc01TBFhWzpEZkjVdf6n1S7ILqVNGeYQHdwGOUKrCrj41H7XM1cHfagarp3P93Ep7NkdJh0TKAUR391kWlOC+W+uk10tLBwwfDFcKpuE7gtLIEh8XxDTBHFbp0/ZZ18kros8mzZ0nc+kkAUZ7ZCHgXXTzpXu1VyBH0RWv+z9CBti3thBhsNZZx3IKIaXm213jgvkd+uvA6gl2T+Ck3TxbVx2A20rt+hNKTca/wcaoadSq9TXLLrRSSobnIezRMG17sIafqCVxy6cQ6zFwrVoZ4psPnl0AJxD3ctano9OYrxuAmcA4lhXsfb5P4X/KSrQt82UVxDdZu3pkQdFIrjay3vIHLR6hDElTT20Jp/+NxxsYtJ39OYmIkB6QC+lYBbqzRuNA43tlM/cwOiC8zc64CHJdeUzN/T8WOHu6NmRvci2JLJ2EdhLxi4RecNAE0eiaPn3gokGVSprytwnzw/meE80kIvyJOJRV9jxBEV42c/DKVriOmXa3nEY49FETN9PDAPtg6c= 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)(6916009)(316002)(1076003)(66946007)(66556008)(66476007)(38350700002)(38100700002)(8676002)(4326008)(36756003)(966005)(6486002)(2906002)(6506007)(44832011)(6512007)(7416002)(508600001)(86362001)(52116002)(6666004)(5660300002)(2616005)(107886003)(83380400001)(8936002)(26005)(186003)(66574015); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?tMb8JO9VCwY85NtMnPj9ZytBzDvV?= =?utf-8?q?sOCYrFJOaRa9PwVrsWChNasvljVGWyOh2arBRLMPrHjA7Sm9RpkWVeiOhoIWfagpq?= =?utf-8?q?owTLHEeiwlEtdGvBquMCROzLbm/Qr5gy2E8WsZsC8Db9UMGfljB1Cj2m8j9JQgIpH?= =?utf-8?q?zfrIUSfBXFW9QGl91RoG2jOzqrc8BHEdLcNasHfv6iv3egehFPyXr7OB/DPXa7XZP?= =?utf-8?q?BVNQT9ltVopx+L1DRq5RZnhLacZGpcqJ+LbPOAIcgMPa0zb6mlzzl/miLtHv1qxNt?= =?utf-8?q?CYvf38JNDBx6pUo/7nH2Eu9uJud/K8q+r3eVLC1MTkTTEJ75lYGejVAdDSMZhfc96?= =?utf-8?q?zuL/0HKHafOSCEcaPCygmvE8YacX57SCNBimC20C2XJ5UI4apwXOipDLlPqNFzFzD?= =?utf-8?q?an4nVQn1RzZV7TIj/tGIW0S4OeItnCrLgCdmNiHuAWV8Ah7e3EjpgJjcc8KiriMeU?= =?utf-8?q?iMbVOkdou/l/qcsdpNR60hYRiV5BLwNbJ17/OC5BvesOSlUlaDkhYBLXLtylSdVln?= =?utf-8?q?SQ4XsdKxXOo6txqqyMg+P9zRDblkO/vrPWjBRvM2W3Zvsn4xVEazkO4/gFqwokgPR?= =?utf-8?q?ZmSv01Q7K/yjAIQOiuagewnqid5ovUieMMDHMjmVMWsO/eaX5GX8Gxg4Eude9PK3v?= =?utf-8?q?Nf2dtIQ93TnHGDaRU2CFY5O276M1fjwvJLC/duifCLVK1FY+8xoxrl65aNGl5AaLL?= =?utf-8?q?xGLv2ROb0KyDx63L1OjE5QMwKZBM4+lAq1I4GmIYDiEfuz7A4013N4Sd7PNQGnaAm?= =?utf-8?q?dZAmHNfCsMRpt7xD9OThf5uh6a7S5BYQKGbt9ZKBF/dmbkH181VUgmlc57uQQeKNR?= =?utf-8?q?PjbGmZ5Jg+xAiukXr8GgItRhPTz2CXRwHD0r14eIVHJYCoQAfVic4b5Buj2ibQ9bI?= =?utf-8?q?dM+zYJIl37yq6JBtTDfi2++PkWljB6GhGIgJag9ypLVLIxR0HOOSdxRAKybR+zFXf?= =?utf-8?q?f8ZS/Qpjlo1DNTJx/dj27KcO8ja9+C/gD6awyA9N8yb+22sQAaHmkDDf7DrAKDndM?= =?utf-8?q?BZCDXiSp48W6TehkaXVgV9n+5y5uCG90gub1V5lF9VfxMQWVYeg5L8K5aeVcDFQI1?= =?utf-8?q?6KyW+0xzoJffAYa0APyNv8MeFkx1CPxl7Agk2W9wG+owSN3NK/y1R1m9hDV4Fl2RG?= =?utf-8?q?GskvFnvxZM96lAEWTH+XEOr4I182V0fFnLtPxxspM8HGMfDBwkkYhN6GvcguiDpS3?= =?utf-8?q?cW6/2INhcpBtSfno76SMdrhgsWP0pI+dxBGWcSdtHXgCkTooXE+J+pmSsl5QHC04h?= =?utf-8?q?67A/cctSiu1uzsKw/r7JZEmhLsOEzwrtVz5Ie4HwMpWJBMXtNf55ZIef+Fg7N9yI2?= =?utf-8?q?XUNfRNgnfV80sFoRBrsfSA/82U7Guxp9sXIa9ncAWWGKh0QrwA2aF308cBassYcVo?= =?utf-8?q?ZxLvOue6eKxoqnAjCEDY5va1nx53HX2Fz11k3ct/mO/IREnbFJu+oshgzcB8c/LMS?= =?utf-8?q?KumQb659LmIdNCzm630LXfJm9fWm5xuLA02C7Wv5qqBNTnvay/4bhMYJT3/zkqyA7?= =?utf-8?q?jIAWfWb1F/KyFt+e3+TxGYmPN4BlhFfCVsEMhlkfTo//rVCAW325Z67vPuEDuEH71?= =?utf-8?q?NazXXyycwvs3brEy3OrUg61PZwM1vBEtsqX+omtdhOQ33KcJoAMW94Z67XfFmivCB?= =?utf-8?q?B0ZX1x1RGXFjSgu8ASZg7s/sveAXuRXq/tFoe1bJJ5zeK0oGauX18=3D?= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 98d2667b-7863-44cd-abdd-08da192f59f3 X-MS-Exchange-CrossTenant-AuthSource: BN7PR02MB4033.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2022 07:13:59.0582 (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: X35ZBg7MqLzZv2yBO3BUaFTn8fTM2j/J7NF0pOd8Mu0AsW1KORSI7Lbvf6evUAbpxCB977KNvEDjg32DELnt3Mp0jsXr44qE8EDe/LYbN/g= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR02MB3281 X-Proofpoint-GUID: KanF8E1Y5pTCdlzTleZ7EVbhs-njDBZT X-Proofpoint-ORIG-GUID: KanF8E1Y5pTCdlzTleZ7EVbhs-njDBZT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-04-08_02,2022-04-07_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, peter.maydell@linaro.org, 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, pbonzini@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. Added a "format" parameter to QMP and HMP screendump command to support PNG image capture using libpng. QMP example usage: { "execute": "screendump", "arguments": { "filename": "/tmp/image", "format":"png" } } HMP example usage: screendump /tmp/image -f png Resolves: https://gitlab.com/qemu-project/qemu/-/issues/718 Signed-off-by: Kshitij Suri Reviewed-by: Daniel P. Berrangé Acked-by: Dr. David Alan Gilbert Acked-by: Markus Armbruster diff to v4: - Modified format to be an optional flag based parameter in HMP. 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..808020d005 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:-fs,device:s?,head:i?", + .params = "filename [-f 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..98f0126999 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.1 +# +## +{ '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. (default: ppm) (Since 7.1) +# # 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); + } } }