1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
#define LOG_TAG "GraphicBufferExtra_hal"
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
#include <stdint.h>
#include <errno.h>
#include <utils/Errors.h>
#include <utils/Log.h>
#include <utils/Trace.h>
#include <system/graphics.h>
#include <graphics_mtk_defs.h>
#include <hardware/gralloc.h>
#include <hardware/gralloc_extra.h>
#include <ui/GraphicBufferExtra.h>
/* ---- IMPLEMENTATION macro ---- */
#define GRALLOC_EXTRA_PROTOTYPE_(...) ( __VA_ARGS__ )
#define GRALLOC_EXTRA_ARGS_(...) ( __VA_ARGS__ )
#define GRALLOC_EXTRA_ARGS_2(...) ( mExtraDev, __VA_ARGS__ )
#define GRALLOC_EXTRA_CHECK_FAIL_RETURN_(API, ERR) \
do { \
if (!mExtraDev) \
{ \
ALOGD("gralloc extra device is not supported"); \
return ERR; \
} \
\
if (!mExtraDev->API) \
{ \
ALOGW("gralloc extra device " #API "(...) is not supported"); \
return ERR; \
} \
} while(0)
#define GRALLOC_EXTRA_IMPLEMENTATION_(RET, ERR, API, PROTOTYPE, ARGS) \
RET android::GraphicBufferExtra:: API PROTOTYPE \
{ \
ATRACE_CALL(); \
RET err; \
\
GRALLOC_EXTRA_CHECK_FAIL_RETURN_(API, ERR); \
\
err = mExtraDev-> API GRALLOC_EXTRA_ARGS_2 ARGS ; \
\
if (err < 0) ALOGW(#API"(...) failed %d", err); \
\
return err; \
} \
extern "C" RET gralloc_extra_##API PROTOTYPE \
{ \
return android::GraphicBufferExtra::get(). API ARGS; \
}
/* ---- IMPLEMENTATION start ---- */
GRALLOC_EXTRA_IMPLEMENTATION_(int, -1, getIonFd,
GRALLOC_EXTRA_PROTOTYPE_(buffer_handle_t handle, int *idx, int *num),
GRALLOC_EXTRA_ARGS_(handle, idx, num)
)
GRALLOC_EXTRA_IMPLEMENTATION_(int, -1, getSecureBuffer,
GRALLOC_EXTRA_PROTOTYPE_(buffer_handle_t handle, int *type, int *hBuffer),
GRALLOC_EXTRA_ARGS_(handle, type, hBuffer)
)
GRALLOC_EXTRA_IMPLEMENTATION_(int, -1, getBufInfo,
GRALLOC_EXTRA_PROTOTYPE_(buffer_handle_t handle, gralloc_buffer_info_t* bufInfo),
GRALLOC_EXTRA_ARGS_(handle, bufInfo)
)
GRALLOC_EXTRA_IMPLEMENTATION_(int, -1, setBufParameter,
GRALLOC_EXTRA_PROTOTYPE_(buffer_handle_t handle, int mask, int value),
GRALLOC_EXTRA_ARGS_(handle, mask, value)
)
GRALLOC_EXTRA_IMPLEMENTATION_(int, -1, getMVA,
GRALLOC_EXTRA_PROTOTYPE_(buffer_handle_t handle, int *mvaddr),
GRALLOC_EXTRA_ARGS_(handle, mvaddr)
)
GRALLOC_EXTRA_IMPLEMENTATION_(int, -1, setBufInfo,
GRALLOC_EXTRA_PROTOTYPE_(buffer_handle_t handle, const char * str),
GRALLOC_EXTRA_ARGS_(handle, str)
)
/* ---- IMPLEMENTATION start end ---- */
#undef GRALLOC_EXTRA_CHECK_FAIL_RETURN_
#undef GRALLOC_EXTRA_IMPLEMENTATION_
#undef GRALLOC_EXTRA_PROTOTYPE_
#undef GRALLOC_EXTRA_ARGS_
#undef GRALLOC_EXTRA_ARGS_2
int android::GraphicBufferExtra::query(
buffer_handle_t handle, GRALLOC_EXTRA_ATTRIBUTE_QUERY attribute, void * out_pointer)
{
ATRACE_CALL();
int err;
if (!mExtraDev || !mExtraDev->query)
{
ALOGW("gralloc extra device query(...) is not supported");
return -GRALLOC_EXTRA_NOT_SUPPORTED;
}
err = mExtraDev->query(mExtraDev, handle, attribute, out_pointer);
if (err < 0)
ALOGW("query(0x%x) failed %d", attribute, err);
return err;
}
int android::GraphicBufferExtra::perform(
buffer_handle_t handle, GRALLOC_EXTRA_ATTRIBUTE_PERFORM attribute, void * in_pointer)
{
ATRACE_CALL();
int err;
if (!mExtraDev || !mExtraDev->perform)
{
ALOGW("gralloc extra device perform(...) is not supported");
return -GRALLOC_EXTRA_NOT_SUPPORTED;
}
err = mExtraDev->perform(mExtraDev, handle, attribute, in_pointer);
if (err < 0)
ALOGW("perform(0x%x) failed %d", attribute, err);
return err;
}
#if 0
int android::GraphicBufferExtra::free_sec(
buffer_handle_t handle)
{
ATRACE_CALL();
int err;
if (!mExtraDev || !mExtraDev->perform)
{
ALOGW("gralloc extra device perform(...) is not supported");
return -GRALLOC_EXTRA_NOT_SUPPORTED;
}
err = mExtraDev->free_sec(mExtraDev, handle);
if (err < 0)
ALOGW("free_sec failed %d", err);
return err;
}
#endif
extern "C" int gralloc_extra_query(
buffer_handle_t handle, GRALLOC_EXTRA_ATTRIBUTE_QUERY attribute, void * out_pointer)
{
return android::GraphicBufferExtra::get().query(handle, attribute, out_pointer);
}
extern "C" int gralloc_extra_perform(
buffer_handle_t handle, GRALLOC_EXTRA_ATTRIBUTE_PERFORM attribute, void * in_pointer)
{
return android::GraphicBufferExtra::get().perform(handle, attribute, in_pointer);
}
#if 0
extern "C" int gralloc_extra_free_sec(buffer_handle_t handle )
{
return android::GraphicBufferExtra::get().free_sec(handle);
}
#endif
static int __gralloc_extra_sf_set_int(int *data, int32_t mask, int32_t value)
{
int32_t old_status;
int32_t new_status;
old_status = *data;
new_status = ( old_status & (~mask) );
new_status |= ( value & mask );
/* Force modify the const member */
*data = new_status;
return GRALLOC_EXTRA_OK;
}
extern "C" int gralloc_extra_sf_set_status(gralloc_extra_ion_sf_info_t *sf_info, int32_t mask, int32_t value)
{
return __gralloc_extra_sf_set_int(&sf_info->status, mask, value);
}
extern "C" int gralloc_extra_sf_set_status2(gralloc_extra_ion_sf_info_t *sf_info, int32_t mask, int32_t value)
{
return __gralloc_extra_sf_set_int(&sf_info->status2, mask, value);
}
/* init the sf_info */
extern "C" int gralloc_extra_sf_init(buffer_handle_t handle, gralloc_extra_ion_sf_info_t * sf_info)
{
int32_t mask = 0;
int32_t value = 0;
int format;
memset(sf_info, 0, sizeof(gralloc_extra_ion_sf_info_t));
if (GRALLOC_EXTRA_OK == gralloc_extra_query(handle, GRALLOC_EXTRA_GET_FORMAT, &format))
{
if (format == HAL_PIXEL_FORMAT_YV12 ||
format == HAL_PIXEL_FORMAT_I420 ||
format == HAL_PIXEL_FORMAT_YUV_PRIVATE ||
format == HAL_PIXEL_FORMAT_NV12_BLK ||
format == HAL_PIXEL_FORMAT_NV12_BLK_FCM ||
format == HAL_PIXEL_FORMAT_YUYV ||
0 )
{
mask |= GRALLOC_EXTRA_MASK_YUV_COLORSPACE;
value |= GRALLOC_EXTRA_BIT_YUV_BT601_NARROW;
}
}
gralloc_extra_sf_set_status(sf_info, mask, value);
return 0;
}
|