blob: 96f79431d5db9857c93504cd3cd20b12327b8185 [file] [log] [blame]
John Stultz18814f62018-02-22 16:02:49 -08001/*
2 * Copyright (C) 2016-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#include <errno.h>
20#include <pthread.h>
21#include <inttypes.h>
22
John Stultzc7e94d82018-06-19 16:44:37 -070023#include <log/log.h>
John Stultz18814f62018-02-22 16:02:49 -080024#include <cutils/atomic.h>
25#include <hardware/hardware.h>
26#include <hardware/fb.h>
27
28#if GRALLOC_USE_GRALLOC1_API == 1
29#include <hardware/gralloc1.h>
30#else
31#include <hardware/gralloc.h>
32#endif
33
34#include "mali_gralloc_module.h"
35#include "mali_gralloc_private_interface_types.h"
36#include "mali_gralloc_buffer.h"
37#include "gralloc_helper.h"
38#include "framebuffer_device.h"
39#include "gralloc_buffer_priv.h"
40#include "mali_gralloc_formats.h"
41#include "mali_gralloc_usages.h"
42#include "mali_gralloc_bufferaccess.h"
43#include "mali_gralloc_reference.h"
44
45#if GRALLOC_USE_GRALLOC1_API == 1
46#include "mali_gralloc_public_interface.h"
47#else
48#include "legacy/alloc_device.h"
49#endif
50
51static int mali_gralloc_module_device_open(const hw_module_t *module, const char *name, hw_device_t **device)
52{
53 int status = -EINVAL;
54
55#if GRALLOC_USE_GRALLOC1_API == 1
56
57 if (!strncmp(name, GRALLOC_HARDWARE_MODULE_ID, MALI_GRALLOC_HARDWARE_MAX_STR_LEN))
58 {
59 status = mali_gralloc_device_open(module, name, device);
60 }
61
62#else
63
64 if (!strncmp(name, GRALLOC_HARDWARE_GPU0, MALI_GRALLOC_HARDWARE_MAX_STR_LEN))
65 {
66 status = alloc_device_open(module, name, device);
67 }
68
69#endif
70 else if (!strncmp(name, GRALLOC_HARDWARE_FB0, MALI_GRALLOC_HARDWARE_MAX_STR_LEN))
71 {
72 status = framebuffer_device_open(module, name, device);
73 }
74
75 return status;
76}
77
78static int gralloc_register_buffer(gralloc_module_t const *module, buffer_handle_t handle)
79{
80 const mali_gralloc_module *m = reinterpret_cast<const mali_gralloc_module *>(module);
81
82 return mali_gralloc_reference_retain(m, handle);
83}
84
85static int gralloc_unregister_buffer(gralloc_module_t const *module, buffer_handle_t handle)
86{
87 const mali_gralloc_module *m = reinterpret_cast<const mali_gralloc_module *>(module);
88
89 return mali_gralloc_reference_release(m, handle, false);
90}
91
92static int gralloc_lock(gralloc_module_t const *module, buffer_handle_t handle, int usage, int l, int t, int w, int h,
93 void **vaddr)
94{
95 const mali_gralloc_module *m = reinterpret_cast<const mali_gralloc_module *>(module);
96
97 return mali_gralloc_lock(m, handle, usage, l, t, w, h, vaddr);
98}
99
100static int gralloc_lock_ycbcr(gralloc_module_t const *module, buffer_handle_t handle, int usage, int l, int t, int w,
101 int h, android_ycbcr *ycbcr)
102{
103 const mali_gralloc_module *m = reinterpret_cast<const mali_gralloc_module *>(module);
104
105 return mali_gralloc_lock_ycbcr(m, handle, usage, l, t, w, h, ycbcr);
106}
107
108static int gralloc_unlock(gralloc_module_t const *module, buffer_handle_t handle)
109{
110 const mali_gralloc_module *m = reinterpret_cast<const mali_gralloc_module *>(module);
111
112 return mali_gralloc_unlock(m, handle);
113}
114
115static int gralloc_lock_async(gralloc_module_t const *module, buffer_handle_t handle, int usage, int l, int t, int w,
116 int h, void **vaddr, int32_t fence_fd)
117{
118 const mali_gralloc_module *m = reinterpret_cast<const mali_gralloc_module *>(module);
119
120 return mali_gralloc_lock_async(m, handle, usage, l, t, w, h, vaddr, fence_fd);
121}
122
123static int gralloc_lock_ycbcr_async(gralloc_module_t const *module, buffer_handle_t handle, int usage, int l, int t,
124 int w, int h, android_ycbcr *ycbcr, int32_t fence_fd)
125{
126 const mali_gralloc_module *m = reinterpret_cast<const mali_gralloc_module *>(module);
127
128 return mali_gralloc_lock_ycbcr_async(m, handle, usage, l, t, w, h, ycbcr, fence_fd);
129}
130
131static int gralloc_unlock_async(gralloc_module_t const *module, buffer_handle_t handle, int32_t *fence_fd)
132{
133 const mali_gralloc_module *m = reinterpret_cast<const mali_gralloc_module *>(module);
134
135 return mali_gralloc_unlock_async(m, handle, fence_fd);
136}
137
138// There is one global instance of the module
139
140static struct hw_module_methods_t mali_gralloc_module_methods = { mali_gralloc_module_device_open };
141
142private_module_t::private_module_t()
143{
144#define INIT_ZERO(obj) (memset(&(obj), 0, sizeof((obj))))
145 base.common.tag = HARDWARE_MODULE_TAG;
146#if GRALLOC_USE_GRALLOC1_API == 1
147 base.common.version_major = GRALLOC_MODULE_API_VERSION_1_0;
148#else
149 base.common.version_major = GRALLOC_MODULE_API_VERSION_0_3;
150#endif
151 base.common.version_minor = 0;
152 base.common.id = GRALLOC_HARDWARE_MODULE_ID;
153 base.common.name = "Graphics Memory Allocator Module";
154 base.common.author = "ARM Ltd.";
155 base.common.methods = &mali_gralloc_module_methods;
156 base.common.dso = NULL;
157 INIT_ZERO(base.common.reserved);
158
159#if GRALLOC_USE_GRALLOC1_API == 0
160 base.registerBuffer = gralloc_register_buffer;
161 base.unregisterBuffer = gralloc_unregister_buffer;
162 base.lock = gralloc_lock;
163 base.lock_ycbcr = gralloc_lock_ycbcr;
164 base.unlock = gralloc_unlock;
165 base.lockAsync = gralloc_lock_async;
166 base.lockAsync_ycbcr = gralloc_lock_ycbcr_async;
167 base.unlockAsync = gralloc_unlock_async;
168 base.perform = NULL;
Valerie Hauc2747e72019-04-25 10:17:58 -0700169 base.getTransportSize = NULL;
170 base.validateBufferSize = NULL;
John Stultz18814f62018-02-22 16:02:49 -0800171 INIT_ZERO(base.reserved_proc);
172#endif
173
174 framebuffer = NULL;
175 flags = 0;
176 numBuffers = 0;
177 bufferMask = 0;
178 pthread_mutex_init(&(lock), NULL);
179 currentBuffer = NULL;
180 INIT_ZERO(info);
181 INIT_ZERO(finfo);
182 xdpi = 0.0f;
183 ydpi = 0.0f;
184 fps = 0.0f;
185 swapInterval = 1;
186 ion_client = -1;
187
188#undef INIT_ZERO
189};
190
191/*
192 * HAL_MODULE_INFO_SYM will be initialized using the default constructor
193 * implemented above
194 */
195struct private_module_t HAL_MODULE_INFO_SYM;