From nobody Tue Feb 10 12:58:50 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1647263264781998.9630839989128; Mon, 14 Mar 2022 06:07:44 -0700 (PDT) Received: from localhost ([::1]:40548 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nTkQJ-0006wA-N5 for importer@patchew.org; Mon, 14 Mar 2022 09:07:43 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33692) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nTkJa-0004fP-QX for qemu-devel@nongnu.org; Mon, 14 Mar 2022 09:00:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:27826) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nTkJY-00037Z-8i for qemu-devel@nongnu.org; Mon, 14 Mar 2022 09:00:46 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-630-xplI0cWGNI2MNQMdlp0ahw-1; Mon, 14 Mar 2022 09:00:40 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6E0BA3C1EA52; Mon, 14 Mar 2022 13:00:39 +0000 (UTC) Received: from localhost (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id C49D9463E09; Mon, 14 Mar 2022 13:00:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647262843; 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: in-reply-to:in-reply-to:references:references; bh=KkQnyUCGjkrsCbou8EryJJhDknNNAec4lt7j2S6Ur9g=; b=O/g1OKLr8YUD3wAOOeFcWGsXeJVzjQ85ynbIqe+oRFU5asRPV8bQwBC7E/SzGfc86HFWZ3 UKSYjTVJg/G3Q2FjNOXuAPMl0vTmiLddQ5LJVTLKgT+o9pt4VUxM0rcifVjr0340kNeG1B 78uSH5iC6GryBuBQA4CahQShnMLtC3k= X-MC-Unique: xplI0cWGNI2MNQMdlp0ahw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PULL 10/12] ui/dbus: fix texture sharing Date: Mon, 14 Mar 2022 16:59:38 +0400 Message-Id: <20220314125940.1866728-11-marcandre.lureau@redhat.com> In-Reply-To: <20220314125940.1866728-1-marcandre.lureau@redhat.com> References: <20220314125940.1866728-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: , Cc: peter.maydell@linaro.org, kraxel@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1647263266859100001 From: Marc-Andr=C3=A9 Lureau The DBus listener naively create, update and destroy textures without taking into account other listeners. The texture were shared, but texture update was unnecessarily duplicated. Teach DisplayGLCtx to do optionally shared texture handling. This is only implemented for DBus display at this point, however the same infrastructure could potentially be used for other future combinations. Reported-by: Akihiko Odaki Signed-off-by: Marc-Andr=C3=A9 Lureau Acked-by: Gerd Hoffmann --- include/ui/console.h | 10 ++++++++++ ui/console.c | 26 ++++++++++++++++++++++++++ ui/dbus-listener.c | 11 ----------- ui/dbus.c | 26 ++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 11 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index 18a10c0b7db0..0f84861933e1 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -290,10 +290,20 @@ typedef struct DisplayGLCtxOps { QEMUGLContext ctx); int (*dpy_gl_ctx_make_current)(DisplayGLCtx *dgc, QEMUGLContext ctx); + void (*dpy_gl_ctx_create_texture)(DisplayGLCtx *dgc, + DisplaySurface *surface); + void (*dpy_gl_ctx_destroy_texture)(DisplayGLCtx *dgc, + DisplaySurface *surface); + void (*dpy_gl_ctx_update_texture)(DisplayGLCtx *dgc, + DisplaySurface *surface, + int x, int y, int w, int h); } DisplayGLCtxOps; =20 struct DisplayGLCtx { const DisplayGLCtxOps *ops; +#ifdef CONFIG_OPENGL + QemuGLShader *gls; /* optional shared shader */ +#endif }; =20 DisplayState *init_displaystate(void); diff --git a/ui/console.c b/ui/console.c index 06ba82db61c9..5bfecea4549e 100644 --- a/ui/console.c +++ b/ui/console.c @@ -1073,6 +1073,27 @@ static void displaychangelistener_gfx_switch(Display= ChangeListener *dcl, } } =20 +static void dpy_gfx_create_texture(QemuConsole *con, DisplaySurface *surfa= ce) +{ + if (con->gl && con->gl->ops->dpy_gl_ctx_create_texture) { + con->gl->ops->dpy_gl_ctx_create_texture(con->gl, surface); + } +} + +static void dpy_gfx_destroy_texture(QemuConsole *con, DisplaySurface *surf= ace) +{ + if (con->gl && con->gl->ops->dpy_gl_ctx_destroy_texture) { + con->gl->ops->dpy_gl_ctx_destroy_texture(con->gl, surface); + } +} + +static void dpy_gfx_update_texture(QemuConsole *con, DisplaySurface *surfa= ce, + int x, int y, int w, int h) +{ + if (con->gl && con->gl->ops->dpy_gl_ctx_update_texture) { + con->gl->ops->dpy_gl_ctx_update_texture(con->gl, surface, x, y, w,= h); + } +} =20 static void displaychangelistener_display_console(DisplayChangeListener *d= cl, QemuConsole *con, @@ -1085,6 +1106,7 @@ static void displaychangelistener_display_console(Dis= playChangeListener *dcl, if (!con || !console_compatible_with(con, dcl, errp)) { if (!dummy) { dummy =3D qemu_create_placeholder_surface(640, 480, nodev); + dpy_gfx_create_texture(con, dummy); } displaychangelistener_gfx_switch(dcl, dummy, TRUE); return; @@ -1105,6 +1127,7 @@ static void displaychangelistener_display_console(Dis= playChangeListener *dcl, con->scanout.texture.width, con->scanout.texture.height); } else if (con->scanout.kind =3D=3D SCANOUT_SURFACE) { + dpy_gfx_create_texture(con, con->surface); displaychangelistener_gfx_switch(dcl, con->surface, TRUE); } } @@ -1637,6 +1660,7 @@ void dpy_gfx_update(QemuConsole *con, int x, int y, i= nt w, int h) if (!qemu_console_is_visible(con)) { return; } + dpy_gfx_update_texture(con, con->surface, x, y, w, h); QLIST_FOREACH(dcl, &s->listeners, next) { if (con !=3D (dcl->con ? dcl->con : active_console)) { continue; @@ -1681,12 +1705,14 @@ void dpy_gfx_replace_surface(QemuConsole *con, =20 con->scanout.kind =3D SCANOUT_SURFACE; con->surface =3D surface; + dpy_gfx_create_texture(con, surface); QLIST_FOREACH(dcl, &s->listeners, next) { if (con !=3D (dcl->con ? dcl->con : active_console)) { continue; } displaychangelistener_gfx_switch(dcl, surface, FALSE); } + dpy_gfx_destroy_texture(con, old_surface); qemu_free_displaysurface(old_surface); } =20 diff --git a/ui/dbus-listener.c b/ui/dbus-listener.c index 81c119b13a2c..a287edd2fc15 100644 --- a/ui/dbus-listener.c +++ b/ui/dbus-listener.c @@ -42,7 +42,6 @@ struct _DBusDisplayListener { =20 DisplayChangeListener dcl; DisplaySurface *ds; - QemuGLShader *gls; int gl_updates; }; =20 @@ -240,10 +239,6 @@ static void dbus_gl_gfx_update(DisplayChangeListener *= dcl, { DBusDisplayListener *ddl =3D container_of(dcl, DBusDisplayListener, dc= l); =20 - if (ddl->ds) { - surface_gl_update_texture(ddl->gls, ddl->ds, x, y, w, h); - } - ddl->gl_updates++; } =20 @@ -285,15 +280,11 @@ static void dbus_gl_gfx_switch(DisplayChangeListener = *dcl, { DBusDisplayListener *ddl =3D container_of(dcl, DBusDisplayListener, dc= l); =20 - if (ddl->ds) { - surface_gl_destroy_texture(ddl->gls, ddl->ds); - } ddl->ds =3D new_surface; if (ddl->ds) { int width =3D surface_width(ddl->ds); int height =3D surface_height(ddl->ds); =20 - surface_gl_create_texture(ddl->gls, ddl->ds); /* TODO: lazy send dmabuf (there are unnecessary sent otherwise) */ dbus_scanout_texture(&ddl->dcl, ddl->ds->texture, false, width, height, 0, 0, width, height); @@ -403,7 +394,6 @@ dbus_display_listener_dispose(GObject *object) g_clear_object(&ddl->conn); g_clear_pointer(&ddl->bus_name, g_free); g_clear_object(&ddl->proxy); - g_clear_pointer(&ddl->gls, qemu_gl_fini_shader); =20 G_OBJECT_CLASS(dbus_display_listener_parent_class)->dispose(object); } @@ -414,7 +404,6 @@ dbus_display_listener_constructed(GObject *object) DBusDisplayListener *ddl =3D DBUS_DISPLAY_LISTENER(object); =20 if (display_opengl) { - ddl->gls =3D qemu_gl_init_shader(); ddl->dcl.ops =3D &dbus_gl_dcl_ops; } else { ddl->dcl.ops =3D &dbus_dcl_ops; diff --git a/ui/dbus.c b/ui/dbus.c index 22c82d2f323a..7a87612379e8 100644 --- a/ui/dbus.c +++ b/ui/dbus.c @@ -55,11 +55,33 @@ dbus_is_compatible_dcl(DisplayGLCtx *dgc, return dcl->ops =3D=3D &dbus_gl_dcl_ops || dcl->ops =3D=3D &dbus_conso= le_dcl_ops; } =20 +static void +dbus_create_texture(DisplayGLCtx *ctx, DisplaySurface *surface) +{ + surface_gl_create_texture(ctx->gls, surface); +} + +static void +dbus_destroy_texture(DisplayGLCtx *ctx, DisplaySurface *surface) +{ + surface_gl_destroy_texture(ctx->gls, surface); +} + +static void +dbus_update_texture(DisplayGLCtx *ctx, DisplaySurface *surface, + int x, int y, int w, int h) +{ + surface_gl_update_texture(ctx->gls, surface, x, y, w, h); +} + static const DisplayGLCtxOps dbus_gl_ops =3D { .dpy_gl_ctx_is_compatible_dcl =3D dbus_is_compatible_dcl, .dpy_gl_ctx_create =3D dbus_create_context, .dpy_gl_ctx_destroy =3D qemu_egl_destroy_context, .dpy_gl_ctx_make_current =3D qemu_egl_make_context_current, + .dpy_gl_ctx_create_texture =3D dbus_create_texture, + .dpy_gl_ctx_destroy_texture =3D dbus_destroy_texture, + .dpy_gl_ctx_update_texture =3D dbus_update_texture, }; =20 static NotifierList dbus_display_notifiers =3D @@ -90,6 +112,9 @@ dbus_display_init(Object *o) g_autoptr(GDBusObjectSkeleton) vm =3D NULL; =20 dd->glctx.ops =3D &dbus_gl_ops; + if (display_opengl) { + dd->glctx.gls =3D qemu_gl_init_shader(); + } dd->iface =3D qemu_dbus_display1_vm_skeleton_new(); dd->consoles =3D g_ptr_array_new_with_free_func(g_object_unref); =20 @@ -126,6 +151,7 @@ dbus_display_finalize(Object *o) g_clear_object(&dd->iface); g_free(dd->dbus_addr); g_free(dd->audiodev); + g_clear_pointer(&dd->glctx.gls, qemu_gl_fini_shader); dbus_display =3D NULL; } =20 --=20 2.35.1.273.ge6ebfd0e8cbb