From patchwork Tue Sep 12 14:15:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattijs Korpershoek X-Patchwork-Id: 18999 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 44434BE080 for ; Tue, 12 Sep 2023 14:15:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B1188628FA; Tue, 12 Sep 2023 16:15:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1694528132; bh=thJaRfHbcDJpVbGfzpoQQmBT2F4Rvnoe1/XkuZ9bTNk=; h=Date:References:In-Reply-To:To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=oBfRrydbS3InX+p5WR4R/h/3Y6eQIBpFH7ttGlDkWjwf5IjuE/RnLHTSFwq0ZLpGu yFzTt1U4XLD97UK6kSNUyrt7zr2+DHcJFxGynj6pZU1cGCgOVvrfZt8/RVfY5ySRBp MA/LdhFczwacHqs02JfXflL/j7HkVpDDTrIArjEPHoNRq/jWRfQKUfLtVyLThaJXPI L9VU6fZC+fOexxttBIPUc6xLxoUAoze1iOEhe12tR/wPLoxBU8Qfq6qXnet1UZ4ys1 +K3iy0JjnJCDYkGAY8pThyBNQSOyHENeyPLjvM624SuURxcGyLgR8xMgD1uy7ymQVZ PVZNO1RcuRNqA== Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2B08561DF5 for ; Tue, 12 Sep 2023 16:15:30 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="jPJBdp8z"; dkim-atps=neutral Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-40037db2fe7so60976005e9.0 for ; Tue, 12 Sep 2023 07:15:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1694528130; x=1695132930; darn=lists.libcamera.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=NjfjVhvFuPXlJHFJT4RmEMUxoS6VQGc5E8V0sjRslpU=; b=jPJBdp8z1klCx8HjEr844OnRpeb9uEfDw3m2aXZbTViDEllqY5382OdddHAeh/RRa8 OBGEQJ8gguoJM+rLklrhyP1bb0X9PXnrjlpyElQLb1/MyLYeQjz2k/flejPK/iKicJ39 7WxBT8gKzomLhD6rDAX7yuKTnceRq1xCGYO3caN7zFbkgsijttKCtFehb2DE+SMN8taC 2Aw0ZdqYdL7kNUDkdDgY3ENRq13xQFBfplf7MoQNOFfaDEwvaYSo/pT8D0ryOiI+FZOb arM/yFg8OmAznS8OxJfk9KUxfxRLVUEtmzBfJqu7A+Y3W99OCcZKjVSJteGpnkAIkdtI E7hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694528130; x=1695132930; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NjfjVhvFuPXlJHFJT4RmEMUxoS6VQGc5E8V0sjRslpU=; b=aqF0X2jIGFse4uLynZeed9URD5EPlJl2ACCsbed1M9a1Jj9HpRLaWg4v/3NgOEgno2 WTbt2WNABwvUot5FxBGjP/otP0J0QlkWNCdEgsgb5dHH0SBi6YQd9AD8NoBZf5VGGEuf W6P1qKQ7Ss/AXieGjaAY+tyj/68aVWOxbP4pzASx8G86bpD7NGYshgSq67VUGWJ61PnN u6D5HHE3Ct9YMRFdp/PB/7jJaHZh3Zq2CIl2zi/VmGTO1U6DgBwTf6lw8wFRTtzWc48c XYT4/dPH2QqDEF1D9Xn/4oItZ8oQGAULugkGv+aEw1fCkWMf3d2+y0QUYVrXPSylp368 L/mA== X-Gm-Message-State: AOJu0YyWmkAtjy2FJvyRua0GweCd+koFaad5Uj4O74Cz0xgULAH/NzJ1 Dgwys3MS/qnlJCigwvqHGzwvMee0Fe07/k0/bh8= X-Google-Smtp-Source: AGHT+IGRrf9fwQjIVAPByBxSPennwZp+ZvjI2dtbTdQsHrr2dXKqJY9F8Lalz5z8oSFbkZtoPUcgVg== X-Received: by 2002:a7b:c4c5:0:b0:401:b0f2:88cb with SMTP id g5-20020a7bc4c5000000b00401b0f288cbmr11619468wmk.31.1694528129563; Tue, 12 Sep 2023 07:15:29 -0700 (PDT) Received: from [192.168.2.39] ([82.66.159.240]) by smtp.gmail.com with ESMTPSA id y9-20020a7bcd89000000b003fed630f560sm12996380wmj.36.2023.09.12.07.15.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 07:15:29 -0700 (PDT) Date: Tue, 12 Sep 2023 16:15:23 +0200 MIME-Version: 1.0 Message-Id: <20230912-gralloc-api-v4-v2-4-e859da63f98c@baylibre.com> References: <20230912-gralloc-api-v4-v2-0-e859da63f98c@baylibre.com> In-Reply-To: <20230912-gralloc-api-v4-v2-0-e859da63f98c@baylibre.com> To: libcamera-devel@lists.libcamera.org X-Mailer: b4 0.12.3 Subject: [libcamera-devel] [PATCH v2 4/4] android: mm: generic: Use GraphicBufferAllocator instead of gralloc.h 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: Mattijs Korpershoek via libcamera-devel From: Mattijs Korpershoek Reply-To: Mattijs Korpershoek Cc: Guillaume La Roque Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" gralloc.h is a very old API that has been deprecated at least since Android P (9). Switch over to a higher level abstraction of gralloc from libui, which is compatible with Android 11 and up. Libui: * is provided in the VNDK (so it's available to vendors). * is also used in the camera vts test named VtsAidlHalCameraProvider_TargetTest. Drop the libhardware stub since we no longer need it. Notes: * GraphicsBufferAllocator being a Singleton, buffer lifecycle management is easier. * The imported headers from Android generate the -Wextra-semi warning. To avoid patching the files, a pragma has been added before inclusion. Signed-off-by: Mattijs Korpershoek Reviewed-by: Jacopo Mondi --- src/android/mm/generic_frame_buffer_allocator.cpp | 61 ++++++++--------------- src/android/mm/libhardware_stub.c | 17 ------- src/android/mm/meson.build | 8 ++- 3 files changed, 23 insertions(+), 63 deletions(-) diff --git a/src/android/mm/generic_frame_buffer_allocator.cpp b/src/android/mm/generic_frame_buffer_allocator.cpp index 7ecef2c669df..468579068c32 100644 --- a/src/android/mm/generic_frame_buffer_allocator.cpp +++ b/src/android/mm/generic_frame_buffer_allocator.cpp @@ -16,8 +16,11 @@ #include "libcamera/internal/framebuffer.h" #include -#include -#include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wextra-semi" +#include +#pragma GCC diagnostic pop +#include #include "../camera_device.h" #include "../frame_buffer_allocator.h" @@ -33,35 +36,28 @@ class GenericFrameBufferData : public FrameBuffer::Private LIBCAMERA_DECLARE_PUBLIC(FrameBuffer) public: - GenericFrameBufferData(struct alloc_device_t *allocDevice, + GenericFrameBufferData(android::GraphicBufferAllocator &allocDevice, buffer_handle_t handle, const std::vector &planes) : FrameBuffer::Private(planes), allocDevice_(allocDevice), handle_(handle) { - ASSERT(allocDevice_); ASSERT(handle_); } ~GenericFrameBufferData() override { /* - * allocDevice_ is used to destroy handle_. allocDevice_ is - * owned by PlatformFrameBufferAllocator::Private. - * GenericFrameBufferData must be destroyed before it is - * destroyed. - * - * \todo Consider managing alloc_device_t with std::shared_ptr - * if this is difficult to maintain. - * * \todo Thread safety against alloc_device_t is not documented. * Is it no problem to call alloc/free in parallel? */ - allocDevice_->free(allocDevice_, handle_); + android::status_t status = allocDevice_.free(handle_); + if (status != android::NO_ERROR) + LOG(HAL, Error) << "Error freeing framebuffer: " << status; } private: - struct alloc_device_t *allocDevice_; + android::GraphicBufferAllocator &allocDevice_; const buffer_handle_t handle_; }; } /* namespace */ @@ -73,50 +69,33 @@ class PlatformFrameBufferAllocator::Private : public Extensible::Private public: Private(CameraDevice *const cameraDevice) : cameraDevice_(cameraDevice), - hardwareModule_(nullptr), - allocDevice_(nullptr) + allocDevice_(android::GraphicBufferAllocator::get()) { - hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &hardwareModule_); - ASSERT(hardwareModule_); } - ~Private() override; + ~Private() = default; std::unique_ptr allocate(int halPixelFormat, const libcamera::Size &size, uint32_t usage); private: const CameraDevice *const cameraDevice_; - const struct hw_module_t *hardwareModule_; - struct alloc_device_t *allocDevice_; + android::GraphicBufferAllocator &allocDevice_; }; -PlatformFrameBufferAllocator::Private::~Private() -{ - if (allocDevice_) - gralloc_close(allocDevice_); - dlclose(hardwareModule_->dso); -} - std::unique_ptr PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat, const libcamera::Size &size, uint32_t usage) { - if (!allocDevice_) { - int ret = gralloc_open(hardwareModule_, &allocDevice_); - if (ret) { - LOG(HAL, Fatal) << "gralloc_open() failed: " << ret; - return nullptr; - } - } - - int stride = 0; + uint32_t stride = 0; buffer_handle_t handle = nullptr; - int ret = allocDevice_->alloc(allocDevice_, size.width, size.height, - halPixelFormat, usage, &handle, &stride); - if (ret) { - LOG(HAL, Error) << "failed buffer allocation: " << ret; + + android::status_t status = allocDevice_.allocate(size.width, size.height, halPixelFormat, + 1 /*layerCount*/, usage, &handle, &stride, + "libcameraHAL"); + if (status != android::NO_ERROR) { + LOG(HAL, Error) << "failed buffer allocation: " << status; return nullptr; } if (!handle) { diff --git a/src/android/mm/libhardware_stub.c b/src/android/mm/libhardware_stub.c deleted file mode 100644 index 00f15cd90cac..000000000000 --- a/src/android/mm/libhardware_stub.c +++ /dev/null @@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 */ -/* - * Copyright (C) 2023, Ideas on Board - * - * libhardware_stub.c - Android libhardware stub for test compilation - */ - -#include - -#include - -int hw_get_module(const char *id __attribute__((__unused__)), - const struct hw_module_t **module) -{ - *module = NULL; - return -ENOTSUP; -} diff --git a/src/android/mm/meson.build b/src/android/mm/meson.build index e9ceb3afba67..203b8c3e5804 100644 --- a/src/android/mm/meson.build +++ b/src/android/mm/meson.build @@ -4,13 +4,11 @@ platform = get_option('android_platform') if platform == 'generic' android_hal_sources += files(['generic_camera_buffer.cpp', 'generic_frame_buffer_allocator.cpp']) - android_deps += [libdl] - libhardware = dependency('libhardware', required : false) - if libhardware.found() - android_deps += [libhardware] + libui = dependency('libui', required : false) + if libui.found() + android_deps += [libui] else - android_hal_sources += files(['libhardware_stub.c']) android_hal_sources += files(['graphic_buffer_allocator_stub.cpp']) endif elif platform == 'cros'