From patchwork Wed Oct 15 01:22:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 24669 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 EB84AC3332 for ; Wed, 15 Oct 2025 01:23:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7D30D60658; Wed, 15 Oct 2025 03:23:33 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="YOR57/OP"; dkim-atps=neutral Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 97E0C60642 for ; Wed, 15 Oct 2025 03:23:19 +0200 (CEST) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-b40f11a1027so1073927766b.2 for ; Tue, 14 Oct 2025 18:23:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1760491399; x=1761096199; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=466aSq4HGB3YriCFxyHHrht3jJTico5gS2hMItA4Sxs=; b=YOR57/OP6fsh6ODo+R4tAtLonc7RqsBSH4Ohv7EteHo4IfEZcyhZki61AnlKKH3cmE gh/pTfRa8VBGkZ31yQ/hqojIMTsB33vEBLiL02OQueY/NQF9afM2jEK/tovFxX0foXlk Z93liycGu/I8RRGGcwETT19Wk3c1tC1HY+MW7uOxSDD3/TOwLdb4srYpwD1pUvAFSZnj et490l7uqM7ICv3Q7CdXE8GtjwlAu+4z4UJsRAP+A76+1MaiCgjMavUI/ACNWEAeJR/X G1F5BGLTNvWVnMTOaE+OCuG2ZOAQvkwE1asXnR65d9eHvLAYUoICVw4y2LB6CfinV6k4 RofA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760491399; x=1761096199; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=466aSq4HGB3YriCFxyHHrht3jJTico5gS2hMItA4Sxs=; b=VqqZPYTpqe7naUR6X9BgjVIYBuonKdavuciOqqKgcSeXyOG7YSiqF52pyFGY09CfAz 4iBan3QzlvZj1VoYuZy3wY19nQSIqjDROoZTto5OPZ/v60iZzLm9wsWcCnV42jqDvMJV JnYSOvfFKGAAa/pdki3nkEpP6VtfJEqBQbggxnK8IZEsNkbp7kRrgS7gQYRAFn01N/uS ztn3BENnhmi5i9Ytm/LOivi8QE3w2pzIaHYGc+icbF4KgN2431am0+EB6svvIu4ChR1K VokCzLraO822UW/S/MWOFkPRZK673knQKqQ5P889oZe9xNmVhi2LqoCXdEKWghQ1Gyds 8dSg== X-Gm-Message-State: AOJu0YxeQ1jXPNAqgx+5HNvGsgWk2o/G1pTX6rk9stRAqLdLEMb2iHV5 JghvqhajvGBT6f25rsJfsEg8FpUSbgw1b8GxxK+1CDxY5xosMQ1IxmUvOi4GoHaKxSTOczv49rS 2g2qW X-Gm-Gg: ASbGncsW8LODTOTnlr+Hcq1JDXNUMN4znjC+lwXls65g5UfFmhm2siamB3EpENCl2Mi dAar4pzH97kmi/bMDbzwgGFZH91h9PBzJqxlWu9vhKh3tN7hTe3E3hRBDHLVKHWveOHKmgLI6Fg OHDc61nBv7PeXIwUB01c+UJDOkjacOXd/bVQ7KBTEFflSUWoqofSoCfvA+ykjhAvb5zwVXmbUak HP/jp8572ZyYeyXlxg/2mifruZzhKyw50700IrX6aoajF2zaxtiXvra1S/8W2uMa4Ed0tyTRQek WtmOqNhPOF78VfS4wxUMb8aNFHduyI817RZatjRW5m66Dg3PFjYw2NRdOHiC5v1bSxizbakCcS+ 3cD+m0ZahzLUa37dHaz9rVzIe4Qkv0CiB+1iw7fGyYqtkTu/xMLmxdZH1yqkrsjLnm9vOXMm165 tRohNhlZGe7ho2QRhbLGzjVCbbL9+5bpzQ+P/m1M5B X-Google-Smtp-Source: AGHT+IEbLFo+23cBv+hIoNUpyjs+8eeeCLt8ATt4ow+5eACfYZZEALSAOinpb0sN9oPf5cpHWXlC7w== X-Received: by 2002:a17:907:6e88:b0:b3d:35f6:e3cf with SMTP id a640c23a62f3a-b50aca0070cmr2883767666b.60.1760491398673; Tue, 14 Oct 2025 18:23:18 -0700 (PDT) Received: from inspiron14p-linux.nxsw.local (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b5ccd7b202dsm98348466b.82.2025.10.14.18.23.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Oct 2025 18:23:18 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH v3 24/39] libcamera: software_isp: gbm: Add in a GBM helper class for GPU surface access Date: Wed, 15 Oct 2025 02:22:36 +0100 Message-ID: <20251015012251.17508-25-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251015012251.17508-1-bryan.odonoghue@linaro.org> References: <20251015012251.17508-1-bryan.odonoghue@linaro.org> 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" A helper class to interact with GBM. This will allow us to specify the internal storage format of the CPU when making a texture for the Debayer vertext/fragment shaders and thus ensure we receive an uncompressed and untiled output buffer. Signed-off-by: Bryan O'Donoghue --- include/libcamera/internal/gbm.h | 43 ++++++++++++++++++ include/libcamera/internal/meson.build | 1 + src/libcamera/gbm.cpp | 61 ++++++++++++++++++++++++++ src/libcamera/meson.build | 11 +++++ 4 files changed, 116 insertions(+) create mode 100644 include/libcamera/internal/gbm.h create mode 100644 src/libcamera/gbm.cpp diff --git a/include/libcamera/internal/gbm.h b/include/libcamera/internal/gbm.h new file mode 100644 index 00000000..41b5e00f --- /dev/null +++ b/include/libcamera/internal/gbm.h @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Linaro Ltd. + * + * Authors: + * Bryan O'Donoghue + * + * gbm.h - Helper class for managing GBM interactions. + */ + +#pragma once + +#include + +#include + +#include + +namespace libcamera { + +LOG_DECLARE_CATEGORY(GBM) + +/** + * \brief Helper class for managing GBM interactions + * + */ +class GBM +{ +public: + GBM(); + ~GBM(); + + int createDevice(); + struct gbm_device *getDevice() { return gbm_device_; } + PixelFormat getPixelFormat() { return format_; } + +private: + int fd_; + struct gbm_device *gbm_device_; + PixelFormat format_; +}; + +} // namespace libcamera diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build index ecb7c9fa..01a36595 100644 --- a/include/libcamera/internal/meson.build +++ b/include/libcamera/internal/meson.build @@ -24,6 +24,7 @@ libcamera_internal_headers = files([ 'dma_buf_allocator.h', 'formats.h', 'framebuffer.h', + 'gbm.h', 'global_configuration.h', 'ipa_data_serializer.h', 'ipa_manager.h', diff --git a/src/libcamera/gbm.cpp b/src/libcamera/gbm.cpp new file mode 100644 index 00000000..caf9ca1c --- /dev/null +++ b/src/libcamera/gbm.cpp @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2024, Linaro Ltd. + * + * Authors: + * Bryan O'Donoghue + * + * egl.cpp - Helper class for managing GBM interactions. + */ + +#include "libcamera/internal/gbm.h" + +#include +#include +#include +#include + +#include +#include + +namespace libcamera { + +LOG_DEFINE_CATEGORY(GBM) + +GBM::GBM() +{ + fd_ = 0; +} + +GBM::~GBM() +{ + if (gbm_device_) + gbm_device_destroy(gbm_device_); + + if (fd_ >= 0) + close(fd_); +} + +int GBM::createDevice() +{ + const char *dri_node = "/dev/dri/renderD128"; //TODO: get from an env or config setting + + fd_ = open(dri_node, O_RDWR | O_CLOEXEC); + if (fd_ < 0) { + LOG(GBM, Error) << "Open " << dri_node << " fail " << fd_; + return fd_; + } + + gbm_device_ = gbm_create_device(fd_); + if (!gbm_device_) { + LOG(GBM, Error) << "gbm_crate_device fail"; + goto fail; + } + + format_ = libcamera::formats::ARGB8888; + + return 0; +fail: + return -ENODEV; +} +} //namespace libcamera diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 5b9b86f2..fe60c875 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -69,6 +69,16 @@ libcamera_deps = [] libatomic = cc.find_library('atomic', required : false) libthreads = dependency('threads') +libgbm = cc.find_library('gbm', required: false) +gbm_works = cc.check_header('gbm.h', required: false) + +if libgbm.found() and gbm_works + config_h.set('HAVE_GBM', 1) + libcamera_internal_sources += files([ + 'gbm.cpp', + ]) +endif + subdir('base') subdir('converter') subdir('ipa') @@ -176,6 +186,7 @@ libcamera_deps += [ libcamera_base_private, libcrypto, libdl, + libgbm, liblttng, libudev, libyaml,