From nobody Sat Apr 11 23:03:15 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1772507600; cv=none; d=zohomail.com; s=zohoarc; b=HKbO8dN4t0CqYOXtfbwY0PBHaklYuEiRimGmOwtV7irReYPvTgie8D4DT3TxIVKH6SDriDXRnTXKl1/liKUet6CvSxut0bXv/Hnl1a8BTAZDhFpUcnunByN8pJNsAT2InOkU04u3Adr81m4ZcKUnjx3jK6AueB/6gcAIOexgGkg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772507600; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=qZWv3yg1gsMYuOAb8SW1s1PNSrcQhLeCod6VGPDX6dQ=; b=IC7dbw9USAaC2Z1DgPKKlbgu+g70U7QGi8MvkzLU/0uk7b7VXKpfKc4B9rTjpcgFPurQUrU5qCTQE/gCfhoSLy3tx0REoRQgXd3mGpZZvwYg3bXO8w7fJHShAH8E8mYlgwmfQxqdRylgiISPtft6OXI9E0wEdkOUOg9zUJzwK3I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772507599144751.7948118398052; Mon, 2 Mar 2026 19:13:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vxGBO-00018t-Tl; Mon, 02 Mar 2026 22:12:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxGBN-00017q-1P for qemu-devel@nongnu.org; Mon, 02 Mar 2026 22:12:25 -0500 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxGBJ-0005Zn-P7 for qemu-devel@nongnu.org; Mon, 02 Mar 2026 22:12:24 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Mar 2026 19:12:17 -0800 Received: from dongwonk-z390-aorus-ultra.fm.intel.com ([10.105.205.222]) by fmviesa001.fm.intel.com with ESMTP; 02 Mar 2026 19:12:17 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772507542; x=1804043542; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=f3PLxG7obKkufdeeCmWMF1n7vnhFl87d+sDyWglp1+U=; b=Sy92dvJPnLgwnZtxBuqsgTQ7S+uHlZf6BOFKTPk3X9QWKOJV49FbiXqv 1jOil475SKY6Q6yv+7Pv/5QjvhcgkLEYeelxCx1iE1ZScaceNpy6waOIK aEPtJwmRaq6+8rnXz7THWc5/39hvnODQU8nkDYxL0fW4BQaYFRGOF6GkN CZyctXpDyO0yxdzIEjbkTpPC3lZwErURIFnYPHMsq6hsL1wH4ne6QGcA5 HYrRVDp+Tq9J/3IwvJysw/53hBkB8zhlS8Vvkj3BdFCsJu3fGLR0kvfkc TzT/1A234X5n8f2wJuSeyCqi+cAcZzsMLCHH/N9KtB+jgeSQp9JGXpm2c Q==; X-CSE-ConnectionGUID: tjhSXCY1S4KJwMkYm5yong== X-CSE-MsgGUID: rVitdxIqQ/CnaXbi07nT7w== X-IronPort-AV: E=McAfee;i="6800,10657,11717"; a="84881212" X-IronPort-AV: E=Sophos;i="6.21,321,1763452800"; d="scan'208";a="84881212" X-CSE-ConnectionGUID: tQaqoKQNThWcF/d+50qSgw== X-CSE-MsgGUID: TOKDpUcCQdeGKu/HhW12BQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,321,1763452800"; d="scan'208";a="244797607" From: dongwon.kim@intel.com To: qemu-devel@nongnu.org Subject: [PATCH] ui/gtk: Implement dpy_gl_ctx_destroy_texture for gtk-egl and gtk-gl-area Date: Mon, 2 Mar 2026 19:07:14 -0800 Message-Id: <20260303030714.1926907-1-dongwon.kim@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 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=192.198.163.10; envelope-from=dongwon.kim@intel.com; helo=mgamail.intel.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.968, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.495, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1772507607247158500 From: Dongwon Kim Currently, the texture associated with a DisplaySurface is not deleted when the surface is switched or freed, leading to a memory leak in the GPU process. This occurs because the GTK backend lacks a mapping for the 'dpy_gl_ctx_destroy_texture' operation. This patch implements the necessary cleanup functions for both EGL and GL Area backends. Each implementation ensures the appropriate GL context is made current before calling surface_gl_destroy_texture(), ensuring that the underlying GL texture ID is safely released by the driver. Cc: Gerd Hoffmann Cc: Marc-Andr=C3=A9 Lureau Cc: Vivek Kasireddy Signed-off-by: Dongwon Kim --- include/ui/gtk.h | 4 ++++ ui/gtk-egl.c | 10 ++++++++++ ui/gtk-gl-area.c | 8 ++++++++ ui/gtk.c | 2 ++ 4 files changed, 24 insertions(+) diff --git a/include/ui/gtk.h b/include/ui/gtk.h index 3e6ce3cb48..f1765ad5cb 100644 --- a/include/ui/gtk.h +++ b/include/ui/gtk.h @@ -170,6 +170,8 @@ void gd_egl_switch(DisplayChangeListener *dcl, DisplaySurface *surface); QEMUGLContext gd_egl_create_context(DisplayGLCtx *dgc, QEMUGLParams *params); +void gd_egl_destroy_texture(DisplayGLCtx *dgc, + DisplaySurface *surface); void gd_egl_scanout_disable(DisplayChangeListener *dcl); void gd_egl_scanout_texture(DisplayChangeListener *dcl, uint32_t backing_id, @@ -206,6 +208,8 @@ QEMUGLContext gd_gl_area_create_context(DisplayGLCtx *d= gc, QEMUGLParams *params); void gd_gl_area_destroy_context(DisplayGLCtx *dgc, QEMUGLContext ctx); +void gd_gl_area_destroy_texture(DisplayGLCtx *dgc, + DisplaySurface *surface); void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl, QemuDmaBuf *dmabuf); void gd_gl_area_scanout_texture(DisplayChangeListener *dcl, diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c index ae9239999c..c1b32bc41b 100644 --- a/ui/gtk-egl.c +++ b/ui/gtk-egl.c @@ -225,6 +225,16 @@ QEMUGLContext gd_egl_create_context(DisplayGLCtx *dgc, return qemu_egl_create_context(dgc, params); } =20 +void gd_egl_destroy_texture(DisplayGLCtx *dgc, DisplaySurface *surface) +{ + VirtualConsole *vc =3D container_of(dgc, VirtualConsole, gfx.dgc); + + eglMakeCurrent(qemu_egl_display, vc->gfx.esurface, + vc->gfx.esurface, vc->gfx.ectx); + + surface_gl_destroy_texture(dgc->gls, surface); +} + void gd_egl_scanout_disable(DisplayChangeListener *dcl) { VirtualConsole *vc =3D container_of(dcl, VirtualConsole, gfx.dcl); diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c index cd86022d26..84e41f4221 100644 --- a/ui/gtk-gl-area.c +++ b/ui/gtk-gl-area.c @@ -299,6 +299,14 @@ void gd_gl_area_destroy_context(DisplayGLCtx *dgc, QEM= UGLContext ctx) g_clear_object(&ctx); } =20 +void gd_gl_area_destroy_texture(DisplayGLCtx *dgc, DisplaySurface *surface) +{ + VirtualConsole *vc =3D container_of(dgc, VirtualConsole, gfx.dgc); + + gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area)); + surface_gl_destroy_texture(dgc->gls, surface); +} + void gd_gl_area_scanout_texture(DisplayChangeListener *dcl, uint32_t backing_id, bool backing_y_0_top, diff --git a/ui/gtk.c b/ui/gtk.c index 9ebe7e8df0..217f425075 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -636,6 +636,7 @@ static const DisplayGLCtxOps gl_area_ctx_ops =3D { .dpy_gl_ctx_is_compatible_dcl =3D gd_gl_area_is_compatible_dcl, .dpy_gl_ctx_create =3D gd_gl_area_create_context, .dpy_gl_ctx_destroy =3D gd_gl_area_destroy_context, + .dpy_gl_ctx_destroy_texture =3D gd_gl_area_destroy_texture, .dpy_gl_ctx_make_current =3D gd_gl_area_make_current, }; =20 @@ -670,6 +671,7 @@ static const DisplayGLCtxOps egl_ctx_ops =3D { .dpy_gl_ctx_is_compatible_dcl =3D gd_egl_is_compatible_dcl, .dpy_gl_ctx_create =3D gd_egl_create_context, .dpy_gl_ctx_destroy =3D qemu_egl_destroy_context, + .dpy_gl_ctx_destroy_texture =3D gd_egl_destroy_texture, .dpy_gl_ctx_make_current =3D gd_egl_make_current, }; #endif --=20 2.43.0