From patchwork Thu Apr 28 09:55:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 15744 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 8E4FDC3256 for ; Thu, 28 Apr 2022 09:56:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4064D6564B; Thu, 28 Apr 2022 11:56:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1651139760; bh=FL4CukYIa/gQfym5LNrbRBXQpb7DJCUnbFkpwtp2T4c=; 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=v5wPiUFJdFChwXKq+0DDIRXddb0TOIbnJBEQLYVuhqpewqHuT2faPlOYP/ERUUmtq yWALz02xSE7AOG1NHUfC39JjhAh2M2w7DGl6kA9cYFw5KVi8P6hBW31K1o/nPxPu03 m9ivMpZVmwIba6YzLhW9ybGuMDOrNBIbLkwnnewzf3MnRODnJ08vajWP6hYYmk0i8H +yepTpiUfxtuXoCLHPJVIiDdGf8uoqHI1DXl0I6NnshJMtSzqU10NmwqoPhWmFvfln bd4zqLXKUwmEqCxhvh0g8krBWZlHdQgbH5A4jPUbABD2nRveR8t5iXmahZmOGeSOax GcMjfcNFa7qGQ== Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8FCC865640 for ; Thu, 28 Apr 2022 11:55:58 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="kd3bVmGW"; dkim-atps=neutral Received: by mail-pl1-x62b.google.com with SMTP id q13so20816plr.10 for ; Thu, 28 Apr 2022 02:55:58 -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=6cVbQbgEIPaNhwVbTacUHdQMEaMWbOKLd/Ic82wjmCM=; b=kd3bVmGWrW8IUipZtYwkuODguKx3yuvWlLYyJG28vOO1CP9tSUrBsZH9Tg+0z42h1c DQ1Olbhq0PHR60Nlie+iWvvwSeOdBpXIefrFjkz2qof9Dj3jx62ZmvWtoNKJ5oE9rUv4 mDuYgA9T1rkbMIe08hEGM0eNLaZW3Zkgw7C3w= 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=6cVbQbgEIPaNhwVbTacUHdQMEaMWbOKLd/Ic82wjmCM=; b=xSmhDo+0d0kI23pHoX9NNde4TXu0IZ0pj66x0o2M5HNfTZXoi/jw+zs0MRqNBtX58X OiVylVXAKXpHDegCbkYpWgx7P8BeE+mnkDY0r16PHGGFPu1BV+KL0dw9jsfSeUl5cuYm R/YSKd6aQOlcECfmJkMVy5a+yuFysohoSYfSUHJl5gsro4L1dLRxiaLG4rXYr4kE6LL8 GOSjSipLHzRIpD6Xf7+MBLy5yswGuuJesK2SMC+9TXyBRr72ePlG+koU1m1XI6Q+sryk qxF4fgkGmSh9lI1cuNGyCiXm+KvusVwAzn25gBkaztDtH5+YrVHYriifG0PyIO1t5aRX 8hLw== X-Gm-Message-State: AOAM532QB++jAHJQrwdqEA5AvD+R5/rZM4HYdFXGqg/Cj+9RLbW8HGh/ oOUfJgupGWslIS5LvG++TeTxhe8AyB+kTy4Y X-Google-Smtp-Source: ABdhPJzb+VwttoAXyp3pvQq9Yd/wuw5mgCwhmpwONFsSTn5Ll3q49LNuZerRNxzC/py6IIxAcCP8ow== X-Received: by 2002:a17:90a:1116:b0:1d9:a41a:d13d with SMTP id d22-20020a17090a111600b001d9a41ad13dmr16847409pja.206.1651139756769; Thu, 28 Apr 2022 02:55:56 -0700 (PDT) Received: from chenghaoyang.c.googlers.com.com (93.135.240.35.bc.googleusercontent.com. [35.240.135.93]) by smtp.gmail.com with ESMTPSA id x6-20020a17090a46c600b001d960eaed66sm5861256pjg.42.2022.04.28.02.55.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 02:55:56 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Apr 2022 09:55:40 +0000 Message-Id: <20220428095544.2795980-3-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog In-Reply-To: <20220428095544.2795980-1-chenghaoyang@chromium.org> References: <20220428095544.2795980-1-chenghaoyang@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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" 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 | 25 +++++++++++++++++ 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, 75 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..164ff01d 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..c154f4b6 --- /dev/null +++ b/src/android/hal_framebuffer.cpp @@ -0,0 +1,25 @@ +/* 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