From patchwork Mon May 18 20:15:05 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Mader X-Patchwork-Id: 26769 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 AC3ADBDCBD for ; Mon, 18 May 2026 20:16:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 63E3563026; Mon, 18 May 2026 22:16:19 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=collabora.com header.i=robert.mader@collabora.com header.b="iUKxw+E4"; dkim-atps=neutral Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3518162FE1 for ; Mon, 18 May 2026 22:16:17 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; t=1779135372; cv=none; d=zohomail.com; s=zohoarc; b=fRnNaFoHnb5FjIWue8PrJQB83z/vza4Fli0Ztzs+xZ8lEo2vKsCX5XKySyXC5b1oZAUjAI4x6n4eDU0jFZYZp3b2MQ2kpGV9ngYSC/H7snLS8vowdejcE3g76dBSXzulibFgLr6m47AzWt2Y8qGvRMkUFcMwXgmPj6KAVSNXmBs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779135372; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=RctL3Zn3g/C7zA8lhPhIkstnVNimymWPBcHt6xePCKY=; b=dQfXpwBbTp+fIXoD1x1YGqTkWKZ6gB4sEWSxJL/E1abK7j703ggJW8d8iidblEnmAikZxRuLdgmKInWIKe7Vt9fJrX+GVvFWj/N9mPb1aUBaT3rTO6eI8lZ21w5RaP3hu3OHgYCOdw2Cmi78vN6t7SOIbXP33ijFLg2VUu4QjdM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=robert.mader@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1779135372; s=zohomail; d=collabora.com; i=robert.mader@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=RctL3Zn3g/C7zA8lhPhIkstnVNimymWPBcHt6xePCKY=; b=iUKxw+E4SDKkD4aQLjVVgvn9qTvKT/XSPyZCC1/FnYMKxsmtHGVE5N7fHgm45Q88 JjSt0Y84Cz1RWYP9M07Yrag6vmJcqEqu8j2CdzU+jK8gAdtWO0eBWkm3RvPWqZkNNUo hEfesU9RjvWQZ92gC10l2w1pcT7LEmmUf64Za/Vw= Received: by mx.zohomail.com with SMTPS id 1779135370420773.2495325728922; Mon, 18 May 2026 13:16:10 -0700 (PDT) From: Robert Mader To: libcamera-devel@lists.libcamera.org Cc: Robert Mader Subject: [PATCH v2 1/4] egl: Set more eGLImage paramters in constructor Date: Mon, 18 May 2026 22:15:05 +0200 Message-ID: <20260518201508.140849-2-robert.mader@collabora.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260518201508.140849-1-robert.mader@collabora.com> References: <20260518201508.140849-1-robert.mader@collabora.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" The parameters - format, width, height and stride - never change. Set them during construction and remove them from createTexture2D(), making the later match createInputDMABufTexture2D() and createOutputDMABufTexture2D(). Signed-off-by: Robert Mader --- include/libcamera/internal/egl.h | 7 +++--- src/libcamera/egl.cpp | 29 +++++++++++++++++----- src/libcamera/software_isp/debayer_egl.cpp | 12 ++++----- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index 0ad2320b1..8d80d6fb5 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -57,8 +57,8 @@ public: * \param[in] texture_unit OpenGL texture unit * \param[in] texture_unit_uniform_id Shader uniform ID */ - eGLImage(uint32_t width, uint32_t height, uint32_t stride, GLenum texture_unit, uint32_t texture_unit_uniform_id) - : width_(width), height_(height), stride_(stride), + eGLImage(GLint format, uint32_t width, uint32_t height, uint32_t stride, GLenum texture_unit, uint32_t texture_unit_uniform_id) + : format_(format), width_(width), height_(height), stride_(stride), framesize_(stride * height), texture_unit_uniform_id_(texture_unit_uniform_id), texture_unit_(texture_unit) @@ -79,6 +79,7 @@ public: glDeleteTextures(1, &texture_); } + GLint format_; uint32_t width_; /**< Image width in pixels */ uint32_t height_; /**< Image height in pixels */ uint32_t stride_; /**< Row stride in bytes */ @@ -103,7 +104,7 @@ public: int createInputDMABufTexture2D(eGLImage &eglImage, int fd); int createOutputDMABufTexture2D(eGLImage &eglImage, int fd); - void createTexture2D(eGLImage &eglImage, GLint format, uint32_t width, uint32_t height, void *data); + void createTexture2D(eGLImage &eglImage, void *data); void pushEnv(std::vector &shaderEnv, const char *str); void makeCurrent(); diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index 357918711..b8f5d9b85 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -14,6 +14,8 @@ #include #include +#include + #include #include #include @@ -111,13 +113,31 @@ void eGL::syncOutput() */ int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output) { + EGLint drm_format; + ASSERT(tid_ == Thread::currentId()); + switch (eglImage.format_) { + case GL_RED: + case GL_LUMINANCE: + drm_format = DRM_FORMAT_R8; + break; + case GL_RG: + drm_format = DRM_FORMAT_RG88; + break; + case GL_RGBA: + drm_format = DRM_FORMAT_ARGB8888; + break; + default: + LOG(eGL, Error) << "unhandled GL format"; + return -ENODEV; + } + // clang-format off EGLint image_attrs[] = { EGL_WIDTH, (EGLint)eglImage.width_, EGL_HEIGHT, (EGLint)eglImage.height_, - EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888, + EGL_LINUX_DRM_FOURCC_EXT, drm_format, EGL_DMA_BUF_PLANE0_FD_EXT, fd, EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0, EGL_DMA_BUF_PLANE0_PITCH_EXT, (EGLint)eglImage.stride_, @@ -207,9 +227,6 @@ int eGL::createOutputDMABufTexture2D(eGLImage &eglImage, int fd) /** * \brief Create a 2D texture from a memory buffer * \param[in,out] eglImage EGL image to associate with the texture - * \param[in] format OpenGL internal format (e.g., GL_RGB, GL_RGBA) - * \param[in] width Texture width in pixels - * \param[in] height Texture height in pixels * \param[in] data Pointer to pixel data, or nullptr for uninitialised texture * * Creates a 2D texture from a CPU-accessible memory buffer. The texture @@ -217,7 +234,7 @@ int eGL::createOutputDMABufTexture2D(eGLImage &eglImage, int fd) * is useful for uploading static data like lookup tables or uniform color * matrices to the GPU. */ -void eGL::createTexture2D(eGLImage &eglImage, GLint format, uint32_t width, uint32_t height, void *data) +void eGL::createTexture2D(eGLImage &eglImage, void *data) { ASSERT(tid_ == Thread::currentId()); @@ -225,7 +242,7 @@ void eGL::createTexture2D(eGLImage &eglImage, GLint format, uint32_t width, uint glBindTexture(GL_TEXTURE_2D, eglImage.texture_); // Generate texture, bind, associate image to texture, configure, unbind - glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data); + glTexImage2D(GL_TEXTURE_2D, 0, eglImage.format_, eglImage.width_, eglImage.height_, 0, eglImage.format_, GL_UNSIGNED_BYTE, data); // Nearest filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index eae4c57f4..a217e3798 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -506,7 +506,7 @@ int DebayerEGL::debayerGPU(MappedFrameBuffer &in, int out_fd, const DebayerParam egl_.makeCurrent(); /* Create a standard texture input */ - egl_.createTexture2D(*eglImageBayerIn_, glFormat_, inputConfig_.stride / bytesPerPixel_, height_, in.planes()[0].data()); + egl_.createTexture2D(*eglImageBayerIn_, in.planes()[0].data()); /* Generate the output render framebuffer as render to texture */ egl_.createOutputDMABufTexture2D(*eglImageBayerOut_, out_fd); @@ -582,14 +582,14 @@ int DebayerEGL::start() LOG(Debayer, Debug) << "Available fragment shader texture units " << maxTextureImageUnits; + if (initBayerShaders(inputPixelFormat_, outputPixelFormat_)) + return -EINVAL; + /* Raw bayer input as texture */ - eglImageBayerIn_ = std::make_unique(width_, height_, inputConfig_.stride, GL_TEXTURE0, 0); + eglImageBayerIn_ = std::make_unique(glFormat_, inputConfig_.stride / bytesPerPixel_, height_, inputConfig_.stride, GL_TEXTURE0, 0); /* Texture we will render to */ - eglImageBayerOut_ = std::make_unique(outputSize_.width, outputSize_.height, outputConfig_.stride, GL_TEXTURE1, 1); - - if (initBayerShaders(inputPixelFormat_, outputPixelFormat_)) - return -EINVAL; + eglImageBayerOut_ = std::make_unique(GL_RGBA, outputSize_.width, outputSize_.height, outputConfig_.stride, GL_TEXTURE1, 1); return 0; }