1 /*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <BufferAllocator/BufferAllocator.h>
18 #include <BufferAllocator/BufferAllocatorWrapper.h>
19 #include <errno.h>
20 #include <sys/types.h>
21
22 extern "C" {
23
CreateDmabufHeapBufferAllocator()24 BufferAllocator* CreateDmabufHeapBufferAllocator() {
25 return new BufferAllocator();
26 }
27
FreeDmabufHeapBufferAllocator(BufferAllocator * buffer_allocator)28 void FreeDmabufHeapBufferAllocator(BufferAllocator* buffer_allocator) {
29 delete buffer_allocator;
30 };
31
DmabufHeapAlloc(BufferAllocator * buffer_allocator,const char * heap_name,size_t len,unsigned int heap_flags)32 int DmabufHeapAlloc(BufferAllocator* buffer_allocator, const char* heap_name, size_t len,
33 unsigned int heap_flags) {
34 if (!buffer_allocator)
35 return -EINVAL;
36 return buffer_allocator->Alloc(heap_name, len, heap_flags);
37 }
38
MapDmabufHeapNameToIonHeap(BufferAllocator * buffer_allocator,const char * heap_name,const char * ion_heap_name,unsigned int ion_heap_flags,unsigned int legacy_ion_heap_mask,unsigned int legacy_ion_heap_flags)39 int MapDmabufHeapNameToIonHeap(BufferAllocator* buffer_allocator, const char* heap_name,
40 const char* ion_heap_name, unsigned int ion_heap_flags,
41 unsigned int legacy_ion_heap_mask,
42 unsigned int legacy_ion_heap_flags) {
43 if (!buffer_allocator)
44 return -EINVAL;
45 return buffer_allocator->MapNameToIonHeap(heap_name, ion_heap_name, ion_heap_flags,
46 legacy_ion_heap_mask, legacy_ion_heap_flags);
47 }
48
DmabufHeapCpuSyncStart(BufferAllocator * buffer_allocator,unsigned int dmabuf_fd,SyncType sync_type,int (* legacy_ion_cpu_sync)(int))49 int DmabufHeapCpuSyncStart(BufferAllocator* buffer_allocator, unsigned int dmabuf_fd,
50 SyncType sync_type, int (*legacy_ion_cpu_sync)(int)) {
51 if (!buffer_allocator)
52 return -EINVAL;
53 return buffer_allocator->CpuSyncStart(dmabuf_fd, sync_type, legacy_ion_cpu_sync);
54 }
55
DmabufHeapCpuSyncEnd(BufferAllocator * buffer_allocator,unsigned int dmabuf_fd,int (* legacy_ion_cpu_sync)(int))56 int DmabufHeapCpuSyncEnd(BufferAllocator* buffer_allocator, unsigned int dmabuf_fd,
57 int (*legacy_ion_cpu_sync)(int)) {
58 if (!buffer_allocator)
59 return -EINVAL;
60 return buffer_allocator->CpuSyncEnd(dmabuf_fd, legacy_ion_cpu_sync);
61 }
62 }
63