summaryrefslogtreecommitdiff
path: root/GrallocHAL/src/4.x/GrallocAllocator.cpp
blob: 1a1e5630ed0db833f0eb2bf4ea3a82970bc47679 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * 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 <hwbinder/IPCThreadState.h>

#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<unsigned long>(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<void> 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<hidl_handle>());
		return Void();
	}
	common::allocate(bufferDescriptor, count, hidl_cb);
	return Void();
}

} // namespace allocator
} // namespace arm