1 /* 2 * Copyright (C) 2020 ARM Limited. All rights reserved. 3 * 4 * Copyright 2016 The Android Open Source Project 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 #ifndef GRALLOC_COMMON_ALLOCATOR_H 19 #define GRALLOC_COMMON_ALLOCATOR_H 20 21 22 #include <functional> 23 24 #include "core/mali_gralloc_bufferdescriptor.h" 25 #include "BufferDescriptor.h" 26 #include <android/hardware/graphics/allocator/4.0/IAllocator.h> 27 28 using android::hardware::graphics::allocator::V4_0::IAllocator; 29 using android::hardware::graphics::mapper::V4_0::Error; 30 31 namespace arm 32 { 33 namespace allocator 34 { 35 namespace common 36 { 37 38 using android::hardware::hidl_handle; 39 using android::hardware::hidl_vec; 40 41 /* 42 * Allocates buffers with the properties specified by the descriptor 43 * 44 * @param bufferDescriptor: Specifies the properties of the buffers to allocate. 45 * @param count: Number of buffers to allocate. 46 * @param hidl_cb [in] HIDL callback function generating - 47 * error : NONE upon success. Otherwise, 48 * BAD_DESCRIPTOR when the descriptor is invalid. 49 * NO_RESOURCES when the allocation cannot be fulfilled 50 * UNSUPPORTED when any of the property encoded in the descriptor 51 * is not supported 52 * stride: Number of pixels between two consecutive rows of the 53 * buffers, when the concept of consecutive rows is defined. 54 * buffers: An array of raw handles to the newly allocated buffers 55 * @param fb_allocator [in] function to use for allocation of buffers with GRALLOC_USAGE_HW_FB 56 */ 57 void allocate(const buffer_descriptor_t &bufferDescriptor, uint32_t count, IAllocator::allocate_cb hidl_cb, 58 std::function<int(const buffer_descriptor_t *, buffer_handle_t *)> fb_allocator = nullptr); 59 60 const std::string dump(); 61 62 bool isSupported(buffer_descriptor_t *const bufDescriptor); 63 64 } // namespace common 65 } // namespace allocator 66 } // namespace arm 67 68 #endif /* GRALLOC_COMMON_ALLOCATOR_H */ 69