From patchwork Thu Aug 5 17:49:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13217 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 1194FC3235 for ; Thu, 5 Aug 2021 17:50:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 65E39687CF; Thu, 5 Aug 2021 19:50:05 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="WyhT1Vlg"; dkim-atps=neutral Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B399B6026D for ; Thu, 5 Aug 2021 19:50:03 +0200 (CEST) Received: by mail-pj1-x102d.google.com with SMTP id s22-20020a17090a1c16b0290177caeba067so16750565pjs.0 for ; Thu, 05 Aug 2021 10:50:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MNAgr7Dyt5On5utIViZLsalHOVlmLlfJl1tTuhzm4w8=; b=WyhT1VlgdzQGWlvktpq0g2mZJ8CnaeIugSBJIt0tL+V43rKNUIxWwcJynpGJhfy0YR VKGlgNX3v8D7zju1gSD/pkkjcUNVptWlk+ASbx47bPvaX9VhgcRS1SXbMR0sOV0xnGEr xcfRdCzgWbgCR61kjs0YTkOjtMe8bsWmL4J8s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MNAgr7Dyt5On5utIViZLsalHOVlmLlfJl1tTuhzm4w8=; b=mrVhBz1Ez359A8nmjGz0N93rTkirNctLdXg4pmjI1T2rp1eIFrXY/d/G3+zbEGQzst ezLv0X5bJ1pTOdR8uzlEpMWMj6bBMUTj+ztTrQdmGgdtWcveTCZ7iCNwdQGXaYYTgiZo 5u+WsIqjhRjyKwdZ7Vu6UGiVnRUn2XtiHgSZOAUuyG5W7WWuJtn+IrKo4G1M7rg4ptS9 R4ZCqOd0fUR0EY5vSb2BzVqH9R1IHwA3kuHg+kXANKJ4TZ4UfOtGI4wEY/Ovr4ENyn/4 DOx4IR3MvxyNRc4E/wKWMjkcnsHDAi18X/zVnthSwGVfq+H8Jmc9fiTtoVBrWMfG+Q0L dxyw== X-Gm-Message-State: AOAM530pvsfQsxcsLJW22QuS+Sax4zRPgmEo7P4Mi8jgphFs/0vg496y mx5pk7/+6e87XHXXgCFrW9SK5oMu68lZXA== X-Google-Smtp-Source: ABdhPJy6GSZqgLcMiZ/uO8G1VatzaW88/1UfaobMbo6xK6VbNuan1/9YhdgsbDnQBUFu6JAcrPoAzw== X-Received: by 2002:a65:6a01:: with SMTP id m1mr820616pgu.201.1628185801812; Thu, 05 Aug 2021 10:50:01 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:490b:61c8:a52a:e6eb]) by smtp.gmail.com with ESMTPSA id p3sm9975460pjt.0.2021.08.05.10.50.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Aug 2021 10:50:01 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org, laurent.pinchart@ideasonboard.com Date: Fri, 6 Aug 2021 02:49:55 +0900 Message-Id: <20210805174955.1579287-1-hiroh@chromium.org> X-Mailer: git-send-email 2.32.0.554.ge1b32706d8-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: framebuffer: Return plane begin address by MappedBuffer::maps() 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" MappedBuffer::maps() returns std::vector. Plane has the address, but the address points the beginning of the buffer containing the plane. This makes the Plane point the beginning of the plane. So MappedBuffer::maps()[i].data() returns the address of i-th plane. Signed-off-by: Hirokazu Honda --- include/libcamera/internal/framebuffer.h | 1 + src/libcamera/framebuffer.cpp | 41 +++++++++++++++++------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/include/libcamera/internal/framebuffer.h b/include/libcamera/internal/framebuffer.h index 8c187adf..2eb3b7c9 100644 --- a/include/libcamera/internal/framebuffer.h +++ b/include/libcamera/internal/framebuffer.h @@ -36,6 +36,7 @@ protected: int error_; std::vector maps_; + std::vector chunks_; private: LIBCAMERA_DISABLE_COPY(MappedBuffer) diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp index a59e93fb..8231c1df 100644 --- a/src/libcamera/framebuffer.cpp +++ b/src/libcamera/framebuffer.cpp @@ -310,6 +310,7 @@ MappedBuffer &MappedBuffer::operator=(MappedBuffer &&other) { error_ = other.error_; maps_ = std::move(other.maps_); + chunks_ = std::move(other.chunks_); other.error_ = -ENOENT; return *this; @@ -317,8 +318,8 @@ MappedBuffer &MappedBuffer::operator=(MappedBuffer &&other) MappedBuffer::~MappedBuffer() { - for (Plane &map : maps_) - munmap(map.data(), map.size()); + for (Plane &chunk : chunks_) + munmap(chunk.data(), chunk.size()); } /** @@ -381,18 +382,36 @@ MappedBuffer::~MappedBuffer() */ MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, int flags) { + if (buffer->planes().empty()) + return; maps_.reserve(buffer->planes().size()); + /* + * Below assumes planes are in the same buffer and planes are + * consecutive. + * \todo remove this assumption. + */ + const int fd = buffer->planes()[0].fd.fd(); + const off_t length = lseek(fd, 0, SEEK_END); + if (length < 0) { + error_ = -errno; + LOG(Buffer, Error) << "Failed to lseek buffer"; + return; + } + + void *address = mmap(nullptr, length, flags, MAP_SHARED, fd, 0); + if (address == MAP_FAILED) { + error_ = -errno; + LOG(Buffer, Error) << "Failed to mmap plane"; + return; + } + chunks_ = { MappedBuffer::Plane(static_cast(address), + static_cast(length)) }; + size_t offset = 0; for (const FrameBuffer::Plane &plane : buffer->planes()) { - void *address = mmap(nullptr, plane.length, flags, - MAP_SHARED, plane.fd.fd(), 0); - if (address == MAP_FAILED) { - error_ = -errno; - LOG(Buffer, Error) << "Failed to mmap plane"; - break; - } - - maps_.emplace_back(static_cast(address), plane.length); + maps_.emplace_back(static_cast(address) + offset, + plane.length); + offset += plane.length; } }