summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libcamera/framebuffer.h4
-rw-r--r--include/libcamera/internal/framebuffer.h8
-rw-r--r--src/libcamera/framebuffer.cpp58
3 files changed, 70 insertions, 0 deletions
diff --git a/include/libcamera/framebuffer.h b/include/libcamera/framebuffer.h
index 502f7897..de172d97 100644
--- a/include/libcamera/framebuffer.h
+++ b/include/libcamera/framebuffer.h
@@ -9,6 +9,7 @@
#include <assert.h>
#include <limits>
+#include <memory>
#include <stdint.h>
#include <vector>
@@ -18,6 +19,7 @@
namespace libcamera {
+class Fence;
class Request;
struct FrameMetadata {
@@ -67,6 +69,8 @@ public:
unsigned int cookie() const { return cookie_; }
void setCookie(unsigned int cookie) { cookie_ = cookie; }
+ std::unique_ptr<Fence> releaseFence();
+
void cancel() { metadata_.status = FrameMetadata::FrameCancelled; }
private:
diff --git a/include/libcamera/internal/framebuffer.h b/include/libcamera/internal/framebuffer.h
index 6e0d8389..97dca963 100644
--- a/include/libcamera/internal/framebuffer.h
+++ b/include/libcamera/internal/framebuffer.h
@@ -7,8 +7,12 @@
#pragma once
+#include <memory>
+#include <utility>
+
#include <libcamera/base/class.h>
+#include <libcamera/fence.h>
#include <libcamera/framebuffer.h>
namespace libcamera {
@@ -24,7 +28,11 @@ public:
void setRequest(Request *request) { request_ = request; }
bool isContiguous() const { return isContiguous_; }
+ Fence *fence() const { return fence_.get(); }
+ void setFence(std::unique_ptr<Fence> fence) { fence_ = std::move(fence); }
+
private:
+ std::unique_ptr<Fence> fence_;
Request *request_;
bool isContiguous_;
};
diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp
index fcf60b4e..049b1c7e 100644
--- a/src/libcamera/framebuffer.cpp
+++ b/src/libcamera/framebuffer.cpp
@@ -148,6 +148,45 @@ FrameBuffer::Private::~Private()
*/
/**
+ * \fn FrameBuffer::Private::fence()
+ * \brief Retrieve a const pointer to the Fence
+ *
+ * This function does only return a reference to the the fence and does not
+ * change its ownership. The fence is stored in the FrameBuffer and can only be
+ * reset with FrameBuffer::releaseFence() in case the buffer has completed with
+ * error due to a Fence wait failure.
+ *
+ * If buffer with a Fence completes with errors due to a failure in handling
+ * the fence, applications are responsible for releasing the Fence before
+ * calling Request::addBuffer() again.
+ *
+ * \sa Request::addBuffer()
+ *
+ * \return A const pointer to the Fence if any, nullptr otherwise
+ */
+
+/**
+ * \fn FrameBuffer::Private::setFence()
+ * \brief Move a \a fence in this buffer
+ * \param[in] fence The Fence
+ *
+ * This function associates a Fence with this Framebuffer. The intended caller
+ * is the Request::addBuffer() function.
+ *
+ * Once a FrameBuffer is associated with a Fence, the FrameBuffer will only be
+ * made available to the hardware device once the Fence has been correctly
+ * signalled.
+ *
+ * \sa Request::prepare()
+ *
+ * If the FrameBuffer completes successfully the core releases the Fence and the
+ * Buffer can be reused immediately. If handling of the Fence fails during the
+ * request preparation, the Fence is not released and is left in the
+ * FrameBuffer. It is applications responsibility to correctly release the
+ * fence and handle it opportunely before using the buffer again.
+ */
+
+/**
* \class FrameBuffer
* \brief Frame buffer data and its associated dynamic metadata
*
@@ -350,6 +389,25 @@ Request *FrameBuffer::request() const
*/
/**
+ * \brief Extract the Fence associated with this Framebuffer
+ *
+ * This function moves the buffer's fence ownership to the caller.
+ * After the fence has been released, calling this function always return
+ * nullptr.
+ *
+ * If buffer with a Fence completes with errors due to a failure in handling
+ * the fence, applications are responsible for releasing the Fence before
+ * calling Request::addBuffer() again.
+ *
+ * \return A unique pointer to the Fence if set, or nullptr if the fence has
+ * been released already
+ */
+std::unique_ptr<Fence> FrameBuffer::releaseFence()
+{
+ return std::move(_d()->fence_);
+}
+
+/**
* \fn FrameBuffer::cancel()
* \brief Marks the buffer as cancelled
*