From nobody Tue Nov 26 20:26:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1704284831; cv=none; d=zohomail.com; s=zohoarc; b=BbtWm1VGdgW/5K/qXn0ySDvWZLuHtIZHyWUW0cRFUDZcq1envFNh8j75DXjqXYEqirOYPpd5dZzyewHPqYXUGyBNMF7rsAGOBIu9WZO8cKO6MRwja10ZBMyTJn1oiILzIf345G5rzVUHL1QHP0PE5ePtuxTq5AoNA94b2daYYOk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704284831; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XBJfRQPFrJr7x2QE0SlgsgPM2jJ1STbI8jYSIeXm3Ew=; b=J/bHOCbkfStRsqfV4XAXvP+SO13UIlmJHmhhm3Nekk0nMAnGzuLiOMRXa68dsUzXySEe/gNk/L7c52G02VEJNwi9nH0ccmc7ZVt1e0XU1hoH4uG8B9XR6JHIOCHtGHWW14a/ARjP/aJG9Hv4GJrvuEGk1zWHOYn7uYdH+a6VmAs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704284831324234.6060603491718; Wed, 3 Jan 2024 04:27:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rL0K2-00055c-BX; Wed, 03 Jan 2024 07:26:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rL0Jz-00054t-Iu for qemu-devel@nongnu.org; Wed, 03 Jan 2024 07:26:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rL0Jx-0002RW-DX for qemu-devel@nongnu.org; Wed, 03 Jan 2024 07:26:07 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-558-G9yaxtw_PLmH3W6adNx_hg-1; Wed, 03 Jan 2024 07:26:02 -0500 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B793C85A58A for ; Wed, 3 Jan 2024 12:26:01 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2402492BE6; Wed, 3 Jan 2024 12:26:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704284763; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=XBJfRQPFrJr7x2QE0SlgsgPM2jJ1STbI8jYSIeXm3Ew=; b=GV8QgdAYTIulfwl2om2hNp29qfBXlnxxWRUsv7EB8xK+2k5oCe23101oHIItI5ebRHl7n3 SpUbsGhCPJnAsohot0oHRGR150hS3KQVs0XuveNQSTyVN9/Qkk/UdGZOHT8WKo24XAH2We 2lkIV8sxObduFC3c9gaYfDbMBwog73w= X-MC-Unique: G9yaxtw_PLmH3W6adNx_hg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH] ui: drop VNC feature _MASK constants Date: Wed, 3 Jan 2024 12:26:00 +0000 Message-ID: <20240103122600.2399662-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -46 X-Spam_score: -4.7 X-Spam_bar: ---- X-Spam_report: (-4.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.601, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1704284831727100001 Each VNC feature enum entry has a corresponding _MASK constant which is the bit-shifted value. It is very easy for contributors to accidentally use the _MASK constant, instead of the non-_MASK constant, or the reverse. No compiler warning is possible and it'll just silently do the wrong thing at runtime. By introducing the vnc_set_feature helper method, we can drop all the _MASK constants and thus prevent any future accidents. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- ui/vnc.c | 34 +++++++++++++++++----------------- ui/vnc.h | 21 ++++----------------- 2 files changed, 21 insertions(+), 34 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 4f23a0fa79..3db87fd89c 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -2144,16 +2144,16 @@ static void set_encodings(VncState *vs, int32_t *en= codings, size_t n_encodings) vs->vnc_encoding =3D enc; break; case VNC_ENCODING_HEXTILE: - vs->features |=3D VNC_FEATURE_HEXTILE_MASK; + vnc_set_feature(vs, VNC_FEATURE_HEXTILE); vs->vnc_encoding =3D enc; break; case VNC_ENCODING_TIGHT: - vs->features |=3D VNC_FEATURE_TIGHT_MASK; + vnc_set_feature(vs, VNC_FEATURE_TIGHT); vs->vnc_encoding =3D enc; break; #ifdef CONFIG_PNG case VNC_ENCODING_TIGHT_PNG: - vs->features |=3D VNC_FEATURE_TIGHT_PNG_MASK; + vnc_set_feature(vs, VNC_FEATURE_TIGHT_PNG); vs->vnc_encoding =3D enc; break; #endif @@ -2163,57 +2163,57 @@ static void set_encodings(VncState *vs, int32_t *en= codings, size_t n_encodings) * So prioritize ZRLE, even if the client hints that it prefers * ZLIB. */ - if ((vs->features & VNC_FEATURE_ZRLE_MASK) =3D=3D 0) { - vs->features |=3D VNC_FEATURE_ZLIB_MASK; + if (!vnc_has_feature(vs, VNC_FEATURE_ZRLE)) { + vnc_set_feature(vs, VNC_FEATURE_ZLIB); vs->vnc_encoding =3D enc; } break; case VNC_ENCODING_ZRLE: - vs->features |=3D VNC_FEATURE_ZRLE_MASK; + vnc_set_feature(vs, VNC_FEATURE_ZRLE); vs->vnc_encoding =3D enc; break; case VNC_ENCODING_ZYWRLE: - vs->features |=3D VNC_FEATURE_ZYWRLE_MASK; + vnc_set_feature(vs, VNC_FEATURE_ZYWRLE); vs->vnc_encoding =3D enc; break; case VNC_ENCODING_DESKTOPRESIZE: - vs->features |=3D VNC_FEATURE_RESIZE_MASK; + vnc_set_feature(vs, VNC_FEATURE_RESIZE); break; case VNC_ENCODING_DESKTOP_RESIZE_EXT: - vs->features |=3D VNC_FEATURE_RESIZE_EXT_MASK; + vnc_set_feature(vs, VNC_FEATURE_RESIZE_EXT); break; case VNC_ENCODING_POINTER_TYPE_CHANGE: - vs->features |=3D VNC_FEATURE_POINTER_TYPE_CHANGE_MASK; + vnc_set_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE); break; case VNC_ENCODING_RICH_CURSOR: - vs->features |=3D VNC_FEATURE_RICH_CURSOR_MASK; + vnc_set_feature(vs, VNC_FEATURE_RICH_CURSOR); break; case VNC_ENCODING_ALPHA_CURSOR: - vs->features |=3D VNC_FEATURE_ALPHA_CURSOR_MASK; + vnc_set_feature(vs, VNC_FEATURE_ALPHA_CURSOR); break; case VNC_ENCODING_EXT_KEY_EVENT: send_ext_key_event_ack(vs); break; case VNC_ENCODING_AUDIO: if (vs->vd->audio_state) { - vs->features |=3D VNC_FEATURE_AUDIO_MASK; + vnc_set_feature(vs, VNC_FEATURE_AUDIO); send_ext_audio_ack(vs); } break; case VNC_ENCODING_WMVi: - vs->features |=3D VNC_FEATURE_WMVI_MASK; + vnc_set_feature(vs, VNC_FEATURE_WMVI); break; case VNC_ENCODING_LED_STATE: - vs->features |=3D VNC_FEATURE_LED_STATE_MASK; + vnc_set_feature(vs, VNC_FEATURE_LED_STATE); break; case VNC_ENCODING_XVP: if (vs->vd->power_control) { - vs->features |=3D VNC_FEATURE_XVP_MASK; + vnc_set_feature(vs, VNC_FEATURE_XVP); send_xvp_message(vs, VNC_XVP_CODE_INIT); } break; case VNC_ENCODING_CLIPBOARD_EXT: - vs->features |=3D VNC_FEATURE_CLIPBOARD_EXT_MASK; + vnc_set_feature(vs, VNC_FEATURE_CLIPBOARD_EXT); vnc_server_cut_text_caps(vs); break; case VNC_ENCODING_COMPRESSLEVEL0 ... VNC_ENCODING_COMPRESSLEVEL0 += 9: diff --git a/ui/vnc.h b/ui/vnc.h index 96d19dce19..8b88555ff2 100644 --- a/ui/vnc.h +++ b/ui/vnc.h @@ -467,23 +467,6 @@ enum VncFeatures { VNC_FEATURE_AUDIO, }; =20 -#define VNC_FEATURE_RESIZE_MASK (1 << VNC_FEATURE_RESIZE) -#define VNC_FEATURE_RESIZE_EXT_MASK (1 << VNC_FEATURE_RESIZE_EXT) -#define VNC_FEATURE_HEXTILE_MASK (1 << VNC_FEATURE_HEXTILE) -#define VNC_FEATURE_POINTER_TYPE_CHANGE_MASK (1 << VNC_FEATURE_POINTER_TYP= E_CHANGE) -#define VNC_FEATURE_WMVI_MASK (1 << VNC_FEATURE_WMVI) -#define VNC_FEATURE_TIGHT_MASK (1 << VNC_FEATURE_TIGHT) -#define VNC_FEATURE_ZLIB_MASK (1 << VNC_FEATURE_ZLIB) -#define VNC_FEATURE_RICH_CURSOR_MASK (1 << VNC_FEATURE_RICH_CURSOR) -#define VNC_FEATURE_ALPHA_CURSOR_MASK (1 << VNC_FEATURE_ALPHA_CURSO= R) -#define VNC_FEATURE_TIGHT_PNG_MASK (1 << VNC_FEATURE_TIGHT_PNG) -#define VNC_FEATURE_ZRLE_MASK (1 << VNC_FEATURE_ZRLE) -#define VNC_FEATURE_ZYWRLE_MASK (1 << VNC_FEATURE_ZYWRLE) -#define VNC_FEATURE_LED_STATE_MASK (1 << VNC_FEATURE_LED_STATE) -#define VNC_FEATURE_XVP_MASK (1 << VNC_FEATURE_XVP) -#define VNC_FEATURE_CLIPBOARD_EXT_MASK (1 << VNC_FEATURE_CLIPBOARD_= EXT) -#define VNC_FEATURE_AUDIO_MASK (1 << VNC_FEATURE_AUDIO) - =20 /* Client -> Server message IDs */ #define VNC_MSG_CLIENT_SET_PIXEL_FORMAT 0 @@ -599,6 +582,10 @@ static inline uint32_t vnc_has_feature(VncState *vs, i= nt feature) { return (vs->features & (1 << feature)); } =20 +static inline void vnc_set_feature(VncState *vs, int feature) { + vs->features |=3D (1 << feature); +} + /* Framebuffer */ void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h, int32_t encoding); --=20 2.43.0