From patchwork Tue Sep 12 09:36:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattijs Korpershoek X-Patchwork-Id: 18986 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 94A40C32B0 for ; Tue, 12 Sep 2023 09:36:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B49E1628F4; Tue, 12 Sep 2023 11:36:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1694511382; 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: From; b=bY8lm3tcQQn1XiptEi6JQ4NB9AZcD05oZ+/4tfhTkCaTIQh7TwqFBN8xQLPSuNuac TG2LiKF/s1oXuFHmJnqH53dmriYQzyINm/SN9Yul2PAQHvGNOWw1Z/yEFqqKypbCd+ VygiIv/ASKMm/wNNx5UXtulIGtYo4Ej+PSzp1SNk+tizCvZZkHuvcwkelVWRnLzEKm DQzCL2Hqt/NZM/MgINNswpwpe/a66GoqCZXHpFhUy5tdQ68LErzecdp/XoKmcpD+bz ZIhI8G70sQOr9QzTSP9R5Fh01Xfum1MssEgpM+iYQBcFLfIvmdTA7rSEHBTEiFZZHZ MvJ9amF5lMOrA== Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5B3B3628E9 for ; Tue, 12 Sep 2023 11:36:20 +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="1V8jVooC"; dkim-atps=neutral Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-402c46c49f4so57790345e9.1 for ; Tue, 12 Sep 2023 02:36:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1694511380; x=1695116180; 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=1V8jVooCdGG1Jd22iZQiY9kaqyfkx7KldPIN3JIBfYwBO8/dulcCD3O3Y6mQJIdbIc 2YHRFn0SOEx3fuDfVnq+7+tDGYrdGORVskMaHNuq0u752dwk060DKcAM/B5eV9UFve7I SLXm1+TXc1t7vi6rW6+uW+V0qgkpuPvOr/dLT6mCN2VEjihNR6jhrpzbf7naDhDBxJE2 obGCB7rJuhzdyaJB5czSDGKZEyZAqjbdcTu63iG6q7xzzdgPIzwvxnM01brUk757QFvk RSw2dxOdaK2gdxKlWwJvQT/LayxbH6jrLpyDJ0fhQ2NXvujsW1/2HpY0y/JiKJ51Gb2K mUww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694511380; x=1695116180; 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=oK5q2y5SzBgOgHKK0yuokdC1oYEKj63pGQtC4uhQSNT0ujBJTVuxeBpm9AaIezVIQO g4ZjzPu8GD2u20fIAxNrjG/pX6++6kVkNesyakrvbQCLWE4K/Zp+xfLfEUzghGBJ8W6l o4y7qntYn2Enp8xYcrgif/AV94BUeI5a8/VFcwNnvY7VGXUJkrT+a8SYL1IozlmAcwZt 7Rjue/4ynsXHRyjB9GtfO496sPEfNA/144iCewrAMeAA216g1h3/Obrtp2jBSxRAZOGp QuB+En8XNJ5UO0+dSoVdgtSkaxejzeaiO8dOPLXSK5gdBt7ON+r2hSI/Pfeh26hMvEIv 2VDw== X-Gm-Message-State: AOJu0Yw/zd0HpTmUGI7twtff+S8c0vUOAopjl/mEeJzIFCt0xn1VpC4I PdEYEDFU6weZV1/j+3SSYZR6qDY1Xv2Lw2LKlPA= X-Google-Smtp-Source: AGHT+IEemB9oUf7KGAKpjTJg3GarY4rBhR5P4MFtG2HaxamwjNXn+tGr4Tb0qmn9xD/1fT/iy/BTPA== X-Received: by 2002:a7b:ce85:0:b0:401:bf62:9456 with SMTP id q5-20020a7bce85000000b00401bf629456mr9744354wmj.8.1694511379928; Tue, 12 Sep 2023 02:36:19 -0700 (PDT) Received: from [192.168.2.39] ([82.66.159.240]) by smtp.gmail.com with ESMTPSA id y10-20020a05600c364a00b00401b242e2e6sm15578253wmq.47.2023.09.12.02.36.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 02:36:19 -0700 (PDT) Date: Tue, 12 Sep 2023 11:36:11 +0200 MIME-Version: 1.0 Message-Id: <20230912-gralloc-api-v4-v1-2-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 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 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