From patchwork Tue Sep 12 14:15:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattijs Korpershoek X-Patchwork-Id: 18997 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 51957C32B0 for ; Tue, 12 Sep 2023 14:15:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9B30261DEF; Tue, 12 Sep 2023 16:15:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1694528131; bh=lgj0ZB2d6fBtKECTnBueFfk0BmVgG8zjpZqDhXO0D7M=; 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=uuSN7GQ/HEc89awNX5MEfHtmK1rSiLP5GVf3/0u4J9dAx2lA0l6ol4kEDTa2uxUBa 7/bfIIwqzocgEz5NsWLRJQHpui/WFqHvIB0EDZiT8a2jl+3N37WgksRptNchmjfDDZ K6TY/cjQRIGRSIK0dni1KR9Q+9PgB/LdXUsPwVMkPpWs9f+XZmpqQV1fmU3oQqR16B /SFJ2LKkZIchtWSwuzGwADn7gmynqhkd5yBwwMWz9FSI0anN3N0v1sM92GWUY15BFc aLcfFeWHX9h7h8Sk/USIFcBuWpmRqrkulxkUyV5/qArzTusKNZt/DyNkhmG5I7+tLn 6K1EjDmHAAGGg== Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 72528628F5 for ; Tue, 12 Sep 2023 16:15:28 +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="zGPCgBu5"; dkim-atps=neutral Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-401da71b7c5so64377275e9.2 for ; Tue, 12 Sep 2023 07:15:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1694528128; x=1695132928; 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=OqTOWyJSnZVOAfjh8r0tYOaae7jupjSbWMDA90wU7i8=; b=zGPCgBu5IXK934oI+JhYw/zQ4xZjK48CdlSNGgkaIK+XFU2fP0gRd3wt0/qJEt4WBQ KzsXc/eLh/gdPEpdmSU2sY4XAiuJrqRflJ1+Pq1Hmxn+i8RQf9dOkLx7CJt+l6xd8Bud iIWxOIyJ1o1qVinPjAMKoWFCIkOPbgxirLwcsc7/Jd4kSb5papXgIeAqT8RCZK4bsf1p 0X8f9F3x8mPPxvP3muc6Uqoj1nKQnT1adsL759+w50d6Wdz5qBO/ZnZmfKkOWRhaTxwS LmNTP1Amzohyq+rHOvNCHV51ZaVyiWeHVYIEZuYLce9SqcVml2v8DftvMarFU3XMLg3K DleA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694528128; x=1695132928; 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=OqTOWyJSnZVOAfjh8r0tYOaae7jupjSbWMDA90wU7i8=; b=PVk8pUSBzemUenPEmqrA7Qk8hcwuW4+IFPB95hPnF0pKhpwfKil5HiazJzZCdi/S/C 0BFs/mJtBFvQElpdVYI46C/pvPKbfpktYH1GWR+wSNRZZ6ooa+J5sRlV61IOeSUrU11B 3ucpvsk+ESdTz+dQSopgu+GCD0c0ELHDMgsEMRe10gFbXVnoQ8xGsBuBuV6WNqUbmMET ZOgqrfOeXElewNE65nSD/eBaNoOy1S+joWC6C6f9obj7KVFGYvrj5DPflIS89OkksVlk hNls/SEZ4J1KI1zmmBRHmu9UsJ4vG7UQam6ZcsUmOaBdWjiCSxWxvvUceIC4x+d2b3Ud Uncw== X-Gm-Message-State: AOJu0YyX+rrBzr+8H8Q6txqli8afkP4f2VzElQISLnDOfenD/WRUezLN iLt4CE7JamFvfeywFJzI0HurYQwPPPHDWvepuio= X-Google-Smtp-Source: AGHT+IGqKh7XHA3cZ5hZB0ubfSyrIPv9NuMpULgP03S5ULHH2X9PDu4C4Gaq6EvVA7nXtdPAJ+vZRQ== X-Received: by 2002:a05:600c:1da6:b0:403:b86:f624 with SMTP id p38-20020a05600c1da600b004030b86f624mr5532305wms.23.1694528128003; Tue, 12 Sep 2023 07:15:28 -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.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 07:15:27 -0700 (PDT) Date: Tue, 12 Sep 2023 16:15:21 +0200 MIME-Version: 1.0 Message-Id: <20230912-gralloc-api-v4-v2-2-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 2/4] android: Import GraphicBufferAllocator header from vndk v33 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" The GraphicBufferAllocator class (from libui) provides a more modern interface to Android buffer allocation. Moreover, the gralloc.h API has been deprecated since Android P (9). Import the GraphicBufferAllocator.h from the VNDK. These have been imported from: URL: https://android.googlesource.com/platform/prebuilts/vndk/v33/ rev: 390028a9da88 ("Update VNDK snapshot v33 to build 9948968. am: 3042508aee am: 7092391a46") No changes have been made to the files, besides adding the SPDX comment. Note: because GraphicBufferAllocator has lots of Android-specific dependencies, a future patch is needed to stub/simplify this include. Signed-off-by: Mattijs Korpershoek --- .../libs/ui/include/ui/GraphicBufferAllocator.h | 111 +++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/include/android/frameworks/native/libs/ui/include/ui/GraphicBufferAllocator.h b/include/android/frameworks/native/libs/ui/include/ui/GraphicBufferAllocator.h new file mode 100644 index 000000000000..e4674d746e37 --- /dev/null +++ b/include/android/frameworks/native/libs/ui/include/ui/GraphicBufferAllocator.h @@ -0,0 +1,111 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* + * + * Copyright 2009, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_BUFFER_ALLOCATOR_H +#define ANDROID_BUFFER_ALLOCATOR_H + +#include + +#include +#include + +#include + +#include + +#include +#include +#include +#include + +namespace android { + +class GrallocAllocator; +class GraphicBufferMapper; + +class GraphicBufferAllocator : public Singleton +{ +public: + static inline GraphicBufferAllocator& get() { return getInstance(); } + + /** + * Allocates and imports a gralloc buffer. + * + * The handle must be freed with GraphicBufferAllocator::free() when no longer needed. + */ + status_t allocate(uint32_t w, uint32_t h, PixelFormat format, uint32_t layerCount, + uint64_t usage, buffer_handle_t* handle, uint32_t* stride, + std::string requestorName); + + /** + * Allocates and does NOT import a gralloc buffer. Buffers cannot be used until they have + * been imported. This function is for advanced use cases only. + * + * The raw native handle must be freed by calling native_handle_close() followed by + * native_handle_delete(). + */ + status_t allocateRawHandle(uint32_t w, uint32_t h, PixelFormat format, uint32_t layerCount, + uint64_t usage, buffer_handle_t* handle, uint32_t* stride, + std::string requestorName); + + /** + * DEPRECATED: GraphicBufferAllocator does not use the graphicBufferId. + */ + status_t allocate(uint32_t w, uint32_t h, PixelFormat format, + uint32_t layerCount, uint64_t usage, + buffer_handle_t* handle, uint32_t* stride, uint64_t graphicBufferId, + std::string requestorName); + + status_t free(buffer_handle_t handle); + + uint64_t getTotalSize() const; + + void dump(std::string& res, bool less = true) const; + static void dumpToSystemLog(bool less = true); + +protected: + struct alloc_rec_t { + uint32_t width; + uint32_t height; + uint32_t stride; + PixelFormat format; + uint32_t layerCount; + uint64_t usage; + size_t size; + std::string requestorName; + }; + + status_t allocateHelper(uint32_t w, uint32_t h, PixelFormat format, uint32_t layerCount, + uint64_t usage, buffer_handle_t* handle, uint32_t* stride, + std::string requestorName, bool importBuffer); + + static Mutex sLock; + static KeyedVector sAllocList; + + friend class Singleton; + GraphicBufferAllocator(); + ~GraphicBufferAllocator(); + + GraphicBufferMapper& mMapper; + std::unique_ptr mAllocator; +}; + +// --------------------------------------------------------------------------- +}; // namespace android + +#endif // ANDROID_BUFFER_ALLOCATOR_H