xref: /aosp_15_r20/external/minigbm/cros_gralloc/aidl/Allocator.h (revision d95af8df99a05bcb8679a54dc3ab8e5cd312b38e)
1*d95af8dfSAndroid Build Coastguard Worker /*
2*d95af8dfSAndroid Build Coastguard Worker  * Copyright 2022 The Chromium OS Authors. All rights reserved.
3*d95af8dfSAndroid Build Coastguard Worker  * Use of this source code is governed by a BSD-style license that can be
4*d95af8dfSAndroid Build Coastguard Worker  * found in the LICENSE file.
5*d95af8dfSAndroid Build Coastguard Worker  */
6*d95af8dfSAndroid Build Coastguard Worker 
7*d95af8dfSAndroid Build Coastguard Worker #ifndef MINIGBM_CROSGRALLOC_AIDL_ALLOCATOR_H_
8*d95af8dfSAndroid Build Coastguard Worker #define MINIGBM_CROSGRALLOC_AIDL_ALLOCATOR_H_
9*d95af8dfSAndroid Build Coastguard Worker 
10*d95af8dfSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/allocator/AllocationResult.h>
11*d95af8dfSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/allocator/BnAllocator.h>
12*d95af8dfSAndroid Build Coastguard Worker #include <android/hardware/graphics/mapper/4.0/IMapper.h>
13*d95af8dfSAndroid Build Coastguard Worker 
14*d95af8dfSAndroid Build Coastguard Worker #include "cros_gralloc/cros_gralloc_driver.h"
15*d95af8dfSAndroid Build Coastguard Worker #include "cros_gralloc/cros_gralloc_helpers.h"
16*d95af8dfSAndroid Build Coastguard Worker 
17*d95af8dfSAndroid Build Coastguard Worker namespace aidl::android::hardware::graphics::allocator::impl {
18*d95af8dfSAndroid Build Coastguard Worker 
19*d95af8dfSAndroid Build Coastguard Worker class Allocator : public BnAllocator {
20*d95af8dfSAndroid Build Coastguard Worker   public:
21*d95af8dfSAndroid Build Coastguard Worker     Allocator() = default;
22*d95af8dfSAndroid Build Coastguard Worker 
23*d95af8dfSAndroid Build Coastguard Worker     bool init();
24*d95af8dfSAndroid Build Coastguard Worker 
25*d95af8dfSAndroid Build Coastguard Worker     ndk::ScopedAStatus allocate(const std::vector<uint8_t>& descriptor, int32_t count,
26*d95af8dfSAndroid Build Coastguard Worker                                 allocator::AllocationResult* outResult) override;
27*d95af8dfSAndroid Build Coastguard Worker 
28*d95af8dfSAndroid Build Coastguard Worker     ndk::ScopedAStatus allocate2(const BufferDescriptorInfo& descriptor, int32_t count,
29*d95af8dfSAndroid Build Coastguard Worker                                  allocator::AllocationResult* outResult) override;
30*d95af8dfSAndroid Build Coastguard Worker 
31*d95af8dfSAndroid Build Coastguard Worker     ndk::ScopedAStatus isSupported(const BufferDescriptorInfo& descriptor,
32*d95af8dfSAndroid Build Coastguard Worker                                    bool* outResult) override;
33*d95af8dfSAndroid Build Coastguard Worker 
34*d95af8dfSAndroid Build Coastguard Worker     ndk::ScopedAStatus getIMapperLibrarySuffix(std::string* outResult) override;
35*d95af8dfSAndroid Build Coastguard Worker 
36*d95af8dfSAndroid Build Coastguard Worker   protected:
37*d95af8dfSAndroid Build Coastguard Worker     ndk::SpAIBinder createBinder() override;
38*d95af8dfSAndroid Build Coastguard Worker 
39*d95af8dfSAndroid Build Coastguard Worker   private:
40*d95af8dfSAndroid Build Coastguard Worker     using Dataspace = aidl::android::hardware::graphics::common::Dataspace;
41*d95af8dfSAndroid Build Coastguard Worker 
42*d95af8dfSAndroid Build Coastguard Worker     ndk::ScopedAStatus allocate(const struct cros_gralloc_buffer_descriptor& descriptor,
43*d95af8dfSAndroid Build Coastguard Worker                                 int32_t count, allocator::AllocationResult* outResult);
44*d95af8dfSAndroid Build Coastguard Worker 
45*d95af8dfSAndroid Build Coastguard Worker     ndk::ScopedAStatus allocateBuffer(const struct cros_gralloc_buffer_descriptor& descriptor,
46*d95af8dfSAndroid Build Coastguard Worker                                       int32_t* outStride, native_handle_t** outHandle);
47*d95af8dfSAndroid Build Coastguard Worker 
48*d95af8dfSAndroid Build Coastguard Worker     void releaseBufferAndHandle(native_handle_t* handle);
49*d95af8dfSAndroid Build Coastguard Worker 
50*d95af8dfSAndroid Build Coastguard Worker     std::shared_ptr<cros_gralloc_driver> mDriver;
51*d95af8dfSAndroid Build Coastguard Worker };
52*d95af8dfSAndroid Build Coastguard Worker 
53*d95af8dfSAndroid Build Coastguard Worker }  // namespace aidl::android::hardware::graphics::allocator::impl
54*d95af8dfSAndroid Build Coastguard Worker 
55*d95af8dfSAndroid Build Coastguard Worker #endif