Patch Detail
Show a patch.
GET /api/patches/24138/?format=api
{ "id": 24138, "url": "https://patchwork.libcamera.org/api/patches/24138/?format=api", "web_url": "https://patchwork.libcamera.org/patch/24138/", "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": "<20250815113400.20623-9-laurent.pinchart@ideasonboard.com>", "date": "2025-08-15T11:34:00", "name": "[v2,8/8] libcamera: framebuffer: Replace vector with span in constructor", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "cd65481e231e8b250ded6a0c178ba973ff8db59d", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/24138/mbox/", "series": [ { "id": 5383, "url": "https://patchwork.libcamera.org/api/series/5383/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5383", "date": "2025-08-15T11:33:52", "name": "libcamera: Use span in FrameBuffer & assorted cleanups", "version": 2, "mbox": "https://patchwork.libcamera.org/series/5383/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/24138/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/24138/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 A6ABEBEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 15 Aug 2025 11:34:42 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1787169267;\n\tFri, 15 Aug 2025 13:34:42 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1536369267\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Aug 2025 13:34:33 +0200 (CEST)", "from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 12BE1605;\n\tFri, 15 Aug 2025 13:33:38 +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=\"Ykyv9KBr\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1755257618;\n\tbh=8DnZOUdaaa39MSpmMhZLYsOmSaGOlnlLPO8R75YQZDc=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Ykyv9KBr3H+vJsz6qhf4bTyaphAkn1Afcv7gq74FsZQLUStNJbD+dqkAnic5ND4xZ\n\tsdQRTw7IdaCbDuiiZHy2WyTeod8Fu/EoBnWGI5A2qC6Z80JUOn/Dz++xQuUyLi7cbv\n\tUUmEdsCPOchE9W9CV9GCrDAfIjwLaSowU2JIExnw=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "=?utf-8?q?Daniel_R=C3=A1kos?= <daniel.rakos@rastergrid.com>", "Subject": "[PATCH v2 8/8] libcamera: framebuffer: Replace vector with span in\n\tconstructor", "Date": "Fri, 15 Aug 2025 14:34:00 +0300", "Message-ID": "<20250815113400.20623-9-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.49.1", "In-Reply-To": "<20250815113400.20623-1-laurent.pinchart@ideasonboard.com>", "References": "<20250815113400.20623-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "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": "The FrameBuffer constructor takes a list of planes as an std::vector.\nThe caller may stores the planes in a different type of container,\nresulting in the needless allocation of a temporary vector. Replace it\nwith a span.\n\nSuggested-by: Daniel Rákos <daniel.rakos@rastergrid.com>\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n include/libcamera/framebuffer.h | 4 ++--\n include/libcamera/internal/framebuffer.h | 3 ++-\n src/android/mm/cros_frame_buffer_allocator.cpp | 2 +-\n src/android/mm/generic_frame_buffer_allocator.cpp | 2 +-\n src/libcamera/framebuffer.cpp | 10 +++++-----\n src/libcamera/pipeline/ipu3/ipu3.cpp | 5 ++++-\n src/libcamera/pipeline/mali-c55/mali-c55.cpp | 5 ++++-\n src/libcamera/pipeline/rkisp1/rkisp1.cpp | 5 ++++-\n src/libcamera/pipeline/rpi/common/pipeline_base.cpp | 6 ++++--\n src/libcamera/pipeline/vimc/vimc.cpp | 5 ++++-\n src/libcamera/pipeline/virtual/virtual.cpp | 3 ++-\n src/libcamera/v4l2_videodevice.cpp | 6 +++---\n 12 files changed, 36 insertions(+), 20 deletions(-)", "diff": "diff --git a/include/libcamera/framebuffer.h b/include/libcamera/framebuffer.h\nindex e83825b466aa..723525d05294 100644\n--- a/include/libcamera/framebuffer.h\n+++ b/include/libcamera/framebuffer.h\n@@ -58,11 +58,11 @@ public:\n \t\tunsigned int length;\n \t};\n \n-\tFrameBuffer(const std::vector<Plane> &planes, unsigned int cookie = 0);\n+\tFrameBuffer(Span<const Plane> planes, unsigned int cookie = 0);\n \tFrameBuffer(std::unique_ptr<Private> d);\n \tvirtual ~FrameBuffer() {}\n \n-\tconst std::vector<Plane> &planes() const;\n+\tSpan<const Plane> planes() const;\n \tRequest *request() const;\n \tconst FrameMetadata &metadata() const;\n \ndiff --git a/include/libcamera/internal/framebuffer.h b/include/libcamera/internal/framebuffer.h\nindex 97b49d42063f..67b090fc307f 100644\n--- a/include/libcamera/internal/framebuffer.h\n+++ b/include/libcamera/internal/framebuffer.h\n@@ -12,6 +12,7 @@\n #include <utility>\n \n #include <libcamera/base/class.h>\n+#include <libcamera/base/span.h>\n \n #include <libcamera/fence.h>\n #include <libcamera/framebuffer.h>\n@@ -23,7 +24,7 @@ class FrameBuffer::Private : public Extensible::Private\n \tLIBCAMERA_DECLARE_PUBLIC(FrameBuffer)\n \n public:\n-\tPrivate(const std::vector<Plane> &planes, uint64_t cookie = 0);\n+\tPrivate(Span<const Plane> planes, uint64_t cookie = 0);\n \tvirtual ~Private();\n \n \tvoid setRequest(Request *request) { request_ = request; }\ndiff --git a/src/android/mm/cros_frame_buffer_allocator.cpp b/src/android/mm/cros_frame_buffer_allocator.cpp\nindex 264c0d481272..7ec116e1500d 100644\n--- a/src/android/mm/cros_frame_buffer_allocator.cpp\n+++ b/src/android/mm/cros_frame_buffer_allocator.cpp\n@@ -29,7 +29,7 @@ class CrosFrameBufferData : public FrameBuffer::Private\n \n public:\n \tCrosFrameBufferData(cros::ScopedBufferHandle scopedHandle,\n-\t\t\t const std::vector<FrameBuffer::Plane> &planes)\n+\t\t\t Span<const FrameBuffer::Plane> planes)\n \t\t: FrameBuffer::Private(planes), scopedHandle_(std::move(scopedHandle))\n \t{\n \t}\ndiff --git a/src/android/mm/generic_frame_buffer_allocator.cpp b/src/android/mm/generic_frame_buffer_allocator.cpp\nindex 79625a9a3c75..25ad6b035e73 100644\n--- a/src/android/mm/generic_frame_buffer_allocator.cpp\n+++ b/src/android/mm/generic_frame_buffer_allocator.cpp\n@@ -35,7 +35,7 @@ class GenericFrameBufferData : public FrameBuffer::Private\n public:\n \tGenericFrameBufferData(struct alloc_device_t *allocDevice,\n \t\t\t buffer_handle_t handle,\n-\t\t\t const std::vector<FrameBuffer::Plane> &planes)\n+\t\t\t Span<const FrameBuffer::Plane> planes)\n \t\t: FrameBuffer::Private(planes), allocDevice_(allocDevice),\n \t\t handle_(handle)\n \t{\ndiff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp\nindex 219db50d6527..765dab95a843 100644\n--- a/src/libcamera/framebuffer.cpp\n+++ b/src/libcamera/framebuffer.cpp\n@@ -130,9 +130,9 @@ LOG_DEFINE_CATEGORY(Buffer)\n * \\param[in] planes The frame memory planes\n * \\param[in] cookie Cookie\n */\n-FrameBuffer::Private::Private(const std::vector<Plane> &planes, uint64_t cookie)\n-\t: planes_(planes), cookie_(cookie), request_(nullptr),\n-\t isContiguous_(true)\n+FrameBuffer::Private::Private(Span<const Plane> planes, uint64_t cookie)\n+\t: planes_(planes.begin(), planes.end()), cookie_(cookie),\n+\t request_(nullptr), isContiguous_(true)\n {\n \tmetadata_.planes_.resize(planes_.size());\n }\n@@ -315,7 +315,7 @@ ino_t fileDescriptorInode(const SharedFD &fd)\n * \\param[in] planes The frame memory planes\n * \\param[in] cookie Cookie\n */\n-FrameBuffer::FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie)\n+FrameBuffer::FrameBuffer(Span<const Plane> planes, unsigned int cookie)\n \t: FrameBuffer(std::make_unique<Private>(planes, cookie))\n {\n }\n@@ -365,7 +365,7 @@ FrameBuffer::FrameBuffer(std::unique_ptr<Private> d)\n * \\brief Retrieve the static plane descriptors\n * \\return Array of plane descriptors\n */\n-const std::vector<FrameBuffer::Plane> &FrameBuffer::planes() const\n+Span<const FrameBuffer::Plane> FrameBuffer::planes() const\n {\n \treturn _d()->planes_;\n }\ndiff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex 7ae85e5063db..a147af2291a3 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -680,8 +680,11 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera)\n \n \tauto pushBuffer = [&](std::vector<IPABuffer> &buffers,\n \t\t\t const std::unique_ptr<FrameBuffer> &buffer) {\n+\t\tSpan<const FrameBuffer::Plane> planes = buffer->planes();\n+\n \t\tbuffer->setCookie(ipaBufferId++);\n-\t\tbuffers.emplace_back(buffer->cookie(), buffer->planes());\n+\t\tbuffers.emplace_back(buffer->cookie(),\n+\t\t\t\t std::vector<FrameBuffer::Plane>{ planes.begin(), planes.end() });\n \t};\n \n \tfor (const std::unique_ptr<FrameBuffer> &buffer : imgu->paramBuffers_)\ndiff --git a/src/libcamera/pipeline/mali-c55/mali-c55.cpp b/src/libcamera/pipeline/mali-c55/mali-c55.cpp\nindex f03a03fef35c..2e9fad3285b9 100644\n--- a/src/libcamera/pipeline/mali-c55/mali-c55.cpp\n+++ b/src/libcamera/pipeline/mali-c55/mali-c55.cpp\n@@ -1136,8 +1136,11 @@ int PipelineHandlerMaliC55::allocateBuffers(Camera *camera)\n \tauto pushBuffer = [&](std::queue<FrameBuffer *> &queue,\n \t\t\t std::vector<IPABuffer> &buffers,\n \t\t\t const std::unique_ptr<FrameBuffer> &buffer) {\n+\t\tSpan<const FrameBuffer::Plane> planes = buffer->planes();\n+\n \t\tbuffer->setCookie(ipaBufferId++);\n-\t\tbuffers.emplace_back(buffer->cookie(), buffer->planes());\n+\t\tbuffers.emplace_back(buffer->cookie(),\n+\t\t\t\t std::vector<FrameBuffer::Plane>{ planes.begin(), planes.end() });\n \t\tqueue.push(buffer.get());\n \t};\n \ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex 99347c9f6258..d5972b0e7e93 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -1031,8 +1031,11 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera)\n \tauto pushBuffer = [&](std::vector<IPABuffer> &buffers,\n \t\t\t std::queue<FrameBuffer *> &queue,\n \t\t\t const std::unique_ptr<FrameBuffer> &buffer) {\n+\t\tSpan<const FrameBuffer::Plane> planes = buffer->planes();\n+\n \t\tbuffer->setCookie(ipaBufferId++);\n-\t\tbuffers.emplace_back(buffer->cookie(), buffer->planes());\n+\t\tbuffers.emplace_back(buffer->cookie(),\n+\t\t\t\t std::vector<FrameBuffer::Plane>{ planes.begin(), planes.end() });\n \t\tqueue.push(buffer.get());\n \t};\n \ndiff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\nindex 09d30f34d9b7..c209aa596311 100644\n--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n@@ -883,8 +883,10 @@ void PipelineHandlerBase::mapBuffers(Camera *camera, const BufferMap &buffers, u\n \t * handler and the IPA.\n \t */\n \tfor (auto const &[id, buffer] : buffers) {\n-\t\tbufferIds.push_back(IPABuffer(mask | id,\n-\t\t\t\t\t buffer.buffer->planes()));\n+\t\tSpan<const FrameBuffer::Plane> planes = buffer.buffer->planes();\n+\n+\t\tbufferIds.emplace_back(mask | id,\n+\t\t\t\t std::vector<FrameBuffer::Plane>{ planes.begin(), planes.end() });\n \t\tdata->bufferIds_.insert(mask | id);\n \t}\n \ndiff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp\nindex 07273bd2b6c3..5022101505a1 100644\n--- a/src/libcamera/pipeline/vimc/vimc.cpp\n+++ b/src/libcamera/pipeline/vimc/vimc.cpp\n@@ -363,8 +363,11 @@ int PipelineHandlerVimc::start(Camera *camera, [[maybe_unused]] const ControlLis\n \t/* Map the mock IPA buffers to VIMC IPA to exercise IPC code paths. */\n \tstd::vector<IPABuffer> ipaBuffers;\n \tfor (auto [i, buffer] : utils::enumerate(data->mockIPABufs_)) {\n+\t\tSpan<const FrameBuffer::Plane> planes = buffer->planes();\n+\n \t\tbuffer->setCookie(i + 1);\n-\t\tipaBuffers.emplace_back(buffer->cookie(), buffer->planes());\n+\t\tipaBuffers.emplace_back(buffer->cookie(),\n+\t\t\t\t\tstd::vector<FrameBuffer::Plane>{ planes.begin(), planes.end() });\n \t}\n \tdata->ipa_->mapBuffers(ipaBuffers);\n \ndiff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp\nindex 049ebcba58ec..f9538129c956 100644\n--- a/src/libcamera/pipeline/virtual/virtual.cpp\n+++ b/src/libcamera/pipeline/virtual/virtual.cpp\n@@ -315,7 +315,8 @@ int PipelineHandlerVirtual::queueRequestDevice([[maybe_unused]] Camera *camera,\n \t\t\t\tfmd.sequence = streamConfig.seq++;\n \t\t\t\tfmd.timestamp = timestamp;\n \n-\t\t\t\tfor (const auto [i, p] : utils::enumerate(buffer->planes()))\n+\t\t\t\tSpan<const FrameBuffer::Plane> planes = buffer->planes();\n+\t\t\t\tfor (const auto [i, p] : utils::enumerate(planes))\n \t\t\t\t\tfmd.planes()[i].bytesused = p.length;\n \n \t\t\t\tfound = true;\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex ba1889a939cb..7b48d911db73 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -288,7 +288,7 @@ V4L2BufferCache::Entry::Entry(bool free, uint64_t lastUsed, const FrameBuffer &b\n \n bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const\n {\n-\tconst std::vector<FrameBuffer::Plane> &planes = buffer.planes();\n+\tSpan<const FrameBuffer::Plane> planes = buffer.planes();\n \n \tif (planes_.size() != planes.size())\n \t\treturn false;\n@@ -1676,7 +1676,7 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)\n \tbuf.field = V4L2_FIELD_NONE;\n \n \tbool multiPlanar = V4L2_TYPE_IS_MULTIPLANAR(buf.type);\n-\tconst std::vector<FrameBuffer::Plane> &planes = buffer->planes();\n+\tSpan<const FrameBuffer::Plane> planes = buffer->planes();\n \tconst unsigned int numV4l2Planes = format_.planesCount;\n \n \t/*\n@@ -1909,7 +1909,7 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer()\n \t}\n \tmetadata.sequence -= firstFrame_.value();\n \n-\tconst std::vector<FrameBuffer::Plane> &framebufferPlanes = buffer->planes();\n+\tSpan<const FrameBuffer::Plane> framebufferPlanes = buffer->planes();\n \tunsigned int numV4l2Planes = multiPlanar ? buf.length : 1;\n \n \tif (numV4l2Planes != framebufferPlanes.size()) {\n", "prefixes": [ "v2", "8/8" ] }