From patchwork Sat Sep 23 16:23:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattijs Korpershoek X-Patchwork-Id: 19081 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 7DFC3C326C for ; Sat, 23 Sep 2023 16:23:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 88D356294B; Sat, 23 Sep 2023 18:23:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1695486223; 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=uvLhJCF3dgR5LtUEgYuLIkSzItArVhATrFlb+hCQY3gSWK8ha+hlrjncVrMHirfxk eglPqM3o2R2vKPRykDfZ2N+stA8VIC4tr8z5I31ofrN+0p2gQVjfGY0BD9coP1u1nJ +nKEmP29RPFGunCxj2xKEGTIOxU+82xNWIto6Vl1itXYNVCT+KpnPXP+wq5LJ9Ae+v y0t05Nht2mb1mAvUpyEK6KSQXh/pxAJm1DkudAiJ8FdcpasG0qYuaa/CxnCU7MCkKx y3npj7jDXyHNkT972O9BHrwg0M5tMgOVz/u7+zGYuCF3hhchCp9AGfLBegDPEyE0Eb V9mblu2MVxdEg== Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 460CF61DE7 for ; Sat, 23 Sep 2023 18:23:40 +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="MblEazqf"; dkim-atps=neutral Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-31fa15f4cc6so3696097f8f.2 for ; Sat, 23 Sep 2023 09:23:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695486220; x=1696091020; 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=MblEazqfnwhljlLNteurkg9y1wawC/1nLic1EBI5byLGZk4DiUnpGtnXpnFK4CGCOm Pt2kSA592+jpjSYk4jM2YYYvS37Lb2ZPL935f+a1nTB26ttByLwSnt89qKzI0Vnt0aG5 p2H3Gid8yNS/A8/OeRRGnt21R/+QV2ZOTz3J+S7lBFkU/R4pgLjYLXLLbNU0zxh9u0uL m//3eCUzPc+3/xwai+ae8JoyTgR9Rv6aUXel3rHXIw9ZeagQ8cLXgY9vSAm62BWWIeKv iBxXXtcfthH3jgXuTEFc7bVVZrvizTnUtxlP0ezMO2bMQ4QVrSglJ8VGGgNK7nhrIQcn hIJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695486220; x=1696091020; 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=uj2uA5C9BWUw074mKvO5/x6t3lr8rlGCVGphDIWjZe6oZmAUd7IrtUMla+egVlW9cJ JFV8StVymuGXliyvqFRt4kYX8bFqruBSUggB6gtChIup07ZctREr2NFUvd+fASccPpJ1 mOJQjpNU69vRw8acXIquVFnrdW29ssATuNxnwsG39Yh38ufFys7kIl6+VL+NuGV2oY1+ omlhgBzSmDcHtcz4pheFukJnTSf36kv7QimY2sHSdPNe0e03BQ53/8WSv3W4CDYJAvG1 YoGlG+PZvocyIzDtWD3VuWyJ6wwDazpGHVqRx6Wm/0IFYreGR3St0nC6UHsiduqaAXTy qQuA== X-Gm-Message-State: AOJu0YwvNTui6zJYqHEoTp2YcsacUyvSiCKqcHU396GKmBgX2sZY6Shy xs8IYcCeSc3rD7TyWyWnZ9n4pw== X-Google-Smtp-Source: AGHT+IGhn9dywGJNkcd6Twijd5731w0O0PYaRhh9OdRZVT6lWOvpMw2b3w9jH0VZc1SYpxcFYLf2sg== X-Received: by 2002:adf:fe85:0:b0:319:8a28:4001 with SMTP id l5-20020adffe85000000b003198a284001mr2069800wrr.41.1695486219995; Sat, 23 Sep 2023 09:23:39 -0700 (PDT) Received: from [192.168.0.39] ([2a01:e0a:324:38a0:25d4:3d10:65f9:654e]) by smtp.gmail.com with ESMTPSA id y7-20020adfd087000000b00317f70240afsm7200595wrh.27.2023.09.23.09.23.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 09:23:39 -0700 (PDT) Date: Sat, 23 Sep 2023 18:23:32 +0200 MIME-Version: 1.0 Message-Id: <20230923-gralloc-api-v4-v3-2-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 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: Jacopo Mondi , 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