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