From patchwork Thu Dec 1 09:27:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 17924 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 23E0FC3284 for ; Thu, 1 Dec 2022 09:27:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 67AD26333E; Thu, 1 Dec 2022 10:27:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1669886867; bh=yBofSPsRWhqy1SHwJL6wRgxHfkNtSapeoFSfzmk7Vhc=; 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=CQpz6r42u57EYpNwZJMQL6rgchGGMxvQlaCE+bLMEibwii+lRQNseGtB9GdfTp3D4 Y85DgV7Y0+fCq3sK+kVqJ53cG/NNcde4rhJg+Vfrixq0Am0Ia4N++Qe9+QxpofN5FC e4L2bt34n0LDLNJQ/E8ESjpVbosMhsHy7QeQzQ+8YeXP4rMyiqcDUVCgn5HdAomiUt Ut/qqPg28YroKKdw9WBFpPRJAfEsMycj47ahAMBhf9JMSu+V9ki2H4vFFHzreg2xbA r2zkm2CUR5DhgOZ+SoEvQdvRcccdN5DwT+NaBXQ4dnHhlzO6w5jqkW4ziGPWm98bqJ rt4TnWjLng6PA== Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A071063335 for ; Thu, 1 Dec 2022 10:27:45 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="XQeqZILb"; dkim-atps=neutral Received: by mail-pf1-x431.google.com with SMTP id l127so683442pfl.2 for ; Thu, 01 Dec 2022 01:27:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2WIVjXf7T7zWWY8SH7R+GpLPzdRSVC2JpAFQv8b5zVI=; b=XQeqZILbGCM+Qr6KmEk3XILbr1nV7Lrym2wr265Wyff2Dj3ry6VA8S6lW1MZY6VmT2 dHqFIX/R9xKEt0cPWEJ8jW7dUbkWuGQhtNXvD4Zg6tdg/KQ2W94W3THs/psQdBl7NY1R 7gHXVlE+iTaGsUxWMEs9qWHsq/IKK6PN323go= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2WIVjXf7T7zWWY8SH7R+GpLPzdRSVC2JpAFQv8b5zVI=; b=vdEkNXGptJHi76m/ZKs0relaOzvS7GKAzkYDu6LsajJR4JaiqdfjRQPVlBpDOSJSw+ 7lT9hXjKY5XFKNgRFEvZ/ypCrd0U/RiGEZF5NPuU35YklXCJXrExSj5HbP7D9ojX9t5g vEoumZrwqsuQltNf/c+eoJL5YEms82zB9SWgHG6zgyuHguuUInUD9Q27bod1FCjO2pmF UKppqrY/++CUQJZ8Bhhi4pTt3hmmwwJCTP5wHiBSQ2SJ+CeYv+zaneW4/KGG1ZrfDXB4 Z1LYJSix156VLEu1Wq9pNaBo+QswVbLAlWeGIKtE1PQ1i8rbRTqCGnkb9oQWJ76DeoD+ 3LbQ== X-Gm-Message-State: ANoB5pmAElrDfFUK4leF/2jCAF90jBr9ckcI7cqME8HEEBNhEPFtl5Cs NYWXJB4iVIOSdsqomiwbTDFIKCuBDmwNR8Uf X-Google-Smtp-Source: AA0mqf48xgkM9+cCpBBEeEOpHAHx0/Z8jtr5m5SjLrEVSx2PUYGRHs1ikrj8F5krW2dslr6+kmeHyQ== X-Received: by 2002:a65:4c42:0:b0:477:f872:8b6 with SMTP id l2-20020a654c42000000b00477f87208b6mr23000323pgr.457.1669886863555; Thu, 01 Dec 2022 01:27:43 -0800 (PST) Received: from chenghaoyang-low.c.googlers.com.com (46.165.189.35.bc.googleusercontent.com. [35.189.165.46]) by smtp.gmail.com with ESMTPSA id z9-20020a1709027e8900b00186b8752a78sm3108050pla.80.2022.12.01.01.27.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 01:27:43 -0800 (PST) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Thu, 1 Dec 2022 09:27:29 +0000 Message-Id: <20221201092733.2042078-3-chenghaoyang@google.com> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog In-Reply-To: <20221201092733.2042078-1-chenghaoyang@google.com> References: <20221201092733.2042078-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 2/6] Add HALFrameBuffer and replace FrameBuffer in src/android 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: Harvey Yang via libcamera-devel From: Harvey Yang Reply-To: Harvey Yang Cc: Harvey Yang Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Harvey Yang AndroidFrameBuffer 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 --- src/android/camera_device.cpp | 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 +++++--- 7 files changed, 67 insertions(+), 12 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 b20e389b..872161ba 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; @@ -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/frame_buffer_allocator.h b/src/android/frame_buffer_allocator.h index 5d2eeda1..e5c94922 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 00000000..4ac5a820 --- /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 - Android 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 00000000..ec737e70 --- /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 - Android 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 1bba54de..c2773f9e 100644 --- a/src/android/meson.build +++ b/src/android/meson.build @@ -37,6 +37,7 @@ endif android_deps += [libyuv_dep] android_hal_sources = files([ + 'hal_framebuffer.cpp', 'camera3_hal.cpp', 'camera_capabilities.cpp', 'camera_device.cpp', diff --git a/src/android/mm/cros_frame_buffer_allocator.cpp b/src/android/mm/cros_frame_buffer_allocator.cpp index 0665c77b..0a5c59f2 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 956623df..3750e1bf 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