From nobody Sat May 4 02:57:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1568877081; cv=none; d=zoho.com; s=zohoarc; b=aHF/3iCnKactv2fn7oXBpGXILm/AV2AMlucM2V6hwXsK8+tvMd7eXfDZ2qU8yD9XbpzzaHTpcDUHE2ShemMDL6z8xwChh4vYFS9sn2vN/BdCBNGX7cDRCLIA9NRw7LiUSGYuevEKrB6kMPcPkurmjhTYWig7HkFkQPCe5ftZGT4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568877081; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=gFj5s4BEjgA4gbhhEyyqG9dYbl3DVj03OcHpk4KhT9U=; b=A36BdIzlqnb8hPQTypXwCQxFPuMt8DRYic2jKG9Gb5YYCI7FlQ5gcEuaMdycWZVNCCS8dGdRfpWRln1QyiLhtpCUBFKUwTR+pqROxZNes0aYcM8UbucYphoIVLxyF8DqyfFlXJ8LP6y9eGjGWNLcmIkZac1yZdRe53ijlbI+xCo= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568877081072162.51170373695015; Thu, 19 Sep 2019 00:11:21 -0700 (PDT) Received: from localhost ([::1]:39266 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAqau-0002qu-6C for importer@patchew.org; Thu, 19 Sep 2019 03:11:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53379) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAqZC-0001F4-55 for qemu-devel@nongnu.org; Thu, 19 Sep 2019 03:09:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iAqZ9-0004yx-Ta for qemu-devel@nongnu.org; Thu, 19 Sep 2019 03:09:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38122) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iAqZ9-0004xP-Gl for qemu-devel@nongnu.org; Thu, 19 Sep 2019 03:09:23 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E534381DE0 for ; Thu, 19 Sep 2019 07:09:21 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-47.ams2.redhat.com [10.36.116.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FFEF5D9CC; Thu, 19 Sep 2019 07:09:19 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 762FB17536; Thu, 19 Sep 2019 09:09:18 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 19 Sep 2019 09:09:15 +0200 Message-Id: <20190919070918.16059-2-kraxel@redhat.com> In-Reply-To: <20190919070918.16059-1-kraxel@redhat.com> References: <20190919070918.16059-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 19 Sep 2019 07:09:21 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/4] ui/egl: fix framebuffer reads X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Fix egl_fb_read() to use the (destination) surface size instead of the (source) framebuffer source for glReadPixels. Pass the DisplaySurface instead of the pixeldata pointer to egl_fb_read() to make this possible. With that in place framebuffer reads work fine even if the surface and framebuffer sizes don't match, so we can remove the guest-triggerable asserts in egl_scanout_flush(). Buglink: https://bugzilla.redhat.com//show_bug.cgi?id=3D1749659 Signed-off-by: Gerd Hoffmann Reviewed-by: Marc-Andr=C3=A9 Lureau Message-id: 20190909073911.24787-1-kraxel@redhat.com --- include/ui/egl-helpers.h | 2 +- ui/egl-headless.c | 4 +--- ui/egl-helpers.c | 6 +++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/ui/egl-helpers.h b/include/ui/egl-helpers.h index dad19e9873fb..94a4b3e6f3bd 100644 --- a/include/ui/egl-helpers.h +++ b/include/ui/egl-helpers.h @@ -25,7 +25,7 @@ void egl_fb_setup_for_tex(egl_fb *fb, int width, int heig= ht, GLuint texture, bool delete); void egl_fb_setup_new_tex(egl_fb *fb, int width, int height); void egl_fb_blit(egl_fb *dst, egl_fb *src, bool flip); -void egl_fb_read(void *dst, egl_fb *src); +void egl_fb_read(DisplaySurface *dst, egl_fb *src); =20 void egl_texture_blit(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool fl= ip); void egl_texture_blend(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool f= lip, diff --git a/ui/egl-headless.c b/ui/egl-headless.c index 05b2e7d7b17f..fe2a0d1eab98 100644 --- a/ui/egl-headless.c +++ b/ui/egl-headless.c @@ -133,8 +133,6 @@ static void egl_scanout_flush(DisplayChangeListener *dc= l, if (!edpy->guest_fb.texture || !edpy->ds) { return; } - assert(surface_width(edpy->ds) =3D=3D edpy->guest_fb.width); - assert(surface_height(edpy->ds) =3D=3D edpy->guest_fb.height); assert(surface_format(edpy->ds) =3D=3D PIXMAN_x8r8g8b8); =20 if (edpy->cursor_fb.texture) { @@ -149,7 +147,7 @@ static void egl_scanout_flush(DisplayChangeListener *dc= l, egl_fb_blit(&edpy->blit_fb, &edpy->guest_fb, edpy->y_0_top); } =20 - egl_fb_read(surface_data(edpy->ds), &edpy->blit_fb); + egl_fb_read(edpy->ds, &edpy->blit_fb); dpy_gfx_update(edpy->dcl.con, x, y, w, h); } =20 diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c index edc53f6d3464..7c530c2825be 100644 --- a/ui/egl-helpers.c +++ b/ui/egl-helpers.c @@ -102,12 +102,12 @@ void egl_fb_blit(egl_fb *dst, egl_fb *src, bool flip) GL_COLOR_BUFFER_BIT, GL_LINEAR); } =20 -void egl_fb_read(void *dst, egl_fb *src) +void egl_fb_read(DisplaySurface *dst, egl_fb *src) { glBindFramebuffer(GL_READ_FRAMEBUFFER, src->framebuffer); glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); - glReadPixels(0, 0, src->width, src->height, - GL_BGRA, GL_UNSIGNED_BYTE, dst); + glReadPixels(0, 0, surface_width(dst), surface_height(dst), + GL_BGRA, GL_UNSIGNED_BYTE, surface_data(dst)); } =20 void egl_texture_blit(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool fl= ip) --=20 2.18.1 From nobody Sat May 4 02:57:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1568877083; cv=none; d=zoho.com; s=zohoarc; b=BPQ5kxgnpTE8FINNtP9Ldc5m3OGscIuwSfQtJNg2xvBde/GsvhgT+9prJ6GDYw8Eo6eY00XdzrsYhWY2YSHPjF2tqkkdLM6AcW6k9/h4H6GsMVumEFP5bN0NYaTAsGaO8tJWxah7VL7IqebHOqWc8pXnlePfuOcqpgmW9/5zVSY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568877083; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=+nNU47Go4FQE7DgMqpxE5VIm7PAGAZox4G/4rM64ozA=; b=FbQM07JyuLFAj2WhePDIG0sML/kI6bjLoVZg/oslDhzU3ypsFO7UA3jMMIhUoko609m+ns8tGYgtuQtCR9x4/JqJzkyauv3CTTNzBMM7gh5VHJX53eSuAzn+Kgt1K5yRT+a1zgaM64Ph8kzPoRuZOpLJFBSkZZx3CsfSj0D5HBg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 156887708385781.22508447411576; Thu, 19 Sep 2019 00:11:23 -0700 (PDT) Received: from localhost ([::1]:39268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAqav-0002sn-Uz for importer@patchew.org; Thu, 19 Sep 2019 03:11:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53369) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAqZC-0001Ew-Bf for qemu-devel@nongnu.org; Thu, 19 Sep 2019 03:09:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iAqZ9-0004yp-R8 for qemu-devel@nongnu.org; Thu, 19 Sep 2019 03:09:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52584) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iAqZ9-0004xM-Hf for qemu-devel@nongnu.org; Thu, 19 Sep 2019 03:09:23 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D3B361DA3 for ; Thu, 19 Sep 2019 07:09:21 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-47.ams2.redhat.com [10.36.116.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5047860C18; Thu, 19 Sep 2019 07:09:19 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 7EF8C17538; Thu, 19 Sep 2019 09:09:18 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 19 Sep 2019 09:09:16 +0200 Message-Id: <20190919070918.16059-3-kraxel@redhat.com> In-Reply-To: <20190919070918.16059-1-kraxel@redhat.com> References: <20190919070918.16059-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.71]); Thu, 19 Sep 2019 07:09:21 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/4] vnc: fix websocket field in events X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Just need to fill VncClientInfo.websocket in vnc_client_cache_addr(). Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D1748175 Signed-off-by: Gerd Hoffmann Reviewed-by: Stefan Hajnoczi Message-id: 20190904055250.22421-1-kraxel@redhat.com --- ui/vnc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/vnc.c b/ui/vnc.c index bd1674602220..bc43c4ca16bf 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -278,6 +278,7 @@ static void vnc_client_cache_addr(VncState *client) vnc_init_basic_info_from_remote_addr(client->sioc, qapi_VncClientInfo_base(client->i= nfo), &err); + client->info->websocket =3D client->websocket; if (err) { qapi_free_VncClientInfo(client->info); client->info =3D NULL; --=20 2.18.1 From nobody Sat May 4 02:57:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1568877197; cv=none; d=zoho.com; s=zohoarc; b=VRipQaFRFjK5i+l1rcx+nWieeBanr2Vbmb8EPzw2ThMKjN/15hjKZSGnF6cccJnNdmJdJxonr6zTvriN0I5CZ3T951y6NOJXCXqWN2RpoBaiVzUC+mVAC0pJY/8xU2VEqvlVcxctuMhp1LBTASN8qk0/DH6eIMGGfZjI8XBF9Ig= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568877197; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=BusqguTxl74wsQq8x10unc7YNfOmlu5T3fKl9+Vo9K4=; b=YSMOsOlNrYAalv/EotGYZMYMifds1C3TlOIXzc2i5Q//cZ9Ne1lgU4gcX3iwEZqP7oZ1FWDNADeZ6S3hhlDQmaJsZr5T12d3AkO+uwd3azJwDy8xn3XyOgTVgXGevVQwiLK0FwBaywwWhnjspPYw4MP0rtZ22ULcwh65+dmYxHc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568877197385839.2255045396817; Thu, 19 Sep 2019 00:13:17 -0700 (PDT) Received: from localhost ([::1]:39306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAqcu-0005hZ-0C for importer@patchew.org; Thu, 19 Sep 2019 03:13:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53463) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAqZI-0001JW-Eh for qemu-devel@nongnu.org; Thu, 19 Sep 2019 03:09:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iAqZB-00050J-Ct for qemu-devel@nongnu.org; Thu, 19 Sep 2019 03:09:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41514) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iAqZA-0004z1-J5 for qemu-devel@nongnu.org; Thu, 19 Sep 2019 03:09:25 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B397E3083391; Thu, 19 Sep 2019 07:09:23 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-47.ams2.redhat.com [10.36.116.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 502216012E; Thu, 19 Sep 2019 07:09:19 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 8F304A1E0; Thu, 19 Sep 2019 09:09:18 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 19 Sep 2019 09:09:17 +0200 Message-Id: <20190919070918.16059-4-kraxel@redhat.com> In-Reply-To: <20190919070918.16059-1-kraxel@redhat.com> References: <20190919070918.16059-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 19 Sep 2019 07:09:23 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/4] ui: add an embedded Barrier client X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Laurent Vivier This allows to receive mouse and keyboard events from a Barrier server. This is enabled by adding the following parameter on the command line ... -object input-barrier,id=3D$id,name=3D$name ... Where $name is the name declared in the screens section of barrier.conf The barrier server (barriers) must be configured and must run on the local host. For instance: section: screens localhost: ... VM-1: ... end section: links localhost: right =3D VM-1 VM-1: left =3D localhost end Then on the QEMU command line: ... -object input-barrier,id=3Dbarrie0,name=3DVM-1 ... When the mouse will move out of the screen of the local host on the right, the mouse and the keyboard will be grabbed and all related events will be send to the guest OS. This is usefull when qemu is configured without emulated graphic card but with a VFIO attached graphic card. More information about Barrier can be found at: https://github.com/debauchee/barrier This avoids to install the Barrier server in the guest OS, for instance when it is not supported or during the installation. Signed-off-by: Laurent Vivier Message-id: 20190906083812.29487-1-laurent@vivier.eu Signed-off-by: Gerd Hoffmann --- docs/barrier.txt | 370 ++++++++++++++++++++++ ui/input-barrier.h | 112 +++++++ ui/input-barrier.c | 750 +++++++++++++++++++++++++++++++++++++++++++++ ui/Makefile.objs | 1 + 4 files changed, 1233 insertions(+) create mode 100644 docs/barrier.txt create mode 100644 ui/input-barrier.h create mode 100644 ui/input-barrier.c diff --git a/docs/barrier.txt b/docs/barrier.txt new file mode 100644 index 000000000000..b21d15015d96 --- /dev/null +++ b/docs/barrier.txt @@ -0,0 +1,370 @@ + QEMU Barrier Client + + +* About + + Barrier is a KVM (Keyboard-Video-Mouse) software forked from Symless's + synergy 1.9 codebase. + + See https://github.com/debauchee/barrier + +* QEMU usage + + Generally, mouse and keyboard are grabbed through the QEMU video + interface emulation. + + But when we want to use a video graphic adapter via a PCI passthrough + there is no way to provide the keyboard and mouse inputs to the VM + except by plugging a second set of mouse and keyboard to the host + or by installing a KVM software in the guest OS. + + The QEMU Barrier client avoids this by implementing directly the Barri= er + protocol into QEMU. + + This protocol is enabled by adding an input-barrier object to QEMU. + + Syntax: input-barrier,id=3D,name=3D + [,server=3D][,port=3D] + [,x-origin=3D][,y-origin=3D] + [,width=3D][,height=3D] + + The object can be added on the QEMU command line, for instance with: + + ... -object input-barrier,id=3Dbarrier0,name=3DVM-1 ... + + where VM-1 is the name the display configured int the Barrier server + on the host providing the mouse and the keyboard events. + + by default is "localhost", port is 24800, + and are set to 0, and to + 1920 and 1080. + + If Barrier server is stopped QEMU needs to be reconnected manually, + by removing and re-adding the input-barrier object, for instance + with the help of the HMP monitor: + + (qemu) object_del barrier0 + (qemu) object_add input-barrier,id=3Dbarrier0,name=3DVM-1 + +* Message format + + Message format between the server and client is in two parts: + + 1- the payload length is a 32bit integer in network endianness, + 2- the payload + + The payload starts with a 4byte string (without NUL) which is the + command. The first command between the server and the client + is the only command not encoded on 4 bytes ("Barrier"). + The remaining part of the payload is decoded according to the command. + +* Protocol Description (from barrier/src/lib/barrier/protocol_types.h) + + - barrierCmdHello "Barrier" + + Direction: server -> client + Parameters: { int16_t minor, int16_t major } + Description: + + Say hello to client + minor =3D protocol major version number supported by server + major =3D protocol minor version number supported by server + + - barrierCmdHelloBack "Barrier" + + Direction: client ->server + Parameters: { int16_t minor, int16_t major, char *name} + Description: + + Respond to hello from server + minor =3D protocol major version number supported by client + major =3D protocol minor version number supported by client + name =3D client name + + - barrierCmdDInfo "DINF" + + Direction: client ->server + Parameters: { int16_t x_origin, int16_t y_origin, int16_t width, int= 16_t height, int16_t x, int16_t y} + Description: + + The client screen must send this message in response to the + barrierCmdQInfo message. It must also send this message when the + screen's resolution changes. In this case, the client screen sh= ould + ignore any barrierCmdDMouseMove messages until it receives a + barrierCmdCInfoAck in order to prevent attempts to move the mous= e off + the new screen area. + + - barrierCmdCNoop "CNOP" + + Direction: client -> server + Parameters: None + Description: + + No operation + + - barrierCmdCClose "CBYE" + + Direction: server -> client + Parameters: None + Description: + + Close connection + + - barrierCmdCEnter "CINN" + + Direction: server -> client + Parameters: { int16_t x, int16_t y, int32_t seq, int16_t modifier } + Description: + + Enter screen. + x,y =3D entering screen absolute coordinates + seq =3D sequence number, which is used to order messages be= tween + screens. the secondary screen must return this number + with some messages + modifier =3D modifier key mask. this will have bits set for each + toggle modifier key that is activated on entry to the + screen. the secondary screen should adjust its toggle + modifiers to reflect that state. + + - barrierCmdCLeave "COUT" + + Direction: server -> client + Parameters: None + Description: + + Leaving screen. the secondary screen should send clipboard data= in + response to this message for those clipboards that it has grabbed + (i.e. has sent a barrierCmdCClipboard for and has not received a + barrierCmdCClipboard for with a greater sequence number) and that + were grabbed or have changed since the last leave. + + - barrierCmdCClipboard "CCLP" + + Direction: server -> client + Parameters: { int8_t id, int32_t seq } + Description: + + Grab clipboard. Sent by screen when some other app on that screen + grabs a clipboard. + id =3D the clipboard identifier + seq =3D sequence number. Client must use the sequence number pas= sed in + the most recent barrierCmdCEnter. the server always sends= 0. + + - barrierCmdCScreenSaver "CSEC" + + Direction: server -> client + Parameters: { int8_t started } + Description: + + Screensaver change. + started =3D Screensaver on primary has started (1) or closed (0) + + - barrierCmdCResetOptions "CROP" + + Direction: server -> client + Parameters: None + Description: + + Reset options. Client should reset all of its options to their + defaults. + + - barrierCmdCInfoAck "CIAK" + + Direction: server -> client + Parameters: None + Description: + + Resolution change acknowledgment. Sent by server in response to a + client screen's barrierCmdDInfo. This is sent for every + barrierCmdDInfo, whether or not the server had sent a barrierCmd= QInfo. + + - barrierCmdCKeepAlive "CALV" + + Direction: server -> client + Parameters: None + Description: + + Keep connection alive. Sent by the server periodically to verify + that connections are still up and running. clients must reply in + kind on receipt. if the server gets an error sending the messag= e or + does not receive a reply within a reasonable time then the server + disconnects the client. if the client doesn't receive these (or= any + message) periodically then it should disconnect from the server.= the + appropriate interval is defined by an option. + + - barrierCmdDKeyDown "DKDN" + + Direction: server -> client + Parameters: { int16_t keyid, int16_t modifier [,int16_t button] } + Description: + + Key pressed. + keyid =3D X11 key id + modified =3D modified mask + button =3D X11 Xkb keycode (optional) + + - barrierCmdDKeyRepeat "DKRP" + + Direction: server -> client + Parameters: { int16_t keyid, int16_t modifier, int16_t repeat [,int1= 6_t button] } + Description: + + Key auto-repeat. + keyid =3D X11 key id + modified =3D modified mask + repeat =3D number of repeats + button =3D X11 Xkb keycode (optional) + + - barrierCmdDKeyUp "DKUP" + + Direction: server -> client + Parameters: { int16_t keyid, int16_t modifier [,int16_t button] } + Description: + + Key released. + keyid =3D X11 key id + modified =3D modified mask + button =3D X11 Xkb keycode (optional) + + - barrierCmdDMouseDown "DMDN" + + Direction: server -> client + Parameters: { int8_t button } + Description: + + Mouse button pressed. + button =3D button id + + - barrierCmdDMouseUp "DMUP" + + Direction: server -> client + Parameters: { int8_t button } + Description: + + Mouse button release. + button =3D button id + + - barrierCmdDMouseMove "DMMV" + + Direction: server -> client + Parameters: { int16_t x, int16_t y } + Description: + + Absolute mouse moved. + x,y =3D absolute screen coordinates + + - barrierCmdDMouseRelMove "DMRM" + + Direction: server -> client + Parameters: { int16_t x, int16_t y } + Description: + + Relative mouse moved. + x,y =3D r relative screen coordinates + + - barrierCmdDMouseWheel "DMWM" + + Direction: server -> client + Parameters: { int16_t x , int16_t y } or { int16_t y } + Description: + + Mouse scroll. The delta should be +120 for one tick forward (away + from the user) or right and -120 for one tick backward (toward t= he + user) or left. + x =3D x delta + y =3D y delta + + - barrierCmdDClipboard "DCLP" + + Direction: server -> client + Parameters: { int8_t id, int32_t seq, int8_t mark, char *data } + Description: + + Clipboard data. + id =3D clipboard id + seq =3D sequence number. The sequence number is 0 when sent by t= he + server. Client screens should use the/ sequence number fr= om + the most recent barrierCmdCEnter. + + - barrierCmdDSetOptions "DSOP" + + Direction: server -> client + Parameters: { int32 t nb, { int32_t id, int32_t val }[] } + Description: + + Set options. Client should set the given option/value pairs. + nb =3D numbers of { id, val } entries + id =3D option id + val =3D option new value + + - barrierCmdDFileTransfer "DFTR" + + Direction: server -> client + Parameters: { int8_t mark, char *content } + Description: + + Transfer file data. + mark =3D 0 means the content followed is the file size + 1 means the content followed is the chunk data + 2 means the file transfer is finished + + - barrierCmdDDragInfo "DDRG" int16_t char * + + Direction: server -> client + Parameters: { int16_t nb, char *content } + Description: + + Drag information. + nb =3D number of dragging objects + content =3D object's directory + + - barrierCmdQInfo "QINF" + + Direction: server -> client + Parameters: None + Description: + + Query screen info + Client should reply with a barrierCmdDInfo + + - barrierCmdEIncompatible "EICV" + + Direction: server -> client + Parameters: { int16_t nb, major *minor } + Description: + + Incompatible version. + major =3D major version + minor =3D minor version + + - barrierCmdEBusy "EBSY" + + Direction: server -> client + Parameters: None + Description: + + Name provided when connecting is already in use. + + - barrierCmdEUnknown "EUNK" + + Direction: server -> client + Parameters: None + Description: + + Unknown client. Name provided when connecting is not in primary's + screen configuration map. + + - barrierCmdEBad "EBAD" + + Direction: server -> client + Parameters: None + Description: + + Protocol violation. Server should disconnect after sending this + message. + +* TO DO + + - Enable SSL + - Manage SetOptions/ResetOptions commands + diff --git a/ui/input-barrier.h b/ui/input-barrier.h new file mode 100644 index 000000000000..e5b090590ad5 --- /dev/null +++ b/ui/input-barrier.h @@ -0,0 +1,112 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#ifndef UI_INPUT_BARRIER_H +#define UI_INPUT_BARRIER_H + +/* Barrier protocol */ +#define BARRIER_VERSION_MAJOR 1 +#define BARRIER_VERSION_MINOR 6 + +enum barrierCmd { + barrierCmdCNoop, + barrierCmdCClose, + barrierCmdCEnter, + barrierCmdCLeave, + barrierCmdCClipboard, + barrierCmdCScreenSaver, + barrierCmdCResetOptions, + barrierCmdCInfoAck, + barrierCmdCKeepAlive, + barrierCmdDKeyDown, + barrierCmdDKeyRepeat, + barrierCmdDKeyUp, + barrierCmdDMouseDown, + barrierCmdDMouseUp, + barrierCmdDMouseMove, + barrierCmdDMouseRelMove, + barrierCmdDMouseWheel, + barrierCmdDClipboard, + barrierCmdDInfo, + barrierCmdDSetOptions, + barrierCmdDFileTransfer, + barrierCmdDDragInfo, + barrierCmdQInfo, + barrierCmdEIncompatible, + barrierCmdEBusy, + barrierCmdEUnknown, + barrierCmdEBad, + /* connection sequence */ + barrierCmdHello, + barrierCmdHelloBack, +}; + +enum { + barrierButtonNone, + barrierButtonLeft, + barrierButtonMiddle, + barrierButtonRight, + barrierButtonExtra0 +}; + +struct barrierVersion { + int16_t major; + int16_t minor; +}; + +struct barrierMouseButton { + int8_t buttonid; +}; + +struct barrierEnter { + int16_t x; + int16_t y; + int32_t seqn; + int16_t modifier; +}; + +struct barrierMousePos { + int16_t x; + int16_t y; +}; + +struct barrierKey { + int16_t keyid; + int16_t modifier; + int16_t button; +}; + +struct barrierRepeat { + int16_t keyid; + int16_t modifier; + int16_t repeat; + int16_t button; +}; + +#define BARRIER_MAX_OPTIONS 32 +struct barrierSet { + int nb; + struct { + int id; + char nul; + int value; + } option[BARRIER_MAX_OPTIONS]; +}; + +struct barrierMsg { + enum barrierCmd cmd; + union { + struct barrierVersion version; + struct barrierMouseButton mousebutton; + struct barrierMousePos mousepos; + struct barrierEnter enter; + struct barrierKey key; + struct barrierRepeat repeat; + struct barrierSet set; + }; +}; +#endif diff --git a/ui/input-barrier.c b/ui/input-barrier.c new file mode 100644 index 000000000000..a2c961f285a4 --- /dev/null +++ b/ui/input-barrier.c @@ -0,0 +1,750 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "sysemu/sysemu.h" +#include "qemu/main-loop.h" +#include "qemu/sockets.h" +#include "qapi/error.h" +#include "qom/object_interfaces.h" +#include "io/channel-socket.h" +#include "ui/input.h" +#include "ui/vnc_keysym.h" /* use name2keysym from VNC as we use X11 value= s */ +#include "qemu/cutils.h" +#include "qapi/qmp/qerror.h" +#include "input-barrier.h" + +#define TYPE_INPUT_BARRIER "input-barrier" +#define INPUT_BARRIER(obj) \ + OBJECT_CHECK(InputBarrier, (obj), TYPE_INPUT_BARRIER) +#define INPUT_BARRIER_GET_CLASS(obj) \ + OBJECT_GET_CLASS(InputBarrierClass, (obj), TYPE_INPUT_BARRIER) +#define INPUT_BARRIER_CLASS(klass) \ + OBJECT_CLASS_CHECK(InputBarrierClass, (klass), TYPE_INPUT_BARRIER) + +typedef struct InputBarrier InputBarrier; +typedef struct InputBarrierClass InputBarrierClass; + +#define MAX_HELLO_LENGTH 1024 + +struct InputBarrier { + Object parent; + + QIOChannelSocket *sioc; + guint ioc_tag; + + /* display properties */ + gchar *name; + int16_t x_origin, y_origin; + int16_t width, height; + + /* keyboard/mouse server */ + + SocketAddress saddr; + + char buffer[MAX_HELLO_LENGTH]; +}; + +struct InputBarrierClass { + ObjectClass parent_class; +}; + +static const char *cmd_names[] =3D { + [barrierCmdCNoop] =3D "CNOP", + [barrierCmdCClose] =3D "CBYE", + [barrierCmdCEnter] =3D "CINN", + [barrierCmdCLeave] =3D "COUT", + [barrierCmdCClipboard] =3D "CCLP", + [barrierCmdCScreenSaver] =3D "CSEC", + [barrierCmdCResetOptions] =3D "CROP", + [barrierCmdCInfoAck] =3D "CIAK", + [barrierCmdCKeepAlive] =3D "CALV", + [barrierCmdDKeyDown] =3D "DKDN", + [barrierCmdDKeyRepeat] =3D "DKRP", + [barrierCmdDKeyUp] =3D "DKUP", + [barrierCmdDMouseDown] =3D "DMDN", + [barrierCmdDMouseUp] =3D "DMUP", + [barrierCmdDMouseMove] =3D "DMMV", + [barrierCmdDMouseRelMove] =3D "DMRM", + [barrierCmdDMouseWheel] =3D "DMWM", + [barrierCmdDClipboard] =3D "DCLP", + [barrierCmdDInfo] =3D "DINF", + [barrierCmdDSetOptions] =3D "DSOP", + [barrierCmdDFileTransfer] =3D "DFTR", + [barrierCmdDDragInfo] =3D "DDRG", + [barrierCmdQInfo] =3D "QINF", + [barrierCmdEIncompatible] =3D "EICV", + [barrierCmdEBusy] =3D "EBSY", + [barrierCmdEUnknown] =3D "EUNK", + [barrierCmdEBad] =3D "EBAD", + [barrierCmdHello] =3D "Barrier", + [barrierCmdHelloBack] =3D "Barrier", +}; + +static kbd_layout_t *kbd_layout; + +static int input_barrier_to_qcode(uint16_t keyid, uint16_t keycode) +{ + /* keycode is optional, if it is not provided use keyid */ + if (keycode && keycode <=3D qemu_input_map_xorgkbd_to_qcode_len) { + return qemu_input_map_xorgkbd_to_qcode[keycode]; + } + + if (keyid >=3D 0xE000 && keyid <=3D 0xEFFF) { + keyid +=3D 0x1000; + } + + /* keyid is the X11 key id */ + if (kbd_layout) { + keycode =3D keysym2scancode(kbd_layout, keyid, NULL, false); + + return qemu_input_key_number_to_qcode(keycode); + } + + return qemu_input_map_x11_to_qcode[keyid]; +} + +static int input_barrier_to_mouse(uint8_t buttonid) +{ + switch (buttonid) { + case barrierButtonLeft: + return INPUT_BUTTON_LEFT; + case barrierButtonMiddle: + return INPUT_BUTTON_MIDDLE; + case barrierButtonRight: + return INPUT_BUTTON_RIGHT; + case barrierButtonExtra0: + return INPUT_BUTTON_SIDE; + } + return buttonid; +} + +#define read_char(x, p, l) \ +do { \ + int size =3D sizeof(char); \ + if (l < size) { \ + return G_SOURCE_REMOVE; \ + } \ + x =3D *(char *)p; \ + p +=3D size; \ + l -=3D size; \ +} while (0) + +#define read_short(x, p, l) \ +do { \ + int size =3D sizeof(short); \ + if (l < size) { \ + return G_SOURCE_REMOVE; \ + } \ + x =3D ntohs(*(short *)p); \ + p +=3D size; \ + l -=3D size; \ +} while (0) + +#define write_short(p, x, l) \ +do { \ + int size =3D sizeof(short); \ + if (l < size) { \ + return G_SOURCE_REMOVE; \ + } \ + *(short *)p =3D htons(x); \ + p +=3D size; \ + l -=3D size; \ +} while (0) + +#define read_int(x, p, l) \ +do { \ + int size =3D sizeof(int); \ + if (l < size) { \ + return G_SOURCE_REMOVE; \ + } \ + x =3D ntohl(*(int *)p); \ + p +=3D size; \ + l -=3D size; \ +} while (0) + +#define write_int(p, x, l) \ +do { \ + int size =3D sizeof(int); \ + if (l < size) { \ + return G_SOURCE_REMOVE; \ + } \ + *(int *)p =3D htonl(x); \ + p +=3D size; \ + l -=3D size; \ +} while (0) + +#define write_cmd(p, c, l) \ +do { \ + int size =3D strlen(cmd_names[c]); \ + if (l < size) { \ + return G_SOURCE_REMOVE; \ + } \ + memcpy(p, cmd_names[c], size); \ + p +=3D size; \ + l -=3D size; \ +} while (0) + +#define write_string(p, s, l) \ +do { \ + int size =3D strlen(s); \ + if (l < size + sizeof(int)) { \ + return G_SOURCE_REMOVE; \ + } \ + *(int *)p =3D htonl(size); \ + p +=3D sizeof(size); \ + l -=3D sizeof(size); \ + memcpy(p, s, size); \ + p +=3D size; \ + l -=3D size; \ +} while (0) + +static gboolean readcmd(InputBarrier *ib, struct barrierMsg *msg) +{ + int ret, len, i; + enum barrierCmd cmd; + char *p; + + ret =3D qio_channel_read(QIO_CHANNEL(ib->sioc), (char *)&len, sizeof(l= en), + NULL); + if (ret < 0) { + return G_SOURCE_REMOVE; + } + + len =3D ntohl(len); + if (len > MAX_HELLO_LENGTH) { + return G_SOURCE_REMOVE; + } + + ret =3D qio_channel_read(QIO_CHANNEL(ib->sioc), ib->buffer, len, NULL); + if (ret < 0) { + return G_SOURCE_REMOVE; + } + + p =3D ib->buffer; + if (len >=3D strlen(cmd_names[barrierCmdHello]) && + memcmp(p, cmd_names[barrierCmdHello], + strlen(cmd_names[barrierCmdHello])) =3D=3D 0) { + cmd =3D barrierCmdHello; + p +=3D strlen(cmd_names[barrierCmdHello]); + len -=3D strlen(cmd_names[barrierCmdHello]); + } else { + for (cmd =3D 0; cmd < barrierCmdHello; cmd++) { + if (memcmp(ib->buffer, cmd_names[cmd], 4) =3D=3D 0) { + break; + } + } + + if (cmd =3D=3D barrierCmdHello) { + return G_SOURCE_REMOVE; + } + p +=3D 4; + len -=3D 4; + } + + msg->cmd =3D cmd; + switch (cmd) { + /* connection */ + case barrierCmdHello: + read_short(msg->version.major, p, len); + read_short(msg->version.minor, p, len); + break; + case barrierCmdDSetOptions: + read_int(msg->set.nb, p, len); + msg->set.nb /=3D 2; + if (msg->set.nb > BARRIER_MAX_OPTIONS) { + msg->set.nb =3D BARRIER_MAX_OPTIONS; + } + i =3D 0; + while (len && i < msg->set.nb) { + read_int(msg->set.option[i].id, p, len); + /* it's a string, restore endianness */ + msg->set.option[i].id =3D htonl(msg->set.option[i].id); + msg->set.option[i].nul =3D 0; + read_int(msg->set.option[i].value, p, len); + i++; + } + break; + case barrierCmdQInfo: + break; + + /* mouse */ + case barrierCmdDMouseMove: + case barrierCmdDMouseRelMove: + read_short(msg->mousepos.x, p, len); + read_short(msg->mousepos.y, p, len); + break; + case barrierCmdDMouseDown: + case barrierCmdDMouseUp: + read_char(msg->mousebutton.buttonid, p, len); + break; + case barrierCmdDMouseWheel: + read_short(msg->mousepos.y, p, len); + msg->mousepos.x =3D 0; + if (len) { + msg->mousepos.x =3D msg->mousepos.y; + read_short(msg->mousepos.y, p, len); + } + break; + + /* keyboard */ + case barrierCmdDKeyDown: + case barrierCmdDKeyUp: + read_short(msg->key.keyid, p, len); + read_short(msg->key.modifier, p, len); + msg->key.button =3D 0; + if (len) { + read_short(msg->key.button, p, len); + } + break; + case barrierCmdDKeyRepeat: + read_short(msg->repeat.keyid, p, len); + read_short(msg->repeat.modifier, p, len); + read_short(msg->repeat.repeat, p, len); + msg->repeat.button =3D 0; + if (len) { + read_short(msg->repeat.button, p, len); + } + break; + case barrierCmdCInfoAck: + case barrierCmdCResetOptions: + case barrierCmdCEnter: + case barrierCmdDClipboard: + case barrierCmdCKeepAlive: + case barrierCmdCLeave: + case barrierCmdCClose: + break; + + /* Invalid from the server */ + case barrierCmdHelloBack: + case barrierCmdCNoop: + case barrierCmdDInfo: + break; + + /* Error codes */ + case barrierCmdEIncompatible: + read_short(msg->version.major, p, len); + read_short(msg->version.minor, p, len); + break; + case barrierCmdEBusy: + case barrierCmdEUnknown: + case barrierCmdEBad: + break; + default: + return G_SOURCE_REMOVE; + } + + return G_SOURCE_CONTINUE; +} + +static gboolean writecmd(InputBarrier *ib, struct barrierMsg *msg) +{ + char *p; + int ret, i; + int avail, len; + + p =3D ib->buffer; + avail =3D MAX_HELLO_LENGTH; + + /* reserve space to store the length */ + p +=3D sizeof(int); + avail -=3D sizeof(int); + + switch (msg->cmd) { + case barrierCmdHello: + if (msg->version.major < BARRIER_VERSION_MAJOR || + (msg->version.major =3D=3D BARRIER_VERSION_MAJOR && + msg->version.minor < BARRIER_VERSION_MINOR)) { + ib->ioc_tag =3D 0; + return G_SOURCE_REMOVE; + } + write_cmd(p, barrierCmdHelloBack, avail); + write_short(p, BARRIER_VERSION_MAJOR, avail); + write_short(p, BARRIER_VERSION_MINOR, avail); + write_string(p, ib->name, avail); + break; + case barrierCmdCClose: + ib->ioc_tag =3D 0; + return G_SOURCE_REMOVE; + case barrierCmdQInfo: + write_cmd(p, barrierCmdDInfo, avail); + write_short(p, ib->x_origin, avail); + write_short(p, ib->y_origin, avail); + write_short(p, ib->width, avail); + write_short(p, ib->height, avail); + write_short(p, 0, avail); /* warpsize (obsolete) */ + write_short(p, 0, avail); /* mouse x */ + write_short(p, 0, avail); /* mouse y */ + break; + case barrierCmdCInfoAck: + break; + case barrierCmdCResetOptions: + /* TODO: reset options */ + break; + case barrierCmdDSetOptions: + /* TODO: set options */ + break; + case barrierCmdCEnter: + break; + case barrierCmdDClipboard: + break; + case barrierCmdCKeepAlive: + write_cmd(p, barrierCmdCKeepAlive, avail); + break; + case barrierCmdCLeave: + break; + + /* mouse */ + case barrierCmdDMouseMove: + qemu_input_queue_abs(NULL, INPUT_AXIS_X, msg->mousepos.x, + ib->x_origin, ib->width); + qemu_input_queue_abs(NULL, INPUT_AXIS_Y, msg->mousepos.y, + ib->y_origin, ib->height); + qemu_input_event_sync(); + break; + case barrierCmdDMouseRelMove: + qemu_input_queue_rel(NULL, INPUT_AXIS_X, msg->mousepos.x); + qemu_input_queue_rel(NULL, INPUT_AXIS_Y, msg->mousepos.y); + qemu_input_event_sync(); + break; + case barrierCmdDMouseDown: + qemu_input_queue_btn(NULL, + input_barrier_to_mouse(msg->mousebutton.butto= nid), + true); + qemu_input_event_sync(); + break; + case barrierCmdDMouseUp: + qemu_input_queue_btn(NULL, + input_barrier_to_mouse(msg->mousebutton.butto= nid), + false); + qemu_input_event_sync(); + break; + case barrierCmdDMouseWheel: + qemu_input_queue_btn(NULL, (msg->mousepos.y > 0) ? INPUT_BUTTON_WH= EEL_UP + : INPUT_BUTTON_WHEEL_DOWN, true); + qemu_input_event_sync(); + qemu_input_queue_btn(NULL, (msg->mousepos.y > 0) ? INPUT_BUTTON_WH= EEL_UP + : INPUT_BUTTON_WHEEL_DOWN, false); + qemu_input_event_sync(); + break; + + /* keyboard */ + case barrierCmdDKeyDown: + qemu_input_event_send_key_qcode(NULL, + input_barrier_to_qcode(msg->key.keyid, msg->key.bu= tton), + true); + break; + case barrierCmdDKeyRepeat: + for (i =3D 0; i < msg->repeat.repeat; i++) { + qemu_input_event_send_key_qcode(NULL, + input_barrier_to_qcode(msg->repeat.keyid, msg->repeat.bu= tton), + false); + qemu_input_event_send_key_qcode(NULL, + input_barrier_to_qcode(msg->repeat.keyid, msg->repeat.bu= tton), + true); + } + break; + case barrierCmdDKeyUp: + qemu_input_event_send_key_qcode(NULL, + input_barrier_to_qcode(msg->key.keyid, msg->key.bu= tton), + false); + break; + default: + write_cmd(p, barrierCmdEUnknown, avail); + break;; + } + + len =3D MAX_HELLO_LENGTH - avail - sizeof(int); + if (len) { + p =3D ib->buffer; + avail =3D sizeof(len); + write_int(p, len, avail); + ret =3D qio_channel_write(QIO_CHANNEL(ib->sioc), ib->buffer, + len + sizeof(len), NULL); + if (ret < 0) { + ib->ioc_tag =3D 0; + return G_SOURCE_REMOVE; + } + } + + return G_SOURCE_CONTINUE; +} + +static gboolean input_barrier_event(QIOChannel *ioc G_GNUC_UNUSED, + GIOCondition condition, void *opaque) +{ + InputBarrier *ib =3D opaque; + int ret; + struct barrierMsg msg; + + ret =3D readcmd(ib, &msg); + if (ret =3D=3D G_SOURCE_REMOVE) { + ib->ioc_tag =3D 0; + return G_SOURCE_REMOVE; + } + + return writecmd(ib, &msg); +} + +static void input_barrier_complete(UserCreatable *uc, Error **errp) +{ + InputBarrier *ib =3D INPUT_BARRIER(uc); + Error *local_err =3D NULL; + + if (!ib->name) { + error_setg(errp, QERR_MISSING_PARAMETER, "name"); + return; + } + + /* + * Connect to the primary + * Primary is the server where the keyboard and the mouse + * are connected and forwarded to the secondary (the client) + */ + + ib->sioc =3D qio_channel_socket_new(); + qio_channel_set_name(QIO_CHANNEL(ib->sioc), "barrier-client"); + + qio_channel_socket_connect_sync(ib->sioc, &ib->saddr, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + qio_channel_set_delay(QIO_CHANNEL(ib->sioc), false); + + ib->ioc_tag =3D qio_channel_add_watch(QIO_CHANNEL(ib->sioc), G_IO_IN, + input_barrier_event, ib, NULL); +} + +static void input_barrier_instance_finalize(Object *obj) +{ + InputBarrier *ib =3D INPUT_BARRIER(obj); + + if (ib->ioc_tag) { + g_source_remove(ib->ioc_tag); + ib->ioc_tag =3D 0; + } + + if (ib->sioc) { + qio_channel_close(QIO_CHANNEL(ib->sioc), NULL); + object_unref(OBJECT(ib->sioc)); + } + g_free(ib->name); + g_free(ib->saddr.u.inet.host); + g_free(ib->saddr.u.inet.port); +} + +static char *input_barrier_get_name(Object *obj, Error **errp) +{ + InputBarrier *ib =3D INPUT_BARRIER(obj); + + return g_strdup(ib->name); +} + +static void input_barrier_set_name(Object *obj, const char *value, + Error **errp) +{ + InputBarrier *ib =3D INPUT_BARRIER(obj); + + if (ib->name) { + error_setg(errp, "name property already set"); + return; + } + ib->name =3D g_strdup(value); +} + +static char *input_barrier_get_server(Object *obj, Error **errp) +{ + InputBarrier *ib =3D INPUT_BARRIER(obj); + + return g_strdup(ib->saddr.u.inet.host); +} + +static void input_barrier_set_server(Object *obj, const char *value, + Error **errp) +{ + InputBarrier *ib =3D INPUT_BARRIER(obj); + + g_free(ib->saddr.u.inet.host); + ib->saddr.u.inet.host =3D g_strdup(value); +} + +static char *input_barrier_get_port(Object *obj, Error **errp) +{ + InputBarrier *ib =3D INPUT_BARRIER(obj); + + return g_strdup(ib->saddr.u.inet.port); +} + +static void input_barrier_set_port(Object *obj, const char *value, + Error **errp) +{ + InputBarrier *ib =3D INPUT_BARRIER(obj); + + g_free(ib->saddr.u.inet.port); + ib->saddr.u.inet.port =3D g_strdup(value); +} + +static void input_barrier_set_x_origin(Object *obj, const char *value, + Error **errp) +{ + InputBarrier *ib =3D INPUT_BARRIER(obj); + int result, err; + + err =3D qemu_strtoi(value, NULL, 0, &result); + if (err < 0 || result < 0 || result > SHRT_MAX) { + error_setg(errp, + "x-origin property must be in the range [0..%d]", SHRT_= MAX); + return; + } + ib->x_origin =3D result; +} + +static char *input_barrier_get_x_origin(Object *obj, Error **errp) +{ + InputBarrier *ib =3D INPUT_BARRIER(obj); + + return g_strdup_printf("%d", ib->x_origin); +} + +static void input_barrier_set_y_origin(Object *obj, const char *value, + Error **errp) +{ + InputBarrier *ib =3D INPUT_BARRIER(obj); + int result, err; + + err =3D qemu_strtoi(value, NULL, 0, &result); + if (err < 0 || result < 0 || result > SHRT_MAX) { + error_setg(errp, + "y-origin property must be in the range [0..%d]", SHRT_= MAX); + return; + } + ib->y_origin =3D result; +} + +static char *input_barrier_get_y_origin(Object *obj, Error **errp) +{ + InputBarrier *ib =3D INPUT_BARRIER(obj); + + return g_strdup_printf("%d", ib->y_origin); +} + +static void input_barrier_set_width(Object *obj, const char *value, + Error **errp) +{ + InputBarrier *ib =3D INPUT_BARRIER(obj); + int result, err; + + err =3D qemu_strtoi(value, NULL, 0, &result); + if (err < 0 || result < 0 || result > SHRT_MAX) { + error_setg(errp, + "width property must be in the range [0..%d]", SHRT_MAX= ); + return; + } + ib->width =3D result; +} + +static char *input_barrier_get_width(Object *obj, Error **errp) +{ + InputBarrier *ib =3D INPUT_BARRIER(obj); + + return g_strdup_printf("%d", ib->width); +} + +static void input_barrier_set_height(Object *obj, const char *value, + Error **errp) +{ + InputBarrier *ib =3D INPUT_BARRIER(obj); + int result, err; + + err =3D qemu_strtoi(value, NULL, 0, &result); + if (err < 0 || result < 0 || result > SHRT_MAX) { + error_setg(errp, + "height property must be in the range [0..%d]", SHRT_MA= X); + return; + } + ib->height =3D result; +} + +static char *input_barrier_get_height(Object *obj, Error **errp) +{ + InputBarrier *ib =3D INPUT_BARRIER(obj); + + return g_strdup_printf("%d", ib->height); +} + +static void input_barrier_instance_init(Object *obj) +{ + InputBarrier *ib =3D INPUT_BARRIER(obj); + + ib->saddr.type =3D SOCKET_ADDRESS_TYPE_INET; + ib->saddr.u.inet.host =3D g_strdup("localhost"); + ib->saddr.u.inet.port =3D g_strdup("24800"); + + ib->x_origin =3D 0; + ib->y_origin =3D 0; + ib->width =3D 1920; + ib->height =3D 1080; + + object_property_add_str(obj, "name", + input_barrier_get_name, + input_barrier_set_name, NULL); + object_property_add_str(obj, "server", + input_barrier_get_server, + input_barrier_set_server, NULL); + object_property_add_str(obj, "port", + input_barrier_get_port, + input_barrier_set_port, NULL); + object_property_add_str(obj, "x-origin", + input_barrier_get_x_origin, + input_barrier_set_x_origin, NULL); + object_property_add_str(obj, "y-origin", + input_barrier_get_y_origin, + input_barrier_set_y_origin, NULL); + object_property_add_str(obj, "width", + input_barrier_get_width, + input_barrier_set_width, NULL); + object_property_add_str(obj, "height", + input_barrier_get_height, + input_barrier_set_height, NULL); +} + +static void input_barrier_class_init(ObjectClass *oc, void *data) +{ + UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(oc); + + ucc->complete =3D input_barrier_complete; + + /* always use generic keymaps */ + if (keyboard_layout) { + /* We use X11 key id, so use VNC name2keysym */ + kbd_layout =3D init_keyboard_layout(name2keysym, keyboard_layout, + &error_fatal); + } +} + +static const TypeInfo input_barrier_info =3D { + .name =3D TYPE_INPUT_BARRIER, + .parent =3D TYPE_OBJECT, + .class_size =3D sizeof(InputBarrierClass), + .class_init =3D input_barrier_class_init, + .instance_size =3D sizeof(InputBarrier), + .instance_init =3D input_barrier_instance_init, + .instance_finalize =3D input_barrier_instance_finalize, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_USER_CREATABLE }, + { } + } +}; + +static void register_types(void) +{ + type_register_static(&input_barrier_info); +} + +type_init(register_types); diff --git a/ui/Makefile.objs b/ui/Makefile.objs index ba39080edb2b..e6da6ff047fd 100644 --- a/ui/Makefile.objs +++ b/ui/Makefile.objs @@ -9,6 +9,7 @@ vnc-obj-y +=3D vnc-jobs.o =20 common-obj-y +=3D keymaps.o console.o cursor.o qemu-pixman.o common-obj-y +=3D input.o input-keymap.o input-legacy.o kbd-state.o +common-obj-y +=3D input-barrier.o common-obj-$(CONFIG_LINUX) +=3D input-linux.o common-obj-$(CONFIG_SPICE) +=3D spice-core.o spice-input.o spice-display.o common-obj-$(CONFIG_COCOA) +=3D cocoa.o --=20 2.18.1 From nobody Sat May 4 02:57:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1568877198; cv=none; d=zoho.com; s=zohoarc; b=DTqTBYYBGPt/NCQ9P+27+RJnXeWSvvvNhkfqALlZPOzhyqyiC07IZIMU81VVA4aWS/hnWBCJn18LvVr8EGtTGmRXCnZuHwxbWnD1T7hoCtyKDZWTeHnsAG2SU4vMC7tlVkkFDM3lLgH2f//P5vI+FQORlMT/nUs4L9qjWYTOrX4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568877198; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=w98D7/vUb9njsVU/9+m67aFWMtgcl7guV1EsIhpoO7k=; b=HT1PpJ3GlGWf/sGlHtxo9n/NyzTD+7fJM7V0OfuX0fbdqwDqKya3IMBJTlgiDpxLBYJjJ4FhwZFu3Kwf5HEenawFIjF1lDMNi//eJMXU1Z1th3WRE9DzAmuMuMkyctAJHXxSpjFAoHsNZcAxIYGHOKYMujiFwB/OY+Nzy6Jqgfw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568877198127889.1152804577104; Thu, 19 Sep 2019 00:13:18 -0700 (PDT) Received: from localhost ([::1]:39308 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAqcu-0005ht-QA for importer@patchew.org; Thu, 19 Sep 2019 03:13:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53436) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAqZG-0001HO-Mt for qemu-devel@nongnu.org; Thu, 19 Sep 2019 03:09:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iAqZA-0004zC-6u for qemu-devel@nongnu.org; Thu, 19 Sep 2019 03:09:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55832) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iAqZ9-0004xz-Ot for qemu-devel@nongnu.org; Thu, 19 Sep 2019 03:09:24 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 11BA810CBC4B; Thu, 19 Sep 2019 07:09:23 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-47.ams2.redhat.com [10.36.116.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4EBD060872; Thu, 19 Sep 2019 07:09:19 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id A193B9D75; Thu, 19 Sep 2019 09:09:18 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 19 Sep 2019 09:09:18 +0200 Message-Id: <20190919070918.16059-5-kraxel@redhat.com> In-Reply-To: <20190919070918.16059-1-kraxel@redhat.com> References: <20190919070918.16059-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.66]); Thu, 19 Sep 2019 07:09:23 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 4/4] vnc: fix memory leak when vnc disconnect X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Li Qiang Currently when qemu receives a vnc connect, it creates a 'VncState' to represent this connection. In 'vnc_worker_thread_loop' it creates a local 'VncState'. The connection 'VcnState' and local 'VncState' exchange data in 'vnc_async_encoding_start' and 'vnc_async_encoding_end'. In 'zrle_compress_data' it calls 'deflateInit2' to allocate the libz library opaque data. The 'VncState' used in 'zrle_compress_data' is the local 'VncState'. In 'vnc_zrle_clear' it calls 'deflateEnd' to free the libz library opaque data. The 'VncState' used in 'vnc_zrle_clear' is the connect= ion 'VncState'. In currently implementation there will be a memory leak when the vnc disconnect. Following is the asan output backtrack: Direct leak of 29760 byte(s) in 5 object(s) allocated from: 0 0xffffa67ef3c3 in __interceptor_calloc (/lib64/libasan.so.4+0xd33c3) 1 0xffffa65071cb in g_malloc0 (/lib64/libglib-2.0.so.0+0x571cb) 2 0xffffa5e968f7 in deflateInit2_ (/lib64/libz.so.1+0x78f7) 3 0xaaaacec58613 in zrle_compress_data ui/vnc-enc-zrle.c:87 4 0xaaaacec58613 in zrle_send_framebuffer_update ui/vnc-enc-zrle.c:344 5 0xaaaacec34e77 in vnc_send_framebuffer_update ui/vnc.c:919 6 0xaaaacec5e023 in vnc_worker_thread_loop ui/vnc-jobs.c:271 7 0xaaaacec5e5e7 in vnc_worker_thread ui/vnc-jobs.c:340 8 0xaaaacee4d3c3 in qemu_thread_start util/qemu-thread-posix.c:502 9 0xffffa544e8bb in start_thread (/lib64/libpthread.so.0+0x78bb) 10 0xffffa53965cb in thread_start (/lib64/libc.so.6+0xd55cb) This is because the opaque allocated in 'deflateInit2' is not freed in 'deflateEnd'. The reason is that the 'deflateEnd' calls 'deflateStateCheck' and in the latter will check whether 's->strm !=3D strm'(libz's data struct= ure). This check will be true so in 'deflateEnd' it just return 'Z_STREAM_ERROR' = and not free the data allocated in 'deflateInit2'. The reason this happens is that the 'VncState' contains the whole 'VncZrle', so when calling 'deflateInit2', the 's->strm' will be the local address. So 's->strm !=3D strm' will be true. To fix this issue, we need to make 'zrle' of 'VncState' to be a pointer. Then the connection 'VncState' and local 'VncState' exchange mechanism will work as expection. The 'tight' of 'VncState' has the same issue, let's also= turn it to a pointer. Reported-by: Ying Fang Signed-off-by: Li Qiang Message-id: 20190831153922.121308-1-liq3ea@163.com Signed-off-by: Gerd Hoffmann --- ui/vnc.h | 4 +- ui/vnc-enc-tight.c | 219 +++++++++++++++++++++--------------------- ui/vnc-enc-zlib.c | 11 ++- ui/vnc-enc-zrle.c | 68 ++++++------- ui/vnc-enc-zrle.inc.c | 2 +- ui/vnc.c | 28 +++--- 6 files changed, 170 insertions(+), 162 deletions(-) diff --git a/ui/vnc.h b/ui/vnc.h index 86438609673a..fea79c2fc998 100644 --- a/ui/vnc.h +++ b/ui/vnc.h @@ -338,10 +338,10 @@ struct VncState /* Encoding specific, if you add something here, don't forget to * update vnc_async_encoding_start() */ - VncTight tight; + VncTight *tight; VncZlib zlib; VncHextile hextile; - VncZrle zrle; + VncZrle *zrle; VncZywrle zywrle; =20 Notifier mouse_mode_notifier; diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c index 9084c2201b31..1e0851826a84 100644 --- a/ui/vnc-enc-tight.c +++ b/ui/vnc-enc-tight.c @@ -116,7 +116,7 @@ static int send_png_rect(VncState *vs, int x, int y, in= t w, int h, =20 static bool tight_can_send_png_rect(VncState *vs, int w, int h) { - if (vs->tight.type !=3D VNC_ENCODING_TIGHT_PNG) { + if (vs->tight->type !=3D VNC_ENCODING_TIGHT_PNG) { return false; } =20 @@ -144,7 +144,7 @@ tight_detect_smooth_image24(VncState *vs, int w, int h) int pixels =3D 0; int pix, left[3]; unsigned int errors; - unsigned char *buf =3D vs->tight.tight.buffer; + unsigned char *buf =3D vs->tight->tight.buffer; =20 /* * If client is big-endian, color samples begin from the second @@ -215,7 +215,7 @@ tight_detect_smooth_image24(VncState *vs, int w, int h) int pixels =3D 0; \ int sample, sum, left[3]; \ unsigned int errors; \ - unsigned char *buf =3D vs->tight.tight.buffer; \ + unsigned char *buf =3D vs->tight->tight.buffer; = \ \ endian =3D 0; /* FIXME */ \ \ @@ -296,8 +296,8 @@ static int tight_detect_smooth_image(VncState *vs, int w, int h) { unsigned int errors; - int compression =3D vs->tight.compression; - int quality =3D vs->tight.quality; + int compression =3D vs->tight->compression; + int quality =3D vs->tight->quality; =20 if (!vs->vd->lossy) { return 0; @@ -309,7 +309,7 @@ tight_detect_smooth_image(VncState *vs, int w, int h) return 0; } =20 - if (vs->tight.quality !=3D (uint8_t)-1) { + if (vs->tight->quality !=3D (uint8_t)-1) { if (w * h < VNC_TIGHT_JPEG_MIN_RECT_SIZE) { return 0; } @@ -320,9 +320,9 @@ tight_detect_smooth_image(VncState *vs, int w, int h) } =20 if (vs->client_pf.bytes_per_pixel =3D=3D 4) { - if (vs->tight.pixel24) { + if (vs->tight->pixel24) { errors =3D tight_detect_smooth_image24(vs, w, h); - if (vs->tight.quality !=3D (uint8_t)-1) { + if (vs->tight->quality !=3D (uint8_t)-1) { return (errors < tight_conf[quality].jpeg_threshold24); } return (errors < tight_conf[compression].gradient_threshold24); @@ -352,7 +352,7 @@ tight_detect_smooth_image(VncState *vs, int w, int h) uint##bpp##_t c0, c1, ci; \ int i, n0, n1; \ \ - data =3D (uint##bpp##_t *)vs->tight.tight.buffer; \ + data =3D (uint##bpp##_t *)vs->tight->tight.buffer; \ \ c0 =3D data[0]; \ i =3D 1; \ @@ -423,9 +423,9 @@ static int tight_fill_palette(VncState *vs, int x, int = y, { int max; =20 - max =3D count / tight_conf[vs->tight.compression].idx_max_colors_divis= or; + max =3D count / tight_conf[vs->tight->compression].idx_max_colors_divi= sor; if (max < 2 && - count >=3D tight_conf[vs->tight.compression].mono_min_rect_size) { + count >=3D tight_conf[vs->tight->compression].mono_min_rect_size) { max =3D 2; } if (max >=3D 256) { @@ -558,7 +558,7 @@ tight_filter_gradient24(VncState *vs, uint8_t *buf, int= w, int h) int x, y, c; =20 buf32 =3D (uint32_t *)buf; - memset(vs->tight.gradient.buffer, 0, w * 3 * sizeof(int)); + memset(vs->tight->gradient.buffer, 0, w * 3 * sizeof(int)); =20 if (1 /* FIXME */) { shift[0] =3D vs->client_pf.rshift; @@ -575,7 +575,7 @@ tight_filter_gradient24(VncState *vs, uint8_t *buf, int= w, int h) upper[c] =3D 0; here[c] =3D 0; } - prev =3D (int *)vs->tight.gradient.buffer; + prev =3D (int *)vs->tight->gradient.buffer; for (x =3D 0; x < w; x++) { pix32 =3D *buf32++; for (c =3D 0; c < 3; c++) { @@ -615,7 +615,7 @@ tight_filter_gradient24(VncState *vs, uint8_t *buf, int= w, int h) int prediction; \ int x, y, c; \ \ - memset (vs->tight.gradient.buffer, 0, w * 3 * sizeof(int)); \ + memset(vs->tight->gradient.buffer, 0, w * 3 * sizeof(int)); \ \ endian =3D 0; /* FIXME */ \ \ @@ -631,7 +631,7 @@ tight_filter_gradient24(VncState *vs, uint8_t *buf, int= w, int h) upper[c] =3D 0; \ here[c] =3D 0; \ } \ - prev =3D (int *)vs->tight.gradient.buffer; \ + prev =3D (int *)vs->tight->gradient.buffer; = \ for (x =3D 0; x < w; x++) { \ pix =3D *buf; \ if (endian) { \ @@ -785,7 +785,7 @@ static void extend_solid_area(VncState *vs, int x, int = y, int w, int h, static int tight_init_stream(VncState *vs, int stream_id, int level, int strategy) { - z_streamp zstream =3D &vs->tight.stream[stream_id]; + z_streamp zstream =3D &vs->tight->stream[stream_id]; =20 if (zstream->opaque =3D=3D NULL) { int err; @@ -803,15 +803,15 @@ static int tight_init_stream(VncState *vs, int stream= _id, return -1; } =20 - vs->tight.levels[stream_id] =3D level; + vs->tight->levels[stream_id] =3D level; zstream->opaque =3D vs; } =20 - if (vs->tight.levels[stream_id] !=3D level) { + if (vs->tight->levels[stream_id] !=3D level) { if (deflateParams(zstream, level, strategy) !=3D Z_OK) { return -1; } - vs->tight.levels[stream_id] =3D level; + vs->tight->levels[stream_id] =3D level; } return 0; } @@ -839,11 +839,11 @@ static void tight_send_compact_size(VncState *vs, siz= e_t len) static int tight_compress_data(VncState *vs, int stream_id, size_t bytes, int level, int strategy) { - z_streamp zstream =3D &vs->tight.stream[stream_id]; + z_streamp zstream =3D &vs->tight->stream[stream_id]; int previous_out; =20 if (bytes < VNC_TIGHT_MIN_TO_COMPRESS) { - vnc_write(vs, vs->tight.tight.buffer, vs->tight.tight.offset); + vnc_write(vs, vs->tight->tight.buffer, vs->tight->tight.offset); return bytes; } =20 @@ -852,13 +852,13 @@ static int tight_compress_data(VncState *vs, int stre= am_id, size_t bytes, } =20 /* reserve memory in output buffer */ - buffer_reserve(&vs->tight.zlib, bytes + 64); + buffer_reserve(&vs->tight->zlib, bytes + 64); =20 /* set pointers */ - zstream->next_in =3D vs->tight.tight.buffer; - zstream->avail_in =3D vs->tight.tight.offset; - zstream->next_out =3D vs->tight.zlib.buffer + vs->tight.zlib.offset; - zstream->avail_out =3D vs->tight.zlib.capacity - vs->tight.zlib.offset; + zstream->next_in =3D vs->tight->tight.buffer; + zstream->avail_in =3D vs->tight->tight.offset; + zstream->next_out =3D vs->tight->zlib.buffer + vs->tight->zlib.offset; + zstream->avail_out =3D vs->tight->zlib.capacity - vs->tight->zlib.offs= et; previous_out =3D zstream->avail_out; zstream->data_type =3D Z_BINARY; =20 @@ -868,14 +868,14 @@ static int tight_compress_data(VncState *vs, int stre= am_id, size_t bytes, return -1; } =20 - vs->tight.zlib.offset =3D vs->tight.zlib.capacity - zstream->avail_out; + vs->tight->zlib.offset =3D vs->tight->zlib.capacity - zstream->avail_o= ut; /* ...how much data has actually been produced by deflate() */ bytes =3D previous_out - zstream->avail_out; =20 tight_send_compact_size(vs, bytes); - vnc_write(vs, vs->tight.zlib.buffer, bytes); + vnc_write(vs, vs->tight->zlib.buffer, bytes); =20 - buffer_reset(&vs->tight.zlib); + buffer_reset(&vs->tight->zlib); =20 return bytes; } @@ -927,16 +927,17 @@ static int send_full_color_rect(VncState *vs, int x, = int y, int w, int h) =20 vnc_write_u8(vs, stream << 4); /* no flushing, no filter */ =20 - if (vs->tight.pixel24) { - tight_pack24(vs, vs->tight.tight.buffer, w * h, &vs->tight.tight.o= ffset); + if (vs->tight->pixel24) { + tight_pack24(vs, vs->tight->tight.buffer, w * h, + &vs->tight->tight.offset); bytes =3D 3; } else { bytes =3D vs->client_pf.bytes_per_pixel; } =20 bytes =3D tight_compress_data(vs, stream, w * h * bytes, - tight_conf[vs->tight.compression].raw_zlib= _level, - Z_DEFAULT_STRATEGY); + tight_conf[vs->tight->compression].raw_zlib_le= vel, + Z_DEFAULT_STRATEGY); =20 return (bytes >=3D 0); } @@ -947,14 +948,14 @@ static int send_solid_rect(VncState *vs) =20 vnc_write_u8(vs, VNC_TIGHT_FILL << 4); /* no flushing, no filter */ =20 - if (vs->tight.pixel24) { - tight_pack24(vs, vs->tight.tight.buffer, 1, &vs->tight.tight.offse= t); + if (vs->tight->pixel24) { + tight_pack24(vs, vs->tight->tight.buffer, 1, &vs->tight->tight.off= set); bytes =3D 3; } else { bytes =3D vs->client_pf.bytes_per_pixel; } =20 - vnc_write(vs, vs->tight.tight.buffer, bytes); + vnc_write(vs, vs->tight->tight.buffer, bytes); return 1; } =20 @@ -963,7 +964,7 @@ static int send_mono_rect(VncState *vs, int x, int y, { ssize_t bytes; int stream =3D 1; - int level =3D tight_conf[vs->tight.compression].mono_zlib_level; + int level =3D tight_conf[vs->tight->compression].mono_zlib_level; =20 #ifdef CONFIG_VNC_PNG if (tight_can_send_png_rect(vs, w, h)) { @@ -991,26 +992,26 @@ static int send_mono_rect(VncState *vs, int x, int y, uint32_t buf[2] =3D {bg, fg}; size_t ret =3D sizeof (buf); =20 - if (vs->tight.pixel24) { + if (vs->tight->pixel24) { tight_pack24(vs, (unsigned char*)buf, 2, &ret); } vnc_write(vs, buf, ret); =20 - tight_encode_mono_rect32(vs->tight.tight.buffer, w, h, bg, fg); + tight_encode_mono_rect32(vs->tight->tight.buffer, w, h, bg, fg); break; } case 2: vnc_write(vs, &bg, 2); vnc_write(vs, &fg, 2); - tight_encode_mono_rect16(vs->tight.tight.buffer, w, h, bg, fg); + tight_encode_mono_rect16(vs->tight->tight.buffer, w, h, bg, fg); break; default: vnc_write_u8(vs, bg); vnc_write_u8(vs, fg); - tight_encode_mono_rect8(vs->tight.tight.buffer, w, h, bg, fg); + tight_encode_mono_rect8(vs->tight->tight.buffer, w, h, bg, fg); break; } - vs->tight.tight.offset =3D bytes; + vs->tight->tight.offset =3D bytes; =20 bytes =3D tight_compress_data(vs, stream, bytes, level, Z_DEFAULT_STRA= TEGY); return (bytes >=3D 0); @@ -1040,7 +1041,7 @@ static void write_palette(int idx, uint32_t color, vo= id *opaque) static bool send_gradient_rect(VncState *vs, int x, int y, int w, int h) { int stream =3D 3; - int level =3D tight_conf[vs->tight.compression].gradient_zlib_level; + int level =3D tight_conf[vs->tight->compression].gradient_zlib_level; ssize_t bytes; =20 if (vs->client_pf.bytes_per_pixel =3D=3D 1) { @@ -1050,23 +1051,23 @@ static bool send_gradient_rect(VncState *vs, int x,= int y, int w, int h) vnc_write_u8(vs, (stream | VNC_TIGHT_EXPLICIT_FILTER) << 4); vnc_write_u8(vs, VNC_TIGHT_FILTER_GRADIENT); =20 - buffer_reserve(&vs->tight.gradient, w * 3 * sizeof (int)); + buffer_reserve(&vs->tight->gradient, w * 3 * sizeof(int)); =20 - if (vs->tight.pixel24) { - tight_filter_gradient24(vs, vs->tight.tight.buffer, w, h); + if (vs->tight->pixel24) { + tight_filter_gradient24(vs, vs->tight->tight.buffer, w, h); bytes =3D 3; } else if (vs->client_pf.bytes_per_pixel =3D=3D 4) { - tight_filter_gradient32(vs, (uint32_t *)vs->tight.tight.buffer, w,= h); + tight_filter_gradient32(vs, (uint32_t *)vs->tight->tight.buffer, w= , h); bytes =3D 4; } else { - tight_filter_gradient16(vs, (uint16_t *)vs->tight.tight.buffer, w,= h); + tight_filter_gradient16(vs, (uint16_t *)vs->tight->tight.buffer, w= , h); bytes =3D 2; } =20 - buffer_reset(&vs->tight.gradient); + buffer_reset(&vs->tight->gradient); =20 bytes =3D w * h * bytes; - vs->tight.tight.offset =3D bytes; + vs->tight->tight.offset =3D bytes; =20 bytes =3D tight_compress_data(vs, stream, bytes, level, Z_FILTERED); @@ -1077,7 +1078,7 @@ static int send_palette_rect(VncState *vs, int x, int= y, int w, int h, VncPalette *palette) { int stream =3D 2; - int level =3D tight_conf[vs->tight.compression].idx_zlib_level; + int level =3D tight_conf[vs->tight->compression].idx_zlib_level; int colors; ssize_t bytes; =20 @@ -1104,12 +1105,12 @@ static int send_palette_rect(VncState *vs, int x, i= nt y, palette_iter(palette, write_palette, &priv); vnc_write(vs, header, sizeof(header)); =20 - if (vs->tight.pixel24) { + if (vs->tight->pixel24) { tight_pack24(vs, vs->output.buffer + old_offset, colors, &offs= et); vs->output.offset =3D old_offset + offset; } =20 - tight_encode_indexed_rect32(vs->tight.tight.buffer, w * h, palette= ); + tight_encode_indexed_rect32(vs->tight->tight.buffer, w * h, palett= e); break; } case 2: @@ -1119,7 +1120,7 @@ static int send_palette_rect(VncState *vs, int x, int= y, =20 palette_iter(palette, write_palette, &priv); vnc_write(vs, header, sizeof(header)); - tight_encode_indexed_rect16(vs->tight.tight.buffer, w * h, palette= ); + tight_encode_indexed_rect16(vs->tight->tight.buffer, w * h, palett= e); break; } default: @@ -1127,7 +1128,7 @@ static int send_palette_rect(VncState *vs, int x, int= y, break; } bytes =3D w * h; - vs->tight.tight.offset =3D bytes; + vs->tight->tight.offset =3D bytes; =20 bytes =3D tight_compress_data(vs, stream, bytes, level, Z_DEFAULT_STRATEGY); @@ -1146,7 +1147,7 @@ static int send_palette_rect(VncState *vs, int x, int= y, static void jpeg_init_destination(j_compress_ptr cinfo) { VncState *vs =3D cinfo->client_data; - Buffer *buffer =3D &vs->tight.jpeg; + Buffer *buffer =3D &vs->tight->jpeg; =20 cinfo->dest->next_output_byte =3D (JOCTET *)buffer->buffer + buffer->o= ffset; cinfo->dest->free_in_buffer =3D (size_t)(buffer->capacity - buffer->of= fset); @@ -1156,7 +1157,7 @@ static void jpeg_init_destination(j_compress_ptr cinf= o) static boolean jpeg_empty_output_buffer(j_compress_ptr cinfo) { VncState *vs =3D cinfo->client_data; - Buffer *buffer =3D &vs->tight.jpeg; + Buffer *buffer =3D &vs->tight->jpeg; =20 buffer->offset =3D buffer->capacity; buffer_reserve(buffer, 2048); @@ -1168,7 +1169,7 @@ static boolean jpeg_empty_output_buffer(j_compress_pt= r cinfo) static void jpeg_term_destination(j_compress_ptr cinfo) { VncState *vs =3D cinfo->client_data; - Buffer *buffer =3D &vs->tight.jpeg; + Buffer *buffer =3D &vs->tight->jpeg; =20 buffer->offset =3D buffer->capacity - cinfo->dest->free_in_buffer; } @@ -1187,7 +1188,7 @@ static int send_jpeg_rect(VncState *vs, int x, int y,= int w, int h, int quality) return send_full_color_rect(vs, x, y, w, h); } =20 - buffer_reserve(&vs->tight.jpeg, 2048); + buffer_reserve(&vs->tight->jpeg, 2048); =20 cinfo.err =3D jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); @@ -1222,9 +1223,9 @@ static int send_jpeg_rect(VncState *vs, int x, int y,= int w, int h, int quality) =20 vnc_write_u8(vs, VNC_TIGHT_JPEG << 4); =20 - tight_send_compact_size(vs, vs->tight.jpeg.offset); - vnc_write(vs, vs->tight.jpeg.buffer, vs->tight.jpeg.offset); - buffer_reset(&vs->tight.jpeg); + tight_send_compact_size(vs, vs->tight->jpeg.offset); + vnc_write(vs, vs->tight->jpeg.buffer, vs->tight->jpeg.offset); + buffer_reset(&vs->tight->jpeg); =20 return 1; } @@ -1240,7 +1241,7 @@ static void write_png_palette(int idx, uint32_t pix, = void *opaque) VncState *vs =3D priv->vs; png_colorp color =3D &priv->png_palette[idx]; =20 - if (vs->tight.pixel24) + if (vs->tight->pixel24) { color->red =3D (pix >> vs->client_pf.rshift) & vs->client_pf.rmax; color->green =3D (pix >> vs->client_pf.gshift) & vs->client_pf.gma= x; @@ -1267,10 +1268,10 @@ static void png_write_data(png_structp png_ptr, png= _bytep data, { VncState *vs =3D png_get_io_ptr(png_ptr); =20 - buffer_reserve(&vs->tight.png, vs->tight.png.offset + length); - memcpy(vs->tight.png.buffer + vs->tight.png.offset, data, length); + buffer_reserve(&vs->tight->png, vs->tight->png.offset + length); + memcpy(vs->tight->png.buffer + vs->tight->png.offset, data, length); =20 - vs->tight.png.offset +=3D length; + vs->tight->png.offset +=3D length; } =20 static void png_flush_data(png_structp png_ptr) @@ -1295,8 +1296,8 @@ static int send_png_rect(VncState *vs, int x, int y, = int w, int h, png_infop info_ptr; png_colorp png_palette =3D NULL; pixman_image_t *linebuf; - int level =3D tight_png_conf[vs->tight.compression].png_zlib_level; - int filters =3D tight_png_conf[vs->tight.compression].png_filters; + int level =3D tight_png_conf[vs->tight->compression].png_zlib_level; + int filters =3D tight_png_conf[vs->tight->compression].png_filters; uint8_t *buf; int dy; =20 @@ -1340,21 +1341,23 @@ static int send_png_rect(VncState *vs, int x, int y= , int w, int h, png_set_PLTE(png_ptr, info_ptr, png_palette, palette_size(palette)= ); =20 if (vs->client_pf.bytes_per_pixel =3D=3D 4) { - tight_encode_indexed_rect32(vs->tight.tight.buffer, w * h, pal= ette); + tight_encode_indexed_rect32(vs->tight->tight.buffer, w * h, + palette); } else { - tight_encode_indexed_rect16(vs->tight.tight.buffer, w * h, pal= ette); + tight_encode_indexed_rect16(vs->tight->tight.buffer, w * h, + palette); } } =20 png_write_info(png_ptr, info_ptr); =20 - buffer_reserve(&vs->tight.png, 2048); + buffer_reserve(&vs->tight->png, 2048); linebuf =3D qemu_pixman_linebuf_create(PIXMAN_BE_r8g8b8, w); buf =3D (uint8_t *)pixman_image_get_data(linebuf); for (dy =3D 0; dy < h; dy++) { if (color_type =3D=3D PNG_COLOR_TYPE_PALETTE) { - memcpy(buf, vs->tight.tight.buffer + (dy * w), w); + memcpy(buf, vs->tight->tight.buffer + (dy * w), w); } else { qemu_pixman_linebuf_fill(linebuf, vs->vd->server, w, x, y + dy= ); } @@ -1372,27 +1375,27 @@ static int send_png_rect(VncState *vs, int x, int y= , int w, int h, =20 vnc_write_u8(vs, VNC_TIGHT_PNG << 4); =20 - tight_send_compact_size(vs, vs->tight.png.offset); - vnc_write(vs, vs->tight.png.buffer, vs->tight.png.offset); - buffer_reset(&vs->tight.png); + tight_send_compact_size(vs, vs->tight->png.offset); + vnc_write(vs, vs->tight->png.buffer, vs->tight->png.offset); + buffer_reset(&vs->tight->png); return 1; } #endif /* CONFIG_VNC_PNG */ =20 static void vnc_tight_start(VncState *vs) { - buffer_reset(&vs->tight.tight); + buffer_reset(&vs->tight->tight); =20 // make the output buffer be the zlib buffer, so we can compress it la= ter - vs->tight.tmp =3D vs->output; - vs->output =3D vs->tight.tight; + vs->tight->tmp =3D vs->output; + vs->output =3D vs->tight->tight; } =20 static void vnc_tight_stop(VncState *vs) { // switch back to normal output/zlib buffers - vs->tight.tight =3D vs->output; - vs->output =3D vs->tight.tmp; + vs->tight->tight =3D vs->output; + vs->output =3D vs->tight->tmp; } =20 static int send_sub_rect_nojpeg(VncState *vs, int x, int y, int w, int h, @@ -1426,9 +1429,9 @@ static int send_sub_rect_jpeg(VncState *vs, int x, in= t y, int w, int h, int ret; =20 if (colors =3D=3D 0) { - if (force || (tight_jpeg_conf[vs->tight.quality].jpeg_full && + if (force || (tight_jpeg_conf[vs->tight->quality].jpeg_full && tight_detect_smooth_image(vs, w, h))) { - int quality =3D tight_conf[vs->tight.quality].jpeg_quality; + int quality =3D tight_conf[vs->tight->quality].jpeg_quality; =20 ret =3D send_jpeg_rect(vs, x, y, w, h, quality); } else { @@ -1440,9 +1443,9 @@ static int send_sub_rect_jpeg(VncState *vs, int x, in= t y, int w, int h, ret =3D send_mono_rect(vs, x, y, w, h, bg, fg); } else if (colors <=3D 256) { if (force || (colors > 96 && - tight_jpeg_conf[vs->tight.quality].jpeg_idx && + tight_jpeg_conf[vs->tight->quality].jpeg_idx && tight_detect_smooth_image(vs, w, h))) { - int quality =3D tight_conf[vs->tight.quality].jpeg_quality; + int quality =3D tight_conf[vs->tight->quality].jpeg_quality; =20 ret =3D send_jpeg_rect(vs, x, y, w, h, quality); } else { @@ -1480,20 +1483,20 @@ static int send_sub_rect(VncState *vs, int x, int y= , int w, int h) qemu_thread_atexit_add(&vnc_tight_cleanup_notifier); } =20 - vnc_framebuffer_update(vs, x, y, w, h, vs->tight.type); + vnc_framebuffer_update(vs, x, y, w, h, vs->tight->type); =20 vnc_tight_start(vs); vnc_raw_send_framebuffer_update(vs, x, y, w, h); vnc_tight_stop(vs); =20 #ifdef CONFIG_VNC_JPEG - if (!vs->vd->non_adaptive && vs->tight.quality !=3D (uint8_t)-1) { + if (!vs->vd->non_adaptive && vs->tight->quality !=3D (uint8_t)-1) { double freq =3D vnc_update_freq(vs, x, y, w, h); =20 - if (freq < tight_jpeg_conf[vs->tight.quality].jpeg_freq_min) { + if (freq < tight_jpeg_conf[vs->tight->quality].jpeg_freq_min) { allow_jpeg =3D false; } - if (freq >=3D tight_jpeg_conf[vs->tight.quality].jpeg_freq_thresho= ld) { + if (freq >=3D tight_jpeg_conf[vs->tight->quality].jpeg_freq_thresh= old) { force_jpeg =3D true; vnc_sent_lossy_rect(vs, x, y, w, h); } @@ -1503,7 +1506,7 @@ static int send_sub_rect(VncState *vs, int x, int y, = int w, int h) colors =3D tight_fill_palette(vs, x, y, w * h, &bg, &fg, color_count_p= alette); =20 #ifdef CONFIG_VNC_JPEG - if (allow_jpeg && vs->tight.quality !=3D (uint8_t)-1) { + if (allow_jpeg && vs->tight->quality !=3D (uint8_t)-1) { ret =3D send_sub_rect_jpeg(vs, x, y, w, h, bg, fg, colors, color_count_palette, force_jpeg); } else { @@ -1520,7 +1523,7 @@ static int send_sub_rect(VncState *vs, int x, int y, = int w, int h) =20 static int send_sub_rect_solid(VncState *vs, int x, int y, int w, int h) { - vnc_framebuffer_update(vs, x, y, w, h, vs->tight.type); + vnc_framebuffer_update(vs, x, y, w, h, vs->tight->type); =20 vnc_tight_start(vs); vnc_raw_send_framebuffer_update(vs, x, y, w, h); @@ -1538,8 +1541,8 @@ static int send_rect_simple(VncState *vs, int x, int = y, int w, int h, int rw, rh; int n =3D 0; =20 - max_size =3D tight_conf[vs->tight.compression].max_rect_size; - max_width =3D tight_conf[vs->tight.compression].max_rect_width; + max_size =3D tight_conf[vs->tight->compression].max_rect_size; + max_width =3D tight_conf[vs->tight->compression].max_rect_width; =20 if (split && (w > max_width || w * h > max_size)) { max_sub_width =3D (w > max_width) ? max_width : w; @@ -1648,16 +1651,16 @@ static int tight_send_framebuffer_update(VncState *= vs, int x, int y, =20 if (vs->client_pf.bytes_per_pixel =3D=3D 4 && vs->client_pf.rmax =3D= =3D 0xFF && vs->client_pf.bmax =3D=3D 0xFF && vs->client_pf.gmax =3D=3D 0xFF) { - vs->tight.pixel24 =3D true; + vs->tight->pixel24 =3D true; } else { - vs->tight.pixel24 =3D false; + vs->tight->pixel24 =3D false; } =20 #ifdef CONFIG_VNC_JPEG - if (vs->tight.quality !=3D (uint8_t)-1) { + if (vs->tight->quality !=3D (uint8_t)-1) { double freq =3D vnc_update_freq(vs, x, y, w, h); =20 - if (freq > tight_jpeg_conf[vs->tight.quality].jpeg_freq_threshold)= { + if (freq > tight_jpeg_conf[vs->tight->quality].jpeg_freq_threshold= ) { return send_rect_simple(vs, x, y, w, h, false); } } @@ -1669,8 +1672,8 @@ static int tight_send_framebuffer_update(VncState *vs= , int x, int y, =20 /* Calculate maximum number of rows in one non-solid rectangle. */ =20 - max_rows =3D tight_conf[vs->tight.compression].max_rect_size; - max_rows /=3D MIN(tight_conf[vs->tight.compression].max_rect_width, w); + max_rows =3D tight_conf[vs->tight->compression].max_rect_size; + max_rows /=3D MIN(tight_conf[vs->tight->compression].max_rect_width, w= ); =20 return find_large_solid_color_rect(vs, x, y, w, h, max_rows); } @@ -1678,33 +1681,33 @@ static int tight_send_framebuffer_update(VncState *= vs, int x, int y, int vnc_tight_send_framebuffer_update(VncState *vs, int x, int y, int w, int h) { - vs->tight.type =3D VNC_ENCODING_TIGHT; + vs->tight->type =3D VNC_ENCODING_TIGHT; return tight_send_framebuffer_update(vs, x, y, w, h); } =20 int vnc_tight_png_send_framebuffer_update(VncState *vs, int x, int y, int w, int h) { - vs->tight.type =3D VNC_ENCODING_TIGHT_PNG; + vs->tight->type =3D VNC_ENCODING_TIGHT_PNG; return tight_send_framebuffer_update(vs, x, y, w, h); } =20 void vnc_tight_clear(VncState *vs) { int i; - for (i=3D0; itight.stream); i++) { - if (vs->tight.stream[i].opaque) { - deflateEnd(&vs->tight.stream[i]); + for (i =3D 0; i < ARRAY_SIZE(vs->tight->stream); i++) { + if (vs->tight->stream[i].opaque) { + deflateEnd(&vs->tight->stream[i]); } } =20 - buffer_free(&vs->tight.tight); - buffer_free(&vs->tight.zlib); - buffer_free(&vs->tight.gradient); + buffer_free(&vs->tight->tight); + buffer_free(&vs->tight->zlib); + buffer_free(&vs->tight->gradient); #ifdef CONFIG_VNC_JPEG - buffer_free(&vs->tight.jpeg); + buffer_free(&vs->tight->jpeg); #endif #ifdef CONFIG_VNC_PNG - buffer_free(&vs->tight.png); + buffer_free(&vs->tight->png); #endif } diff --git a/ui/vnc-enc-zlib.c b/ui/vnc-enc-zlib.c index 33e9df2f6ade..900ae5b30f6b 100644 --- a/ui/vnc-enc-zlib.c +++ b/ui/vnc-enc-zlib.c @@ -76,7 +76,8 @@ static int vnc_zlib_stop(VncState *vs) zstream->zalloc =3D vnc_zlib_zalloc; zstream->zfree =3D vnc_zlib_zfree; =20 - err =3D deflateInit2(zstream, vs->tight.compression, Z_DEFLATED, M= AX_WBITS, + err =3D deflateInit2(zstream, vs->tight->compression, Z_DEFLATED, + MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY); =20 if (err !=3D Z_OK) { @@ -84,16 +85,16 @@ static int vnc_zlib_stop(VncState *vs) return -1; } =20 - vs->zlib.level =3D vs->tight.compression; + vs->zlib.level =3D vs->tight->compression; zstream->opaque =3D vs; } =20 - if (vs->tight.compression !=3D vs->zlib.level) { - if (deflateParams(zstream, vs->tight.compression, + if (vs->tight->compression !=3D vs->zlib.level) { + if (deflateParams(zstream, vs->tight->compression, Z_DEFAULT_STRATEGY) !=3D Z_OK) { return -1; } - vs->zlib.level =3D vs->tight.compression; + vs->zlib.level =3D vs->tight->compression; } =20 // reserve memory in output buffer diff --git a/ui/vnc-enc-zrle.c b/ui/vnc-enc-zrle.c index 7493a8472306..17fd28a2e2b0 100644 --- a/ui/vnc-enc-zrle.c +++ b/ui/vnc-enc-zrle.c @@ -37,18 +37,18 @@ static const int bits_per_packed_pixel[] =3D { =20 static void vnc_zrle_start(VncState *vs) { - buffer_reset(&vs->zrle.zrle); + buffer_reset(&vs->zrle->zrle); =20 /* make the output buffer be the zlib buffer, so we can compress it la= ter */ - vs->zrle.tmp =3D vs->output; - vs->output =3D vs->zrle.zrle; + vs->zrle->tmp =3D vs->output; + vs->output =3D vs->zrle->zrle; } =20 static void vnc_zrle_stop(VncState *vs) { /* switch back to normal output/zlib buffers */ - vs->zrle.zrle =3D vs->output; - vs->output =3D vs->zrle.tmp; + vs->zrle->zrle =3D vs->output; + vs->output =3D vs->zrle->tmp; } =20 static void *zrle_convert_fb(VncState *vs, int x, int y, int w, int h, @@ -56,24 +56,24 @@ static void *zrle_convert_fb(VncState *vs, int x, int y= , int w, int h, { Buffer tmp; =20 - buffer_reset(&vs->zrle.fb); - buffer_reserve(&vs->zrle.fb, w * h * bpp + bpp); + buffer_reset(&vs->zrle->fb); + buffer_reserve(&vs->zrle->fb, w * h * bpp + bpp); =20 tmp =3D vs->output; - vs->output =3D vs->zrle.fb; + vs->output =3D vs->zrle->fb; =20 vnc_raw_send_framebuffer_update(vs, x, y, w, h); =20 - vs->zrle.fb =3D vs->output; + vs->zrle->fb =3D vs->output; vs->output =3D tmp; - return vs->zrle.fb.buffer; + return vs->zrle->fb.buffer; } =20 static int zrle_compress_data(VncState *vs, int level) { - z_streamp zstream =3D &vs->zrle.stream; + z_streamp zstream =3D &vs->zrle->stream; =20 - buffer_reset(&vs->zrle.zlib); + buffer_reset(&vs->zrle->zlib); =20 if (zstream->opaque !=3D vs) { int err; @@ -93,13 +93,13 @@ static int zrle_compress_data(VncState *vs, int level) } =20 /* reserve memory in output buffer */ - buffer_reserve(&vs->zrle.zlib, vs->zrle.zrle.offset + 64); + buffer_reserve(&vs->zrle->zlib, vs->zrle->zrle.offset + 64); =20 /* set pointers */ - zstream->next_in =3D vs->zrle.zrle.buffer; - zstream->avail_in =3D vs->zrle.zrle.offset; - zstream->next_out =3D vs->zrle.zlib.buffer + vs->zrle.zlib.offset; - zstream->avail_out =3D vs->zrle.zlib.capacity - vs->zrle.zlib.offset; + zstream->next_in =3D vs->zrle->zrle.buffer; + zstream->avail_in =3D vs->zrle->zrle.offset; + zstream->next_out =3D vs->zrle->zlib.buffer + vs->zrle->zlib.offset; + zstream->avail_out =3D vs->zrle->zlib.capacity - vs->zrle->zlib.offset; zstream->data_type =3D Z_BINARY; =20 /* start encoding */ @@ -108,8 +108,8 @@ static int zrle_compress_data(VncState *vs, int level) return -1; } =20 - vs->zrle.zlib.offset =3D vs->zrle.zlib.capacity - zstream->avail_out; - return vs->zrle.zlib.offset; + vs->zrle->zlib.offset =3D vs->zrle->zlib.capacity - zstream->avail_out; + return vs->zrle->zlib.offset; } =20 /* Try to work out whether to use RLE and/or a palette. We do this by @@ -259,14 +259,14 @@ static int zrle_send_framebuffer_update(VncState *vs,= int x, int y, size_t bytes; int zywrle_level; =20 - if (vs->zrle.type =3D=3D VNC_ENCODING_ZYWRLE) { - if (!vs->vd->lossy || vs->tight.quality =3D=3D (uint8_t)-1 - || vs->tight.quality =3D=3D 9) { + if (vs->zrle->type =3D=3D VNC_ENCODING_ZYWRLE) { + if (!vs->vd->lossy || vs->tight->quality =3D=3D (uint8_t)-1 + || vs->tight->quality =3D=3D 9) { zywrle_level =3D 0; - vs->zrle.type =3D VNC_ENCODING_ZRLE; - } else if (vs->tight.quality < 3) { + vs->zrle->type =3D VNC_ENCODING_ZRLE; + } else if (vs->tight->quality < 3) { zywrle_level =3D 3; - } else if (vs->tight.quality < 6) { + } else if (vs->tight->quality < 6) { zywrle_level =3D 2; } else { zywrle_level =3D 1; @@ -337,30 +337,30 @@ static int zrle_send_framebuffer_update(VncState *vs,= int x, int y, =20 vnc_zrle_stop(vs); bytes =3D zrle_compress_data(vs, Z_DEFAULT_COMPRESSION); - vnc_framebuffer_update(vs, x, y, w, h, vs->zrle.type); + vnc_framebuffer_update(vs, x, y, w, h, vs->zrle->type); vnc_write_u32(vs, bytes); - vnc_write(vs, vs->zrle.zlib.buffer, vs->zrle.zlib.offset); + vnc_write(vs, vs->zrle->zlib.buffer, vs->zrle->zlib.offset); return 1; } =20 int vnc_zrle_send_framebuffer_update(VncState *vs, int x, int y, int w, in= t h) { - vs->zrle.type =3D VNC_ENCODING_ZRLE; + vs->zrle->type =3D VNC_ENCODING_ZRLE; return zrle_send_framebuffer_update(vs, x, y, w, h); } =20 int vnc_zywrle_send_framebuffer_update(VncState *vs, int x, int y, int w, = int h) { - vs->zrle.type =3D VNC_ENCODING_ZYWRLE; + vs->zrle->type =3D VNC_ENCODING_ZYWRLE; return zrle_send_framebuffer_update(vs, x, y, w, h); } =20 void vnc_zrle_clear(VncState *vs) { - if (vs->zrle.stream.opaque) { - deflateEnd(&vs->zrle.stream); + if (vs->zrle->stream.opaque) { + deflateEnd(&vs->zrle->stream); } - buffer_free(&vs->zrle.zrle); - buffer_free(&vs->zrle.fb); - buffer_free(&vs->zrle.zlib); + buffer_free(&vs->zrle->zrle); + buffer_free(&vs->zrle->fb); + buffer_free(&vs->zrle->zlib); } diff --git a/ui/vnc-enc-zrle.inc.c b/ui/vnc-enc-zrle.inc.c index abf6b86e4eba..c107d8affcff 100644 --- a/ui/vnc-enc-zrle.inc.c +++ b/ui/vnc-enc-zrle.inc.c @@ -96,7 +96,7 @@ static void ZRLE_ENCODE(VncState *vs, int x, int y, int w= , int h, static void ZRLE_ENCODE_TILE(VncState *vs, ZRLE_PIXEL *data, int w, int h, int zywrle_level) { - VncPalette *palette =3D &vs->zrle.palette; + VncPalette *palette =3D &vs->zrle->palette; =20 int runs =3D 0; int single_pixels =3D 0; diff --git a/ui/vnc.c b/ui/vnc.c index bc43c4ca16bf..87b8045afec2 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -1307,6 +1307,8 @@ void vnc_disconnect_finish(VncState *vs) object_unref(OBJECT(vs->sioc)); vs->sioc =3D NULL; vs->magic =3D 0; + g_free(vs->zrle); + g_free(vs->tight); g_free(vs); } =20 @@ -2058,8 +2060,8 @@ static void set_encodings(VncState *vs, int32_t *enco= dings, size_t n_encodings) =20 vs->features =3D 0; vs->vnc_encoding =3D 0; - vs->tight.compression =3D 9; - vs->tight.quality =3D -1; /* Lossless by default */ + vs->tight->compression =3D 9; + vs->tight->quality =3D -1; /* Lossless by default */ vs->absolute =3D -1; =20 /* @@ -2127,11 +2129,11 @@ static void set_encodings(VncState *vs, int32_t *en= codings, size_t n_encodings) vs->features |=3D VNC_FEATURE_LED_STATE_MASK; break; case VNC_ENCODING_COMPRESSLEVEL0 ... VNC_ENCODING_COMPRESSLEVEL0 += 9: - vs->tight.compression =3D (enc & 0x0F); + vs->tight->compression =3D (enc & 0x0F); break; case VNC_ENCODING_QUALITYLEVEL0 ... VNC_ENCODING_QUALITYLEVEL0 + 9: if (vs->vd->lossy) { - vs->tight.quality =3D (enc & 0x0F); + vs->tight->quality =3D (enc & 0x0F); } break; default: @@ -3034,6 +3036,8 @@ static void vnc_connect(VncDisplay *vd, QIOChannelSoc= ket *sioc, int i; =20 trace_vnc_client_connect(vs, sioc); + vs->zrle =3D g_new0(VncZrle, 1); + vs->tight =3D g_new0(VncTight, 1); vs->magic =3D VNC_MAGIC; vs->sioc =3D sioc; object_ref(OBJECT(vs->sioc)); @@ -3045,19 +3049,19 @@ static void vnc_connect(VncDisplay *vd, QIOChannelS= ocket *sioc, buffer_init(&vs->output, "vnc-output/%p", sioc); buffer_init(&vs->jobs_buffer, "vnc-jobs_buffer/%p", sioc); =20 - buffer_init(&vs->tight.tight, "vnc-tight/%p", sioc); - buffer_init(&vs->tight.zlib, "vnc-tight-zlib/%p", sioc); - buffer_init(&vs->tight.gradient, "vnc-tight-gradient/%p", sioc); + buffer_init(&vs->tight->tight, "vnc-tight/%p", sioc); + buffer_init(&vs->tight->zlib, "vnc-tight-zlib/%p", sioc); + buffer_init(&vs->tight->gradient, "vnc-tight-gradient/%p", sioc); #ifdef CONFIG_VNC_JPEG - buffer_init(&vs->tight.jpeg, "vnc-tight-jpeg/%p", sioc); + buffer_init(&vs->tight->jpeg, "vnc-tight-jpeg/%p", sioc); #endif #ifdef CONFIG_VNC_PNG - buffer_init(&vs->tight.png, "vnc-tight-png/%p", sioc); + buffer_init(&vs->tight->png, "vnc-tight-png/%p", sioc); #endif buffer_init(&vs->zlib.zlib, "vnc-zlib/%p", sioc); - buffer_init(&vs->zrle.zrle, "vnc-zrle/%p", sioc); - buffer_init(&vs->zrle.fb, "vnc-zrle-fb/%p", sioc); - buffer_init(&vs->zrle.zlib, "vnc-zrle-zlib/%p", sioc); + buffer_init(&vs->zrle->zrle, "vnc-zrle/%p", sioc); + buffer_init(&vs->zrle->fb, "vnc-zrle-fb/%p", sioc); + buffer_init(&vs->zrle->zlib, "vnc-zrle-zlib/%p", sioc); =20 if (skipauth) { vs->auth =3D VNC_AUTH_NONE; --=20 2.18.1