[{"id":35445,"web_url":"https://patchwork.libcamera.org/comment/35445/","msgid":"<1d971a3b-8109-4c28-9160-2cceea3a7ce1@ideasonboard.com>","date":"2025-08-15T12:12:18","subject":"Re: [PATCH v2 8/8] libcamera: framebuffer: Replace vector with span\n\tin constructor","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"2025. 08. 15. 13:34 keltezéssel, Laurent Pinchart írta:\n> The FrameBuffer constructor takes a list of planes as an std::vector.\n> The caller may stores the planes in a different type of container,\n> resulting in the needless allocation of a temporary vector. Replace it\n> with a span.\n> \n> Suggested-by: Daniel Rákos <daniel.rakos@rastergrid.com>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n\nReviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n\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(-)\n> \n> diff --git a/include/libcamera/framebuffer.h b/include/libcamera/framebuffer.h\n> index 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\n\n>   \tRequest *request() const;\n>   \tconst FrameMetadata &metadata() const;\n>   \n> diff --git a/include/libcamera/internal/framebuffer.h b/include/libcamera/internal/framebuffer.h\n> index 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; }\n> diff --git a/src/android/mm/cros_frame_buffer_allocator.cpp b/src/android/mm/cros_frame_buffer_allocator.cpp\n> index 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}\n> diff --git a/src/android/mm/generic_frame_buffer_allocator.cpp b/src/android/mm/generic_frame_buffer_allocator.cpp\n> index 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{\n> diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp\n> index 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>   }\n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index 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_)\n> diff --git a/src/libcamera/pipeline/mali-c55/mali-c55.cpp b/src/libcamera/pipeline/mali-c55/mali-c55.cpp\n> index 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>   \n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> index 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>   \n> diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> index 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>   \n> diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp\n> index 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>   \n> diff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp\n> index 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;\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 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()) {","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 89CD9BDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 15 Aug 2025 12:12:25 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2363F69257;\n\tFri, 15 Aug 2025 14:12:24 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8372B61443\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Aug 2025 14:12:22 +0200 (CEST)","from [192.168.33.21] (185.221.141.188.nat.pool.zt.hu\n\t[185.221.141.188])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 633C756D;\n\tFri, 15 Aug 2025 14:11:27 +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=\"lQIDyaal\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1755259887;\n\tbh=LBj7GmUgPuyRQ5Tf0iA5wZNhoWfzIMA/DCG81Adl1K4=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=lQIDyaalIwBXT48qstvmngXOuL0xFqPjlpDk9ZO3TiYDMJrC5vt1pMAK4W1NdI2R+\n\tGfm2O0WRO6WUIAMerJWk0hiYY5UaWHOk53NnV+s2uFs6nok5yzIprMcXVUfeFaGJpF\n\tZIj4x3RstjulmUlTUCEJRgs5/6lixfMKqrddQjio=","Message-ID":"<1d971a3b-8109-4c28-9160-2cceea3a7ce1@ideasonboard.com>","Date":"Fri, 15 Aug 2025 14:12:18 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v2 8/8] libcamera: framebuffer: Replace vector with span\n\tin constructor","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Cc":"=?utf-8?q?Daniel_R=C3=A1kos?= <daniel.rakos@rastergrid.com>","References":"<20250815113400.20623-1-laurent.pinchart@ideasonboard.com>\n\t<20250815113400.20623-9-laurent.pinchart@ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20250815113400.20623-9-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","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>"}}]