From patchwork Tue Aug 12 17:23:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 24095 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 1FC50BEFBE for ; Tue, 12 Aug 2025 17:23:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4B5596921B; Tue, 12 Aug 2025 19:23:31 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="s/1WLveA"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 286666921A for ; Tue, 12 Aug 2025 19:23:29 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 040DD4A4; Tue, 12 Aug 2025 19:22:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1755019356; bh=2jZ8wX4rztGOO3uj2DVqBc2kfBXcxkc401xxrV/RJvw=; h=From:To:Cc:Subject:Date:From; b=s/1WLveA/xi3VO+YQaY1c77+0sryPFf+9O4rn3FzsLbAs6YpWs5pc1ZgyCLNczgBS JI/2tqNZ6FwntnX+ezzUgumyrPfjavn8kyKr46iM8kqVIYao2SAntBwdJGhwvFkCHG 3bK/c8/aaUl82EBdF9gTW71mqvp6GjoTgNlPRD9w= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: =?utf-8?q?Daniel_R=C3=A1kos?= Subject: [PATCH] libcamera: framebuffer: Replace vector with span in constructor Date: Tue, 12 Aug 2025 20:23:10 +0300 Message-ID: <20250812172310.17441-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.49.1 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 FrameBuffer constructor takes a list of planes as an std::vector. The caller may stores the planes in a different type of container, resulting in the needless allocation of a temporary vector. Replace it with a span. Suggested-by: Daniel Rákos Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Barnabás Pőcze --- include/libcamera/framebuffer.h | 2 +- include/libcamera/internal/framebuffer.h | 3 ++- src/android/mm/cros_frame_buffer_allocator.cpp | 2 +- src/android/mm/generic_frame_buffer_allocator.cpp | 2 +- src/libcamera/framebuffer.cpp | 8 ++++---- 5 files changed, 9 insertions(+), 8 deletions(-) base-commit: aa0a91c48ddb38c302390d5c4899cb9e093ddd24 diff --git a/include/libcamera/framebuffer.h b/include/libcamera/framebuffer.h index e83825b466aa..653c1a96132f 100644 --- a/include/libcamera/framebuffer.h +++ b/include/libcamera/framebuffer.h @@ -58,7 +58,7 @@ public: unsigned int length; }; - FrameBuffer(const std::vector &planes, unsigned int cookie = 0); + FrameBuffer(Span planes, unsigned int cookie = 0); FrameBuffer(std::unique_ptr d); virtual ~FrameBuffer() {} diff --git a/include/libcamera/internal/framebuffer.h b/include/libcamera/internal/framebuffer.h index 97b49d42063f..67b090fc307f 100644 --- a/include/libcamera/internal/framebuffer.h +++ b/include/libcamera/internal/framebuffer.h @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -23,7 +24,7 @@ class FrameBuffer::Private : public Extensible::Private LIBCAMERA_DECLARE_PUBLIC(FrameBuffer) public: - Private(const std::vector &planes, uint64_t cookie = 0); + Private(Span planes, uint64_t cookie = 0); virtual ~Private(); void setRequest(Request *request) { request_ = request; } diff --git a/src/android/mm/cros_frame_buffer_allocator.cpp b/src/android/mm/cros_frame_buffer_allocator.cpp index 264c0d481272..7ec116e1500d 100644 --- a/src/android/mm/cros_frame_buffer_allocator.cpp +++ b/src/android/mm/cros_frame_buffer_allocator.cpp @@ -29,7 +29,7 @@ class CrosFrameBufferData : public FrameBuffer::Private public: CrosFrameBufferData(cros::ScopedBufferHandle scopedHandle, - const std::vector &planes) + Span planes) : FrameBuffer::Private(planes), scopedHandle_(std::move(scopedHandle)) { } diff --git a/src/android/mm/generic_frame_buffer_allocator.cpp b/src/android/mm/generic_frame_buffer_allocator.cpp index 79625a9a3c75..25ad6b035e73 100644 --- a/src/android/mm/generic_frame_buffer_allocator.cpp +++ b/src/android/mm/generic_frame_buffer_allocator.cpp @@ -35,7 +35,7 @@ class GenericFrameBufferData : public FrameBuffer::Private public: GenericFrameBufferData(struct alloc_device_t *allocDevice, buffer_handle_t handle, - const std::vector &planes) + Span planes) : FrameBuffer::Private(planes), allocDevice_(allocDevice), handle_(handle) { diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp index 219db50d6527..cb849b8e40fe 100644 --- a/src/libcamera/framebuffer.cpp +++ b/src/libcamera/framebuffer.cpp @@ -130,9 +130,9 @@ LOG_DEFINE_CATEGORY(Buffer) * \param[in] planes The frame memory planes * \param[in] cookie Cookie */ -FrameBuffer::Private::Private(const std::vector &planes, uint64_t cookie) - : planes_(planes), cookie_(cookie), request_(nullptr), - isContiguous_(true) +FrameBuffer::Private::Private(Span planes, uint64_t cookie) + : planes_(std::begin(planes), std::end(planes)), cookie_(cookie), + request_(nullptr), isContiguous_(true) { metadata_.planes_.resize(planes_.size()); } @@ -315,7 +315,7 @@ ino_t fileDescriptorInode(const SharedFD &fd) * \param[in] planes The frame memory planes * \param[in] cookie Cookie */ -FrameBuffer::FrameBuffer(const std::vector &planes, unsigned int cookie) +FrameBuffer::FrameBuffer(Span planes, unsigned int cookie) : FrameBuffer(std::make_unique(planes, cookie)) { }