1 /*
2  * Copyright (C) 2017 ARM Limited. All rights reserved.
3  *
4  * Copyright (C) 2008 The Android Open Source Project
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef GRALLOC_PRIV_H_
20 #define GRALLOC_PRIV_H_
21 
22 #include <stdint.h>
23 #include <pthread.h>
24 #include <errno.h>
25 #include <linux/fb.h>
26 #include <sys/types.h>
27 #include <unistd.h>
28 #include <sys/mman.h>
29 #include <cutils/native_handle.h>
30 #include <utils/Log.h>
31 
32 /* As this file is included by clients, support GRALLOC_USE_GRALLOC1_API
33  * flag for 0.3 and 1.0 clients. 2.x+ clients must set GRALLOC_VERSION_MAJOR,
34  * which is supported for all versions.
35  */
36 #ifndef GRALLOC_VERSION_MAJOR
37    #ifdef GRALLOC_USE_GRALLOC1_API
38       #if GRALLOC_USE_GRALLOC1_API == 0
39          #define GRALLOC_VERSION_MAJOR 0
40       #elif GRALLOC_USE_GRALLOC1_API == 1
41          #define GRALLOC_VERSION_MAJOR 1
42       #endif
43    #else
44         #if PLATFORM_SDK_VERSION > 24
45             #define GRALLOC_VERSION_MAJOR 1
46         #else
47             #define GRALLOC_VERSION_MAJOR 0
48         #endif
49    #endif
50 #endif
51 
52 #if GRALLOC_VERSION_MAJOR == 2
53     #if PLATFORM_SDK_VERSION >= 28
54         #define HIDL_IMAPPER_NAMESPACE V2_1
55         #define HIDL_IALLOCATOR_NAMESPACE V2_0
56         #define HIDL_COMMON_NAMESPACE V1_1
57 
58         /* Allocator = 2.0, Mapper = 2.1 and Common = 1.1 */
59         #define HIDL_ALLOCATOR_VERSION_SCALED 200
60         #define HIDL_MAPPER_VERSION_SCALED 210
61         #define HIDL_COMMON_VERSION_SCALED 110
62     #elif PLATFORM_SDK_VERSION >= 26
63         #define HIDL_IMAPPER_NAMESPACE V2_0
64         #define HIDL_IALLOCATOR_NAMESPACE V2_0
65         #define HIDL_COMMON_NAMESPACE V1_0
66 
67         /* Allocator = 2.0, Mapper = 2.0 and Common = 1.0 */
68         #define HIDL_ALLOCATOR_VERSION_SCALED 200
69         #define HIDL_MAPPER_VERSION_SCALED 200
70         #define HIDL_COMMON_VERSION_SCALED 100
71     #else
72         #error "Gralloc 2.x is not supported on platform SDK version PLATFORM_SDK_VERSION"
73     #endif
74 #endif
75 
76 #if (GRALLOC_VERSION_MAJOR != 2) && (GRALLOC_VERSION_MAJOR != 1) && (GRALLOC_VERSION_MAJOR != 0)
77     #error " Gralloc version $(GRALLOC_VERSION_MAJOR) is not supported"
78 #endif
79 
80 #if GRALLOC_VERSION_MAJOR == 1
81 #include <hardware/gralloc1.h>
82 #elif GRALLOC_VERSION_MAJOR == 0
83 #include <hardware/gralloc.h>
84 #endif
85 
86 #include "mali_gralloc_formats.h"
87 #include "mali_gralloc_usages.h"
88 #include "gralloc_helper.h"
89 
90 #if (GRALLOC_VERSION_MAJOR == 2) || (GRALLOC_VERSION_MAJOR == 0) || \
91     ((GRALLOC_VERSION_MAJOR == 1) && !defined(GRALLOC_DISABLE_PRIVATE_BUFFER_DEF))
92 
93 /*
94  * This header file contains the private buffer definition. For gralloc 0.3 it will
95  * always be exposed, but for gralloc 1.0 it will be removed at some point in the future.
96  *
97  * GRALLOC_DISABLE_PRIVATE_BUFFER_DEF is intended for DDKs to test while implementing
98  * the new private API.
99  */
100 #include "mali_gralloc_buffer.h"
101 #endif
102 
103 #if GRALLOC_VERSION_MAJOR == 1
104 
105 /* gralloc 1.0 supports the new private interface that abstracts
106  * the private buffer definition to a set of defined APIs.
107  */
108 #include "mali_gralloc_private_interface.h"
109 #endif
110 
111 #endif /* GRALLOC_PRIV_H_ */
112