1 /*
2 * Copyright (C) 2016-2018 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 #include <errno.h>
20 #include <pthread.h>
21 #include <inttypes.h>
22
23 #include <log/log.h>
24 #include <cutils/atomic.h>
25 #include <system/window.h>
26 #include <hardware/hardware.h>
27 #include <hardware/fb.h>
28
29 #if GRALLOC_VERSION_MAJOR == 1
30 #include <hardware/gralloc1.h>
31 #elif GRALLOC_VERSION_MAJOR == 0
32 #include <hardware/gralloc.h>
33 #endif
34
35 #include "mali_gralloc_module.h"
36 #include "mali_gralloc_private_interface_types.h"
37 #include "mali_gralloc_buffer.h"
38 #include "gralloc_helper.h"
39 #include "framebuffer_device.h"
40 #include "gralloc_buffer_priv.h"
41 #include "mali_gralloc_formats.h"
42 #include "mali_gralloc_usages.h"
43 #include "mali_gralloc_bufferaccess.h"
44 #include "mali_gralloc_reference.h"
45
46 #if GRALLOC_VERSION_MAJOR == 1
47 #include "mali_gralloc_public_interface.h"
48 #elif GRALLOC_VERSION_MAJOR == 0
49 #include "legacy/alloc_device.h"
50 #endif
51
mali_gralloc_module_device_open(const hw_module_t * module,const char * name,hw_device_t ** device)52 static int mali_gralloc_module_device_open(const hw_module_t *module, const char *name,
53 hw_device_t **device)
54 {
55 int status = -EINVAL;
56
57 #if GRALLOC_VERSION_MAJOR == 1
58
59 if (!strncmp(name, GRALLOC_HARDWARE_MODULE_ID, MALI_GRALLOC_HARDWARE_MAX_STR_LEN))
60 {
61 status = mali_gralloc_device_open(module, name, device);
62 }
63
64 #else
65
66 if (!strncmp(name, GRALLOC_HARDWARE_GPU0, MALI_GRALLOC_HARDWARE_MAX_STR_LEN))
67 {
68 status = alloc_device_open(module, name, device);
69 }
70
71 #endif
72 else if (!strncmp(name, GRALLOC_HARDWARE_FB0, MALI_GRALLOC_HARDWARE_MAX_STR_LEN))
73 {
74 status = framebuffer_device_open(module, name, device);
75 }
76
77 return status;
78 }
79
gralloc_register_buffer(gralloc_module_t const * module,buffer_handle_t handle)80 int gralloc_register_buffer(gralloc_module_t const *module, buffer_handle_t handle)
81 {
82 const mali_gralloc_module *m = reinterpret_cast<const mali_gralloc_module *>(module);
83
84 return mali_gralloc_reference_retain(m, handle);
85 }
86
gralloc_unregister_buffer(gralloc_module_t const * module,buffer_handle_t handle)87 int gralloc_unregister_buffer(gralloc_module_t const *module, buffer_handle_t handle)
88 {
89 const mali_gralloc_module *m = reinterpret_cast<const mali_gralloc_module *>(module);
90
91 return mali_gralloc_reference_release(m, handle, false);
92 }
93
gralloc_lock(gralloc_module_t const * module,buffer_handle_t handle,int usage,int l,int t,int w,int h,void ** vaddr)94 int gralloc_lock(gralloc_module_t const *module, buffer_handle_t handle, int usage,
95 int l, int t, int w, int h, void **vaddr)
96 {
97 const mali_gralloc_module *m = reinterpret_cast<const mali_gralloc_module *>(module);
98
99 return mali_gralloc_lock(m, handle, (unsigned int)usage, l, t, w, h, vaddr);
100 }
101
gralloc_lock_ycbcr(gralloc_module_t const * module,buffer_handle_t handle,int usage,int l,int t,int w,int h,android_ycbcr * ycbcr)102 int gralloc_lock_ycbcr(gralloc_module_t const *module, buffer_handle_t handle,
103 int usage, int l, int t, int w, int h, android_ycbcr *ycbcr)
104 {
105 const mali_gralloc_module *m = reinterpret_cast<const mali_gralloc_module *>(module);
106
107 return mali_gralloc_lock_ycbcr(m, handle, (unsigned int)usage, l, t, w, h, ycbcr);
108 }
109
gralloc_unlock(gralloc_module_t const * module,buffer_handle_t handle)110 int gralloc_unlock(gralloc_module_t const *module, buffer_handle_t handle)
111 {
112 const mali_gralloc_module *m = reinterpret_cast<const mali_gralloc_module *>(module);
113
114 return mali_gralloc_unlock(m, handle);
115 }
116
gralloc_lock_async(gralloc_module_t const * module,buffer_handle_t handle,int usage,int l,int t,int w,int h,void ** vaddr,int32_t fence_fd)117 int gralloc_lock_async(gralloc_module_t const *module, buffer_handle_t handle,
118 int usage, int l, int t, int w, int h, void **vaddr,
119 int32_t fence_fd)
120 {
121 const mali_gralloc_module *m = reinterpret_cast<const mali_gralloc_module *>(module);
122
123 return mali_gralloc_lock_async(m, handle, (unsigned int)usage, l, t, w, h, vaddr, fence_fd);
124 }
125
gralloc_lock_ycbcr_async(gralloc_module_t const * module,buffer_handle_t handle,int usage,int l,int t,int w,int h,android_ycbcr * ycbcr,int32_t fence_fd)126 int gralloc_lock_ycbcr_async(gralloc_module_t const *module, buffer_handle_t handle,
127 int usage, int l, int t, int w, int h,
128 android_ycbcr *ycbcr, int32_t fence_fd)
129 {
130 const mali_gralloc_module *m = reinterpret_cast<const mali_gralloc_module *>(module);
131
132 return mali_gralloc_lock_ycbcr_async(m, handle, (unsigned int)usage, l, t, w, h, ycbcr, fence_fd);
133 }
134
gralloc_unlock_async(gralloc_module_t const * module,buffer_handle_t handle,int32_t * fence_fd)135 int gralloc_unlock_async(gralloc_module_t const *module, buffer_handle_t handle,
136 int32_t *fence_fd)
137 {
138 const mali_gralloc_module *m = reinterpret_cast<const mali_gralloc_module *>(module);
139
140 return mali_gralloc_unlock_async(m, handle, fence_fd);
141 }
142
143 struct hw_module_methods_t mali_gralloc_module_methods = { mali_gralloc_module_device_open };
144
145 /* Export the private module as HAL_MODULE_INFO_SYM symbol as required by Gralloc v0.3 / v1.0 */
146 struct private_module_t HAL_MODULE_INFO_SYM;
147