From patchwork Mon Apr 21 15:35:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 23191 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 C1993C327D for ; Mon, 21 Apr 2025 15:36:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8228868AC8; Mon, 21 Apr 2025 17:36:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DSMr6xEJ"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1B1DC68AC2 for ; Mon, 21 Apr 2025 17:36:00 +0200 (CEST) Received: from pb-laptop.local (185.221.143.16.nat.pool.zt.hu [185.221.143.16]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5DADE6D6; Mon, 21 Apr 2025 17:33:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1745249633; bh=1tyum2zF6T/OXe1ZVnWsUhzpxhe5AIafayvnExR6jBg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DSMr6xEJEEQFUduNAP7t6faTlw6v+zntxkped7aj9n9ad+2S/FbZiQziOcxS7jNiQ GN497aoEn0tBAs7Zvet9ULJcRwijiNkL0IFy0QPw7ND2AYsdW6fycHLEBjbEpe3/99 JoLMi6WAn1gQPems6UoAHhprjf5DyD2bRkn/Sjyw= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Jacopo Mondi Subject: [PATCH v2 1/5] libcamera: controls: Give name to the union containing storage Date: Mon, 21 Apr 2025 17:35:52 +0200 Message-ID: <20250421153556.171192-2-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250421153556.171192-1-barnabas.pocze@ideasonboard.com> References: <20250421153556.171192-1-barnabas.pocze@ideasonboard.com> 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" In order to be able to copy the storage as one unit, regardless of which member is active give a name to the union member. Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- include/libcamera/controls.h | 6 +++--- src/libcamera/controls.cpp | 17 ++++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 4bfe9615c..1dc6ccffa 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -238,9 +238,9 @@ private: bool isArray_; std::size_t numElements_ : 32; union { - uint64_t value_; - void *storage_; - }; + uint64_t internal; + void *external; + } storage_; void release(); void set(ControlType type, bool isArray, const void *data, diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 70f6f6092..d384e1ef7 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -122,10 +123,8 @@ void ControlValue::release() { std::size_t size = numElements_ * ControlValueSize[type_]; - if (size > sizeof(value_)) { - delete[] reinterpret_cast(storage_); - storage_ = nullptr; - } + if (size > sizeof(storage_.internal)) + delete[] reinterpret_cast(std::exchange(storage_.external, nullptr)); } ControlValue::~ControlValue() @@ -192,9 +191,9 @@ ControlValue &ControlValue::operator=(const ControlValue &other) Span ControlValue::data() const { std::size_t size = numElements_ * ControlValueSize[type_]; - const uint8_t *data = size > sizeof(value_) - ? reinterpret_cast(storage_) - : reinterpret_cast(&value_); + const uint8_t *data = size > sizeof(storage_.internal) + ? reinterpret_cast(storage_.external) + : reinterpret_cast(&storage_.internal); return { data, size }; } @@ -391,8 +390,8 @@ void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElemen if (oldSize == newSize) return; - if (newSize > sizeof(value_)) - storage_ = reinterpret_cast(new uint8_t[newSize]); + if (newSize > sizeof(storage_.internal)) + storage_.external = new uint8_t[newSize]; } /** From patchwork Mon Apr 21 15:35:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 23192 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 9E230C32A2 for ; Mon, 21 Apr 2025 15:36:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 88D0468AD0; Mon, 21 Apr 2025 17:36:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="VQryxAPW"; 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 6300868ABA for ; Mon, 21 Apr 2025 17:36:00 +0200 (CEST) Received: from pb-laptop.local (185.221.143.16.nat.pool.zt.hu [185.221.143.16]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C1AD66D5 for ; Mon, 21 Apr 2025 17:33:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1745249633; bh=Wq3YC8y0FCw4YsT9h4BTerhI+7A5jfaxldCogU8rsHM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VQryxAPWRzAKxH/VZ3IcsXltvVw+JOv6LK6axLaJugV80r6HyGaKcnZ1JgUTcBNIN HbbAFr+j/flKvb5tUEHGTI5icgJiCBFAy+NBfSIoCKg6ZegzJPdKU1YZldXd15mHKr ceD7NGPWm59j9Lo4eGEZq8OphHdolotL9vfSBhWU= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [PATCH v2 2/5] libcamera: controls: Replace `numElements_` bit field Date: Mon, 21 Apr 2025 17:35:53 +0200 Message-ID: <20250421153556.171192-3-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250421153556.171192-1-barnabas.pocze@ideasonboard.com> References: <20250421153556.171192-1-barnabas.pocze@ideasonboard.com> 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" Instead of using a 32-bit wide bit field of `std::size_t`, simply use a `uint32_t` to store the number of elements. This makes it possible to construct references, and use e.g. `std::swap()`. Signed-off-by: Barnabás Pőcze --- include/libcamera/controls.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 1dc6ccffa..3f3580036 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -236,7 +236,7 @@ public: private: ControlType type_ : 8; bool isArray_; - std::size_t numElements_ : 32; + uint32_t numElements_; union { uint64_t internal; void *external; From patchwork Mon Apr 21 15:35:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 23193 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 DD0D0C327D for ; Mon, 21 Apr 2025 15:36:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3211168ACE; Mon, 21 Apr 2025 17:36:06 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="omWxDcj0"; 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 BCD7968AC3 for ; Mon, 21 Apr 2025 17:36:00 +0200 (CEST) Received: from pb-laptop.local (185.221.143.16.nat.pool.zt.hu [185.221.143.16]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1840D73E; Mon, 21 Apr 2025 17:33:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1745249634; bh=kLmYPN72UTTxjzDEdUKeIyAXCAEfWQyE3Pjl4ZvlQ0w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=omWxDcj0cMDfr70mJW2528gGMVkB7z2EtFGC31rCj1R2gUyBkWkb8pQBiliSdBg2y cr+THAz2HHwmo4QVla4WMoOd4fmK/8ZZ5FnhqLPVbaO5TD7o4IATfO3OdoCyi77+FZ tcQkRlthYG0Rv0fzLBDKm8wsS6TlkcppfUA5twQI= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Jacopo Mondi Subject: [PATCH v2 3/5] libcamera: controls: Implement move ctor/assignment Date: Mon, 21 Apr 2025 17:35:54 +0200 Message-ID: <20250421153556.171192-4-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250421153556.171192-1-barnabas.pocze@ideasonboard.com> References: <20250421153556.171192-1-barnabas.pocze@ideasonboard.com> 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" Implement a move constructor and move assignment operator for `ControlValue`. The `ControlValue` type already has an "empty" state that is used when creating a default constructed `ControlValue`, so have the moved-from instance return to that state after move construction/assignment. This is useful, for example, for `std::vector` as most implementations will use the copy constructor when reallocating if no nothrow move constructor is available. Having a nothrow move constructor avoids the extra copies. It is also useful when using temporaries of `ControlValue` with other containers such as `std::optional`, and it also makes `ControlInfo` "cheaply" move constructible/assignable. Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- include/libcamera/controls.h | 26 ++++++++++++++++++++++++++ src/libcamera/controls.cpp | 18 ++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 3f3580036..866d667c4 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -165,6 +166,31 @@ public: ControlValue(const ControlValue &other); ControlValue &operator=(const ControlValue &other); + ControlValue(ControlValue &&other) noexcept + : type_(other.type_), + isArray_(std::exchange(other.isArray_, false)), + numElements_(std::exchange(other.numElements_, 0)), + storage_(std::exchange(other.storage_, {})) + { + other.type_ = ControlTypeNone; + } + + ControlValue &operator=(ControlValue &&other) noexcept + { + if (this != &other) { + release(); + + type_ = other.type_; + isArray_ = std::exchange(other.isArray_, false); + numElements_ = std::exchange(other.numElements_, 0); + storage_ = std::exchange(other.storage_, {}); + + other.type_ = ControlTypeNone; + } + + return *this; + } + ControlType type() const { return type_; } bool isNone() const { return type_ == ControlTypeNone; } bool isArray() const { return isArray_; } diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index d384e1ef7..135e87613 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -155,6 +155,24 @@ ControlValue &ControlValue::operator=(const ControlValue &other) return *this; } +/** + * \fn ControlValue::ControlValue(ControlValue &&other) noexcept + * \brief Move constructor for ControlValue + * \param[in] other The ControlValue object to move from + * + * Move constructs a ControlValue instance from \a other. + * After this operation \a other will be in the same state + * as a default constructed ControlValue instance. + */ + +/** + * \fn ControlValue &ControlValue::operator=(ControlValue &&other) noexcept + * \brief Move assignment operator for ControlValue + * \param[in] other The ControlValue object to move from + * + * \sa ControlValue::ControlValue(ControlValue &&other) + */ + /** * \fn ControlValue::type() * \brief Retrieve the data type of the value From patchwork Mon Apr 21 15:35:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 23194 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 0E1E0C331E for ; Mon, 21 Apr 2025 15:36:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E876268ACA; Mon, 21 Apr 2025 17:36:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="cNcDB6T8"; 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 16EE568AC2 for ; Mon, 21 Apr 2025 17:36:01 +0200 (CEST) Received: from pb-laptop.local (185.221.143.16.nat.pool.zt.hu [185.221.143.16]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6AC566D5; Mon, 21 Apr 2025 17:33:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1745249634; bh=1cAs7nNJZnmC61fakZ7EkFpphcpojXJw7mR0Xw6X6/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cNcDB6T8bVyj9WGlvefoJhi7GerW7kpzZlK3nH5C7LRM1aT6nDk99g6myEvdLDV7D 2Sls2/nCWfHyKec8wYvPsQIusYk3fU20QvO1MAjo4qF3PGuZVb0r1tnkjWpO1gECzx CKw5UeF1JeCtQHdA3T7BIsmAdc9alFJB3Bmwkc5M= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Jacopo Mondi Subject: [PATCH v2 4/5] libcamera: controls: Implement `swap()` Date: Mon, 21 Apr 2025 17:35:55 +0200 Message-ID: <20250421153556.171192-5-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250421153556.171192-1-barnabas.pocze@ideasonboard.com> References: <20250421153556.171192-1-barnabas.pocze@ideasonboard.com> 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" Implement both free and member function `swap()` for `ControlValue`. The general `std::swap()` swaps two values by combining a move construction and two move assignments, but for `ControlValue` a simpler implementation can be provided by just swapping the members. Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- include/libcamera/controls.h | 19 +++++++++++++++++++ src/libcamera/controls.cpp | 15 +++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 866d667c4..62ee5ebd6 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -259,6 +259,25 @@ public: void reserve(ControlType type, bool isArray = false, std::size_t numElements = 1); + void swap(ControlValue &other) noexcept + { + /* `type_` is a bit field, so `std::swap()` cannot be used. */ + { + auto tmp = type_; + type_ = other.type_; + other.type_ = tmp; + } + + std::swap(isArray_, other.isArray_); + std::swap(numElements_, other.numElements_); + std::swap(storage_, other.storage_); + } + + friend void swap(ControlValue &a, ControlValue &b) noexcept + { + a.swap(b); + } + private: ControlType type_ : 8; bool isArray_; diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 135e87613..ae54f8c77 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -412,6 +412,21 @@ void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElemen storage_.external = new uint8_t[newSize]; } +/** + * \fn ControlValue::swap(ControlValue &other) noexcept + * \brief Swap two control values + * + * This function swaps the contained value of \a this with that of \a other. + */ + +/** + * \fn ControlValue::swap(ControlValue &a, ControlValue &b) noexcept + * \brief Swap two control values + * + * This function swaps the contained value of \a a with that of \a b. + * \sa ControlValue::swap() + */ + /** * \class ControlId * \brief Control static metadata From patchwork Mon Apr 21 15:35:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 23195 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 DC1F6C331F for ; Mon, 21 Apr 2025 15:36:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9F90C68AD6; Mon, 21 Apr 2025 17:36:08 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="RAQezxr4"; 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 5BC5168ABA for ; Mon, 21 Apr 2025 17:36:01 +0200 (CEST) Received: from pb-laptop.local (185.221.143.16.nat.pool.zt.hu [185.221.143.16]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C27036D6 for ; Mon, 21 Apr 2025 17:33:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1745249634; bh=/HpccjLfFl/rXKy0yW2JbUFdz0Ez1+VbSg6Whi5yDc4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=RAQezxr4xEKSsmksYmiHOlf5FprRHMMSCpTzA1f/nb4tWyh/LSF5Hqq9evkil1ZMV ip8e3mrWa7SZSs02+KyxQGsxOgV18cPVEOC07taTN4FDCdr95xcvofn4907nkG9cRf huj2o6iaF4xaVqykobUnlzCOqmvv/wIIqVdaYJ8A= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [PATCH v2 5/5] libcamera: controls: Add rvalue overload for `ControlList::set()` Date: Mon, 21 Apr 2025 17:35:56 +0200 Message-ID: <20250421153556.171192-6-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250421153556.171192-1-barnabas.pocze@ideasonboard.com> References: <20250421153556.171192-1-barnabas.pocze@ideasonboard.com> 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" Add an overload of `ControlList::set()` that takes the `ControlValue` argument as an rvalue reference, therefore enabling the use of move assignment. Signed-off-by: Barnabás Pőcze --- include/libcamera/controls.h | 1 + src/libcamera/controls.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 62ee5ebd6..611252f20 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -516,6 +516,7 @@ public: const ControlValue &get(unsigned int id) const; void set(unsigned int id, const ControlValue &value); + void set(unsigned int id, ControlValue &&value); const ControlInfoMap *infoMap() const { return infoMap_; } const ControlIdMap *idMap() const { return idmap_; } diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index ae54f8c77..c22c6bdb9 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -1189,6 +1189,18 @@ void ControlList::set(unsigned int id, const ControlValue &value) *val = value; } +/** + * \copydoc ControlList::set(unsigned int, const ControlValue &) + */ +void ControlList::set(unsigned int id, ControlValue &&value) +{ + ControlValue *val = find(id); + if (!val) + return; + + *val = std::move(value); +} + /** * \fn ControlList::infoMap() * \brief Retrieve the ControlInfoMap used to construct the ControlList