/* * Copyright (C) 2020 Arm Limited. All rights reserved. * * 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. */ #include #include "GrallocAllocator.h" #include "hidl_common/BufferDescriptor.h" #include "hidl_common/Allocator.h" #include "allocator/mali_gralloc_ion.h" namespace arm { namespace allocator { using android::hardware::graphics::allocator::V4_0::IAllocator; using android::hardware::graphics::mapper::V4_0::Error; using android::hardware::Return; using android::hardware::hidl_handle; using android::hardware::hidl_vec; using android::hardware::Void; using android::hardware::hidl_string; unsigned long callingPid() { android::hardware::IPCThreadState* ipc = android::hardware::IPCThreadState::self(); return static_cast(ipc->getCallingPid()); } GrallocAllocator::GrallocAllocator() { MALI_GRALLOC_LOGV("Arm Module IAllocator %d.%d, pid = %d ppid = %d", GRALLOC_VERSION_MAJOR, (HIDL_ALLOCATOR_VERSION_SCALED - (GRALLOC_VERSION_MAJOR * 100)) / 10, getpid(), getppid()); } GrallocAllocator::~GrallocAllocator() { mali_gralloc_ion_close(); } Return GrallocAllocator::allocate(const BufferDescriptor &descriptor, uint32_t count, allocate_cb hidl_cb) { MALI_GRALLOC_LOGV("Allocation request from process: %lu", callingPid()); buffer_descriptor_t bufferDescriptor; if (!mapper::common::grallocDecodeBufferDescriptor(descriptor, bufferDescriptor)) { hidl_cb(Error::BAD_DESCRIPTOR, 0, hidl_vec()); return Void(); } common::allocate(bufferDescriptor, count, hidl_cb); return Void(); } } // namespace allocator } // namespace arm