From patchwork Fri Jul 15 14:38:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 16649 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 F2537BE173 for ; Fri, 15 Jul 2022 14:38:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 355A86330A; Fri, 15 Jul 2022 16:38:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657895914; bh=Q+41rMk7T3BPQTQvEk44SVZPvQYv1BAV5oka8Nhw+SY=; 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=Z5gHjzU0xw2y/lwFmZwplDbYxVXFek+286p2iDWl8g6DfDRoQk53WEIed4r0JzBZH 4EkRHeKywwdPYCy4HDtt9YWVNOj9t92UAmrn+0BrxeOUeihA954YVNjZ8HbOID33A2 5fMY5cKqG3ZAm8u4chvx4YrzcltS4ptrG4KBiPGqnEEv6tLtoF+QMX6MssXG5j8EcA WIUnvHpBwJDfjS+D2P+cYGP/TNHU0sjMRkMRWnRapwwlCF6SwV8DeqScPM6EhKdOHG 3Hr+GD0m6Ohxdbw/nPalhKNcXSrBtqdCHPxA64xYVWPZiolU4r71wXhj0MCGq8RE/J gMB8CkXQR3QiA== Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A29E16330E for ; Fri, 15 Jul 2022 16:38:32 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="II0dfq6n"; dkim-atps=neutral Received: by mail-pj1-x1031.google.com with SMTP id o31-20020a17090a0a2200b001ef7bd037bbso6330312pjo.0 for ; Fri, 15 Jul 2022 07:38:32 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=Iy1ely/RL4WS1+NMPV2x/SpEDy7WLYF/BuzpSB9JZ/Q=; b=II0dfq6niwymsoW2ja9Sm40K+3RdSYu+uzj9DfSMgdosRXH6e4XOWiQK7gRZvwxJew vpJa0LTLfnJS0JBnBoqr5HNFsz80VHCC1rDVZ71SBAZP8kacEh/wkPgktaiAAg1rjlYy /sGXzlxUWqCX8T++AjKMDYXb8CaesBIIlTY08= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Iy1ely/RL4WS1+NMPV2x/SpEDy7WLYF/BuzpSB9JZ/Q=; b=5QaHaZO9A9r/lEh0R8K/mExw8hZW2q87Ci4CbdQJFWOwXLVw8yo9gioOG6tWoFBKf7 IDcvWTzLHSQZUYhlGTgqaDO1Vl0xrbl47SUnsG+YaAulEBjYYchAa6D3AW+W/if8u3WH rq8iQOKxSjfOxDfAzSVMXXysdrE/b1+cU+z6rXRhXNzWpT9V9FXKGYrc72wDo32hYtyB GYkPCEtsWcxS5MdM7M6qbhEfhY+MY44X6H2UvbWBsCAo+5H8b7gLxQ/EoSYm20xlEROw SbqBs5B18Yl+vYEgvqfYOZSywvU7v9iZkHkn+f9x1kQVqiuB5y5RDUy5wX+J+ncUQeaV QomA== X-Gm-Message-State: AJIora9YDyNS0fpmbR8MQWDGtaYmuMMOsytrC9B2A6FQkgAhaqGhvKjD mb1pjT4HRGBS/8JDDGpJGCM0yNwU7q1eOQ== X-Google-Smtp-Source: AGRyM1tVRTtlsg/6LmayuJVbeli9tRcDwS7An4WrDkfILdYhu4Zkw6C+84oPYYXimzGubXvMTYqvng== X-Received: by 2002:a17:903:234d:b0:16c:3e90:12f5 with SMTP id c13-20020a170903234d00b0016c3e9012f5mr13596557plh.82.1657895910714; Fri, 15 Jul 2022 07:38:30 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (208.158.221.35.bc.googleusercontent.com. [35.221.158.208]) by smtp.gmail.com with ESMTPSA id f15-20020aa7968f000000b00528c22fbb45sm3972782pfk.141.2022.07.15.07.38.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 07:38:30 -0700 (PDT) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Fri, 15 Jul 2022 14:38:18 +0000 Message-Id: <20220715143822.672321-3-chenghaoyang@google.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220715143822.672321-1-chenghaoyang@google.com> References: <20220715143822.672321-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 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: Cheng-Hao 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 --- src/android/camera_device.cpp | 3 ++- src/android/frame_buffer_allocator.h | 7 ++--- src/android/hal_framebuffer.cpp | 23 ++++++++++++++++ src/android/hal_framebuffer.h | 27 +++++++++++++++++++ src/android/meson.build | 1 + .../mm/cros_frame_buffer_allocator.cpp | 14 ++++++---- .../mm/generic_frame_buffer_allocator.cpp | 12 +++++---- 7 files changed, 73 insertions(+), 14 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 00d48471..2a35d686 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -29,6 +29,7 @@ #include "camera_hal_config.h" #include "camera_ops.h" #include "camera_request.h" +#include "hal_framebuffer.h" using namespace libcamera; @@ -754,7 +755,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..196c3190 --- /dev/null +++ b/src/android/hal_framebuffer.cpp @@ -0,0 +1,23 @@ +/* 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, + const std::vector &planes, + buffer_handle_t handle) + : FrameBuffer(std::move(d), planes), 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..33f9e4e0 --- /dev/null +++ b/src/android/hal_framebuffer.h @@ -0,0 +1,27 @@ +/* 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, + const std::vector &planes, + 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 75b4bf20..c6790cba 100644 --- a/src/android/meson.build +++ b/src/android/meson.build @@ -38,6 +38,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 52e8c180..bf5a8ae6 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; @@ -47,11 +48,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) @@ -80,9 +81,12 @@ PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat, plane.length = cros::CameraBufferManager::GetPlaneSize(handle, i); } - return std::make_unique( - std::make_unique(std::move(scopedHandle)), - planes); + auto fb = std::make_unique( + std::make_unique( + std::move(scopedHandle)), + planes, handle); + + return fb; } 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 acb2fa2b..dd205dfe 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; @@ -77,7 +78,7 @@ public: ~Private() override; - std::unique_ptr + std::unique_ptr allocate(int halPixelFormat, const libcamera::Size &size, uint32_t usage); private: @@ -92,7 +93,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) @@ -135,9 +136,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