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 #include "cros_gralloc/gralloc4/CrosGralloc4Metadata.h" 17 18 namespace aidl::android::hardware::graphics::allocator::impl { 19 20 class Allocator : public BnAllocator { 21 public: 22 Allocator() = default; 23 24 bool init(); 25 26 ndk::ScopedAStatus allocate(const std::vector<uint8_t>& descriptor, int32_t count, 27 allocator::AllocationResult* outResult) override; 28 29 protected: 30 ndk::SpAIBinder createBinder() override; 31 32 private: 33 ndk::ScopedAStatus allocate( 34 const ::android::hardware::graphics::mapper::V4_0::IMapper::BufferDescriptorInfo& 35 descriptor, 36 int32_t* outStride, native_handle_t** outHandle); 37 38 ndk::ScopedAStatus initializeMetadata( 39 cros_gralloc_handle_t crosHandle, 40 const struct cros_gralloc_buffer_descriptor& crosDescriptor); 41 42 void releaseBufferAndHandle(native_handle_t* handle); 43 44 cros_gralloc_driver* mDriver = nullptr; 45 }; 46 47 } // namespace aidl::android::hardware::graphics::allocator::impl 48 49 #endif