From patchwork Tue Apr 26 09:14:07 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: 15720 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 BB299C0F1B for ; Tue, 26 Apr 2022 09:16:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 69F8265648; Tue, 26 Apr 2022 11:16:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1650964576; bh=sKwiuYaZ+MuyA5kpHrycmVck9KFSEcBct5hTugdDRJs=; 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=Y1ud+XDtxDlOtbxLzUlhhiZtibyrRaTd72VXnTqG12TwAimetM4alRRaWREgGY5qw xYQWpbNrYq+QmoPdBfom02UIG2x5McdaVRichKiJvlMApgXmXCSi+jOhOyVGs4eYfi 75NquTyIHSraiZHnLegdChmsyM1zx253qRuJ70l4wIdeB9bcv1DuQk97zM0z4/gLeb v/DvQiFieRG2+2RJbdVWK8ajzKAKLVtSPs6Z74neEzgbhYHvXvbsS0rP7er9pIWlK4 2L7yNP/FAHjVUUnRtXpvzwlLQXjDM7j412/hxU3OEHS+A4gp7oTXsDUOe+k6AN130B ezIc1WL1lO0nw== Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CAE7360431 for ; Tue, 26 Apr 2022 11:16:14 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="M5xt6IwC"; dkim-atps=neutral Received: by mail-pl1-x630.google.com with SMTP id q8so6470076plx.3 for ; Tue, 26 Apr 2022 02:16:14 -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=DVcLjICLzdcchRVeSKDG7Y1ioaGg+EZiZ3KEhXdCJ4Y=; b=M5xt6IwCN2vUDLbSx3+lHC5kgzYgjMn21uGJAsBKCPQRcli6oi43gsBSgqMCKV1cSx YGwWislHpjRzuGWI0dQSJdnWkw/5S3E0HkS42yIuVzZUY50uYTdQvfzUcPRpRLoHRLMU eWQxQnN/dT3yLlbabZP6iKKNxt8wXPYCn5J9o= 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=DVcLjICLzdcchRVeSKDG7Y1ioaGg+EZiZ3KEhXdCJ4Y=; b=Gqzj3HeVMatvQ2qWorMV6zmU+b74jZSz834VsWj3H/9lUghD60vR/dG9CLAhrm7GZv r+AtfH/zgvpNfS1hVcfdOe1LH51m+4fIpp4VjuHwjtIYGfyensjlpem8P/IfqQNbW5yv Bx2V6mQuXcLaAgAUErMnTHJ+g3BwkcHxgKcLNVLtr+y69RU+qp78oNWf1rUYCJcQgQsd fTUPK9budaDk2JIinGbf53QcO6l4ARwc3OckwqOIR09uXUdQqMHua0P9t8AwoRzEZp62 eG/2YVfIS1f9a18OfQk/++NrZfII64DHu5dPKF8gKCKqU4NRdOGVbfGG/vjZTUBkM9KJ 9pJA== X-Gm-Message-State: AOAM533DTM2wZXfR56uwASEWFpbsGM55ZjwH0HhU5mG+HGR5yoETkIOc c+dyrqezkDJeoweE4wsXcN86OzgwZ/aLvS8K X-Google-Smtp-Source: ABdhPJxl/Imvjb2dRKPhlZ4zRqlol6abO+9bR3iJbnhEjhG/aa8rnCYdnpE1SjeBF+in+YcxjWTn6Q== X-Received: by 2002:a17:90a:df0f:b0:1d9:2372:b55e with SMTP id gp15-20020a17090adf0f00b001d92372b55emr19988295pjb.104.1650964572878; Tue, 26 Apr 2022 02:16:12 -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 w123-20020a623081000000b005056a4d71e3sm14441042pfw.77.2022.04.26.02.16.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 02:16:12 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Apr 2022 09:14:07 +0000 Message-Id: <20220426091409.1352047-3-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog In-Reply-To: <20220426091409.1352047-1-chenghaoyang@chromium.org> References: <20220426091409.1352047-1-chenghaoyang@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/4] Add AndroidFrameBuffer 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" AndroidFrameBuffer is derived from FrameBuffer with access to buffer_handle_t, which is needed for JEA usage. Signed-off-by: Harvey Yang --- src/android/android_framebuffer.cpp | 32 +++++++++++++++++++ src/android/android_framebuffer.h | 28 ++++++++++++++++ src/android/camera_device.cpp | 3 +- src/android/frame_buffer_allocator.h | 7 ++-- src/android/meson.build | 1 + .../mm/cros_frame_buffer_allocator.cpp | 13 +++++--- .../mm/generic_frame_buffer_allocator.cpp | 11 ++++--- 7 files changed, 81 insertions(+), 14 deletions(-) create mode 100644 src/android/android_framebuffer.cpp create mode 100644 src/android/android_framebuffer.h diff --git a/src/android/android_framebuffer.cpp b/src/android/android_framebuffer.cpp new file mode 100644 index 00000000..1ff7018e --- /dev/null +++ b/src/android/android_framebuffer.cpp @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * android_framebuffer.cpp - Android Frame buffer handling + */ + +#include "android_framebuffer.h" + +#include + +AndroidFrameBuffer::AndroidFrameBuffer( + buffer_handle_t handle, + std::unique_ptr d, + const std::vector &planes, + unsigned int cookie) + : FrameBuffer(std::move(d), planes, cookie), handle_(handle) +{ +} + +AndroidFrameBuffer::AndroidFrameBuffer( + buffer_handle_t handle, + const std::vector &planes, + unsigned int cookie) + : FrameBuffer(planes, cookie), handle_(handle) +{ +} + +buffer_handle_t AndroidFrameBuffer::getHandle() const +{ + return handle_; +} diff --git a/src/android/android_framebuffer.h b/src/android/android_framebuffer.h new file mode 100644 index 00000000..49df9756 --- /dev/null +++ b/src/android/android_framebuffer.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * android_framebuffer.h - Android Frame buffer handling + */ + +#pragma once + +#include "libcamera/internal/framebuffer.h" + +#include + +class AndroidFrameBuffer final : public libcamera::FrameBuffer +{ +public: + AndroidFrameBuffer( + buffer_handle_t handle, std::unique_ptr d, + const std::vector &planes, + unsigned int cookie = 0); + AndroidFrameBuffer(buffer_handle_t handle, + const std::vector &planes, + unsigned int cookie = 0); + buffer_handle_t getHandle() const; + +private: + buffer_handle_t handle_ = nullptr; +}; diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 00d48471..643b4dee 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -25,6 +25,7 @@ #include "system/graphics.h" +#include "android_framebuffer.h" #include "camera_buffer.h" #include "camera_hal_config.h" #include "camera_ops.h" @@ -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(camera3buffer, planes); } int CameraDevice::processControls(Camera3RequestDescriptor *descriptor) diff --git a/src/android/frame_buffer_allocator.h b/src/android/frame_buffer_allocator.h index 5d2eeda1..d7b2118e 100644 --- a/src/android/frame_buffer_allocator.h +++ b/src/android/frame_buffer_allocator.h @@ -13,9 +13,10 @@ #include #include -#include #include +#include "android_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/meson.build b/src/android/meson.build index 75b4bf20..27be27bb 100644 --- a/src/android/meson.build +++ b/src/android/meson.build @@ -38,6 +38,7 @@ endif android_deps += [libyuv_dep] android_hal_sources = files([ + 'android_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..163c5d75 100644 --- a/src/android/mm/cros_frame_buffer_allocator.cpp +++ b/src/android/mm/cros_frame_buffer_allocator.cpp @@ -14,6 +14,7 @@ #include "libcamera/internal/framebuffer.h" +#include "../android_framebuffer.h" #include "../camera_device.h" #include "../frame_buffer_allocator.h" #include "cros-camera/camera_buffer_manager.h" @@ -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,11 @@ 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(handle, + std::make_unique(std::move(scopedHandle)), + planes); + + 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..c79b7b10 100644 --- a/src/android/mm/generic_frame_buffer_allocator.cpp +++ b/src/android/mm/generic_frame_buffer_allocator.cpp @@ -18,6 +18,7 @@ #include #include +#include "../android_framebuffer.h" #include "../camera_device.h" #include "../frame_buffer_allocator.h" @@ -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,9 @@ PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat, offset += planeSize; } - return std::make_unique( - std::make_unique(allocDevice_, handle), - planes); + return std::make_unique(handle, + std::make_unique(allocDevice_, handle), + planes); } PUBLIC_FRAME_BUFFER_ALLOCATOR_IMPLEMENTATION