{"id":19083,"url":"https://patchwork.libcamera.org/api/1.1/patches/19083/?format=json","web_url":"https://patchwork.libcamera.org/patch/19083/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20230923-gralloc-api-v4-v3-4-9a9e039284ba@baylibre.com>","date":"2023-09-23T16:23:34","name":"[libcamera-devel,v3,4/4] android: mm: generic: Use GraphicBufferAllocator instead of gralloc.h","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"d8b18a17e687490513c827d74a960b5dcd9a81e8","submitter":{"id":153,"url":"https://patchwork.libcamera.org/api/1.1/people/153/?format=json","name":"Mattijs Korpershoek","email":"mkorpershoek@baylibre.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/19083/mbox/","series":[{"id":4035,"url":"https://patchwork.libcamera.org/api/1.1/series/4035/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4035","date":"2023-09-23T16:23:30","name":"android: switch over to modern gralloc API via libui","version":3,"mbox":"https://patchwork.libcamera.org/series/4035/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19083/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19083/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 2F6F4C326C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 23 Sep 2023 16:23:47 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BF3776294B;\n\tSat, 23 Sep 2023 18:23:46 +0200 (CEST)","from mail-wm1-x330.google.com (mail-wm1-x330.google.com\n\t[IPv6:2a00:1450:4864:20::330])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D6C1162946\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 23 Sep 2023 18:23:42 +0200 (CEST)","by mail-wm1-x330.google.com with SMTP id\n\t5b1f17b1804b1-4053cf48670so25297985e9.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 23 Sep 2023 09:23:42 -0700 (PDT)","from [192.168.0.39] ([2a01:e0a:324:38a0:25d4:3d10:65f9:654e])\n\tby smtp.gmail.com with ESMTPSA id\n\ty7-20020adfd087000000b00317f70240afsm7200595wrh.27.2023.09.23.09.23.41\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSat, 23 Sep 2023 09:23:41 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1695486226;\n\tbh=ucAA6j7B+oiN09RDQkUor/fxhuupMT6VWM5gL1TMQf8=;\n\th=Date:References:In-Reply-To:To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=1jxP5KnKZr92YDwt8VqLZSRXZ1NAP61JSonq+574OuVGdhSLyY4iryXtXAayUDAgZ\n\tKriyDbZpNGHIAej8hlaQG85WEC0iZt7Agp+St/bUcHwvVQY8y0iv2LBWMrJI/OR94I\n\t1jQzXhQSFC/fgU/mNW2GbpqSoeWMIW1L6408gb+9bHmNOrDdJq1/+Zbb5BzTCpg/TX\n\tzAc853jjXhhdRgyQemgN8QMA6TcQV/k8jD3F7PoVOnvxXLiSB4qQhfaAfbCNnxxW5v\n\tk26DQ8LEQVKYl83SjEfu7r897M6h6Zk8fUUP+5enTgXmB+1evVMKzoGNMyRMmSwE65\n\tr4PLVdjKV7djQ==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695486222;\n\tx=1696091022; darn=lists.libcamera.org; \n\th=cc:to:in-reply-to:references:message-id:content-transfer-encoding\n\t:mime-version:subject:date:from:from:to:cc:subject:date:message-id\n\t:reply-to; bh=1uGenlFyLv/JhRh2NyVmUvgesNJ0eIJ6c6DG1nsxTNA=;\n\tb=b+mPU0vS7egdwwUNYtwexn0mqU+kn+mWeR2WgXfLF4oyT+e/Mz9RmQXo+Jw08psP3Z\n\tyj5VnEeJTmtyt/HNJ3wO2qOlOCWCbmgJIwdMTzodjiunvR9UOszJ7FSZ55xG50t0jY5p\n\tDnpZmaDcSxKtWOGaMuAuQvkxkVilEPmGei8UMlx4Y0NFf0Xd1zzfvHHEZfbMkuqojW/O\n\tdwnKMGQ9dmTJx7LHXr0o9jDPfFECQv0/GLZ3AnSKMNlXwJ4/l/2oyli16jSUAGvv5RIF\n\t9zdg/uzKjWVbGpagrwPintYKpRy5R4d5P+JqU4lOs7m5gtMoGEW57GQJzDAVt2XFnSvp\n\txfdQ=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=baylibre-com.20230601.gappssmtp.com\n\theader.i=@baylibre-com.20230601.gappssmtp.com header.b=\"b+mPU0vS\"; \n\tdkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1695486222; x=1696091022;\n\th=cc:to:in-reply-to:references:message-id:content-transfer-encoding\n\t:mime-version:subject:date:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=1uGenlFyLv/JhRh2NyVmUvgesNJ0eIJ6c6DG1nsxTNA=;\n\tb=gKzrqAnmAkpdQroWbKzpDIwLj+S0Kx2C7rJShfXWRdkCKLkAMP/QPWq/QSZmft1v0A\n\tsakez9n6hnM67+hEx4zhse5Il3DmqD2WJt411iNlv5NuUuTOeqmbKMIqRI9CYVaXB9Ke\n\taWr7r14Y7UMwHx82ttlOUTTP1mbI9ouu5fA5ltu7TiHNPJj8Pm5Yb+FqTafOJ9a+0N6s\n\t0vm1tgvHjvQoC+DhRmlt072PV7tfDW0rBqPCTCjazPnZxDNBirONxKHj0iZ9s1yyCEte\n\tvs0Gb52bVRsfeMErob+rE0n7qHENGqWzIrEkAgX4BAJqmMoig9LHxJE3Pdc1YUEp7zzD\n\tuAXw==","X-Gm-Message-State":"AOJu0YwbEnGg0TAomgpkpRnr7F9qW0UG7RamKFVRoVMxy47KAllGFnw7\n\tKivNMv3LpkAXZqNH1Q1To+Ck4g==","X-Google-Smtp-Source":"AGHT+IHIH3O9gg1eL/Cw9eTyJe7B17uPW8KKwbhOCiR3zF5xJBFhuvwCh9LWjDWQ8gi38UzTUZJIig==","X-Received":"by 2002:a1c:720c:0:b0:401:38dc:891c with SMTP id\n\tn12-20020a1c720c000000b0040138dc891cmr2094342wmc.5.1695486221711; \n\tSat, 23 Sep 2023 09:23:41 -0700 (PDT)","Date":"Sat, 23 Sep 2023 18:23:34 +0200","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"7bit","Message-Id":"<20230923-gralloc-api-v4-v3-4-9a9e039284ba@baylibre.com>","References":"<20230923-gralloc-api-v4-v3-0-9a9e039284ba@baylibre.com>","In-Reply-To":"<20230923-gralloc-api-v4-v3-0-9a9e039284ba@baylibre.com>","To":"libcamera-devel@lists.libcamera.org","X-Mailer":"b4 0.12.4-dev-6aa5d","Subject":"[libcamera-devel] [PATCH v3 4/4] android: mm: generic: Use\n\tGraphicBufferAllocator instead of gralloc.h","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Mattijs Korpershoek via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Mattijs Korpershoek <mkorpershoek@baylibre.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tGuillaume La Roque <glaroque@baylibre.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"gralloc.h is a very old API that has been deprecated at least since\nAndroid P (9).\n\nSwitch over to a higher level abstraction of gralloc from libui, which\nis compatible with Android 11 and up.\nLibui:\n* is provided in the VNDK (so it's available to vendors).\n* is also used in the camera vts test named VtsAidlHalCameraProvider_TargetTest.\n\nDrop the libhardware stub since we no longer need it.\n\nNotes:\n* GraphicsBufferAllocator being a Singleton, buffer lifecycle\n  management is easier.\n* The imported headers from Android generate the -Wextra-semi warning.\n  To avoid patching the files, a pragma has been added before inclusion.\n\nSigned-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\n src/android/mm/generic_frame_buffer_allocator.cpp | 68 ++++++++---------------\n src/android/mm/libhardware_stub.c                 | 17 ------\n src/android/mm/meson.build                        |  8 ---\n 3 files changed, 22 insertions(+), 71 deletions(-)","diff":"diff --git a/src/android/mm/generic_frame_buffer_allocator.cpp b/src/android/mm/generic_frame_buffer_allocator.cpp\nindex 7ecef2c669df..1f2fbe334f2c 100644\n--- a/src/android/mm/generic_frame_buffer_allocator.cpp\n+++ b/src/android/mm/generic_frame_buffer_allocator.cpp\n@@ -16,8 +16,11 @@\n #include \"libcamera/internal/framebuffer.h\"\n \n #include <hardware/camera3.h>\n-#include <hardware/gralloc.h>\n-#include <hardware/hardware.h>\n+#pragma GCC diagnostic push\n+#pragma GCC diagnostic ignored \"-Wextra-semi\"\n+#include <ui/GraphicBufferAllocator.h>\n+#pragma GCC diagnostic pop\n+#include <utils/Errors.h>\n \n #include \"../camera_device.h\"\n #include \"../frame_buffer_allocator.h\"\n@@ -33,35 +36,26 @@ class GenericFrameBufferData : public FrameBuffer::Private\n \tLIBCAMERA_DECLARE_PUBLIC(FrameBuffer)\n \n public:\n-\tGenericFrameBufferData(struct alloc_device_t *allocDevice,\n-\t\t\t       buffer_handle_t handle,\n+\tGenericFrameBufferData(buffer_handle_t handle,\n \t\t\t       const std::vector<FrameBuffer::Plane> &planes)\n-\t\t: FrameBuffer::Private(planes), allocDevice_(allocDevice),\n-\t\t  handle_(handle)\n+\t\t: FrameBuffer::Private(planes), handle_(handle)\n \t{\n-\t\tASSERT(allocDevice_);\n \t\tASSERT(handle_);\n \t}\n \n \t~GenericFrameBufferData() override\n \t{\n \t\t/*\n-\t\t * allocDevice_ is used to destroy handle_. allocDevice_ is\n-\t\t * owned by PlatformFrameBufferAllocator::Private.\n-\t\t * GenericFrameBufferData must be destroyed before it is\n-\t\t * destroyed.\n-\t\t *\n-\t\t * \\todo Consider managing alloc_device_t with std::shared_ptr\n-\t\t * if this is difficult to maintain.\n-\t\t *\n \t\t * \\todo Thread safety against alloc_device_t is not documented.\n \t\t * Is it no problem to call alloc/free in parallel?\n \t\t */\n-\t\tallocDevice_->free(allocDevice_, handle_);\n+\t\tauto &allocator = android::GraphicBufferAllocator::get();\n+\t\tandroid::status_t status = allocator.free(handle_);\n+\t\tif (status != android::NO_ERROR)\n+\t\t\tLOG(HAL, Error) << \"Error freeing framebuffer: \" << status;\n \t}\n \n private:\n-\tstruct alloc_device_t *allocDevice_;\n \tconst buffer_handle_t handle_;\n };\n } /* namespace */\n@@ -72,51 +66,33 @@ class PlatformFrameBufferAllocator::Private : public Extensible::Private\n \n public:\n \tPrivate(CameraDevice *const cameraDevice)\n-\t\t: cameraDevice_(cameraDevice),\n-\t\t  hardwareModule_(nullptr),\n-\t\t  allocDevice_(nullptr)\n+\t\t: cameraDevice_(cameraDevice)\n \t{\n-\t\thw_get_module(GRALLOC_HARDWARE_MODULE_ID, &hardwareModule_);\n-\t\tASSERT(hardwareModule_);\n \t}\n \n-\t~Private() override;\n+\t~Private() = default;\n \n \tstd::unique_ptr<HALFrameBuffer>\n \tallocate(int halPixelFormat, const libcamera::Size &size, uint32_t usage);\n \n private:\n \tconst CameraDevice *const cameraDevice_;\n-\tconst struct hw_module_t *hardwareModule_;\n-\tstruct alloc_device_t *allocDevice_;\n };\n \n-PlatformFrameBufferAllocator::Private::~Private()\n-{\n-\tif (allocDevice_)\n-\t\tgralloc_close(allocDevice_);\n-\tdlclose(hardwareModule_->dso);\n-}\n-\n std::unique_ptr<HALFrameBuffer>\n PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat,\n \t\t\t\t\t\tconst libcamera::Size &size,\n \t\t\t\t\t\tuint32_t usage)\n {\n-\tif (!allocDevice_) {\n-\t\tint ret = gralloc_open(hardwareModule_, &allocDevice_);\n-\t\tif (ret) {\n-\t\t\tLOG(HAL, Fatal) << \"gralloc_open() failed: \" << ret;\n-\t\t\treturn nullptr;\n-\t\t}\n-\t}\n-\n-\tint stride = 0;\n+\tuint32_t stride = 0;\n \tbuffer_handle_t handle = nullptr;\n-\tint ret = allocDevice_->alloc(allocDevice_, size.width, size.height,\n-\t\t\t\t      halPixelFormat, usage, &handle, &stride);\n-\tif (ret) {\n-\t\tLOG(HAL, Error) << \"failed buffer allocation: \" << ret;\n+\n+\tauto &allocator = android::GraphicBufferAllocator::get();\n+\tandroid::status_t status = allocator.allocate(size.width, size.height, halPixelFormat,\n+\t\t\t\t\t\t      1 /*layerCount*/, usage, &handle, &stride,\n+\t\t\t\t\t\t      \"libcameraHAL\");\n+\tif (status != android::NO_ERROR) {\n+\t\tLOG(HAL, Error) << \"failed buffer allocation: \" << status;\n \t\treturn nullptr;\n \t}\n \tif (!handle) {\n@@ -143,7 +119,7 @@ PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat,\n \n \treturn std::make_unique<HALFrameBuffer>(\n \t\tstd::make_unique<GenericFrameBufferData>(\n-\t\t\tallocDevice_, handle, planes),\n+\t\t\thandle, planes),\n \t\thandle);\n }\n \ndiff --git a/src/android/mm/libhardware_stub.c b/src/android/mm/libhardware_stub.c\ndeleted file mode 100644\nindex 00f15cd90cac..000000000000\n--- a/src/android/mm/libhardware_stub.c\n+++ /dev/null\n@@ -1,17 +0,0 @@\n-/* SPDX-License-Identifier: Apache-2.0 */\n-/*\n- * Copyright (C) 2023, Ideas on Board\n- *\n- * libhardware_stub.c - Android libhardware stub for test compilation\n- */\n-\n-#include <errno.h>\n-\n-#include <hardware/hardware.h>\n-\n-int hw_get_module(const char *id __attribute__((__unused__)),\n-\t\t  const struct hw_module_t **module)\n-{\n-\t*module = NULL;\n-\treturn -ENOTSUP;\n-}\ndiff --git a/src/android/mm/meson.build b/src/android/mm/meson.build\nindex 4d1fb718e94e..301a2622008b 100644\n--- a/src/android/mm/meson.build\n+++ b/src/android/mm/meson.build\n@@ -4,14 +4,6 @@ platform = get_option('android_platform')\n if platform == 'generic'\n     android_hal_sources += files(['generic_camera_buffer.cpp',\n                                   'generic_frame_buffer_allocator.cpp'])\n-    android_deps += [libdl]\n-\n-    libhardware = dependency('libhardware', required : false)\n-    if libhardware.found()\n-        android_deps += [libhardware]\n-    else\n-        android_hal_sources += files(['libhardware_stub.c'])\n-    endif\n \n     libui = dependency('libui', required : false)\n     if libui.found()\n","prefixes":["libcamera-devel","v3","4/4"]}