From patchwork Thu Nov 26 11:03:39 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Remy Alipoursafari X-Patchwork-Id: 29092 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 1D778BDE17 for ; Thu, 26 Nov 2026 11:05:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F3C686AA0F; Thu, 26 Nov 2026 12:05:09 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="M0dLPzjg"; dkim-atps=neutral Received: from sender5-pp-f112.zoho.com (sender5-pp-f112.zoho.com [165.173.182.112]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A7E9C6AA0F for ; Thu, 26 Nov 2026 12:05:06 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; t=1795691102; cv=none; d=zohomail.com; s=zohoarc; b=BHVwWTfYtrZyqvoRC05AEyQIuyhO5pxMW44PduxA/Q4DkyGiIZ0JyG6rKNj6zQUPuBV2zTF1D/R0F7qGVmEqNA6sjUsRaEKj/DNz85wvC477q7hArGXJ/jTcDeDbvb2ecLymI8Wl0bWYne6uoXOTleu9bJ21fxfombcKiFAGoPE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795691102; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=4NtcfY+QZ6HTVbZVHLng7C7WL3NOte0ZzRgvPwoGKjA=; b=R/D+rRhKpeboyS9MPr0bgkeq0P7fBquWptEmdYTVywKQL5wntg/zcitSctVyO/iqwtFrM34dAAaNWSLeMD5AtH1mbA6QdzMv41VhQx9Cg6CXGcmnlrx923YEfZ86veeZBPSh1bAH2biy/r776V3PSa1ArpHIo3fMFKWSxMGZXUw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=remy.alipoursafari@collabora.com; dmarc=pass header.from= DKIM-Signature: a=rsa-sha256; b=M0dLPzjge2EXsx/xAT2LN0IsMlPSr6ot9es/FqT6kEhSfx5o2T1r9uVd8lOUGkF6yc/PG2J/bNqTYMaUOlRf5D3ZCobrZ90PkN2s5LXrvH5ByO1fb2+X1R98o9X0VxnfQpd25yCZOx2nZ19mIa+UfKCb/T3eKj78K04BzplsYSE=; c=relaxed/relaxed; s=zohomail; d=collabora.com; v=1; bh=4NtcfY+QZ6HTVbZVHLng7C7WL3NOte0ZzRgvPwoGKjA=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc; Received: by smtp.zohomail.com with SMTPS id 1795691101073268.86673859042844; Thu, 26 Nov 2026 03:05:01 -0800 (PST) From: Remy Alipoursafari To: libcamera-devel@lists.libcamera.org Cc: =?utf-8?q?Lo=C3=AFc_Molinari?= , Robert Mader , Remy Alipoursafari Subject: [PATCH 1/6] libcamera: egl: Add GL extension & version checks Date: Fri, 27 Nov 2026 00:03:39 +1300 Message-ID: <20261126110422.362455-2-remy.alipoursafari@collabora.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261126110422.362455-1-remy.alipoursafari@collabora.com> References: <20261126110422.362455-1-remy.alipoursafari@collabora.com> MIME-Version: 1.0 X-ZohoMailClient: External 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: Loïc Molinari Allow EGL and OpenGL ES extensions to be queried for whether or not they exist in the current context. Also allows for checking the OpenGL ES context's version. Signed-off-by: Loïc Molinari Signed-off-by: Remy Alipoursafari Reviewed-by: Robert Mader --- include/libcamera/internal/egl.h | 11 ++++ src/libcamera/egl.cpp | 89 +++++++++++++++++++++++++++++++- 2 files changed, 98 insertions(+), 2 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index d6fb6fe0..10a9a3c5 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -109,6 +109,10 @@ public: void resetEGLContext(); static EGLDisplay probeDisplay(); + bool hasEGLExtension(const char *name) const; + bool hasGLESExtension(const char *name) const; + bool hasGLESVersion(unsigned int major, unsigned int minor) const; + int createInputDMABufTexture2D(eGLImage &eglImage, int fd); int createOutputDMABufTexture2D(eGLImage &eglImage, int fd); void createTexture2D(eGLImage &eglImage, const void *data, GLint filter); @@ -142,6 +146,13 @@ private: EGLDisplay display_ = EGL_NO_DISPLAY; EGLContext context_ = EGL_NO_CONTEXT; + const char *eglExtensions_ = NULL; + const char *glesExtensions_ = NULL; + unsigned int glesMajor_ = 0; + unsigned int glesMinor_ = 0; + + static bool hasExtension(const char *extensions, const char *name); + int compileShader(int shaderType, GLuint &shaderId, std::span shaderData, std::span shaderEnv); diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index ff9e54a1..8bc70b7d 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -10,6 +10,7 @@ #include "libcamera/internal/egl.h" #include +#include #include #include #include @@ -397,6 +398,7 @@ int eGL::initEGLContext() VTable vtable = {}; EGLint numConfigs; EGLConfig config; + const char *glesVersion; if (context_ != EGL_NO_CONTEXT) return -EEXIST; @@ -409,7 +411,8 @@ int eGL::initEGLContext() LOG(eGL, Info) << "EGL: EGL_VERSION: " << eglQueryString(display_, EGL_VERSION); LOG(eGL, Info) << "EGL: EGL_VENDOR: " << eglQueryString(display_, EGL_VENDOR); LOG(eGL, Info) << "EGL: EGL_CLIENT_APIS: " << eglQueryString(display_, EGL_CLIENT_APIS); - LOG(eGL, Info) << "EGL: EGL_EXTENSIONS: " << eglQueryString(display_, EGL_EXTENSIONS); + eglExtensions_ = eglQueryString(display_, EGL_EXTENSIONS); + LOG(eGL, Info) << "EGL: EGL_EXTENSIONS: " << eglExtensions_; vtable.eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR"); if (!vtable.eglCreateImageKHR) { @@ -446,7 +449,16 @@ int eGL::initEGLContext() makeCurrent(); LOG(eGL, Info) << "EGL: GL_RENDERER: " << glGetString(GL_RENDERER); - LOG(eGL, Info) << "EGL: GL_VERSION: " << glGetString(GL_VERSION); + glesVersion = (const char *)glGetString(GL_VERSION); + LOG(eGL, Info) << "EGL: GL_VERSION: " << glesVersion; + glesExtensions_ = (const char *)glGetString(GL_EXTENSIONS); + LOG(eGL, Info) << "EGL: GL_EXTENSIONS: " << glesExtensions_; + + if (sscanf(glesVersion, "OpenGL ES %u.%u", + &glesMajor_, &glesMinor_) != 2) { + LOG(eGL, Error) << "glGetString(GL_VERSION) invalid"; + goto fail; + } return 0; fail: @@ -454,6 +466,74 @@ fail: return -ENODEV; } +/** + * \brief Check EGL extension availability + * \param[in] name Extension name + * + * Checks whether a given EGL extension is currently available. + * + * \return True when available, false if not + */ +bool eGL::hasEGLExtension(const char *name) const +{ + return hasExtension(eglExtensions_, name); +} + +/** + * \brief Check GLES extension availability + * \param[in] name Extension name + * + * Checks whether a given OpenGL ES extension is currently available in the + * context. + * + * \return True when available, false if not + */ +bool eGL::hasGLESExtension(const char *name) const +{ + return hasExtension(glesExtensions_, name); +} + +/** + * \brief Checks extension availability + * \param[in] extensions Space separated string listing available extensions + * \param[in] name Extension name to check against + * + * Checks whether a given extension is within the extensions list. + * + * \return True when available, false if not + */ +bool eGL::hasExtension(const char *extensions, const char *name) +{ + size_t len = strlen(name); + const char *p = extensions; + + if (!extensions) + return false; + + // Full match search (separated by spaces or begin/end of string). + while ((p = strstr(p, name))) { + if ((p == extensions || p[-1] == ' ') && + (p[len] == ' ' || p[len] == '\0')) { + return true; + } + p += len; + } + + return false; +} + +/** + * \brief Whether the GLES version is at or above a minimum version + * \param[in] major Major version number + * \param[in] minor Minor version number + * + * \return True when at or beyond specified version, false otherwise + */ +bool eGL::hasGLESVersion(unsigned int major, unsigned int minor) const +{ + return glesMajor_ > major || (glesMajor_ == major && glesMinor_ >= minor); +} + /** * \brief Destroy the EGL context * @@ -468,6 +548,11 @@ void eGL::resetEGLContext() eglDestroyContext(display_, std::exchange(context_, EGL_NO_CONTEXT)); } + eglExtensions_ = NULL; + glesExtensions_ = NULL; + glesMajor_ = 0; + glesMinor_ = 0; + tid_ = -1; vtable_ = {}; }