From patchwork Mon Aug 10 10:59:39 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 27727 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id DB87BBE080 for ; Mon, 10 Aug 2026 10:59:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D2DBE6820C; Mon, 10 Aug 2026 12:59:55 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="i8gN+dkF"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2C77C681C0 for ; Mon, 10 Aug 2026 12:59:47 +0200 (CEST) Received: from pb-laptop.local (185.221.141.208.nat.pool.zt.hu [185.221.141.208]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 36D5312F for ; Mon, 10 Aug 2026 12:58:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1786359513; bh=ehJ8meUetMIHbPR9HDPOsgBuTQSDYi0Whd2yT4TJb9g=; h=From:To:Subject:Date:In-Reply-To:References:From; b=i8gN+dkF88zmYfdnAs84p1puhQirQFu88SDs1NKXujSspGWoftPudlJThhZevcbyK Z7NVDzGI1FLAFVOuAjTXGcW38ERGOgdXJ2NLp0/J2n6z/U02tsL9PmwzPGi3qRujOz BSNLetDoIrln/UqP2W62WNpmP4kGgOFbTwTTha9o= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [RFC PATCH v2 5/8] libcamera: egl: Add `resetEGLContext()` Date: Mon, 10 Aug 2026 12:59:39 +0200 Message-ID: <20260810105942.1098192-6-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260810105942.1098192-1-barnabas.pocze@ideasonboard.com> References: <20260810105942.1098192-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a function that undoes the effects of `initEGLContext()`. Signed-off-by: Barnabás Pőcze Reviewed-by: Milan Zamazal --- include/libcamera/internal/egl.h | 1 + src/libcamera/egl.cpp | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index fb77225ac4..e18bb91f4d 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -103,6 +103,7 @@ public: ~eGL(); int initEGLContext(); + void resetEGLContext(); static EGLDisplay probeDisplay(); int createInputDMABufTexture2D(eGLImage &eglImage, int fd); diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index 3de5fab816..237791bca1 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -71,14 +71,11 @@ eGL::eGL(EGLDisplay display) } /** - * \brief Destroy the EGL helper - * - * Destroys the EGL context and surface if they were successfully created. + * \brief Release all EGL resources */ eGL::~eGL() { - if (context_ != EGL_NO_CONTEXT) - eglDestroyContext(display_, context_); + resetEGLContext(); } /** @@ -436,6 +433,24 @@ fail: return -ENODEV; } +/** + * \brief Destroy the EGL context + * + * This function destroys the EGL context created by initEGLContext(). + */ +void eGL::resetEGLContext() +{ + if (context_ != EGL_NO_CONTEXT) { + if (tid_ == Thread::currentId()) + eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + + eglDestroyContext(display_, std::exchange(context_, EGL_NO_CONTEXT)); + } + + tid_ = -1; + vtable_ = {}; +} + /** * \brief Make the EGL context current for the calling thread *