Show a patch.

GET /api/patches/26864/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 26864,
    "url": "https://patchwork.libcamera.org/api/patches/26864/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/26864/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20260610093812.3604734-1-qi.hou@nxp.com>",
    "date": "2026-06-10T09:38:12",
    "name": "[v2] libcamera: software_isp: Probe EGL availability before creating DebayerEGL",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "7c3e5e46c8b621feed305ac25e39f617b3f541a0",
    "submitter": {
        "id": 195,
        "url": "https://patchwork.libcamera.org/api/people/195/?format=api",
        "name": "Qi Hou",
        "email": "qi.hou@nxp.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/26864/mbox/",
    "series": [
        {
            "id": 5985,
            "url": "https://patchwork.libcamera.org/api/series/5985/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5985",
            "date": "2026-06-10T09:38:12",
            "name": "[v2] libcamera: software_isp: Probe EGL availability before creating DebayerEGL",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/5985/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/26864/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/26864/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>",
        "X-Original-To": "parsemail@patchwork.libcamera.org",
        "Delivered-To": "parsemail@patchwork.libcamera.org",
        "Received": [
            "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id BB8DFC324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 10 Jun 2026 09:38:23 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DDBB261EFB;\n\tWed, 10 Jun 2026 11:38:22 +0200 (CEST)",
            "from inva021.nxp.com (inva021.nxp.com [92.121.34.21])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5FB7C60989\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Jun 2026 11:38:21 +0200 (CEST)",
            "from inva021.nxp.com (localhost [127.0.0.1])\n\tby inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 0269E20180A;\n\tWed, 10 Jun 2026 11:38:21 +0200 (CEST)",
            "from aprdc01srsp001v.ap-rdc01.nxp.com\n\t(aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16])\n\tby inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id C0B4E201290;\n\tWed, 10 Jun 2026 11:38:20 +0200 (CEST)",
            "from lsvm11u0000124.swis.ap-northeast-2.aws.nxp.com\n\t(lsvm11u0000124.swis.ap-northeast-2.aws.nxp.com [10.52.8.111])\n\tby aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id\n\t9EFAC1800071; Wed, 10 Jun 2026 17:38:19 +0800 (+08)"
        ],
        "From": "Qi Hou <qi.hou@nxp.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "jared.hu@nxp.com,\n\tqi.hou@nxp.com,\n\tjulien.vuillaumier@nxp.com",
        "Subject": "[PATCH v2] libcamera: software_isp: Probe EGL availability before\n\tcreating DebayerEGL",
        "Date": "Wed, 10 Jun 2026 18:38:12 +0900",
        "Message-Id": "<20260610093812.3604734-1-qi.hou@nxp.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-Virus-Scanned": "ClamAV using ClamSMTP",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "<libcamera-devel.lists.libcamera.org>",
        "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>",
        "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>",
        "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>",
        "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>",
        "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "When HAVE_DEBAYER_EGL is enabled, the SoftwareIsp constructor\nunconditionally creates a DebayerEGL instance. If the platform lacks\nEGL surfaceless support, DebayerEGL::start() fails with -ENODEV after\nSwStatsCpu ownership has already been moved, making fallback to\nDebayerCpu impossible.\n\nAdd a static eGL::isAvailable() method that probes whether EGL\nsurfaceless rendering can be initialised. Extract the common display\nobtaining logic (eglBindAPI, eglGetPlatformDisplay, eglInitialize)\ninto a private eGL::probeDisplay() helper that is shared by both\nisAvailable() and initEGLContext(), avoiding code duplication.\n\nThe SoftwareIsp constructor now calls eGL::isAvailable() before\ncreating DebayerEGL. If EGL is not available, the existing fallback\npath creates a DebayerCpu instance instead.\n\nSigned-off-by: Qi Hou <qi.hou@nxp.com>\n---\n include/libcamera/internal/egl.h            |  4 ++\n src/libcamera/egl.cpp                       | 60 ++++++++++++++++-----\n src/libcamera/software_isp/software_isp.cpp | 10 +++-\n 3 files changed, 58 insertions(+), 16 deletions(-)",
    "diff": "diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h\nindex 57f90d93..27c5c29d 100644\n--- a/include/libcamera/internal/egl.h\n+++ b/include/libcamera/internal/egl.h\n@@ -99,6 +99,8 @@ private:\n class eGL\n {\n public:\n+\tstatic bool isAvailable();\n+\n \teGL();\n \t~eGL();\n \n@@ -127,6 +129,8 @@ public:\n private:\n \tLIBCAMERA_DISABLE_COPY_AND_MOVE(eGL)\n \n+\tstatic EGLDisplay probeDisplay();\n+\n \tpid_t tid_;\n \n \tEGLDisplay display_ = EGL_NO_DISPLAY;\ndiff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp\nindex c185bb7a..860f18dd 100644\n--- a/src/libcamera/egl.cpp\n+++ b/src/libcamera/egl.cpp\n@@ -267,6 +267,50 @@ void eGL::createTexture2D(eGLImage &eglImage, void *data)\n \tglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);\n }\n \n+EGLDisplay eGL::probeDisplay()\n+{\n+\tEGLDisplay display;\n+\n+\tif (!eglBindAPI(EGL_OPENGL_ES_API)) {\n+\t\tLOG(eGL, Info) << \"API bind fail\";\n+\t\treturn EGL_NO_DISPLAY;\n+\t}\n+\n+\tdisplay = eglGetPlatformDisplay(EGL_PLATFORM_SURFACELESS_MESA,\n+\t\t\t\t\t EGL_DEFAULT_DISPLAY,\n+\t\t\t\t\t nullptr);\n+\n+\tif (display == EGL_NO_DISPLAY) {\n+\t\tLOG(eGL, Info) << \"Unable to get EGL display\";\n+\t\treturn EGL_NO_DISPLAY;\n+\t}\n+\n+\tif (eglInitialize(display, nullptr, nullptr) != EGL_TRUE) {\n+\t\tLOG(eGL, Error) << \"eglInitialize fail\";\n+\t\treturn EGL_NO_DISPLAY;\n+\t}\n+\n+\treturn display;\n+}\n+\n+/**\n+ * \\brief Probe whether EGL surfaceless rendering is available\n+ *\n+ * Checks if an EGL surfaceless display can be obtained and initialised.\n+ * The display is immediately terminated so that no resources are leaked.\n+ *\n+ * \\return true if EGL surfaceless rendering is available, false otherwise\n+ */\n+bool eGL::isAvailable()\n+{\n+\tEGLDisplay display = probeDisplay();\n+\tif (display == EGL_NO_DISPLAY)\n+\t\treturn false;\n+\n+\teglTerminate(display);\n+\treturn true;\n+}\n+\n /**\n  * \\brief Initialise the EGL context\n  *\n@@ -297,21 +341,9 @@ int eGL::initEGLContext()\n \tEGLint numConfigs;\n \tEGLConfig config;\n \n-\tif (!eglBindAPI(EGL_OPENGL_ES_API)) {\n-\t\tLOG(eGL, Error) << \"API bind fail\";\n-\t\tgoto fail;\n-\t}\n-\n-\tdisplay_ = eglGetPlatformDisplay(EGL_PLATFORM_SURFACELESS_MESA,\n-\t\t\t\t\t EGL_DEFAULT_DISPLAY,\n-\t\t\t\t\t nullptr);\n+\tdisplay_ = probeDisplay();\n \tif (display_ == EGL_NO_DISPLAY) {\n-\t\tLOG(eGL, Error) << \"Unable to get EGL display\";\n-\t\tgoto fail;\n-\t}\n-\n-\tif (eglInitialize(display_, nullptr, nullptr) != EGL_TRUE) {\n-\t\tLOG(eGL, Error) << \"eglInitialize fail\";\n+\t\tLOG(eGL, Error) << \"Unable to probe display\";\n \t\tgoto fail;\n \t}\n \ndiff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\nindex 781cf02f..ff8c3465 100644\n--- a/src/libcamera/software_isp/software_isp.cpp\n+++ b/src/libcamera/software_isp/software_isp.cpp\n@@ -119,8 +119,14 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,\n \t\t}\n \t}\n \n-\tif (!softISPMode || softISPMode == \"gpu\")\n-\t\tdebayer_ = std::make_unique<DebayerEGL>(std::move(stats), cm);\n+\tif (!softISPMode || softISPMode == \"gpu\") {\n+\t\tif (eGL::isAvailable()) {\n+\t\t\tdebayer_ = std::make_unique<DebayerEGL>(std::move(stats), cm);\n+\t\t} else {\n+\t\t\tLOG(SoftwareIsp, Info)\n+\t\t\t\t<< \"EGL not available, falling back to CPU debayer\";\n+\t\t}\n+\t}\n \n #endif\n \tif (!debayer_)\n",
    "prefixes": [
        "v2"
    ]
}