From patchwork Sun May 28 16:07:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattijs Korpershoek X-Patchwork-Id: 18652 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 C7A65C3213 for ; Sun, 28 May 2023 16:07:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 418FE626FA; Sun, 28 May 2023 18:07:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1685290036; bh=6+pjW13oltCtROF2IVRJffgTr9KVfE/2DAmq3nHKMh8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=JMD/ui95JKVQLHbP/numb+fUkeMS3GOj6RyGp3u7KVKkwkwXQvXXMlUIPVGsvy8VG /DJR5QUzW/nIXea9cHBmr6zdhPK1yr5q0GV161RIJ0kxCO3vICxiG0EADGx5TL28Vi NPaiFDLNjyvwHl16L6pnNhjT9BNTclP2NCt1QGfhpVIww1DVUboB8wvQiH4eCKA6iC hiILL33voiUdCA6xtuEnx2wrMzV0NkOxUVK8U4mwE5ONhxpDrb4m+XNN6mUWjilglW UF8oW0IknYGR3Bums0+fPJm8aqMMSM+cA89QOx1qjPBaxIrgbVufIFtdwOBVRtJztM 2hgJWs5HkrNkA== Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 73A42626F7 for ; Sun, 28 May 2023 18:07:13 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20221208.gappssmtp.com header.i=@baylibre-com.20221208.gappssmtp.com header.b="cIChiBlD"; dkim-atps=neutral Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1b00ffb4186so15054685ad.0 for ; Sun, 28 May 2023 09:07:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1685290032; x=1687882032; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=EvYTol28kVRNmd8znfjquRAfwKGtksg+QahfMbqU5AA=; b=cIChiBlDYJSbgzrSAXZ4Oudg43hPoIZRkaBTMJUd9m4/1XZ2wsXYbOu/WVKUm6bA1P o7Z2FleZOQba5eW0/HXkgSoVmIMkbebKewAoEoIYmjwpMFNpg4MiJhzS7DCmUob7T+xz Ey0h7gyVgkGyADTF7/xyJ3b241n/I0LmvfIaalzE4wzxk8LIcogBV9kWkjJea9SYBXqi EzVf6wQ8sFMjuz2qlPt7GrSbaP61DJmoFSIIUn87mw0lzwonVuu3g1g9D4+lKqVAQhgZ ESZMY0xW9gdCXt9ErSqR10rR1PgAJrqBANuXb2SXOP4+hMEMHVWdLwADcPQDbndEeN75 AwkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685290032; x=1687882032; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EvYTol28kVRNmd8znfjquRAfwKGtksg+QahfMbqU5AA=; b=cG+sxFC9TFurBsZsTP6E0gkitCb26QPi5bjoKxpGkfYGEXMQLJynQYouKmjpTa1iLy PqbZpGkTna3NYDEhlR4cYy+cgubswypx33TJYKEbikztxXZ8y5TBHJunb3E1Q2shswxz s7MAhvVNLOH/fn+I2lZD7//MmgucqzCGj2YZNIh7cz/rcKX6IsntH/V7zKGdpRpzKbvd 4o3iwYQFOJWPD34I25F5lLKK7rVInuTIXEz7Fok+X4B1WsgKTCbf/6IMm57u972bnyYA REi3bzj4cidIlpij6Z6H50LdgVUOTgnTDlqE3ZQfZ2EU5L90Ddw/f5REDPbFpCgOFdy6 /JhA== X-Gm-Message-State: AC+VfDzZanBH240RMtpzcAWZgShUjIUZ7qfJHrMrvgbFbmIav2O000qi vM04lPPLkDUq+Q0SLpc37bkq8A== X-Google-Smtp-Source: ACHHUZ76r1y0fksO8ZF3Wbf49qFRgK/ILrMrowbpYbrE1WoL1kOYbeo0C9dkgBC01QxaP0ot8ANoAw== X-Received: by 2002:a17:902:9a85:b0:1b0:25ff:a8af with SMTP id w5-20020a1709029a8500b001b025ffa8afmr4829357plp.60.1685290031669; Sun, 28 May 2023 09:07:11 -0700 (PDT) Received: from [10.228.2.211] (224.155.55.84.rev.sfr.net. [84.55.155.224]) by smtp.gmail.com with ESMTPSA id z22-20020a1709028f9600b001ac40488620sm6462590plo.92.2023.05.28.09.07.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 May 2023 09:07:11 -0700 (PDT) Date: Sun, 28 May 2023 18:07:00 +0200 MIME-Version: 1.0 Message-Id: <20230227-android-gralloc-v3-1-babbdf049259@baylibre.com> To: libcamera-devel@lists.libcamera.org X-Mailer: b4 0.12.2 Subject: [libcamera-devel] [PATCH RESEND v3] android: mm: generic: use GRALLOC_HARDWARE_MODULE_ID 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 Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" PlatformFrameBufferAllocator is an abstraction over gralloc. Right now hardwareModule_ points towards a CAMERA_HARDWARE_MODULE_ID. When gralloc_open() is called we observe: libcamera: DEBUG HAL camera3_hal.cpp:75 Open camera gpu0 libcamera: ERROR Camera camera.cpp:524 Camera in Configured state trying acquire() requiring state Available 01-23 14:14:04.742 370 416 E libcamera: FATAL HAL generic_frame_buffer_allocator.cpp:105 gralloc_open() failed: -87 Which is wrong, gralloc_open() is attempting to re-open the camera HAL, instead of the gralloc HAL. Point to a GRALLOC_HARDWARE_MODULE_ID instead so that we can request buffers from gralloc in android. Note: this add a new dependency on android's libhardware [1] [1] https://android.googlesource.com/platform/hardware/libhardware Fixes: c58662c5770e ("android: Introduce PlatformFrameBufferAllocator") Signed-off-by: Mattijs Korpershoek Reviewed-by: Laurent Pinchart --- * Tested on an integration branch in Android 12 (Using android.bp) * Build tested with meson setup build -Dandroid=enabled -Dandroid_platform=generic --- Changes in v3: - Add missing meson.build change to define libhardware dependency - Link to v2: https://lists.libcamera.org/pipermail/libcamera-devel/2023-February/036884.html Changes in v2: - Add dlclose() in PlatformFrameBufferAllocator destructor (Laurent) - Removed RFC, as linking against an AOSP lib for android is OK. - Link to v1: https://lists.libcamera.org/pipermail/libcamera-devel/2023-February/036857.html --- src/android/mm/generic_frame_buffer_allocator.cpp | 7 +++++-- src/android/mm/meson.build | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) --- base-commit: 58e0b6e18c425072a47594f42fc0b61801403aca change-id: 20230227-android-gralloc-04e31d5edc68 Best regards, diff --git a/src/android/mm/generic_frame_buffer_allocator.cpp b/src/android/mm/generic_frame_buffer_allocator.cpp index 3750e1bf52a9..7ecef2c669df 100644 --- a/src/android/mm/generic_frame_buffer_allocator.cpp +++ b/src/android/mm/generic_frame_buffer_allocator.cpp @@ -5,6 +5,7 @@ * generic_camera_buffer.cpp - Allocate FrameBuffer using gralloc API */ +#include #include #include @@ -72,9 +73,10 @@ class PlatformFrameBufferAllocator::Private : public Extensible::Private public: Private(CameraDevice *const cameraDevice) : cameraDevice_(cameraDevice), - hardwareModule_(cameraDevice->camera3Device()->common.module), + hardwareModule_(nullptr), allocDevice_(nullptr) { + hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &hardwareModule_); ASSERT(hardwareModule_); } @@ -85,7 +87,7 @@ public: private: const CameraDevice *const cameraDevice_; - struct hw_module_t *const hardwareModule_; + const struct hw_module_t *hardwareModule_; struct alloc_device_t *allocDevice_; }; @@ -93,6 +95,7 @@ PlatformFrameBufferAllocator::Private::~Private() { if (allocDevice_) gralloc_close(allocDevice_); + dlclose(hardwareModule_->dso); } std::unique_ptr diff --git a/src/android/mm/meson.build b/src/android/mm/meson.build index d40a3b0ba2eb..42eeab3bcfa9 100644 --- a/src/android/mm/meson.build +++ b/src/android/mm/meson.build @@ -4,6 +4,7 @@ platform = get_option('android_platform') if platform == 'generic' android_hal_sources += files(['generic_camera_buffer.cpp', 'generic_frame_buffer_allocator.cpp']) + android_deps += [dependency('libhardware')] elif platform == 'cros' android_hal_sources += files(['cros_camera_buffer.cpp', 'cros_frame_buffer_allocator.cpp'])