[{"id":38602,"web_url":"https://patchwork.libcamera.org/comment/38602/","msgid":"<177608651414.1693075.15607354284856448554@ping.linuxembedded.co.uk>","date":"2026-04-13T13:21:54","subject":"Re: [PATCH v1 1/3] libcamera: egl: Remove `eGLImage::image_`","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Barnabás Pőcze (2026-04-13 12:47:11)\n> From: Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>\n> \n> This member stores an egl image handle, but currently there is no need for it\n> since the image handle is only really used in `createDMABufTexture2D()`.\n> (`destroyDMABufTexture()` is an unused function.)\n> \n> So remove the member (and the unused function), and instead destroy the image\n> immediately after calling `glEGLImageTargetTexture2DOES()`. The texture will\n> keep a reference to the image, so this is safe to do. In fact, this solves\n> an issue, specifically, the egl images were never destroyed, and continuously\n> leaked during streaming.\n> \n> Fixes: f520b29fe9e6 (\"libcamera: software_isp: debayer_egl: Add an eGL Debayer class\")\n> Closes: https://gitlab.freedesktop.org/camera/libcamera/-/work_items/322\n> Signed-off-by: Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>\n> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n\n\nI think I saw someone tested this, or was that Gianfranco ?\n\nAnyway, if it's fixing things then great!\n\nNothing I object to so:\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n> \n> Supersedes https://patchwork.libcamera.org/patch/26319/\n> \n> ---\n>  include/libcamera/internal/egl.h |  2 --\n>  src/libcamera/egl.cpp            | 37 +++++++++-----------------------\n>  2 files changed, 10 insertions(+), 29 deletions(-)\n> \n> diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h\n> index 8a2d96d7a..0ad2320b1 100644\n> --- a/include/libcamera/internal/egl.h\n> +++ b/include/libcamera/internal/egl.h\n> @@ -88,7 +88,6 @@ public:\n>         GLenum texture_unit_; /**< Texture unit associated with this image eg (GL_TEXTURE0) */\n>         GLuint texture_; /**< OpenGL texture object ID */\n>         GLuint fbo_; /**< OpenGL frame buffer object ID */\n> -       EGLImageKHR image_; /**< EGL Image handle */\n> \n>  private:\n>         LIBCAMERA_DISABLE_COPY_AND_MOVE(eGLImage)\n> @@ -104,7 +103,6 @@ public:\n> \n>         int createInputDMABufTexture2D(eGLImage &eglImage, int fd);\n>         int createOutputDMABufTexture2D(eGLImage &eglImage, int fd);\n> -       void destroyDMABufTexture(eGLImage &eglImage);\n>         void createTexture2D(eGLImage &eglImage, GLint format, uint32_t width, uint32_t height, void *data);\n> \n>         void pushEnv(std::vector<std::string> &shaderEnv, const char *str);\n> diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp\n> index 5b9bbf410..f65929470 100644\n> --- a/src/libcamera/egl.cpp\n> +++ b/src/libcamera/egl.cpp\n> @@ -112,8 +112,6 @@ void eGL::syncOutput()\n>   */\n>  int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output)\n>  {\n> -       int ret = 0;\n> -\n>         ASSERT(tid_ == Thread::currentId());\n> \n>         // clang-format off\n> @@ -130,14 +128,13 @@ int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output)\n>         };\n>         // clang-format on\n> \n> -       eglImage.image_ = eglCreateImageKHR(display_, EGL_NO_CONTEXT,\n> -                                           EGL_LINUX_DMA_BUF_EXT,\n> -                                           NULL, image_attrs);\n> +       EGLImageKHR image = eglCreateImageKHR(display_, EGL_NO_CONTEXT,\n> +                                             EGL_LINUX_DMA_BUF_EXT,\n> +                                             NULL, image_attrs);\n> \n> -       if (eglImage.image_ == EGL_NO_IMAGE_KHR) {\n> +       if (image == EGL_NO_IMAGE_KHR) {\n>                 LOG(eGL, Error) << \"eglCreateImageKHR fail\";\n> -               ret = -ENODEV;\n> -               goto done;\n> +               return -ENODEV;\n>         }\n> \n>         // Bind texture unit and texture\n> @@ -145,7 +142,8 @@ int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output)\n>         glBindTexture(GL_TEXTURE_2D, eglImage.texture_);\n> \n>         // Generate texture with filter semantics\n> -       glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, eglImage.image_);\n> +       glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);\n> +       eglDestroyImageKHR(display_, image);\n> \n>         // Nearest filtering\n>         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);\n> @@ -163,13 +161,11 @@ int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output)\n>                 GLenum err = glCheckFramebufferStatus(GL_FRAMEBUFFER);\n>                 if (err != GL_FRAMEBUFFER_COMPLETE) {\n>                         LOG(eGL, Error) << \"glFrameBufferTexture2D error \" << err;\n> -                       eglDestroyImageKHR(display_, eglImage.image_);\n> -                       ret = -ENODEV;\n> -                       goto done;\n> +                       return -ENODEV;\n>                 }\n>         }\n> -done:\n> -       return ret;\n> +\n> +       return 0;\n>  }\n> \n>  /**\n> @@ -209,19 +205,6 @@ int eGL::createOutputDMABufTexture2D(eGLImage &eglImage, int fd)\n>         return createDMABufTexture2D(eglImage, fd, true);\n>  }\n> \n> -/**\n> - * \\brief Destroy a DMA-BUF texture's EGL image\n> - * \\param[in,out] eglImage EGL image to destroy\n> - *\n> - * Destroys the EGL image associated with a DMA-BUF texture. The OpenGL\n> - * texture and framebuffer objects are destroyed separately in the\n> - * eGLImage destructor.\n> - */\n> -void eGL::destroyDMABufTexture(eGLImage &eglImage)\n> -{\n> -       eglDestroyImage(display_, std::exchange(eglImage.image_, EGL_NO_IMAGE_KHR));\n> -}\n> -\n>  /**\n>   * \\brief Create a 2D texture from a memory buffer\n>   * \\param[in,out] eglImage EGL image to associate with the texture\n> --\n> 2.53.0","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 AE35FC32BB\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 13 Apr 2026 13:22:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DFACA62E8C;\n\tMon, 13 Apr 2026 15:21:59 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A75356271A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 13 Apr 2026 15:21:57 +0200 (CEST)","from monstersaurus.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 997EF7FE;\n\tMon, 13 Apr 2026 15:20:25 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"EDtRpLCT\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1776086425;\n\tbh=1Out7IwXJ+8n4quuBmPYzWohL6X9nX/dDlR1pPVXdu4=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=EDtRpLCTpx8AZvVFTxyz22712nWFT2x9PojCwL0pyeb1Aov436ysrdj0bLk5xGTPT\n\t2G8TLN9YBVIdUwiZnQfJ+DFAf/L2o7jcxX11J4nGLxxwJU/NJX1ymXs5FMg+Y2/UqT\n\tD0ID3hDMZ5+RdywrPldmXfQ9d28jaUh4+YQHqxwQ=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20260413114713.426459-1-barnabas.pocze@ideasonboard.com>","References":"<20260413114713.426459-1-barnabas.pocze@ideasonboard.com>","Subject":"Re: [PATCH v1 1/3] libcamera: egl: Remove `eGLImage::image_`","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 13 Apr 2026 14:21:54 +0100","Message-ID":"<177608651414.1693075.15607354284856448554@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","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>"}}]