From patchwork Mon Sep 6 22:56:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13675 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 C7258BE175 for ; Mon, 6 Sep 2021 22:57:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 642236917C; Tue, 7 Sep 2021 00:57:13 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="pw2gJD/h"; 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 B2CCF69171 for ; Tue, 7 Sep 2021 00:57:02 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 47A4A993; Tue, 7 Sep 2021 00:57:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1630969022; bh=yQzDE330FE4bfpnJvwkRVv4LxSn+BVXbC0iceJxsrrI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pw2gJD/hgz5l7c+gtXrTYQ8OBZEQJfcD8IVEwNoqIZsVAKnRG0invFvAg5ww81TLA mG28IVIYEgljgMnyU+sepEXmuQBhdhPxwX0H04Yn5kEW/En7XSKftv4QoLzWOk+WKY 5o+vYC18wHtLLBoNbyFQPYesG+VHcQ90O/iVwvtw= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 7 Sep 2021 01:56:15 +0300 Message-Id: <20210906225636.14683-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210906225420.13275-1-laurent.pinchart@ideasonboard.com> References: <20210906225420.13275-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 09/30] libcamera: framebuffer: Add a function to check if planes are contiguous 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" Multi-planar frame buffers can store their planes contiguously in memory, or split them in discontiguous memory areas. Add a private function to check in which of these two categories the frame buffer belongs. This will be used to correctly handle the differences between the V4L2 single and multi planar APIs. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Hirokazu Honda --- Changes v1: - Merge both loops in FrameBuffer::FrameBuffer() --- include/libcamera/internal/framebuffer.h | 2 ++ src/libcamera/framebuffer.cpp | 45 ++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/include/libcamera/internal/framebuffer.h b/include/libcamera/internal/framebuffer.h index 606aed2b4782..cd33c295466e 100644 --- a/include/libcamera/internal/framebuffer.h +++ b/include/libcamera/internal/framebuffer.h @@ -21,9 +21,11 @@ public: Private(); void setRequest(Request *request) { request_ = request; } + bool isContiguous() const { return isContiguous_; } private: Request *request_; + bool isContiguous_; }; } /* namespace libcamera */ diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp index ad63a34a83bf..e71c2ffae034 100644 --- a/src/libcamera/framebuffer.cpp +++ b/src/libcamera/framebuffer.cpp @@ -106,7 +106,7 @@ LOG_DEFINE_CATEGORY(Buffer) */ FrameBuffer::Private::Private() - : request_(nullptr) + : request_(nullptr), isContiguous_(true) { } @@ -120,6 +120,17 @@ FrameBuffer::Private::Private() * handlers, it is called by the pipeline handlers themselves. */ +/** + * \fn FrameBuffer::Private::isContiguous() + * \brief Check if the frame buffer stores planes contiguously in memory + * + * Multi-planar frame buffers can store their planes contiguously in memory, or + * split them into discontiguous memory areas. This function checks in which of + * these two categories the frame buffer belongs. + * + * \return True if the planes are stored contiguously in memory, false otherwise + */ + /** * \class FrameBuffer * \brief Frame buffer data and its associated dynamic metadata @@ -199,8 +210,38 @@ FrameBuffer::FrameBuffer(const std::vector &planes, unsigned int cookie) : Extensible(std::make_unique()), planes_(planes), cookie_(cookie) { - for (const auto &plane : planes_) + unsigned int offset = 0; + bool isContiguous = true; + ino_t inode = 0; + + for (const auto &plane : planes_) { ASSERT(plane.offset != Plane::kInvalidOffset); + + if (plane.offset != offset) { + isContiguous = false; + break; + } + + /* + * Two different dmabuf file descriptors may still refer to the + * same dmabuf instance. Check this using inodes. + */ + if (plane.fd.fd() != planes_[0].fd.fd()) { + if (!inode) + inode = planes_[0].fd.inode(); + if (plane.fd.inode() != inode) { + isContiguous = false; + break; + } + } + + offset += plane.length; + } + + LOG(Buffer, Debug) + << "Buffer is " << (isContiguous ? "not " : "") << "contiguous"; + + _d()->isContiguous_ = isContiguous; } /**