From patchwork Mon Jan 16 00:28:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 18119 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 F377DC3294 for ; Mon, 16 Jan 2023 00:28:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 52788625E8; Mon, 16 Jan 2023 01:28:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1673828893; bh=0dx1q0gSpebx1lZUR61mTZQQw6qIJ4BYIy3cdVECx60=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=qgADqPnLp2dY4vMMga2aZtJHl3jXn9LUziKP9fgGkLEKHZ9ZnwSSFn4SSUywqBNNC RNSuhPrQc5XlEfO8/0AXglSFJc9c3sSH4wYWFriQwag/eFgGyV+qmnLp/s/pwu/AWi l7EccIdFTudtoJeJPMz4QUe1K/Pi0w5xUQs0QJliRm27+skzEQDB/o1KHHSTa+kKHv +4inDjlRSe/LIJHAnaNnnzcVbNLRUE8Kea398yAQO4AOnmjm+mQZIaB2WN2Qj3Oq4f Ehr7o/XwQBvJwOUgHNZ/BbG+GKCLLfW0gHrE9r8dE7ZjEIZ/ACM2hhUVd0kq31FUjp otd5dkWj79pKw== 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 A5203625E3 for ; Mon, 16 Jan 2023 01:28:11 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="UTthdIrg"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2F1CA9B4; Mon, 16 Jan 2023 01:28:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1673828891; bh=0dx1q0gSpebx1lZUR61mTZQQw6qIJ4BYIy3cdVECx60=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UTthdIrgRO0jcSXEr6zKazOmkBkZENZkkq4zPDgN0QKaA/zdt3f4wHLq9Os2x/FOJ JyLU68TQgckB2G/GDGZhKptRBva4v++0GZTSBl97BzRlCOLWo9dFsvbZaYqA/gzc94 FDnClmY9VQAMM02hQA6aklPAZtS+T1PMdfv+kgpc= To: libcamera-devel@lists.libcamera.org Date: Mon, 16 Jan 2023 02:28:02 +0200 Message-Id: <20230116002808.16014-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.38.2 In-Reply-To: <20230116002808.16014-1-laurent.pinchart@ideasonboard.com> References: <20230116002808.16014-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v9 2/8] android: framebuffer: Add HALFrameBuffer and replace FrameBuffer 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Cc: Harvey Yang Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Harvey Yang HALFrameBuffer is derived from FrameBuffer with access to buffer_handle_t, which is needed for JEA usage. Signed-off-by: Harvey Yang Reviewed-by: Laurent Pinchart Reviewed-by: Han-Lin Chen Signed-off-by: Laurent Pinchart --- src/android/camera_device.cpp | 5 ++-- src/android/camera_device.h | 3 ++- src/android/camera_request.h | 3 ++- src/android/frame_buffer_allocator.h | 7 ++--- src/android/hal_framebuffer.cpp | 22 ++++++++++++++++ src/android/hal_framebuffer.h | 26 +++++++++++++++++++ src/android/meson.build | 1 + .../mm/cros_frame_buffer_allocator.cpp | 9 ++++--- .../mm/generic_frame_buffer_allocator.cpp | 11 +++++--- 9 files changed, 72 insertions(+), 15 deletions(-) create mode 100644 src/android/hal_framebuffer.cpp create mode 100644 src/android/hal_framebuffer.h diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index b20e389b9d30..1f7ce4402b63 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -30,6 +30,7 @@ #include "camera_hal_config.h" #include "camera_ops.h" #include "camera_request.h" +#include "hal_framebuffer.h" using namespace libcamera; @@ -771,7 +772,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) return 0; } -std::unique_ptr +std::unique_ptr CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer, PixelFormat pixelFormat, const Size &size) { @@ -794,7 +795,7 @@ CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer, planes[i].length = buf.size(i); } - return std::make_unique(planes); + return std::make_unique(planes, camera3buffer); } int CameraDevice::processControls(Camera3RequestDescriptor *descriptor) diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 64050416e67e..43ee01592e77 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -29,6 +29,7 @@ #include "camera_capabilities.h" #include "camera_metadata.h" #include "camera_stream.h" +#include "hal_framebuffer.h" #include "jpeg/encoder.h" class Camera3RequestDescriptor; @@ -83,7 +84,7 @@ private: void stop() LIBCAMERA_TSA_EXCLUDES(stateMutex_); - std::unique_ptr + std::unique_ptr createFrameBuffer(const buffer_handle_t camera3buffer, libcamera::PixelFormat pixelFormat, const libcamera::Size &size); diff --git a/src/android/camera_request.h b/src/android/camera_request.h index 37b6ae326f3e..20aba79d5057 100644 --- a/src/android/camera_request.h +++ b/src/android/camera_request.h @@ -21,6 +21,7 @@ #include #include "camera_metadata.h" +#include "hal_framebuffer.h" class CameraBuffer; class CameraStream; @@ -44,7 +45,7 @@ public: CameraStream *stream; buffer_handle_t *camera3Buffer; - std::unique_ptr frameBuffer; + std::unique_ptr frameBuffer; libcamera::UniqueFD fence; Status status = Status::Success; libcamera::FrameBuffer *internalBuffer = nullptr; diff --git a/src/android/frame_buffer_allocator.h b/src/android/frame_buffer_allocator.h index 5d2eeda17fc5..e5c9492279d3 100644 --- a/src/android/frame_buffer_allocator.h +++ b/src/android/frame_buffer_allocator.h @@ -13,9 +13,10 @@ #include #include -#include #include +#include "hal_framebuffer.h" + class CameraDevice; class PlatformFrameBufferAllocator : libcamera::Extensible @@ -31,7 +32,7 @@ public: * Note: The returned FrameBuffer needs to be destroyed before * PlatformFrameBufferAllocator is destroyed. */ - std::unique_ptr allocate( + std::unique_ptr allocate( int halPixelFormat, const libcamera::Size &size, uint32_t usage); }; @@ -44,7 +45,7 @@ PlatformFrameBufferAllocator::PlatformFrameBufferAllocator( \ PlatformFrameBufferAllocator::~PlatformFrameBufferAllocator() \ { \ } \ -std::unique_ptr \ +std::unique_ptr \ PlatformFrameBufferAllocator::allocate(int halPixelFormat, \ const libcamera::Size &size, \ uint32_t usage) \ diff --git a/src/android/hal_framebuffer.cpp b/src/android/hal_framebuffer.cpp new file mode 100644 index 000000000000..3f3d1ed1c327 --- /dev/null +++ b/src/android/hal_framebuffer.cpp @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * hal_framebuffer.cpp - HAL Frame Buffer Handling + */ + +#include "hal_framebuffer.h" + +#include + +HALFrameBuffer::HALFrameBuffer(std::unique_ptr d, + buffer_handle_t handle) + : FrameBuffer(std::move(d)), handle_(handle) +{ +} + +HALFrameBuffer::HALFrameBuffer(const std::vector &planes, + buffer_handle_t handle) + : FrameBuffer(planes), handle_(handle) +{ +} diff --git a/src/android/hal_framebuffer.h b/src/android/hal_framebuffer.h new file mode 100644 index 000000000000..dc96a7e193da --- /dev/null +++ b/src/android/hal_framebuffer.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * hal_framebuffer.h - HAL Frame Buffer Handling + */ + +#pragma once + +#include "libcamera/internal/framebuffer.h" + +#include + +class HALFrameBuffer final : public libcamera::FrameBuffer +{ +public: + HALFrameBuffer(std::unique_ptr d, + buffer_handle_t handle); + HALFrameBuffer(const std::vector &planes, + buffer_handle_t handle); + + buffer_handle_t handle() const { return handle_; } + +private: + buffer_handle_t handle_; +}; diff --git a/src/android/meson.build b/src/android/meson.build index 1bba54de07a8..b543c14371aa 100644 --- a/src/android/meson.build +++ b/src/android/meson.build @@ -46,6 +46,7 @@ android_hal_sources = files([ 'camera_ops.cpp', 'camera_request.cpp', 'camera_stream.cpp', + 'hal_framebuffer.cpp', 'jpeg/encoder_libjpeg.cpp', 'jpeg/exif.cpp', 'jpeg/post_processor_jpeg.cpp', diff --git a/src/android/mm/cros_frame_buffer_allocator.cpp b/src/android/mm/cros_frame_buffer_allocator.cpp index 0665c77b1377..0a5c59f2a697 100644 --- a/src/android/mm/cros_frame_buffer_allocator.cpp +++ b/src/android/mm/cros_frame_buffer_allocator.cpp @@ -16,6 +16,7 @@ #include "../camera_device.h" #include "../frame_buffer_allocator.h" +#include "../hal_framebuffer.h" #include "cros-camera/camera_buffer_manager.h" using namespace libcamera; @@ -48,11 +49,11 @@ public: { } - std::unique_ptr + std::unique_ptr allocate(int halPixelFormat, const libcamera::Size &size, uint32_t usage); }; -std::unique_ptr +std::unique_ptr PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat, const libcamera::Size &size, uint32_t usage) @@ -81,8 +82,8 @@ PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat, plane.length = cros::CameraBufferManager::GetPlaneSize(handle, i); } - return std::make_unique( - std::make_unique(std::move(scopedHandle), planes)); + return std::make_unique( + std::make_unique(std::move(scopedHandle), planes), handle); } PUBLIC_FRAME_BUFFER_ALLOCATOR_IMPLEMENTATION diff --git a/src/android/mm/generic_frame_buffer_allocator.cpp b/src/android/mm/generic_frame_buffer_allocator.cpp index 956623df1f80..3750e1bf52a9 100644 --- a/src/android/mm/generic_frame_buffer_allocator.cpp +++ b/src/android/mm/generic_frame_buffer_allocator.cpp @@ -20,6 +20,7 @@ #include "../camera_device.h" #include "../frame_buffer_allocator.h" +#include "../hal_framebuffer.h" using namespace libcamera; @@ -79,7 +80,7 @@ public: ~Private() override; - std::unique_ptr + std::unique_ptr allocate(int halPixelFormat, const libcamera::Size &size, uint32_t usage); private: @@ -94,7 +95,7 @@ PlatformFrameBufferAllocator::Private::~Private() gralloc_close(allocDevice_); } -std::unique_ptr +std::unique_ptr PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat, const libcamera::Size &size, uint32_t usage) @@ -137,8 +138,10 @@ PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat, offset += planeSize; } - return std::make_unique( - std::make_unique(allocDevice_, handle, planes)); + return std::make_unique( + std::make_unique( + allocDevice_, handle, planes), + handle); } PUBLIC_FRAME_BUFFER_ALLOCATOR_IMPLEMENTATION