diff options
author | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2019-12-19 22:57:56 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2019-12-19 22:57:56 +0000 |
commit | 0255ed8a5e9eb8dc4ca69a09e1d0d8dcddcd36a3 (patch) | |
tree | 4c60522b5f9aab2d60a8761a734c53038aa29c0b | |
parent | 5744cc8359ef8c3cf62882d904d966784a394176 (diff) | |
parent | c011de755b68089e17a78cecf5c987af3e856d3d (diff) | |
download | hikey-0255ed8a5e9eb8dc4ca69a09e1d0d8dcddcd36a3.tar.gz |
gralloc960: Clean up previous ion api rework am: 7357dcd8b3 am: c011de755b
Change-Id: I99f9b22c0ca9a7560f3b183a925575609fca3019
-rw-r--r-- | gralloc960/mali_gralloc_ion.cpp | 81 |
1 files changed, 18 insertions, 63 deletions
diff --git a/gralloc960/mali_gralloc_ion.cpp b/gralloc960/mali_gralloc_ion.cpp index d0510545..5fb51797 100644 --- a/gralloc960/mali_gralloc_ion.cpp +++ b/gralloc960/mali_gralloc_ion.cpp @@ -150,6 +150,20 @@ static int find_heap_id(int ion_client, char *name) return heap_id; } +static int alloc_ion_fd(int ion_fd, size_t size, unsigned int heap_mask, unsigned int flags, int *shared_fd) +{ + int heap; + + if (!gralloc_legacy_ion) { + heap = 1 << system_heap_id; + if (heap_mask == ION_HEAP_TYPE_DMA_MASK) + heap = 1 << cma_heap_id; + } else { + heap = heap_mask; + } + + return ion_alloc_fd(ion_fd, size, 0, heap, flags, shared_fd); +} static int alloc_from_ion_heap(int ion_fd, size_t size, unsigned int heap_mask, unsigned int flags, int *min_pgsz) { @@ -161,16 +175,7 @@ static int alloc_from_ion_heap(int ion_fd, size_t size, unsigned int heap_mask, return -1; } - /** - * step 1: ion_alloc new ion_hnd - * step 2: ion_share from ion_hnd and get shared_fd - * step 3: ion free the given ion_hnd - * step 4: when we need to free this ion buffer, just close the shared_fd, - * kernel will count the reference of file struct, so it's safe to - * be transfered between processes. - */ - ret = ion_alloc(ion_fd, size, 0, heap_mask, flags, &ion_hnd); - + ret = alloc_ion_fd(ion_fd, size, heap_mask, flags, &(shared_fd)); if (ret < 0) { #if defined(ION_HEAP_SECURE_MASK) @@ -185,27 +190,10 @@ static int alloc_from_ion_heap(int ion_fd, size_t size, unsigned int heap_mask, /* If everything else failed try system heap */ flags = 0; /* Fallback option flags are not longer valid */ heap_mask = ION_HEAP_SYSTEM_MASK; - ret = ion_alloc(ion_fd, size, 0, heap_mask, flags, &ion_hnd); + ret = alloc_ion_fd(ion_fd, size, heap_mask, flags, &(shared_fd)); } } - ret = ion_share(ion_fd, ion_hnd, &shared_fd); - - if (ret != 0) - { - AERR("ion_share( %d ) failed", ion_fd); - shared_fd = -1; - } - - ret = ion_free(ion_fd, ion_hnd); - - if (0 != ret) - { - AERR("ion_free( %d ) failed", ion_fd); - close(shared_fd); - shared_fd = -1; - } - if (ret >= 0) { switch (heap_mask) @@ -449,24 +437,8 @@ int mali_gralloc_ion_allocate(mali_gralloc_module *m, const gralloc_buffer_descr } set_ion_flags(heap_mask, usage, &priv_heap_flag, &ion_flags); - if (gralloc_legacy_ion) - { - shared_fd = alloc_from_ion_heap(m->ion_client, max_bufDescriptor->size, heap_mask, ion_flags, &min_pgsz); - } - else - { - int heap = 1 << system_heap_id; - if (heap_mask == ION_HEAP_TYPE_DMA_MASK) - heap = 1 << cma_heap_id; - ret = ion_alloc_fd(m->ion_client, max_bufDescriptor->size, 0, heap, 0, &(shared_fd)); - if (ret != 0) - { - AERR("Failed to ion_alloc_fd from ion_client:%d", m->ion_client); - return -1; - } - min_pgsz = SZ_4K; - } + shared_fd = alloc_from_ion_heap(m->ion_client, max_bufDescriptor->size, heap_mask, ion_flags, &min_pgsz); if (shared_fd < 0) { @@ -528,25 +500,8 @@ int mali_gralloc_ion_allocate(mali_gralloc_module *m, const gralloc_buffer_descr } set_ion_flags(heap_mask, usage, &priv_heap_flag, &ion_flags); - if (gralloc_legacy_ion) - { - shared_fd = alloc_from_ion_heap(m->ion_client, bufDescriptor->size, heap_mask, ion_flags, &min_pgsz); - } - else - { - int heap = 1 << system_heap_id; - if (heap_mask == ION_HEAP_TYPE_DMA_MASK) - heap = 1 << cma_heap_id; - ret = ion_alloc_fd(m->ion_client, bufDescriptor->size, 0, heap, 0, &(shared_fd)); - if (ret != 0) - { - AERR("Failed to ion_alloc_fd from ion_client:%d", m->ion_client); - mali_gralloc_ion_free_internal(pHandle, numDescriptors); - return -1; - } - min_pgsz = SZ_4K; - } + shared_fd = alloc_from_ion_heap(m->ion_client, bufDescriptor->size, heap_mask, ion_flags, &min_pgsz); if (shared_fd < 0) { |