xref: /OK3568_Linux_fs/external/mpp/osal/android/os_allocator.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright 2015 Rockchip Electronics Co. LTD
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 #if defined(__ANDROID__)
18 #include "allocator_dma_heap.h"
19 #include "allocator_drm.h"
20 #include "allocator_ext_dma.h"
21 #include "allocator_ion.h"
22 #include "allocator_std.h"
23 #include "mpp_runtime.h"
24 
os_allocator_get(os_allocator * api,MppBufferType type)25 MPP_RET os_allocator_get(os_allocator *api, MppBufferType type)
26 {
27     MPP_RET ret = MPP_OK;
28 
29     switch (type) {
30     case MPP_BUFFER_TYPE_NORMAL :
31         *api = allocator_std;
32     case MPP_BUFFER_TYPE_ION : {
33         *api = (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DMA_HEAP)) ? allocator_dma_heap :
34                (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_ION)) ? allocator_ion :
35 #if HAVE_DRM
36                (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DRM)) ? allocator_drm :
37 #endif
38                allocator_std;
39     } break;
40     case MPP_BUFFER_TYPE_EXT_DMA: {
41         *api = allocator_ext_dma;
42     } break;
43     case MPP_BUFFER_TYPE_DRM : {
44         *api = (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DMA_HEAP)) ? allocator_dma_heap :
45 #if HAVE_DRM
46                (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DRM)) ? allocator_drm :
47 #endif
48                (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_ION)) ? allocator_ion :
49                allocator_std;
50     } break;
51     case MPP_BUFFER_TYPE_DMA_HEAP: {
52         *api = (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DMA_HEAP)) ? allocator_dma_heap :
53                allocator_std;
54     } break;
55     default : {
56         ret = MPP_NOK;
57     } break;
58     }
59     return ret;
60 }
61 #endif
62