From patchwork Mon Aug 14 11:28:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabrielle George X-Patchwork-Id: 18939 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 2BAE0BF415 for ; Mon, 14 Aug 2023 11:29:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 027F1628E2; Mon, 14 Aug 2023 13:28:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1692012540; bh=rW76to3CewSxJAQvDPi+DUc/D/dhgJYr6JQ8WoIjpTg=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=pWJb8VAUmS9xCWpqYPs+Jm+Rm29cCNU0blTTqEC4DvYgk8ZY5m4hw1O/dVpbycefe 1K+lhcO6hcNXlFEjW1uOwxxmnK3Nl21fZyt50vVPjQ66gp6FPR9S/1oRKZhrVo22Xs Zhw4ueR71CWKZ+0893UhWpWdeOzQqwqYRx7NKTIFD9Y0HU+7DEaDgyTM+Xe3KQVMIi 7MMwIj92ujGvaTwEx+sAe1JzyNHXnluPyTNG97KbhIPc/fZLFljY7Kh+FQBNxev+21 3Xb9scJK4sowju3+nEpSP4k8yS0TPRYp6Pujb5VaFeO0I3cqxmnEQbMGppjHwkr2PO FNYpZFkT1Fy9A== Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4566761E0B for ; Mon, 14 Aug 2023 13:28:55 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="rY8pnJ5M"; dkim-atps=neutral Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-6bd0a0a6766so3376165a34.2 for ; Mon, 14 Aug 2023 04:28:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692012534; x=1692617334; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=71lcLD82o1iAaxJ3Re4tzyvkOeuk5oyOwipvfyqdST0=; b=rY8pnJ5Mi2DyNfkXS2wigqfEe/vtvH3t+Go/DGs2PCfQpOotuUnAl6KGv2P9NaxYg7 cYQuEy4M0yMwkF6kRkGDVnmiZS10HIS0Xfc1newMZMJv2iS8eCA5t7p6wisF8zc+mM3V L6JrG9LGhAP0+ik3Rw0Phhn4Bq5OW5iFK3AONxvL3dNUwyeJXpzTcvxt07uQ54Fhy9e8 R3hAKSFawgyDT/tT0NJ1gPq/ARiyG4MGA8UEz/nn8nahnj0jwDakDf1duFnXya7nmi34 mX1ksCw7GdovYSFBGq2z3QdpRNs7fH4SQLPrRustsnRRSK2rLLGKTNxgee1yFi4moYs8 +Y0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692012534; x=1692617334; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=71lcLD82o1iAaxJ3Re4tzyvkOeuk5oyOwipvfyqdST0=; b=HNgm7IASyqaIURPqDZEp628Rur7khxLK6t9J6N0JOL6DWdqO/vItCQI+WV7biUah+4 38uGpqygKVeMmtY2w8qpBZ83kK950sRfPE5fs6BqBa77xHqcBEXt4jxLaKIcOhVZ/1ni 5/3j7BougkN6/72B9rcMUloYSsoSsZ4Rn0uujj/767NwpSneM+Y6jZvfcC9jcP9gEkNK 8PeZtsKJTmk2Q45FXqPgDXnZTq9NiNCbxODVBUnE12vdvJeQBsBSzP53v3M103/krZ75 x+9FlvsBl+7vhFHUKRwg+xV7BV5b+VSbYIWLXuEYXOHA7KjjeLm8ERnoLj3wXPOi91Fo Gscg== X-Gm-Message-State: AOJu0YyYR944pjo3Nskdx4vRTyopT0X/L3gR7zyy3/PUQaGmLUtS2SER 7D/a9K1vyzXotZg4iPsgNait2b5z8/4HTQ== X-Google-Smtp-Source: AGHT+IFv6cfQhSTa63M6Aj8mwrEdcXweH6Asj5AUdP5Dxu3PXz3DHGYt+yr7U/WrcPbgBlQU3wqCzg== X-Received: by 2002:a05:6830:1007:b0:6b9:6712:d4ad with SMTP id a7-20020a056830100700b006b96712d4admr7951864otp.36.1692012533808; Mon, 14 Aug 2023 04:28:53 -0700 (PDT) Received: from localhost.localdomain (97-115-76-16.ptld.qwest.net. [97.115.76.16]) by smtp.gmail.com with ESMTPSA id c3-20020a9d6c83000000b006b92509e76esm4163817otr.32.2023.08.14.04.28.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 04:28:53 -0700 (PDT) To: libcamera-devel@lists.libcamera.org, kieran.bingham@ideasonboard.com, vedantparanjape160201@gmail.com, gabbymg94@gmail.com Date: Mon, 14 Aug 2023 04:28:46 -0700 Message-Id: <20230814112849.176943-3-gabbymg94@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230814112849.176943-1-gabbymg94@gmail.com> References: <20230814112849.176943-1-gabbymg94@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 2/5] libcamera: MappedFrameBuffer: Use stored plane offset 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: , X-Patchwork-Original-From: Gabby George via libcamera-devel From: Gabrielle George Reply-To: Gabby George Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When calling mmap, the mapped frame buffer class hard-codes the offset value to 0. TODO: EDIT ME WHEN YOU HAVE MORE VERBAL REASONING SKILLS Signed-off-by: Gabby George --- include/libcamera/internal/mapped_framebuffer.h | 2 +- src/libcamera/mapped_framebuffer.cpp | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/libcamera/internal/mapped_framebuffer.h b/include/libcamera/internal/mapped_framebuffer.h index fb39adbf..fac86344 100644 --- a/include/libcamera/internal/mapped_framebuffer.h +++ b/include/libcamera/internal/mapped_framebuffer.h @@ -54,7 +54,7 @@ public: using MapFlags = Flags; - MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags); + MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags, bool usePlaneOffset = false); }; LIBCAMERA_FLAGS_ENABLE_OPERATORS(MappedFrameBuffer::MapFlag) diff --git a/src/libcamera/mapped_framebuffer.cpp b/src/libcamera/mapped_framebuffer.cpp index 6860069b..fcbb38ec 100644 --- a/src/libcamera/mapped_framebuffer.cpp +++ b/src/libcamera/mapped_framebuffer.cpp @@ -172,12 +172,13 @@ MappedBuffer::~MappedBuffer() * \brief Map all planes of a FrameBuffer * \param[in] buffer FrameBuffer to be mapped * \param[in] flags Protection flags to apply to map + * \param[in] usePlaneOffset Use offset stored in buffer's plane; default false * * Construct an object to map a frame buffer for CPU access. The mapping can be * made as Read only, Write only or support Read and Write operations by setting * the MapFlag flags accordingly. */ -MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags) +MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags, bool usePlaneOffset) { ASSERT(!buffer->planes().empty()); planes_.reserve(buffer->planes().size()); @@ -223,8 +224,14 @@ MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags) const int fd = plane.fd.get(); auto &info = mappedBuffers[fd]; if (!info.address) { - void *address = mmap(nullptr, info.mapLength, mmapFlags, - MAP_SHARED, fd, 0); + void *address; + if (usePlaneOffset) { + address = mmap(nullptr, plane.length, mmapFlags, + MAP_SHARED, fd, plane.offset); + } else { + address = mmap(nullptr, info.mapLength, mmapFlags, + MAP_SHARED, fd, 0); + } if (address == MAP_FAILED) { error_ = -errno; LOG(Buffer, Error) << "Failed to mmap plane: " @@ -236,7 +243,8 @@ MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags) maps_.emplace_back(info.address, info.mapLength); } - planes_.emplace_back(info.address + plane.offset, plane.length); + uint8_t *storedAddress = usePlaneOffset ? info.address : info.address + plane.offset; + planes_.emplace_back(storedAddress, plane.length); } }