From patchwork Wed Jul 29 02:55:57 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Qi Hou (OSS)" X-Patchwork-Id: 27519 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 F2E3CC3264 for ; Wed, 29 Jul 2026 02:56:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3EF6567FAB; Wed, 29 Jul 2026 04:56:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="Mrl0FIXX"; dkim-atps=neutral Received: from GVXPR05CU001.outbound.protection.outlook.com (mail-swedencentralazlp170130007.outbound.protection.outlook.com [IPv6:2a01:111:f403:c202::7]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B85F767EB2 for ; Wed, 29 Jul 2026 04:56:08 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WUGGEtzDfgbrGwG0xG63SKAoA3a4BQ262RX3RADfc81mxKseMyvIVJQfHLGQQnpEdL5SogPu0MU6dK7joCCyoPPwFkBfKnKxw4+dAeNQ/3PD1gxol9E0C9N26QxEV6RNq/xx6qoCQsDZDGYmoXsqMcfUllBWsWpRJtXVG16hX4y1cKTvTBXUY1OYawpCbf2YVTa7tFVcp45AMPn0IWabeBQzUTErUr0fShpMcgKXhUgpv/mXnhWz0DRthbQ/35yiw0n7WpbPDnqkz+cqmexpdlwxb+9p9pRDkuqaWHwu0VZuzatSps+HNh98Vckul2rlN9rHTE44v3dz6rc5lTdUtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cmr4eQw8fTF/Qc97OLmxlVTvdNhSGcYTYkK5nzO7Uz0=; b=vfNKP4AIRatLisj5sWDBq3bUevcU6lJaLDM3wVES08Lsj/E0RVLfa8h1fX5ofbc4yrulP44hpjZA4O4stkUvJlBFjE5Ysm41f2P0TC5koRmUGcdTIXLAZOCHyb5EywNi2jTi1wd97qMR/w8n/dMaSraMxU7DOph6ai+MrvTDcs6N90W33VTlZQpJaYHaGqENZbll5ow46FV7o4spd7IwcRaqI6Ab1Z0FkeRWRKOtlrPtaDBQxG5YOfqIxsiQ8sCT0xOiH25opyoy1ZOpLaajQmfvK6GRs03M45ag9DuZaKhkcp6H3b/ZTiNO/u48CLFL0UHEYmuywUw8jwlk6sXrEQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cmr4eQw8fTF/Qc97OLmxlVTvdNhSGcYTYkK5nzO7Uz0=; b=Mrl0FIXXS2TvkdlVAgBXBWEGKcgx31Dn7W9l3XKEtL8+KsBdZpnzIdZon0rGvb4Wib1stZwCUt1i7eyaLQTA00HcUAVC8tyqvDCkA3p8WuxVPDnIfeqdZUWlzDxtCmQ/FCKH9kgEBVSDVdd0T5mX7DBvnKvXo84V202ogI6nG0Kz5BPRzJ1hPb1yshMNC3EycCJvrAe2APfv5AAJExChTGbh3z1vizkdefzdGChViDDdXGXHgTFUN6CD8DSIOMjZrmPbn/NWsgyJBzCNf+7YjHGP8V+9lBl1IXhcWlwgUg675STzqXX6tuUBv09ITwCQ7UlE4dLtGa94P60Xqhop4g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AM9PR04MB7556.eurprd04.prod.outlook.com (2603:10a6:20b:2df::11) by GVXPR04MB12342.eurprd04.prod.outlook.com (2603:10a6:150:31a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.12; Wed, 29 Jul 2026 02:56:06 +0000 Received: from AM9PR04MB7556.eurprd04.prod.outlook.com ([fe80::8599:94b0:43ea:32ed]) by AM9PR04MB7556.eurprd04.prod.outlook.com ([fe80::8599:94b0:43ea:32ed%7]) with mapi id 15.21.0270.009; Wed, 29 Jul 2026 02:56:06 +0000 From: qi.hou@oss.nxp.com To: libcamera-devel@lists.libcamera.org Cc: jared.hu@nxp.com, qi.hou@oss.nxp.com, julien.vuillaumier@nxp.com Subject: [PATCH v3] libcamera: egl: Pass EGLDisplay to eGL constructor to avoid double init Date: Wed, 29 Jul 2026 11:55:57 +0900 Message-Id: <20260729025557.2261274-1-qi.hou@oss.nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SE2P216CA0085.KORP216.PROD.OUTLOOK.COM (2603:1096:101:2c6::11) To AM9PR04MB7556.eurprd04.prod.outlook.com (2603:10a6:20b:2df::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB7556:EE_|GVXPR04MB12342:EE_ X-MS-Office365-Filtering-Correlation-Id: 413a86fe-831b-4915-4206-08deed1cef1e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|376014|1800799024|23010399003|19092799006|56012099006|11063799006|10067099003|6133799003|18002099003|3023799007; X-Microsoft-Antispam-Message-Info: pyyGG254/2QFzyYYL7/mG7cqynrOija5qU7zTYp2rRQApBGTpQwLDjXzmSbRM0eIgEvrl6OTdKrxohAIne5SejD3tzfsb3VQzzyTjrYTuImu6/AlyXTsX7s84n4bmI9SL4PRrFQWeTKv+krdlqADqXIj6xgNngDADo7EGSFgMZFuZhW3xO83WGmxXnt6JDAvUIi7WHMKQZzirPHI1O6JCfxv8dW01HWyJNMYHP8Rv9kc2VHEj8VH1VyFOaoTwt6cKQy32Kpm5dgae+nzGwDtTj+A3QysVSfMnHaxKJbo2daX9kQcKXSctNsEnVH8R0sSTEkiIR/cPvaRUc9PybYyPhLELaPFtC3UO265UHuWXKx8AlhlmU2j5mHvwcnnvfI5KnrwM2IEQUJzn+gRF1Yp419q64FRpvHeBHU1Cd1xft13m5wtnWzj9zmE6kRCKtCv8zcMluTJsT77JgHwNdsn3aGSRnpVQGasOWuIJ00wYnw1zPo2u5nwmFQm4AMlMl8FtHGiN+nhRfTKPnjpgZyvQKNY7BZcYCpLrovldyqKKKfMvmRgUo5ZTEp3Hk43XmHsKIah+uvbzb3VCWILDjZ/o1sjnXvgRIF6mwXhaHqJOjBDjNervsnzI5b83TMq9Lr7iPtt8lIsjX4CFT0R9hC+ynQvEX/XXH7v/1ExybopdNM= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR04MB7556.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(1800799024)(23010399003)(19092799006)(56012099006)(11063799006)(10067099003)(6133799003)(18002099003)(3023799007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cuY9L2ebUCWOA/8Epy60fvgNPjmGpSbnxwwpiQKGpRkA8fO6GUAk8uH2bXMBP89Igpv8DFkUGe1wDTGzgf2caAilqELORlnTl4ilKA1jhzq2TtPtY9oHWq7qEuFfjHpJv5g4AKK1c6WFHWq2V2TOyow33t4cZ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4jlHiDwU1DaVAiDEboLSPhfnWnfETBsKDKnj2WM0AYDXB17qbOik7pEKQGg8v94my2+OjxOjuHUBlNokRuxF8b+zw8QZ8rCTD7AK58xwLSib8ot0D2bB13dV/JkeLCn4zkvTowUQ4pAHsWAPPn1gIpX+5YsH1/5vWcXeNRDnC46dVaqilozrXY/O2VxLB+asUnfLCe/Zh6WfqXU9ZBzdfDJ6QHNohn4M/kSCRQqCyTrKbXpmlBI7amI9cJoQ3BzVPbysuVelznmpUdCcI1w3Kd8Ly8U6hd4OITVW73Ql595oQhXlKod8DsVGX/j2R8JKni8XVMTy4D/Duyv6LEgtrgG339jC7Z8DyUnyPGdhFda+3odxslNikNkChDEaF3UG8f2wtxrKXX9PpMEogOmCIyoKqj4X9inxNg5miR1f5+vo/swyUsEmX7zv8dtMZlGjpcX3susmPyaRjf8dOWHAX0lzm6cmnrAFC3mVxpLlSpZ/PFWCG9PM5rYulsfX4SyBJ2hMSgP3bzl7CoMSuEiBP6MoVDi9Lo= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 413a86fe-831b-4915-4206-08deed1cef1e X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB7556.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2026 02:56:06.3382 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: D6M/QlcSdVm7rwQFJgdIe3w7f9JxJ5pF3BkxA0jFHt5D7eNtiv3HyqtMRS5WLh/vTbA4nI1vVqF3CqFUI/LXNaXnW8/df5nMK9qzwew8cbc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB12342 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" From: Qi Hou isAvailable() previously called probeDisplay() to run a full EGL initialisation sequence and then immediately terminated the display with eglTerminate(). When SoftwareIsp subsequently created a DebayerEGL instance, initEGLContext() would call probeDisplay() again, repeating the full initialisation. Fix this by reusing the display obtained during the availability check. probeDisplay() is promoted to a public static method and isAvailable() is removed. The eGL constructor now takes the EGLDisplay as a parameter and stores it directly, so initEGLContext() no longer needs to call probeDisplay(). DebayerEGL is updated to accept and forward the display to eGL, and SoftwareIsp calls eGL::probeDisplay() once, passing the result straight to DebayerEGL when EGL is available. Signed-off-by: Qi Hou --- include/libcamera/internal/egl.h | 5 +-- src/libcamera/egl.cpp | 42 +++++++-------------- src/libcamera/software_isp/debayer_egl.cpp | 5 ++- src/libcamera/software_isp/debayer_egl.h | 2 +- src/libcamera/software_isp/software_isp.cpp | 5 ++- 5 files changed, 23 insertions(+), 36 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index 1e31d490b..7ef1ca0d9 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -99,11 +99,11 @@ private: class eGL { public: - eGL(); + eGL(EGLDisplay display); ~eGL(); int initEGLContext(); - static bool isAvailable(); + static EGLDisplay probeDisplay(); int createInputDMABufTexture2D(eGLImage &eglImage, int fd); int createOutputDMABufTexture2D(eGLImage &eglImage, int fd); @@ -137,7 +137,6 @@ private: EGLContext context_ = EGL_NO_CONTEXT; EGLSurface surface_ = EGL_NO_SURFACE; - static EGLDisplay probeDisplay(); int compileShader(int shaderType, GLuint &shaderId, Span shaderData, Span shaderEnv); diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index 7ec7a654d..01e51cda8 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -64,12 +64,15 @@ LOG_DEFINE_CATEGORY(eGL) /** * \brief Construct an EGL helper + * \param[in] display The EGL display to use * * Creates an eGL instance with uninitialised context. Call initEGLContext() - * to set up the EGL display, context, and load extension functions. + * to set up the EGL context, and load extension functions. */ -eGL::eGL() +eGL::eGL(EGLDisplay display) + : display_(display) { + ASSERT(display_ != EGL_NO_DISPLAY); } /** @@ -299,15 +302,17 @@ void eGL::createTexture2D(eGLImage &eglImage, void *data) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } +/** + * \brief Try to create an EGL display for surfaceless rendering + * + * Tries to create an EGL display for surfaceless rendering. + * + * \return A EGL display handle if successful, otherwise \a EGL_NO_DISPLAY + */ EGLDisplay eGL::probeDisplay() { EGLDisplay display; - if (!eglBindAPI(EGL_OPENGL_ES_API)) { - LOG(eGL, Info) << "API bind fail"; - return EGL_NO_DISPLAY; - } - display = eglGetPlatformDisplay(EGL_PLATFORM_SURFACELESS_MESA, EGL_DEFAULT_DISPLAY, nullptr); @@ -325,24 +330,6 @@ EGLDisplay eGL::probeDisplay() return display; } -/** - * \brief Probe whether EGL surfaceless rendering is available - * - * Checks if an EGL surfaceless display can be obtained and initialised. - * The display is immediately terminated so that no resources are leaked. - * - * \return True if EGL surfaceless rendering is available, false otherwise - */ -bool eGL::isAvailable() -{ - EGLDisplay display = probeDisplay(); - if (display == EGL_NO_DISPLAY) - return false; - - eglTerminate(display); - return true; -} - /** * \brief Update a 2D texture already created * \param[in,out] eglImage EGL image to associate with the texture @@ -403,9 +390,8 @@ int eGL::initEGLContext() EGLint numConfigs; EGLConfig config; - display_ = probeDisplay(); - if (display_ == EGL_NO_DISPLAY) { - LOG(eGL, Error) << "Unable to probe display"; + if (!eglBindAPI(EGL_OPENGL_ES_API)) { + LOG(eGL, Error) << "API bind fail"; goto fail; } diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index dd2041219..20b478b1c 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -40,9 +40,10 @@ namespace libcamera { * \brief Construct a DebayerEGL object * \param[in] stats Statistics processing object * \param[in] cm The camera manager + * \param[in] display The EGL display to use */ -DebayerEGL::DebayerEGL(std::unique_ptr stats, const CameraManager &cm) - : Debayer(cm), stats_(std::move(stats)) +DebayerEGL::DebayerEGL(std::unique_ptr stats, const CameraManager &cm, EGLDisplay display) + : Debayer(cm), stats_(std::move(stats)), egl_(display) { } diff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h index e613639f5..30e51a477 100644 --- a/src/libcamera/software_isp/debayer_egl.h +++ b/src/libcamera/software_isp/debayer_egl.h @@ -40,7 +40,7 @@ class CameraManager; class DebayerEGL : public Debayer { public: - DebayerEGL(std::unique_ptr stats, const CameraManager &cm); + DebayerEGL(std::unique_ptr stats, const CameraManager &cm, EGLDisplay display); ~DebayerEGL(); int configure(const StreamConfiguration &inputCfg, diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp index c73a16ce0..c7165771c 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -120,8 +120,9 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor, } if (!softISPMode || softISPMode == "gpu") { - if (eGL::isAvailable()) { - debayer_ = std::make_unique(std::move(stats), cm); + auto display = eGL::probeDisplay(); + if (display != EGL_NO_DISPLAY) { + debayer_ = std::make_unique(std::move(stats), cm, display); } else { LOG(SoftwareIsp, Info) << "EGL not available, falling back to CPU debayer";