-
Notifications
You must be signed in to change notification settings - Fork 0
/
hwc_rockchip.cpp
executable file
·486 lines (403 loc) · 11.4 KB
/
hwc_rockchip.cpp
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
/*
* Copyright (C) 2018 Fuzhou Rockchip Electronics Co.Ltd.
*
* Modification based on code covered by the Apache License, Version 2.0 (the "License").
* You may not use this software except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS TO YOU ON AN "AS IS" BASIS
* AND ANY AND ALL WARRANTIES AND REPRESENTATIONS WITH RESPECT TO SUCH SOFTWARE, WHETHER EXPRESS,
* IMPLIED, STATUTORY OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF TITLE,
* NON-INFRINGEMENT, MERCHANTABILITY, SATISFACTROY QUALITY, ACCURACY OR FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED.
*
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "hwc_rk"
#include <inttypes.h>
#ifdef TARGET_BOARD_PLATFORM_RK3368
#include <hardware/img_gralloc_public.h>
#endif
#include "hwc_rockchip.h"
#include "hwc_util.h"
#if USE_GRALLOC_4
#include "drmgralloc4.h"
#endif
namespace android {
gralloc_module_t *gralloc;
int hwc_init_version()
{
char acVersion[50];
char acCommit[50];
memset(acVersion,0,sizeof(acVersion));
strcpy(acVersion,GHWC_VERSION);
#ifdef TARGET_BOARD_PLATFORM_RK3288
strcat(acVersion,"-rk3288");
#endif
#ifdef TARGET_BOARD_PLATFORM_RK3368
strcat(acVersion,"-rk3368");
#endif
#ifdef TARGET_BOARD_PLATFORM_RK3366
strcat(acVersion,"-rk3366");
#endif
#ifdef TARGET_BOARD_PLATFORM_RK3399
strcat(acVersion,"-rk3399");
#endif
#ifdef TARGET_BOARD_PLATFORM_RK3326
strcat(acVersion,"-rk3326");
#endif
#ifdef TARGET_BOARD_PLATFORM_RK3126C
strcat(acVersion,"-rk3126c");
#endif
#ifdef TARGET_BOARD_PLATFORM_RK3328
strcat(acVersion,"-rk3328");
#endif
#ifdef RK_MID
strcat(acVersion,"-MID");
#endif
#ifdef RK_BOX
strcat(acVersion,"-BOX");
#endif
#ifdef RK_PHONE
strcat(acVersion,"-PHONE");
#endif
#ifdef RK_VIR
strcat(acVersion,"-VR");
#endif
int ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
(const hw_module_t **)&gralloc);
if (ret) {
ALOGE("Failed to open gralloc module");
return ret;
}
/* RK_GRAPHICS_VER=commit-id:067e5d0: only keep string after '=' */
// sscanf(RK_GRAPHICS_VER, "%*[^=]=%s", acCommit);
// property_set("sys.ghwc.version", acVersion);
// property_set("sys.ghwc.commit", acCommit);
// ALOGD(RK_GRAPHICS_VER);
return 0;
}
int hwc_lock(buffer_handle_t hnd,int usage, int x, int y, int w, int h, void **cpu_addr){
#if USE_GRALLOC_4
return gralloc4::lock(hnd,usage,x,y,w,h,(void **)cpu_addr);
#else // USE_GRALLOC_4
return gralloc->lock(gralloc, hnd, usage, x, y, w, h, (void **)cpu_addr);
#endif
}
int hwc_unlock(buffer_handle_t hnd){
#if USE_GRALLOC_4
gralloc4::unlock(hnd);
return 0;
#else // USE_GRALLOC_4
return gralloc->unlock(gralloc, hnd);
#endif
}
int hwc_get_handle_width(buffer_handle_t hnd)
{
#if USE_GRALLOC_4
uint64_t width;
int err = gralloc4::get_width(hnd, &width);
if (err != android::OK)
{
ALOGE("Failed to get buffer width, err : %d", err);
return -1;
}
return (int)width;
#else // USE_GRALLOC_4
int ret = 0;
int op = GRALLOC_MODULE_PERFORM_GET_HADNLE_WIDTH;
int width = -1;
if(gralloc && gralloc->perform)
ret = gralloc->perform(gralloc, op, hnd, &width);
else
ret = -EINVAL;
if(ret != 0)
{
ALOGE("%s:cann't get value from gralloc", __FUNCTION__);
}
return width;
#endif
}
int hwc_get_handle_height(buffer_handle_t hnd)
{
#if USE_GRALLOC_4
uint64_t height;
int err = gralloc4::get_height(hnd, &height);
if (err != android::OK)
{
ALOGE("Failed to get buffer height, err : %d", err);
return -1;
}
return (int)height;
#else // USE_GRALLOC_4
int ret = 0;
int op = GRALLOC_MODULE_PERFORM_GET_HADNLE_HEIGHT;
int height = -1;
if(gralloc && gralloc->perform)
ret = gralloc->perform(gralloc, op, hnd, &height);
else
ret = -EINVAL;
if(ret != 0)
{
ALOGE("%s:cann't get value from gralloc", __FUNCTION__);
}
return height;
#endif
}
int hwc_get_handle_stride(buffer_handle_t hnd)
{
#if USE_GRALLOC_4
int pixel_stride;
int err = gralloc4::get_pixel_stride(hnd, &pixel_stride);
if (err != android::OK)
{
ALOGE("Failed to get buffer pixel_stride, err : %d", err);
return -1;
}
return pixel_stride;
#else // USE_GRALLOC_4
int ret = 0;
int op = GRALLOC_MODULE_PERFORM_GET_HADNLE_STRIDE;
int stride = -1;
if(gralloc && gralloc->perform)
ret = gralloc->perform(gralloc, op, hnd, &stride);
else
ret = -EINVAL;
if(ret != 0)
{
ALOGE("%s:cann't get value from gralloc", __FUNCTION__);
}
return stride;
#endif
}
int hwc_get_handle_byte_stride(buffer_handle_t hnd)
{
#if USE_GRALLOC_4
int byte_stride;
int err = gralloc4::get_byte_stride(hnd, &byte_stride);
if (err != android::OK)
{
ALOGE("Failed to get buffer byte_stride, err : %d", err);
return -1;
}
return byte_stride;
#else // USE_GRALLOC_4
int ret = 0;
int op = GRALLOC_MODULE_PERFORM_GET_HADNLE_BYTE_STRIDE;
int byte_stride = -1;
if(gralloc && gralloc->perform)
ret = gralloc->perform(gralloc, op, hnd, &byte_stride);
else
ret = -EINVAL;
if(ret != 0)
{
ALOGE("%s:cann't get value from gralloc", __FUNCTION__);
}
return byte_stride;
#endif
}
int hwc_get_handle_format(buffer_handle_t hnd)
{
#if USE_GRALLOC_4
int format_requested;
int err = gralloc4::get_format_requested(hnd, &format_requested);
if (err != android::OK)
{
ALOGE("Failed to get buffer format_requested, err : %d", err);
return -1;
}
return format_requested;
#else // USE_GRALLOC_4
int ret = 0;
int op = GRALLOC_MODULE_PERFORM_GET_HADNLE_FORMAT;
int format = -1;
if(gralloc && gralloc->perform)
ret = gralloc->perform(gralloc, op, hnd, &format);
else
ret = -EINVAL;
if(ret != 0)
{
ALOGE("%s:cann't get value from gralloc", __FUNCTION__);
}
return format;
#endif
}
int hwc_get_handle_usage(buffer_handle_t hnd)
{
#if USE_GRALLOC_4
uint64_t usage;
int err = gralloc4::get_usage(hnd, &usage);
if (err != android::OK)
{
ALOGE("Failed to get buffer usage, err : %d", err);
return -1;
}
return (int)usage;
#else // USE_GRALLOC_4
int ret = 0;
int op = GRALLOC_MODULE_PERFORM_GET_USAGE;
int usage = -1;
if(gralloc && gralloc->perform)
ret = gralloc->perform(gralloc, op, hnd, &usage);
else
ret = -EINVAL;
if(ret != 0)
{
ALOGE("%s:cann't get value from gralloc", __FUNCTION__);
}
return usage;
#endif
}
int hwc_get_handle_size(buffer_handle_t hnd)
{
#if USE_GRALLOC_4
uint64_t allocation_size;
int err = gralloc4::get_allocation_size(hnd, &allocation_size);
if (err != android::OK)
{
ALOGE("Failed to get buffer allocation_size, err : %d", err);
return -1;
}
return (int)allocation_size;
#else // USE_GRALLOC_4
int ret = 0;
int op = GRALLOC_MODULE_PERFORM_GET_HADNLE_SIZE;
int size = -1;
if(gralloc && gralloc->perform)
ret = gralloc->perform(gralloc, op, hnd, &size);
else
ret = -EINVAL;
if(ret != 0)
{
ALOGE("%s:cann't get value from gralloc", __FUNCTION__);
}
return size;
#endif
}
/*
@func hwc_get_handle_attributes:get attributes from handle.Before call this api,As far as now,
we need register the buffer first.May be the register is good for processer I think
@param hnd:
@param attrs: if size of attrs is small than 5,it will return EINVAL else
width = attrs[0]
height = attrs[1]
stride = attrs[2]
format = attrs[3]
size = attrs[4]
*/
int hwc_get_handle_attributes(buffer_handle_t hnd, std::vector<int> *attrs)
{
int ret = 0;
#if USE_GRALLOC_4
#else
int op = GRALLOC_MODULE_PERFORM_GET_HADNLE_ATTRIBUTES;
if (!hnd)
return -EINVAL;
if(gralloc && gralloc->perform)
{
ret = gralloc->perform(gralloc, op, hnd, attrs);
}
else
{
ret = -EINVAL;
}
if(ret) {
ALOGE("hwc_get_handle_attributes fail %d for:%s hnd=%p",ret,strerror(ret),hnd);
}
#endif
return ret;
}
int hwc_get_handle_attibute(buffer_handle_t hnd, attribute_flag_t flag)
{
#if USE_GRALLOC_4
switch ( flag )
{
case ATT_WIDTH:
return hwc_get_handle_width(hnd);
case ATT_HEIGHT:
return hwc_get_handle_height(hnd);
case ATT_STRIDE:
return hwc_get_handle_stride(hnd);
case ATT_FORMAT:
return hwc_get_handle_format(hnd);
case ATT_SIZE:
return hwc_get_handle_size(hnd);
case ATT_BYTE_STRIDE:
return hwc_get_handle_byte_stride(hnd);
default:
LOG_ALWAYS_FATAL("unexpected flag : %d", flag);
return -1;
}
#else // USE_GRALLOC_4
std::vector<int> attrs;
int ret=0;
if(!hnd)
{
ALOGE("%s handle is null",__FUNCTION__);
return -1;
}
ret = hwc_get_handle_attributes(hnd, &attrs);
if(ret < 0)
{
ALOGE("getHandleAttributes fail %d for:%s",ret,strerror(ret));
return ret;
}
else
{
return attrs.at(flag);
}
#endif
}
/*
@func getHandlePrimeFd:get prime_fd from handle.Before call this api,As far as now, we
need register the buffer first.May be the register is good for processer I think
@param hnd:
@return fd: prime_fd. and driver can call the dma_buf_get to get the buffer
*/
int hwc_get_handle_primefd(buffer_handle_t hnd)
{
#if USE_GRALLOC_4
int share_fd;
int err = gralloc4::get_share_fd(hnd, &share_fd);
if (err != android::OK)
{
ALOGE("Failed to get buffer share_fd, err : %d", err);
return -1;
}
return (int)share_fd;
#else // USE_GRALLOC_4
int ret = 0;
int op = GRALLOC_MODULE_PERFORM_GET_HADNLE_PRIME_FD;
int fd = -1;
if(gralloc && gralloc->perform)
ret = gralloc->perform(gralloc, op, hnd, &fd);
else
ret = -EINVAL;
if(ret != 0)
{
ALOGE("%s:cann't get value from gralloc", __FUNCTION__);
}
return fd;
#endif
}
}