blob: 5e0bc616e286d4a6cfec9128b761d44fe3cce079 [file] [log] [blame]
Hridya Valsaraju77a3ad62020-06-22 17:41:16 -07001/*
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
22extern "C" {
23
24BufferAllocator* CreateDmabufHeapBufferAllocator() {
25 return new BufferAllocator();
26}
27
28void FreeDmabufHeapBufferAllocator(BufferAllocator* buffer_allocator) {
29 delete buffer_allocator;
30};
31
32int 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
39int 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
49int 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
56int 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}