libcamera: framebuffer: Replace vector with span in constructor
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 <daniel.rakos@rastergrid.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
This commit is contained in:
@@ -58,11 +58,11 @@ public:
|
||||
unsigned int length;
|
||||
};
|
||||
|
||||
FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie = 0);
|
||||
FrameBuffer(Span<const Plane> planes, unsigned int cookie = 0);
|
||||
FrameBuffer(std::unique_ptr<Private> d);
|
||||
virtual ~FrameBuffer() {}
|
||||
|
||||
const std::vector<Plane> &planes() const;
|
||||
Span<const Plane> planes() const;
|
||||
Request *request() const;
|
||||
const FrameMetadata &metadata() const;
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
#include <libcamera/base/span.h>
|
||||
|
||||
#include <libcamera/fence.h>
|
||||
#include <libcamera/framebuffer.h>
|
||||
@@ -23,7 +24,7 @@ class FrameBuffer::Private : public Extensible::Private
|
||||
LIBCAMERA_DECLARE_PUBLIC(FrameBuffer)
|
||||
|
||||
public:
|
||||
Private(const std::vector<Plane> &planes, uint64_t cookie = 0);
|
||||
Private(Span<const Plane> planes, uint64_t cookie = 0);
|
||||
virtual ~Private();
|
||||
|
||||
void setRequest(Request *request) { request_ = request; }
|
||||
|
||||
@@ -29,7 +29,7 @@ class CrosFrameBufferData : public FrameBuffer::Private
|
||||
|
||||
public:
|
||||
CrosFrameBufferData(cros::ScopedBufferHandle scopedHandle,
|
||||
const std::vector<FrameBuffer::Plane> &planes)
|
||||
Span<const FrameBuffer::Plane> planes)
|
||||
: FrameBuffer::Private(planes), scopedHandle_(std::move(scopedHandle))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class GenericFrameBufferData : public FrameBuffer::Private
|
||||
public:
|
||||
GenericFrameBufferData(struct alloc_device_t *allocDevice,
|
||||
buffer_handle_t handle,
|
||||
const std::vector<FrameBuffer::Plane> &planes)
|
||||
Span<const FrameBuffer::Plane> planes)
|
||||
: FrameBuffer::Private(planes), allocDevice_(allocDevice),
|
||||
handle_(handle)
|
||||
{
|
||||
|
||||
@@ -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<Plane> &planes, uint64_t cookie)
|
||||
: planes_(planes), cookie_(cookie), request_(nullptr),
|
||||
isContiguous_(true)
|
||||
FrameBuffer::Private::Private(Span<const Plane> planes, uint64_t cookie)
|
||||
: planes_(planes.begin(), planes.end()), 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<Plane> &planes, unsigned int cookie)
|
||||
FrameBuffer::FrameBuffer(Span<const Plane> planes, unsigned int cookie)
|
||||
: FrameBuffer(std::make_unique<Private>(planes, cookie))
|
||||
{
|
||||
}
|
||||
@@ -365,7 +365,7 @@ FrameBuffer::FrameBuffer(std::unique_ptr<Private> d)
|
||||
* \brief Retrieve the static plane descriptors
|
||||
* \return Array of plane descriptors
|
||||
*/
|
||||
const std::vector<FrameBuffer::Plane> &FrameBuffer::planes() const
|
||||
Span<const FrameBuffer::Plane> FrameBuffer::planes() const
|
||||
{
|
||||
return _d()->planes_;
|
||||
}
|
||||
|
||||
@@ -680,8 +680,12 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera)
|
||||
|
||||
auto pushBuffers = [&](const std::vector<std::unique_ptr<FrameBuffer>> &buffers) {
|
||||
for (const std::unique_ptr<FrameBuffer> &buffer : buffers) {
|
||||
Span<const FrameBuffer::Plane> planes = buffer->planes();
|
||||
|
||||
buffer->setCookie(ipaBufferId++);
|
||||
ipaBuffers_.emplace_back(buffer->cookie(), buffer->planes());
|
||||
ipaBuffers_.emplace_back(buffer->cookie(),
|
||||
std::vector<FrameBuffer::Plane>{ planes.begin(),
|
||||
planes.end() });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1137,8 +1137,12 @@ int PipelineHandlerMaliC55::allocateBuffers(Camera *camera)
|
||||
std::queue<FrameBuffer *> &queue,
|
||||
std::vector<IPABuffer> &ipaBuffers) {
|
||||
for (const std::unique_ptr<FrameBuffer> &buffer : buffers) {
|
||||
Span<const FrameBuffer::Plane> planes = buffer->planes();
|
||||
|
||||
buffer->setCookie(ipaBufferId++);
|
||||
ipaBuffers.emplace_back(buffer->cookie(), buffer->planes());
|
||||
ipaBuffers.emplace_back(buffer->cookie(),
|
||||
std::vector<FrameBuffer::Plane>{ planes.begin(),
|
||||
planes.end() });
|
||||
queue.push(buffer.get());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1031,9 +1031,12 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera)
|
||||
auto pushBuffers = [&](const std::vector<std::unique_ptr<FrameBuffer>> &buffers,
|
||||
std::queue<FrameBuffer *> &queue) {
|
||||
for (const std::unique_ptr<FrameBuffer> &buffer : buffers) {
|
||||
Span<const FrameBuffer::Plane> planes = buffer->planes();
|
||||
|
||||
buffer->setCookie(ipaBufferId++);
|
||||
data->ipaBuffers_.emplace_back(buffer->cookie(),
|
||||
buffer->planes());
|
||||
std::vector<FrameBuffer::Plane>{ planes.begin(),
|
||||
planes.end() });
|
||||
queue.push(buffer.get());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -883,8 +883,10 @@ void PipelineHandlerBase::mapBuffers(Camera *camera, const BufferMap &buffers, u
|
||||
* handler and the IPA.
|
||||
*/
|
||||
for (auto const &[id, buffer] : buffers) {
|
||||
bufferIds.push_back(IPABuffer(mask | id,
|
||||
buffer.buffer->planes()));
|
||||
Span<const FrameBuffer::Plane> planes = buffer.buffer->planes();
|
||||
|
||||
bufferIds.emplace_back(mask | id,
|
||||
std::vector<FrameBuffer::Plane>{ planes.begin(), planes.end() });
|
||||
data->bufferIds_.insert(mask | id);
|
||||
}
|
||||
|
||||
|
||||
@@ -363,8 +363,11 @@ int PipelineHandlerVimc::start(Camera *camera, [[maybe_unused]] const ControlLis
|
||||
/* Map the mock IPA buffers to VIMC IPA to exercise IPC code paths. */
|
||||
std::vector<IPABuffer> ipaBuffers;
|
||||
for (auto [i, buffer] : utils::enumerate(data->mockIPABufs_)) {
|
||||
Span<const FrameBuffer::Plane> planes = buffer->planes();
|
||||
|
||||
buffer->setCookie(i + 1);
|
||||
ipaBuffers.emplace_back(buffer->cookie(), buffer->planes());
|
||||
ipaBuffers.emplace_back(buffer->cookie(),
|
||||
std::vector<FrameBuffer::Plane>{ planes.begin(), planes.end() });
|
||||
}
|
||||
data->ipa_->mapBuffers(ipaBuffers);
|
||||
|
||||
|
||||
@@ -315,7 +315,8 @@ int PipelineHandlerVirtual::queueRequestDevice([[maybe_unused]] Camera *camera,
|
||||
fmd.sequence = streamConfig.seq++;
|
||||
fmd.timestamp = timestamp;
|
||||
|
||||
for (const auto [i, p] : utils::enumerate(buffer->planes()))
|
||||
Span<const FrameBuffer::Plane> planes = buffer->planes();
|
||||
for (const auto [i, p] : utils::enumerate(planes))
|
||||
fmd.planes()[i].bytesused = p.length;
|
||||
|
||||
found = true;
|
||||
|
||||
@@ -288,7 +288,7 @@ V4L2BufferCache::Entry::Entry(bool free, uint64_t lastUsed, const FrameBuffer &b
|
||||
|
||||
bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const
|
||||
{
|
||||
const std::vector<FrameBuffer::Plane> &planes = buffer.planes();
|
||||
Span<const FrameBuffer::Plane> planes = buffer.planes();
|
||||
|
||||
if (planes_.size() != planes.size())
|
||||
return false;
|
||||
@@ -1676,7 +1676,7 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)
|
||||
buf.field = V4L2_FIELD_NONE;
|
||||
|
||||
bool multiPlanar = V4L2_TYPE_IS_MULTIPLANAR(buf.type);
|
||||
const std::vector<FrameBuffer::Plane> &planes = buffer->planes();
|
||||
Span<const FrameBuffer::Plane> planes = buffer->planes();
|
||||
const unsigned int numV4l2Planes = format_.planesCount;
|
||||
|
||||
/*
|
||||
@@ -1909,7 +1909,7 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer()
|
||||
}
|
||||
metadata.sequence -= firstFrame_.value();
|
||||
|
||||
const std::vector<FrameBuffer::Plane> &framebufferPlanes = buffer->planes();
|
||||
Span<const FrameBuffer::Plane> framebufferPlanes = buffer->planes();
|
||||
unsigned int numV4l2Planes = multiPlanar ? buf.length : 1;
|
||||
|
||||
if (numV4l2Planes != framebufferPlanes.size()) {
|
||||
|
||||
Reference in New Issue
Block a user