{"id":24284,"url":"https://patchwork.libcamera.org/api/patches/24284/?format=json","web_url":"https://patchwork.libcamera.org/patch/24284/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20250904134641.29597-3-laurent.pinchart@ideasonboard.com>","date":"2025-09-04T13:46:41","name":"[v3,2/2] libcamera: framebuffer: Replace vector with span in constructor","commit_ref":"b8d332cdcc130c27232f61369e7bab2d954e7ac6","pull_url":null,"state":"accepted","archived":false,"hash":"5deeb15f85296dc255f2773f0a488f361863b272","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/24284/mbox/","series":[{"id":5422,"url":"https://patchwork.libcamera.org/api/series/5422/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5422","date":"2025-09-04T13:46:39","name":"libcamera: Use span in FrameBuffer","version":3,"mbox":"https://patchwork.libcamera.org/series/5422/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/24284/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/24284/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 0D9A2BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  4 Sep 2025 13:47:16 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9020969348;\n\tThu,  4 Sep 2025 15:47:16 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 63D4769341\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Sep 2025 15:47:06 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(230.215-178-91.adsl-dyn.isp.belgacom.be [91.178.215.230])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id C23E8F09\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Sep 2025 15:45:56 +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=\"UwNvOt73\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1756993556;\n\tbh=4AUIoFoRwu1kt0V02upo+RvHRe1aTcXr8Zj05zZBCY0=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=UwNvOt73kpKEko4rTVIOaqJ7GQM0E2YTKU/1q3TU8YclDYl6JbgvjAF+kG//aP/nF\n\ts6/1BDbUiHGoGJ3vBahjXxdOBRy9Cr8/7LsTEStzPDN+bVoD8Jkvi+Z7bZBqk7+4Yn\n\t8RGF79UPaCE+pNXTRRgzEAAk63gVk0zBh9APRX58=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Subject":"[PATCH v3 2/2] libcamera: framebuffer: Replace vector with span in\n\tconstructor","Date":"Thu,  4 Sep 2025 15:46:41 +0200","Message-ID":"<20250904134641.29597-3-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.49.1","In-Reply-To":"<20250904134641.29597-1-laurent.pinchart@ideasonboard.com>","References":"<20250904134641.29597-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>\nReviewed-by: Barnabás Pőcze <barnabas.pocze@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                |  6 +++++-\n src/libcamera/pipeline/mali-c55/mali-c55.cpp        |  6 +++++-\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, 38 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 bfbc80af6a3c..d6b7edcb5a7f 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -680,8 +680,12 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera)\n \n \tauto pushBuffers = [&](const std::vector<std::unique_ptr<FrameBuffer>> &buffers) {\n \t\tfor (const std::unique_ptr<FrameBuffer> &buffer : buffers) {\n+\t\t\tSpan<const FrameBuffer::Plane> planes = buffer->planes();\n+\n \t\t\tbuffer->setCookie(ipaBufferId++);\n-\t\t\tipaBuffers_.emplace_back(buffer->cookie(), buffer->planes());\n+\t\t\tipaBuffers_.emplace_back(buffer->cookie(),\n+\t\t\t\t\t\t std::vector<FrameBuffer::Plane>{ planes.begin(),\n+\t\t\t\t\t\t\t\t\t\t  planes.end() });\n \t\t}\n \t};\n \ndiff --git a/src/libcamera/pipeline/mali-c55/mali-c55.cpp b/src/libcamera/pipeline/mali-c55/mali-c55.cpp\nindex 97996399fc51..38bdc6138ed1 100644\n--- a/src/libcamera/pipeline/mali-c55/mali-c55.cpp\n+++ b/src/libcamera/pipeline/mali-c55/mali-c55.cpp\n@@ -1137,8 +1137,12 @@ int PipelineHandlerMaliC55::allocateBuffers(Camera *camera)\n \t\t\t       std::queue<FrameBuffer *> &queue,\n \t\t\t       std::vector<IPABuffer> &ipaBuffers) {\n \t\tfor (const std::unique_ptr<FrameBuffer> &buffer : buffers) {\n+\t\t\tSpan<const FrameBuffer::Plane> planes = buffer->planes();\n+\n \t\t\tbuffer->setCookie(ipaBufferId++);\n-\t\t\tipaBuffers.emplace_back(buffer->cookie(), buffer->planes());\n+\t\t\tipaBuffers.emplace_back(buffer->cookie(),\n+\t\t\t\t\t\tstd::vector<FrameBuffer::Plane>{ planes.begin(),\n+\t\t\t\t\t\t\t\t\t\t planes.end() });\n \t\t\tqueue.push(buffer.get());\n \t\t}\n \t};\ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex 291f96836c5e..cfcbb3b2590a 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -1031,9 +1031,12 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera)\n \tauto pushBuffers = [&](const std::vector<std::unique_ptr<FrameBuffer>> &buffers,\n \t\t\t       std::queue<FrameBuffer *> &queue) {\n \t\tfor (const std::unique_ptr<FrameBuffer> &buffer : buffers) {\n+\t\t\tSpan<const FrameBuffer::Plane> planes = buffer->planes();\n+\n \t\t\tbuffer->setCookie(ipaBufferId++);\n \t\t\tdata->ipaBuffers_.emplace_back(buffer->cookie(),\n-\t\t\t\t\t\t       buffer->planes());\n+\t\t\t\t\t\t       std::vector<FrameBuffer::Plane>{ planes.begin(),\n+\t\t\t\t\t\t\t\t\t\t\tplanes.end() });\n \t\t\tqueue.push(buffer.get());\n \t\t}\n \t};\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":["v3","2/2"]}