Patch Detail
Show a patch.
GET /api/1.1/patches/18985/?format=api
{ "id": 18985, "url": "https://patchwork.libcamera.org/api/1.1/patches/18985/?format=api", "web_url": "https://patchwork.libcamera.org/patch/18985/", "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-v1-1-0f80402d8e7a@baylibre.com>", "date": "2023-09-12T09:36:10", "name": "[libcamera-devel,1/4] android: Import libutils/libui headers from vndk v33", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "6ebeca6723e42aaee0bb16803cbfbafb399fde5e", "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/18985/mbox/", "series": [ { "id": 4016, "url": "https://patchwork.libcamera.org/api/1.1/series/4016/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4016", "date": "2023-09-12T09:36:09", "name": "android: switch over to modern gralloc API via libui", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4016/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/18985/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/18985/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 9FE87C3260\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 12 Sep 2023 09:36:23 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E8D7E628FA;\n\tTue, 12 Sep 2023 11:36:21 +0200 (CEST)", "from mail-wm1-x335.google.com (mail-wm1-x335.google.com\n\t[IPv6:2a00:1450:4864:20::335])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9DC0F628E9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 12 Sep 2023 11:36:19 +0200 (CEST)", "by mail-wm1-x335.google.com with SMTP id\n\t5b1f17b1804b1-401bdff4cb4so57772685e9.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 12 Sep 2023 02:36:19 -0700 (PDT)", "from [192.168.2.39] ([82.66.159.240])\n\tby smtp.gmail.com with ESMTPSA id\n\ty10-20020a05600c364a00b00401b242e2e6sm15578253wmq.47.2023.09.12.02.36.18\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 12 Sep 2023 02:36:18 -0700 (PDT)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1694511382;\n\tbh=V8H6oWQC035fz59EKF4waa9Kvjxmd+PEIjSMxtRGSmg=;\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:\n\tFrom;\n\tb=RiY73JBGtVYCjnwTjQJLGEsQy75EmQiRxLQpyWgN7AyO5AlyuhKQcQ5uVLjC27goT\n\twTQwoK50y/+guHKe1EwXjUopsWAndJ+/5phAlJTK/SKJD+WEB3vPkaWJUMzzdHGKG7\n\t4MVulIA91XB4Zbhgx9jazFw4TLMS/yCDTiOcnEVZ1kq993MrQFcmMdjQbo4EvBuzSh\n\tC558XyFGytZEbibehiwX87vX54alnx+hvj3CYer4SUemwucE8SsuHh/gM0+SDtMTqs\n\tu2fCQ7nCNJ5eLH7YotWMk0UrHbFetWWgeHIwIi0gcn0Tqbn29rxtZhThYQWJq86vRn\n\tcZg034ZnJaTBw==", "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1694511379;\n\tx=1695116179; 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=InTK3cpHjAowfn+YPF+0J0VMRNJykgYZo8jT8zXv8lo=;\n\tb=jhm9TmdOxFYbUqbwSgkzN/3drxohVEUrgaht2eqoP7bcdQKdrMshhtoHnMj/YzftjY\n\t/4VAeMNUVs0PRseB09bd3xRYelwWKrpmQGsrJJ+rXfzYTbjQi6f/DA1dFwj0lF2GehP8\n\tCE4b9/IgzUvEjunz2G9boitMIq5eUiNw0Jo35rTL/ShkV70fwO3+fJtP3Z4pDLMZXxnF\n\tOgoQ8ux+rffUzkH2zKfaSISiYPAW3l4/nIXIw6L1KaZ2P3OFsjnuFkdXhPwLlk7dC8aW\n\tm9ng1aBIDmfXIZNQOYqRY0AOoOXmm9O8CnYMSpoDx894dR4ZUe+rDRO8OLWsfd2cRutT\n\t1tgw==" ], "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=\"jhm9TmdO\"; \n\tdkim-atps=neutral", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1694511379; x=1695116179;\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=InTK3cpHjAowfn+YPF+0J0VMRNJykgYZo8jT8zXv8lo=;\n\tb=KiX7/UjMgJguwWcghhlgGkxKHV7Agl35/SXnsOZVH7UNFvVs1kCy2X0Xa0O6a2GSlX\n\ty6iVZW+92ak2flyYsS2hXbqvdRi+ne5H/z2iMpV1dWaTKREFR9hucglha9bTzfYkrunC\n\tlpxDRZF+uYK7W1cgGZFHQhVHcS7YGU/g6ixB9hTaUMpGnpTVUZh6fezVHzgwJfBPINaN\n\tJp+9bX67Pt0xON+0TWEXr1lONAPnhcWksNvN7zoIVx/9TyHy90LIKdPnAoeCebd4hJry\n\tiC2uy7S3Ukv0MGqWsvzzUDNVb6MdJLOojzwyUWSvlDMOz2kA0AsBHx/zf0+trogWx0+i\n\tLp1A==", "X-Gm-Message-State": "AOJu0YyEArX/YpVJU066t41xZOLWe7XILqUkQO45gecEdDWgaFqfeUU8\n\thy1fOmWVsTrx2gdiN/0ecO2MEbHaNTHyytr8RJg=", "X-Google-Smtp-Source": "AGHT+IFI6E9LXncwpyejsGYjLwL9ipb8H8wODoXT1hilBZkADpoGmmPqw86hW53B5pyPvwqt/S3YdQ==", "X-Received": "by 2002:a05:600c:215:b0:401:b53e:6c56 with SMTP id\n\t21-20020a05600c021500b00401b53e6c56mr10320307wmi.3.1694511379085; \n\tTue, 12 Sep 2023 02:36:19 -0700 (PDT)", "Date": "Tue, 12 Sep 2023 11:36:10 +0200", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=\"utf-8\"", "Content-Transfer-Encoding": "7bit", "Message-Id": "<20230912-gralloc-api-v4-v1-1-0f80402d8e7a@baylibre.com>", "References": "<20230912-gralloc-api-v4-v1-0-0f80402d8e7a@baylibre.com>", "In-Reply-To": "<20230912-gralloc-api-v4-v1-0-0f80402d8e7a@baylibre.com>", "To": "libcamera-devel@lists.libcamera.org", "X-Mailer": "b4 0.12.3", "Subject": "[libcamera-devel] [PATCH 1/4] android: Import libutils/libui\n\theaders from vndk v33", "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>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "In order to switch to the more modern GraphicBufferAllocator class, we need\nadditional compile-time dependencies.\n\nImport all the needed headers from the Android Vendor Native Development\nKit (vndk) and add them to the android_includes.\n\nThese have been imported from:\nURL: https://android.googlesource.com/platform/prebuilts/vndk/v33/\nrev: 390028a9da88 (\"Update VNDK snapshot v33 to build 9948968. am: 3042508aee am: 7092391a46\")\n\nNo changes have been made to the files, besides adding the SPDX comment.\n\nSigned-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>\n---\n .../native/libs/ui/include/ui/PixelFormat.h | 75 +++++++\n include/android/meson.build | 2 +\n .../system/core/libutils/include/utils/Compat.h | 94 +++++++++\n .../system/core/libutils/include/utils/Errors.h | 78 ++++++++\n .../system/core/libutils/include/utils/Mutex.h | 219 +++++++++++++++++++++\n .../system/core/libutils/include/utils/Singleton.h | 102 ++++++++++\n .../system/core/libutils/include/utils/Timers.h | 103 ++++++++++\n 7 files changed, 673 insertions(+)", "diff": "diff --git a/include/android/frameworks/native/libs/ui/include/ui/PixelFormat.h b/include/android/frameworks/native/libs/ui/include/ui/PixelFormat.h\nnew file mode 100644\nindex 000000000000..2add09462218\n--- /dev/null\n+++ b/include/android/frameworks/native/libs/ui/include/ui/PixelFormat.h\n@@ -0,0 +1,75 @@\n+/* SPDX-License-Identifier: Apache-2.0 */\n+/*\n+ * Copyright (C) 2005 The Android Open Source Project\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+//\n+\n+// Pixel formats used across the system.\n+// These formats might not all be supported by all renderers, for instance\n+// skia or SurfaceFlinger are not required to support all of these formats\n+// (either as source or destination)\n+\n+\n+#ifndef UI_PIXELFORMAT_H\n+#define UI_PIXELFORMAT_H\n+\n+#include <hardware/hardware.h>\n+\n+namespace android {\n+\n+enum {\n+ //\n+ // these constants need to match those\n+ // in graphics/PixelFormat.java & pixelflinger/format.h\n+ //\n+ PIXEL_FORMAT_UNKNOWN = 0,\n+ PIXEL_FORMAT_NONE = 0,\n+\n+ // logical pixel formats used by the SurfaceFlinger -----------------------\n+ PIXEL_FORMAT_CUSTOM = -4,\n+ // Custom pixel-format described by a PixelFormatInfo structure\n+\n+ PIXEL_FORMAT_TRANSLUCENT = -3,\n+ // System chooses a format that supports translucency (many alpha bits)\n+\n+ PIXEL_FORMAT_TRANSPARENT = -2,\n+ // System chooses a format that supports transparency\n+ // (at least 1 alpha bit)\n+\n+ PIXEL_FORMAT_OPAQUE = -1,\n+ // System chooses an opaque format (no alpha bits required)\n+\n+ // real pixel formats supported for rendering -----------------------------\n+\n+ PIXEL_FORMAT_RGBA_8888 = HAL_PIXEL_FORMAT_RGBA_8888, // 4x8-bit RGBA\n+ PIXEL_FORMAT_RGBX_8888 = HAL_PIXEL_FORMAT_RGBX_8888, // 4x8-bit RGB0\n+ PIXEL_FORMAT_RGB_888 = HAL_PIXEL_FORMAT_RGB_888, // 3x8-bit RGB\n+ PIXEL_FORMAT_RGB_565 = HAL_PIXEL_FORMAT_RGB_565, // 16-bit RGB\n+ PIXEL_FORMAT_BGRA_8888 = HAL_PIXEL_FORMAT_BGRA_8888, // 4x8-bit BGRA\n+ PIXEL_FORMAT_RGBA_5551 = 6, // 16-bit ARGB\n+ PIXEL_FORMAT_RGBA_4444 = 7, // 16-bit ARGB\n+ PIXEL_FORMAT_RGBA_FP16 = HAL_PIXEL_FORMAT_RGBA_FP16, // 64-bit RGBA\n+ PIXEL_FORMAT_RGBA_1010102 = HAL_PIXEL_FORMAT_RGBA_1010102, // 32-bit RGBA\n+ PIXEL_FORMAT_R_8 = 0x38,\n+};\n+\n+typedef int32_t PixelFormat;\n+\n+uint32_t bytesPerPixel(PixelFormat format);\n+\n+}; // namespace android\n+\n+#endif // UI_PIXELFORMAT_H\ndiff --git a/include/android/meson.build b/include/android/meson.build\nindex da2504f2e493..59a4f36b523b 100644\n--- a/include/android/meson.build\n+++ b/include/android/meson.build\n@@ -1,7 +1,9 @@\n # SPDX-License-Identifier: CC0-1.0\n \n android_includes = ([\n+ include_directories('frameworks/native/libs/ui/include/'),\n include_directories('hardware/libhardware/include/'),\n include_directories('metadata/'),\n include_directories('system/core/include'),\n+ include_directories('system/core/libutils/include/'),\n ])\ndiff --git a/include/android/system/core/libutils/include/utils/Compat.h b/include/android/system/core/libutils/include/utils/Compat.h\nnew file mode 100644\nindex 000000000000..bba568bd3226\n--- /dev/null\n+++ b/include/android/system/core/libutils/include/utils/Compat.h\n@@ -0,0 +1,94 @@\n+/* SPDX-License-Identifier: Apache-2.0 */\n+/*\n+ * Copyright (C) 2010 The Android Open Source Project\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+#ifndef __LIB_UTILS_COMPAT_H\n+#define __LIB_UTILS_COMPAT_H\n+\n+#include <unistd.h>\n+\n+#if !defined(__MINGW32__)\n+#include <sys/mman.h>\n+#endif\n+\n+#if defined(__APPLE__)\n+\n+/* Mac OS has always had a 64-bit off_t, so it doesn't have off64_t. */\n+static_assert(sizeof(off_t) >= 8, \"This code requires that Mac OS have at least a 64-bit off_t.\");\n+typedef off_t off64_t;\n+\n+static inline void* mmap64(void* addr, size_t length, int prot, int flags, int fd, off64_t offset) {\n+ return mmap(addr, length, prot, flags, fd, offset);\n+}\n+\n+static inline off64_t lseek64(int fd, off64_t offset, int whence) {\n+ return lseek(fd, offset, whence);\n+}\n+\n+static inline ssize_t pread64(int fd, void* buf, size_t nbytes, off64_t offset) {\n+ return pread(fd, buf, nbytes, offset);\n+}\n+\n+static inline ssize_t pwrite64(int fd, const void* buf, size_t nbytes, off64_t offset) {\n+ return pwrite(fd, buf, nbytes, offset);\n+}\n+\n+static inline int ftruncate64(int fd, off64_t length) {\n+ return ftruncate(fd, length);\n+}\n+\n+#endif /* __APPLE__ */\n+\n+#if defined(_WIN32)\n+#define O_CLOEXEC O_NOINHERIT\n+#define O_NOFOLLOW 0\n+#define DEFFILEMODE 0666\n+#endif /* _WIN32 */\n+\n+#define ZD \"%zd\"\n+#define ZD_TYPE ssize_t\n+\n+/*\n+ * Needed for cases where something should be constexpr if possible, but not\n+ * being constexpr is fine if in pre-C++11 code (such as a const static float\n+ * member variable).\n+ */\n+#if __cplusplus >= 201103L\n+#define CONSTEXPR constexpr\n+#else\n+#define CONSTEXPR\n+#endif\n+\n+/* TEMP_FAILURE_RETRY is not available on macOS, but still useful there. */\n+#ifndef TEMP_FAILURE_RETRY\n+/* Used to retry syscalls that can return EINTR. */\n+#define TEMP_FAILURE_RETRY(exp) \\\n+ ({ \\\n+ __typeof__(exp) _rc; \\\n+ do { \\\n+ _rc = (exp); \\\n+ } while (_rc == -1 && errno == EINTR); \\\n+ _rc; \\\n+ })\n+#endif\n+\n+#if defined(_WIN32)\n+#define OS_PATH_SEPARATOR '\\\\'\n+#else\n+#define OS_PATH_SEPARATOR '/'\n+#endif\n+\n+#endif /* __LIB_UTILS_COMPAT_H */\ndiff --git a/include/android/system/core/libutils/include/utils/Errors.h b/include/android/system/core/libutils/include/utils/Errors.h\nnew file mode 100644\nindex 000000000000..f812844eacc4\n--- /dev/null\n+++ b/include/android/system/core/libutils/include/utils/Errors.h\n@@ -0,0 +1,78 @@\n+/* SPDX-License-Identifier: Apache-2.0 */\n+/*\n+ * Copyright (C) 2007 The Android Open Source Project\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+#pragma once\n+\n+#include <errno.h>\n+#include <stdint.h>\n+#include <sys/types.h>\n+#include <string>\n+\n+namespace android {\n+\n+/**\n+ * The type used to return success/failure from frameworks APIs.\n+ * See the anonymous enum below for valid values.\n+ */\n+typedef int32_t status_t;\n+\n+/*\n+ * Error codes. \n+ * All error codes are negative values.\n+ */\n+\n+enum {\n+ OK = 0, // Preferred constant for checking success.\n+#ifndef NO_ERROR\n+ // Win32 #defines NO_ERROR as well. It has the same value, so there's no\n+ // real conflict, though it's a bit awkward.\n+ NO_ERROR = OK, // Deprecated synonym for `OK`. Prefer `OK` because it doesn't conflict with Windows.\n+#endif\n+\n+ UNKNOWN_ERROR = (-2147483647-1), // INT32_MIN value\n+\n+ NO_MEMORY = -ENOMEM,\n+ INVALID_OPERATION = -ENOSYS,\n+ BAD_VALUE = -EINVAL,\n+ BAD_TYPE = (UNKNOWN_ERROR + 1),\n+ NAME_NOT_FOUND = -ENOENT,\n+ PERMISSION_DENIED = -EPERM,\n+ NO_INIT = -ENODEV,\n+ ALREADY_EXISTS = -EEXIST,\n+ DEAD_OBJECT = -EPIPE,\n+ FAILED_TRANSACTION = (UNKNOWN_ERROR + 2),\n+#if !defined(_WIN32)\n+ BAD_INDEX = -EOVERFLOW,\n+ NOT_ENOUGH_DATA = -ENODATA,\n+ WOULD_BLOCK = -EWOULDBLOCK, \n+ TIMED_OUT = -ETIMEDOUT,\n+ UNKNOWN_TRANSACTION = -EBADMSG,\n+#else \n+ BAD_INDEX = -E2BIG,\n+ NOT_ENOUGH_DATA = (UNKNOWN_ERROR + 3),\n+ WOULD_BLOCK = (UNKNOWN_ERROR + 4),\n+ TIMED_OUT = (UNKNOWN_ERROR + 5),\n+ UNKNOWN_TRANSACTION = (UNKNOWN_ERROR + 6),\n+#endif \n+ FDS_NOT_ALLOWED = (UNKNOWN_ERROR + 7),\n+ UNEXPECTED_NULL = (UNKNOWN_ERROR + 8),\n+};\n+\n+// Human readable name of error\n+std::string statusToString(status_t status);\n+\n+} // namespace android\ndiff --git a/include/android/system/core/libutils/include/utils/Mutex.h b/include/android/system/core/libutils/include/utils/Mutex.h\nnew file mode 100644\nindex 000000000000..72d20bdca888\n--- /dev/null\n+++ b/include/android/system/core/libutils/include/utils/Mutex.h\n@@ -0,0 +1,219 @@\n+/* SPDX-License-Identifier: Apache-2.0 */\n+/*\n+ * Copyright (C) 2007 The Android Open Source Project\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+#ifndef _LIBS_UTILS_MUTEX_H\n+#define _LIBS_UTILS_MUTEX_H\n+\n+#include <stdint.h>\n+#include <sys/types.h>\n+#include <time.h>\n+\n+#if !defined(_WIN32)\n+# include <pthread.h>\n+#endif\n+\n+#include <utils/Errors.h>\n+#include <utils/Timers.h>\n+\n+// Enable thread safety attributes only with clang.\n+// The attributes can be safely erased when compiling with other compilers.\n+#if defined(__clang__) && (!defined(SWIG))\n+#define THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))\n+#else\n+#define THREAD_ANNOTATION_ATTRIBUTE__(x) // no-op\n+#endif\n+\n+#define CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE__(capability(x))\n+\n+#define SCOPED_CAPABILITY THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable)\n+\n+#define GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))\n+\n+#define PT_GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x))\n+\n+#define ACQUIRED_BEFORE(...) THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(__VA_ARGS__))\n+\n+#define ACQUIRED_AFTER(...) THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(__VA_ARGS__))\n+\n+#define REQUIRES(...) THREAD_ANNOTATION_ATTRIBUTE__(requires_capability(__VA_ARGS__))\n+\n+#define REQUIRES_SHARED(...) THREAD_ANNOTATION_ATTRIBUTE__(requires_shared_capability(__VA_ARGS__))\n+\n+#define ACQUIRE(...) THREAD_ANNOTATION_ATTRIBUTE__(acquire_capability(__VA_ARGS__))\n+\n+#define ACQUIRE_SHARED(...) THREAD_ANNOTATION_ATTRIBUTE__(acquire_shared_capability(__VA_ARGS__))\n+\n+#define RELEASE(...) THREAD_ANNOTATION_ATTRIBUTE__(release_capability(__VA_ARGS__))\n+\n+#define RELEASE_SHARED(...) THREAD_ANNOTATION_ATTRIBUTE__(release_shared_capability(__VA_ARGS__))\n+\n+#define TRY_ACQUIRE(...) THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_capability(__VA_ARGS__))\n+\n+#define TRY_ACQUIRE_SHARED(...) \\\n+ THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_shared_capability(__VA_ARGS__))\n+\n+#define EXCLUDES(...) THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__))\n+\n+#define ASSERT_CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE__(assert_capability(x))\n+\n+#define ASSERT_SHARED_CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_capability(x))\n+\n+#define RETURN_CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x))\n+\n+#define NO_THREAD_SAFETY_ANALYSIS THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis)\n+\n+// ---------------------------------------------------------------------------\n+namespace android {\n+// ---------------------------------------------------------------------------\n+\n+class Condition;\n+\n+/*\n+ * NOTE: This class is for code that builds on Win32. Its usage is\n+ * deprecated for code which doesn't build for Win32. New code which\n+ * doesn't build for Win32 should use std::mutex and std::lock_guard instead.\n+ *\n+ * Simple mutex class. The implementation is system-dependent.\n+ *\n+ * The mutex must be unlocked by the thread that locked it. They are not\n+ * recursive, i.e. the same thread can't lock it multiple times.\n+ */\n+class CAPABILITY(\"mutex\") Mutex {\n+ public:\n+ enum {\n+ PRIVATE = 0,\n+ SHARED = 1\n+ };\n+\n+ Mutex();\n+ explicit Mutex(const char* name);\n+ explicit Mutex(int type, const char* name = nullptr);\n+ ~Mutex();\n+\n+ // lock or unlock the mutex\n+ status_t lock() ACQUIRE();\n+ void unlock() RELEASE();\n+\n+ // lock if possible; returns 0 on success, error otherwise\n+ status_t tryLock() TRY_ACQUIRE(0);\n+\n+#if defined(__ANDROID__)\n+ // Lock the mutex, but don't wait longer than timeoutNs (relative time).\n+ // Returns 0 on success, TIMED_OUT for failure due to timeout expiration.\n+ //\n+ // OSX doesn't have pthread_mutex_timedlock() or equivalent. To keep\n+ // capabilities consistent across host OSes, this method is only available\n+ // when building Android binaries.\n+ //\n+ // FIXME?: pthread_mutex_timedlock is based on CLOCK_REALTIME,\n+ // which is subject to NTP adjustments, and includes time during suspend,\n+ // so a timeout may occur even though no processes could run.\n+ // Not holding a partial wakelock may lead to a system suspend.\n+ status_t timedLock(nsecs_t timeoutNs) TRY_ACQUIRE(0);\n+#endif\n+\n+ // Manages the mutex automatically. It'll be locked when Autolock is\n+ // constructed and released when Autolock goes out of scope.\n+ class SCOPED_CAPABILITY Autolock {\n+ public:\n+ inline explicit Autolock(Mutex& mutex) ACQUIRE(mutex) : mLock(mutex) { mLock.lock(); }\n+ inline explicit Autolock(Mutex* mutex) ACQUIRE(mutex) : mLock(*mutex) { mLock.lock(); }\n+ inline ~Autolock() RELEASE() { mLock.unlock(); }\n+\n+ private:\n+ Mutex& mLock;\n+ // Cannot be copied or moved - declarations only\n+ Autolock(const Autolock&);\n+ Autolock& operator=(const Autolock&);\n+ };\n+\n+ private:\n+ friend class Condition;\n+\n+ // A mutex cannot be copied\n+ Mutex(const Mutex&);\n+ Mutex& operator=(const Mutex&);\n+\n+#if !defined(_WIN32)\n+ pthread_mutex_t mMutex;\n+#else\n+ void _init();\n+ void* mState;\n+#endif\n+};\n+\n+// ---------------------------------------------------------------------------\n+\n+#if !defined(_WIN32)\n+\n+inline Mutex::Mutex() {\n+ pthread_mutex_init(&mMutex, nullptr);\n+}\n+inline Mutex::Mutex(__attribute__((unused)) const char* name) {\n+ pthread_mutex_init(&mMutex, nullptr);\n+}\n+inline Mutex::Mutex(int type, __attribute__((unused)) const char* name) {\n+ if (type == SHARED) {\n+ pthread_mutexattr_t attr;\n+ pthread_mutexattr_init(&attr);\n+ pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);\n+ pthread_mutex_init(&mMutex, &attr);\n+ pthread_mutexattr_destroy(&attr);\n+ } else {\n+ pthread_mutex_init(&mMutex, nullptr);\n+ }\n+}\n+inline Mutex::~Mutex() {\n+ pthread_mutex_destroy(&mMutex);\n+}\n+inline status_t Mutex::lock() {\n+ return -pthread_mutex_lock(&mMutex);\n+}\n+inline void Mutex::unlock() {\n+ pthread_mutex_unlock(&mMutex);\n+}\n+inline status_t Mutex::tryLock() {\n+ return -pthread_mutex_trylock(&mMutex);\n+}\n+#if defined(__ANDROID__)\n+inline status_t Mutex::timedLock(nsecs_t timeoutNs) {\n+ timeoutNs += systemTime(SYSTEM_TIME_REALTIME);\n+ const struct timespec ts = {\n+ /* .tv_sec = */ static_cast<time_t>(timeoutNs / 1000000000),\n+ /* .tv_nsec = */ static_cast<long>(timeoutNs % 1000000000),\n+ };\n+ return -pthread_mutex_timedlock(&mMutex, &ts);\n+}\n+#endif\n+\n+#endif // !defined(_WIN32)\n+\n+// ---------------------------------------------------------------------------\n+\n+/*\n+ * Automatic mutex. Declare one of these at the top of a function.\n+ * When the function returns, it will go out of scope, and release the\n+ * mutex.\n+ */\n+\n+typedef Mutex::Autolock AutoMutex;\n+\n+// ---------------------------------------------------------------------------\n+} // namespace android\n+// ---------------------------------------------------------------------------\n+\n+#endif // _LIBS_UTILS_MUTEX_H\ndiff --git a/include/android/system/core/libutils/include/utils/Singleton.h b/include/android/system/core/libutils/include/utils/Singleton.h\nnew file mode 100644\nindex 000000000000..154aed8f28e5\n--- /dev/null\n+++ b/include/android/system/core/libutils/include/utils/Singleton.h\n@@ -0,0 +1,102 @@\n+/* SPDX-License-Identifier: Apache-2.0 */\n+/*\n+ * Copyright (C) 2007 The Android Open Source Project\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+#ifndef ANDROID_UTILS_SINGLETON_H\n+#define ANDROID_UTILS_SINGLETON_H\n+\n+#include <stdint.h>\n+\n+// some vendor code assumes they have atoi() after including this file.\n+#include <stdlib.h>\n+\n+#include <sys/types.h>\n+#include <utils/Mutex.h>\n+#include <cutils/compiler.h>\n+\n+namespace android {\n+// ---------------------------------------------------------------------------\n+\n+// Singleton<TYPE> may be used in multiple libraries, only one of which should\n+// define the static member variables using ANDROID_SINGLETON_STATIC_INSTANCE.\n+// Turn off -Wundefined-var-template so other users don't get:\n+// instantiation of variable 'android::Singleton<TYPE>::sLock' required here,\n+// but no definition is available\n+#if defined(__clang__)\n+#pragma clang diagnostic push\n+#pragma clang diagnostic ignored \"-Wundefined-var-template\"\n+#endif\n+\n+// DO NOT USE: Please use scoped static initialization. For instance:\n+// MyClass& getInstance() {\n+// static MyClass gInstance(...);\n+// return gInstance;\n+// }\n+template <typename TYPE>\n+class ANDROID_API Singleton\n+{\n+public:\n+ static TYPE& getInstance() {\n+ Mutex::Autolock _l(sLock);\n+ TYPE* instance = sInstance;\n+ if (instance == nullptr) {\n+ instance = new TYPE();\n+ sInstance = instance;\n+ }\n+ return *instance;\n+ }\n+\n+ static bool hasInstance() {\n+ Mutex::Autolock _l(sLock);\n+ return sInstance != nullptr;\n+ }\n+ \n+protected:\n+ ~Singleton() { }\n+ Singleton() { }\n+\n+private:\n+ Singleton(const Singleton&);\n+ Singleton& operator = (const Singleton&);\n+ static Mutex sLock;\n+ static TYPE* sInstance;\n+};\n+\n+#if defined(__clang__)\n+#pragma clang diagnostic pop\n+#endif\n+\n+/*\n+ * use ANDROID_SINGLETON_STATIC_INSTANCE(TYPE) in your implementation file\n+ * (eg: <TYPE>.cpp) to create the static instance of Singleton<>'s attributes,\n+ * and avoid to have a copy of them in each compilation units Singleton<TYPE>\n+ * is used.\n+ * NOTE: we use a version of Mutex ctor that takes a parameter, because\n+ * for some unknown reason using the default ctor doesn't emit the variable!\n+ */\n+\n+#define ANDROID_SINGLETON_STATIC_INSTANCE(TYPE) \\\n+ template<> ::android::Mutex \\\n+ (::android::Singleton< TYPE >::sLock)(::android::Mutex::PRIVATE); \\\n+ template<> TYPE* ::android::Singleton< TYPE >::sInstance(nullptr); /* NOLINT */ \\\n+ template class ::android::Singleton< TYPE >;\n+\n+\n+// ---------------------------------------------------------------------------\n+} // namespace android\n+\n+#endif // ANDROID_UTILS_SINGLETON_H\n+\ndiff --git a/include/android/system/core/libutils/include/utils/Timers.h b/include/android/system/core/libutils/include/utils/Timers.h\nnew file mode 100644\nindex 000000000000..40acafabc099\n--- /dev/null\n+++ b/include/android/system/core/libutils/include/utils/Timers.h\n@@ -0,0 +1,103 @@\n+/* SPDX-License-Identifier: Apache-2.0 */\n+/*\n+ * Copyright (C) 2005 The Android Open Source Project\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+#pragma once\n+\n+#include <stdint.h>\n+#include <sys/types.h>\n+#include <sys/time.h>\n+\n+#include <utils/Compat.h>\n+\n+// ------------------------------------------------------------------\n+// C API\n+\n+#ifdef __cplusplus\n+extern \"C\" {\n+#endif\n+\n+typedef int64_t nsecs_t; // nano-seconds\n+\n+static CONSTEXPR inline nsecs_t seconds_to_nanoseconds(nsecs_t secs)\n+{\n+ return secs*1000000000;\n+}\n+\n+static CONSTEXPR inline nsecs_t milliseconds_to_nanoseconds(nsecs_t secs)\n+{\n+ return secs*1000000;\n+}\n+\n+static CONSTEXPR inline nsecs_t microseconds_to_nanoseconds(nsecs_t secs)\n+{\n+ return secs*1000;\n+}\n+\n+static CONSTEXPR inline nsecs_t nanoseconds_to_seconds(nsecs_t secs)\n+{\n+ return secs/1000000000;\n+}\n+\n+static CONSTEXPR inline nsecs_t nanoseconds_to_milliseconds(nsecs_t secs)\n+{\n+ return secs/1000000;\n+}\n+\n+static CONSTEXPR inline nsecs_t nanoseconds_to_microseconds(nsecs_t secs)\n+{\n+ return secs/1000;\n+}\n+\n+static CONSTEXPR inline nsecs_t s2ns(nsecs_t v) {return seconds_to_nanoseconds(v);}\n+static CONSTEXPR inline nsecs_t ms2ns(nsecs_t v) {return milliseconds_to_nanoseconds(v);}\n+static CONSTEXPR inline nsecs_t us2ns(nsecs_t v) {return microseconds_to_nanoseconds(v);}\n+static CONSTEXPR inline nsecs_t ns2s(nsecs_t v) {return nanoseconds_to_seconds(v);}\n+static CONSTEXPR inline nsecs_t ns2ms(nsecs_t v) {return nanoseconds_to_milliseconds(v);}\n+static CONSTEXPR inline nsecs_t ns2us(nsecs_t v) {return nanoseconds_to_microseconds(v);}\n+\n+static CONSTEXPR inline nsecs_t seconds(nsecs_t v) { return s2ns(v); }\n+static CONSTEXPR inline nsecs_t milliseconds(nsecs_t v) { return ms2ns(v); }\n+static CONSTEXPR inline nsecs_t microseconds(nsecs_t v) { return us2ns(v); }\n+\n+enum {\n+ SYSTEM_TIME_REALTIME = 0, // system-wide realtime clock\n+ SYSTEM_TIME_MONOTONIC = 1, // monotonic time since unspecified starting point\n+ SYSTEM_TIME_PROCESS = 2, // high-resolution per-process clock\n+ SYSTEM_TIME_THREAD = 3, // high-resolution per-thread clock\n+ SYSTEM_TIME_BOOTTIME = 4, // same as SYSTEM_TIME_MONOTONIC, but including CPU suspend time\n+};\n+\n+// return the system-time according to the specified clock\n+#ifdef __cplusplus\n+nsecs_t systemTime(int clock = SYSTEM_TIME_MONOTONIC);\n+#else\n+nsecs_t systemTime(int clock);\n+#endif // def __cplusplus\n+\n+/**\n+ * Returns the number of milliseconds to wait between the reference time and the timeout time.\n+ * If the timeout is in the past relative to the reference time, returns 0.\n+ * If the timeout is more than INT_MAX milliseconds in the future relative to the reference time,\n+ * such as when timeoutTime == LLONG_MAX, returns -1 to indicate an infinite timeout delay.\n+ * Otherwise, returns the difference between the reference time and timeout time\n+ * rounded up to the next millisecond.\n+ */\n+int toMillisecondTimeoutDelay(nsecs_t referenceTime, nsecs_t timeoutTime);\n+\n+#ifdef __cplusplus\n+} // extern \"C\"\n+#endif\n", "prefixes": [ "libcamera-devel", "1/4" ] }