Show a patch.

GET /api/1.1/patches/18999/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 18999,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/18999/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/18999/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20230912-gralloc-api-v4-v2-4-e859da63f98c@baylibre.com>",
    "date": "2023-09-12T14:15:23",
    "name": "[libcamera-devel,v2,4/4] android: mm: generic: Use GraphicBufferAllocator instead of gralloc.h",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "48748f01439b2b8032cb0bfa7d8bcd2d4ee61694",
    "submitter": {
        "id": 153,
        "url": "https://patchwork.libcamera.org/api/1.1/people/153/?format=api",
        "name": "Mattijs Korpershoek",
        "email": "mkorpershoek@baylibre.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/18999/mbox/",
    "series": [
        {
            "id": 4018,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4018/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4018",
            "date": "2023-09-12T14:15:19",
            "name": "android: switch over to modern gralloc API via libui",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/4018/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/18999/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/18999/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 44434BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 12 Sep 2023 14:15:33 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B1188628FA;\n\tTue, 12 Sep 2023 16:15:32 +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 2B08561DF5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 12 Sep 2023 16:15:30 +0200 (CEST)",
            "by mail-wm1-x330.google.com with SMTP id\n\t5b1f17b1804b1-40037db2fe7so60976005e9.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 12 Sep 2023 07:15:30 -0700 (PDT)",
            "from [192.168.2.39] ([82.66.159.240])\n\tby smtp.gmail.com with ESMTPSA id\n\ty9-20020a7bcd89000000b003fed630f560sm12996380wmj.36.2023.09.12.07.15.29\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 12 Sep 2023 07:15:29 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1694528132;\n\tbh=thJaRfHbcDJpVbGfzpoQQmBT2F4Rvnoe1/XkuZ9bTNk=;\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=oBfRrydbS3InX+p5WR4R/h/3Y6eQIBpFH7ttGlDkWjwf5IjuE/RnLHTSFwq0ZLpGu\n\tyFzTt1U4XLD97UK6kSNUyrt7zr2+DHcJFxGynj6pZU1cGCgOVvrfZt8/RVfY5ySRBp\n\tMA/LdhFczwacHqs02JfXflL/j7HkVpDDTrIArjEPHoNRq/jWRfQKUfLtVyLThaJXPI\n\tL9VU6fZC+fOexxttBIPUc6xLxoUAoze1iOEhe12tR/wPLoxBU8Qfq6qXnet1UZ4ys1\n\t+K3iy0JjnJCDYkGAY8pThyBNQSOyHENeyPLjvM624SuURxcGyLgR8xMgD1uy7ymQVZ\n\tPVZNO1RcuRNqA==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1694528130;\n\tx=1695132930; 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=NjfjVhvFuPXlJHFJT4RmEMUxoS6VQGc5E8V0sjRslpU=;\n\tb=jPJBdp8z1klCx8HjEr844OnRpeb9uEfDw3m2aXZbTViDEllqY5382OdddHAeh/RRa8\n\tOBGEQJ8gguoJM+rLklrhyP1bb0X9PXnrjlpyElQLb1/MyLYeQjz2k/flejPK/iKicJ39\n\t7WxBT8gKzomLhD6rDAX7yuKTnceRq1xCGYO3caN7zFbkgsijttKCtFehb2DE+SMN8taC\n\t2Aw0ZdqYdL7kNUDkdDgY3ENRq13xQFBfplf7MoQNOFfaDEwvaYSo/pT8D0ryOiI+FZOb\n\tarM/yFg8OmAznS8OxJfk9KUxfxRLVUEtmzBfJqu7A+Y3W99OCcZKjVSJteGpnkAIkdtI\n\tE7hQ=="
        ],
        "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=\"jPJBdp8z\"; \n\tdkim-atps=neutral",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1694528130; x=1695132930;\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=NjfjVhvFuPXlJHFJT4RmEMUxoS6VQGc5E8V0sjRslpU=;\n\tb=aqF0X2jIGFse4uLynZeed9URD5EPlJl2ACCsbed1M9a1Jj9HpRLaWg4v/3NgOEgno2\n\tWTbt2WNABwvUot5FxBGjP/otP0J0QlkWNCdEgsgb5dHH0SBi6YQd9AD8NoBZf5VGGEuf\n\tW6P1qKQ7Ss/AXieGjaAY+tyj/68aVWOxbP4pzASx8G86bpD7NGYshgSq67VUGWJ61PnN\n\tu6D5HHE3Ct9YMRFdp/PB/7jJaHZh3Zq2CIl2zi/VmGTO1U6DgBwTf6lw8wFRTtzWc48c\n\tXYT4/dPH2QqDEF1D9Xn/4oItZ8oQGAULugkGv+aEw1fCkWMf3d2+y0QUYVrXPSylp368\n\tL/mA==",
        "X-Gm-Message-State": "AOJu0YyWmkAtjy2FJvyRua0GweCd+koFaad5Uj4O74Cz0xgULAH/NzJ1\n\tDgwys3MS/qnlJCigwvqHGzwvMee0Fe07/k0/bh8=",
        "X-Google-Smtp-Source": "AGHT+IGRrf9fwQjIVAPByBxSPennwZp+ZvjI2dtbTdQsHrr2dXKqJY9F8Lalz5z8oSFbkZtoPUcgVg==",
        "X-Received": "by 2002:a7b:c4c5:0:b0:401:b0f2:88cb with SMTP id\n\tg5-20020a7bc4c5000000b00401b0f288cbmr11619468wmk.31.1694528129563; \n\tTue, 12 Sep 2023 07:15:29 -0700 (PDT)",
        "Date": "Tue, 12 Sep 2023 16:15:23 +0200",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=\"utf-8\"",
        "Content-Transfer-Encoding": "7bit",
        "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\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": "Guillaume 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>\n---\n src/android/mm/generic_frame_buffer_allocator.cpp | 61 ++++++++---------------\n src/android/mm/libhardware_stub.c                 | 17 -------\n src/android/mm/meson.build                        |  8 ++-\n 3 files changed, 23 insertions(+), 63 deletions(-)",
    "diff": "diff --git a/src/android/mm/generic_frame_buffer_allocator.cpp b/src/android/mm/generic_frame_buffer_allocator.cpp\nindex 7ecef2c669df..468579068c32 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,28 @@ class GenericFrameBufferData : public FrameBuffer::Private\n \tLIBCAMERA_DECLARE_PUBLIC(FrameBuffer)\n \n public:\n-\tGenericFrameBufferData(struct alloc_device_t *allocDevice,\n+\tGenericFrameBufferData(android::GraphicBufferAllocator &allocDevice,\n \t\t\t       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{\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\tandroid::status_t status = allocDevice_.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+\tandroid::GraphicBufferAllocator &allocDevice_;\n \tconst buffer_handle_t handle_;\n };\n } /* namespace */\n@@ -73,50 +69,33 @@ class PlatformFrameBufferAllocator::Private : public Extensible::Private\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  allocDevice_(android::GraphicBufferAllocator::get())\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+\tandroid::GraphicBufferAllocator &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+\tandroid::status_t status = allocDevice_.allocate(size.width, size.height, halPixelFormat,\n+\t\t\t\t\t\t\t 1 /*layerCount*/, usage, &handle, &stride,\n+\t\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) {\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 e9ceb3afba67..203b8c3e5804 100644\n--- a/src/android/mm/meson.build\n+++ b/src/android/mm/meson.build\n@@ -4,13 +4,11 @@ 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+    libui = dependency('libui', required : false)\n+    if libui.found()\n+        android_deps += [libui]\n     else\n-        android_hal_sources += files(['libhardware_stub.c'])\n         android_hal_sources += files(['graphic_buffer_allocator_stub.cpp'])\n     endif\n elif platform == 'cros'\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "4/4"
    ]
}