libcamera: controls: Add zero-copy set API for ControlValue

Extend the ControlValue class with a reserve() function to set the value
without actually copying data, and a non-const data() function that
allows writing data directly to the ControlValue storage. This allows
allocating memory directly in ControlValue, potentially removing a data
copy.

Note that this change was implemented before ByteStreamBuffer gained the
zero-copy read() variant, and doesn't actually save a copy in the
control serializer. It however still simplifies
ControlSerializer::loadControlValue().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
Laurent Pinchart 2020-02-28 17:01:43 +02:00
parent 9ab024f7c2
commit 8daf20485b
4 changed files with 50 additions and 72 deletions

View file

@ -115,6 +115,7 @@ public:
bool isArray() const { return isArray_; }
std::size_t numElements() const { return numElements_; }
Span<const uint8_t> data() const;
Span<uint8_t> data();
std::string toString() const;
@ -174,6 +175,9 @@ public:
value.data(), value.size(), sizeof(typename T::value_type));
}
void reserve(ControlType type, bool isArray = false,
std::size_t numElements = 1);
private:
ControlType type_ : 8;
bool isArray_;