{"id":15127,"url":"https://patchwork.libcamera.org/api/1.1/patches/15127/?format=json","web_url":"https://patchwork.libcamera.org/patch/15127/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20211210205239.354901-5-jacopo@jmondi.org>","date":"2021-12-10T20:52:32","name":"[libcamera-devel,v5,04/11] libcamera: framebuffer: Add Fence to FrameBuffer","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"4c394a9516b2e1bdb631629743204ac805c8e776","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/15127/mbox/","series":[{"id":2837,"url":"https://patchwork.libcamera.org/api/1.1/series/2837/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2837","date":"2021-12-10T20:52:28","name":"libcamera: Add fence","version":5,"mbox":"https://patchwork.libcamera.org/series/2837/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/15127/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15127/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 9D5A5C324B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 10 Dec 2021 20:51:59 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 24B5C608A1;\n\tFri, 10 Dec 2021 21:51:59 +0100 (CET)","from relay11.mail.gandi.net (relay11.mail.gandi.net\n\t[217.70.178.231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5EF986087E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 10 Dec 2021 21:51:54 +0100 (CET)","(Authenticated sender: jacopo@jmondi.org)\n\tby relay11.mail.gandi.net (Postfix) with ESMTPSA id A995B100009;\n\tFri, 10 Dec 2021 20:51:53 +0000 (UTC)"],"From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 10 Dec 2021 21:52:32 +0100","Message-Id":"<20211210205239.354901-5-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.33.1","In-Reply-To":"<20211210205239.354901-1-jacopo@jmondi.org>","References":"<20211210205239.354901-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5 04/11] libcamera: framebuffer: Add\n\tFence to FrameBuffer","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Add to the FrameBuffer::Private class a unique pointer to a\nFence.\n\nThe Fence will be used to signal the availability of the Framebuffer for\nincoming data transfer.\n\nThe Fence will be associated to a FrameBuffer at Request::addBuffer()\ntime, and if correctly signalled, reset by the core at Request queue\ntime.\n\nIf a FrameBuffer completes with errors, due to a Fence wait failure, the\nFence will still be owned by the FrameBuffer and it is application\nresponsibility to correctly reset it before reusing the buffer.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/framebuffer.h          |  4 ++\n include/libcamera/internal/framebuffer.h |  8 ++++\n src/libcamera/framebuffer.cpp            | 58 ++++++++++++++++++++++++\n 3 files changed, 70 insertions(+)","diff":"diff --git a/include/libcamera/framebuffer.h b/include/libcamera/framebuffer.h\nindex 502f7897c7a3..de172d97f460 100644\n--- a/include/libcamera/framebuffer.h\n+++ b/include/libcamera/framebuffer.h\n@@ -9,6 +9,7 @@\n \n #include <assert.h>\n #include <limits>\n+#include <memory>\n #include <stdint.h>\n #include <vector>\n \n@@ -18,6 +19,7 @@\n \n namespace libcamera {\n \n+class Fence;\n class Request;\n \n struct FrameMetadata {\n@@ -67,6 +69,8 @@ public:\n \tunsigned int cookie() const { return cookie_; }\n \tvoid setCookie(unsigned int cookie) { cookie_ = cookie; }\n \n+\tstd::unique_ptr<Fence> releaseFence();\n+\n \tvoid cancel() { metadata_.status = FrameMetadata::FrameCancelled; }\n \n private:\ndiff --git a/include/libcamera/internal/framebuffer.h b/include/libcamera/internal/framebuffer.h\nindex 6e0d83896e8c..97dca9635efa 100644\n--- a/include/libcamera/internal/framebuffer.h\n+++ b/include/libcamera/internal/framebuffer.h\n@@ -7,8 +7,12 @@\n \n #pragma once\n \n+#include <memory>\n+#include <utility>\n+\n #include <libcamera/base/class.h>\n \n+#include <libcamera/fence.h>\n #include <libcamera/framebuffer.h>\n \n namespace libcamera {\n@@ -24,7 +28,11 @@ public:\n \tvoid setRequest(Request *request) { request_ = request; }\n \tbool isContiguous() const { return isContiguous_; }\n \n+\tFence *fence() const { return fence_.get(); }\n+\tvoid setFence(std::unique_ptr<Fence> fence) { fence_ = std::move(fence); }\n+\n private:\n+\tstd::unique_ptr<Fence> fence_;\n \tRequest *request_;\n \tbool isContiguous_;\n };\ndiff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp\nindex fcf60b4efdd2..049b1c7e5b3c 100644\n--- a/src/libcamera/framebuffer.cpp\n+++ b/src/libcamera/framebuffer.cpp\n@@ -147,6 +147,45 @@ FrameBuffer::Private::~Private()\n  * \\return True if the planes are stored contiguously in memory, false otherwise\n  */\n \n+/**\n+ * \\fn FrameBuffer::Private::fence()\n+ * \\brief Retrieve a const pointer to the Fence\n+ *\n+ * This function does only return a reference to the the fence and does not\n+ * change its ownership. The fence is stored in the FrameBuffer and can only be\n+ * reset with FrameBuffer::releaseFence() in case the buffer has completed with\n+ * error due to a Fence wait failure.\n+ *\n+ * If buffer with a Fence completes with errors due to a failure in handling\n+ * the fence, applications are responsible for releasing the Fence before\n+ * calling Request::addBuffer() again.\n+ *\n+ * \\sa Request::addBuffer()\n+ *\n+ * \\return A const pointer to the Fence if any, nullptr otherwise\n+ */\n+\n+/**\n+ * \\fn FrameBuffer::Private::setFence()\n+ * \\brief Move a \\a fence in this buffer\n+ * \\param[in] fence The Fence\n+ *\n+ * This function associates a Fence with this Framebuffer. The intended caller\n+ * is the Request::addBuffer() function.\n+ *\n+ * Once a FrameBuffer is associated with a Fence, the FrameBuffer will only be\n+ * made available to the hardware device once the Fence has been correctly\n+ * signalled.\n+ *\n+ * \\sa Request::prepare()\n+ *\n+ * If the FrameBuffer completes successfully the core releases the Fence and the\n+ * Buffer can be reused immediately. If handling of the Fence fails during the\n+ * request preparation, the Fence is not released and is left in the\n+ * FrameBuffer. It is applications responsibility to correctly release the\n+ * fence and handle it opportunely before using the buffer again.\n+ */\n+\n /**\n  * \\class FrameBuffer\n  * \\brief Frame buffer data and its associated dynamic metadata\n@@ -349,6 +388,25 @@ Request *FrameBuffer::request() const\n  * libcamera core never modifies the buffer cookie.\n  */\n \n+/**\n+ * \\brief Extract the Fence associated with this Framebuffer\n+ *\n+ * This function moves the buffer's fence ownership to the caller.\n+ * After the fence has been released, calling this function always return\n+ * nullptr.\n+ *\n+ * If buffer with a Fence completes with errors due to a failure in handling\n+ * the fence, applications are responsible for releasing the Fence before\n+ * calling Request::addBuffer() again.\n+ *\n+ * \\return A unique pointer to the Fence if set, or nullptr if the fence has\n+ * been released already\n+ */\n+std::unique_ptr<Fence> FrameBuffer::releaseFence()\n+{\n+\treturn std::move(_d()->fence_);\n+}\n+\n /**\n  * \\fn FrameBuffer::cancel()\n  * \\brief Marks the buffer as cancelled\n","prefixes":["libcamera-devel","v5","04/11"]}