-
Notifications
You must be signed in to change notification settings - Fork 4
/
rk_hwc_com.cpp
executable file
·734 lines (582 loc) · 16.7 KB
/
rk_hwc_com.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
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
/*
* rockchip hwcomposer( 2D graphic acceleration unit) .
*
* Copyright (C) 2015 Rockchip Electronics Co., Ltd.
*/
#include "rk_hwcomposer.h"
#ifdef TARGET_BOARD_PLATFORM_RK30XXB
#include <hardware/hal_public.h>
#else
#include "gralloc_priv.h"
#endif
#include <linux/fb.h>
#include <linux/fs.h>
#include <sys/ioctl.h>
//#include <linux/android_pmem.h>
#include <ui/PixelFormat.h>
#include <fcntl.h>
hwcSTATUS
hwcGetBufferInfo(
hwcContext * Context,
struct private_handle_t * Handle,
void * * Logical,
unsigned int * Physical,
unsigned int * Width,
unsigned int * Height,
unsigned int * Stride,
void * * Info
)
{
hwcSTATUS status = hwcSTATUS_OK;
unsigned int width;
unsigned int height;
unsigned int stride;
struct private_handle_t * handle = Handle;
#ifndef TARGET_BOARD_PLATFORM_RK30XXB
stride = Handle->stride;
#else
stride = rkmALIGN(GPU_WIDTH,32);
#endif
width = GPU_WIDTH ;
height = GPU_HEIGHT;
//LOGD(" Handle->width=%d,width=%d",Handle->width,width);
//LOGD("hwcGetBufferInfo width=%d,Handle->format=%x,bytesPerPixel=%d,stride=%d",width,Handle->format,android::bytesPerPixel(Handle->format),stride);
{
#ifndef TARGET_BOARD_PLATFORM_RK30XXB
if (Handle->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)
#else
if (Handle->usage & GRALLOC_USAGE_HW_FB)
#endif
{
/* Framebuffer. */
if (Context->fbFd == 0)
{
struct fb_fix_screeninfo fixInfo;
#ifndef TARGET_BOARD_PLATFORM_RK30XXB
int rel = ioctl(Handle->fd, FBIOGET_FSCREENINFO, &fixInfo);
#else
int iFbFd;
iFbFd = open("/dev/graphics/fb0", O_RDWR, 0);
if (!iFbFd)
{
LOGE("open(dev/graphics/fb0) failed in %s", __func__);
return hwcSTATUS_IO_ERR;
}
int rel = ioctl(iFbFd, FBIOGET_FSCREENINFO, &fixInfo);
#endif
if (rel != 0)
{
LOGE("ioctl(fd, FBIOGET_FSCREENINFO) failed"
" in %s, fd=%d", __func__, Handle->fd);
return hwcSTATUS_IO_ERR;
}
#ifndef TARGET_BOARD_PLATFORM_RK30XXB
Context->fbFd = Handle->fd;
#else
Context->fbFd = iFbFd;
#endif
Context->fbPhysical = fixInfo.smem_start;
Context->fbStride = fixInfo.line_length;
}
#ifndef TARGET_BOARD_PLATFORM_RK30XXB
*Logical = (void *) GPU_BASE;
#else
*Logical = (void *) GPU_BASE;
#endif
#ifndef USE_LCDC_COMPOSER
#ifndef ONLY_USE_FB_BUFFERS
*Physical = Context->membk_fds[Context->membk_index];
#else
*Physical = Context->mFbFd;
#endif
#else
*Physical = Context->mFbFd;/*(unsigned int) (Context->fbPhysical + Handle->offset)
- Context->baseAddress;*/
#endif
*Width = rkmALIGN(Context->fbWidth,32);
*Height = Context->fbHeight;
*Stride = Context->fbStride;
*Info = NULL;
}
else //if (Handle->flags & private_handle_t::PRIV_FLAGS_USES_UMP)
{
/* PMEM type. */
#if 0
struct pmem_region region;
//if (Context->pmemPhysical == ~0U)
{
/* ASSUME: PMEM physical address is constant.
* PMEM physical address must be constant for PMEM pool,
* unless multiple PMEM devices are used. */
if (ioctl(Handle->fd, PMEM_GET_PHYS, ®ion) != 0)
{
LOGE("Get PMEM physical address failed: fd=%d", Handle->fd);
return hwcSTATUS_IO_ERR;
}
Context->pmemPhysical = region.offset;
Context->pmemLength = region.len;
}
#endif
/* Try lock handle once. */
#ifndef TARGET_BOARD_PLATFORM_RK30XXB
*Logical = (void *) GPU_BASE;
#else
const gralloc_module_t * module;
void * vaddr = NULL;
if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
(const hw_module_t **) &module) != 0)
{
return hwcSTATUS_IO_ERR;
}
module->lock(module,
(buffer_handle_t)Handle,
GRALLOC_USAGE_SW_READ_OFTEN,
0, 0, width, height,
&vaddr);
module->unlock(module, (buffer_handle_t)Handle);
*Logical = (void *) GPU_BASE;
#endif
#ifdef USE_LCDC_COMPOSER
*Physical = Handle->phy_addr;//Context->fbPhysical;//Handle->phy_addr; ; // debug
#else
*Physical = 0;
#endif
*Width = width;
*Height = height;
*Stride = stride;
*Info = NULL;
/* Flush cache. */
if(GPU_FORMAT == HAL_PIXEL_FORMAT_YCrCb_NV12_VIDEO)
{
#ifndef TARGET_BOARD_PLATFORM_RK30XXB
tVPU_FRAME *pFrame = (tVPU_FRAME *)Handle->base;
stride = 1 * (rkmALIGN(width,16));//((width + 15) & ~15);
#else
tVPU_FRAME *pFrame = (tVPU_FRAME *)Handle->iBase;
#if 0
stride = rkmALIGN(pFrame->FrameWidth,16) ;
#else
stride = pFrame->FrameWidth;
#endif
#endif
#if 0
*Height = rkmALIGN(pFrame->FrameHeight,16);
*Width = rkmALIGN(pFrame->FrameWidth,16);
#else
*Height = pFrame->FrameHeight;
*Width = pFrame->FrameWidth;
#endif
*Physical = pFrame->FrameBusAddr[0];
*Info = NULL;
*Stride = stride;
ALOGV("hwcGetBufferInfo:video info phy_addr=%p,w=%d,h=%d",pFrame->FrameBusAddr[0],*Width,*Height);
}
}
}
return status;
}
/*******************************************************************************
**
** YUV pixel formats of android hal.
**
** Different android versions have different definitaions.
** These are collected from hardware/libhardware/include/hardware/hardware.h
*/
hwcSTATUS
hwcGetBufFormat(
struct private_handle_t * Handle,
RgaSURF_FORMAT * Format
)
{
struct private_handle_t *handle = Handle;
if (Format != NULL)
{
switch (GPU_FORMAT)
{
case HAL_PIXEL_FORMAT_RGB_565:
*Format = RK_FORMAT_RGB_565;
break;
case HAL_PIXEL_FORMAT_RGBA_8888:
*Format = RK_FORMAT_RGBA_8888;
break;
case HAL_PIXEL_FORMAT_RGBX_8888:
*Format = RK_FORMAT_RGBX_8888;
break;
case HAL_PIXEL_FORMAT_BGRA_8888:
*Format = RK_FORMAT_BGRA_8888;
break;
case HAL_PIXEL_FORMAT_YCrCb_NV12:
/* YUV 420 semi planner: NV12 */
*Format = RK_FORMAT_YCbCr_420_SP;
break;
case HAL_PIXEL_FORMAT_YCrCb_420_SP: // NV21
*Format = RK_FORMAT_YCrCb_420_SP;
break;
case HAL_PIXEL_FORMAT_YCrCb_NV12_VIDEO:
*Format = RK_FORMAT_YCbCr_420_SP;
break;
default:
return hwcSTATUS_INVALID_ARGUMENT;
}
}
return hwcSTATUS_OK;
}
#if ENABLE_HWC_WORMHOLE
/*
* Area spliting feature depends on the following 3 functions:
* '_AllocateArea', '_FreeArea' and '_SplitArea'.
*/
#define MEM_SIZE 512
hwcArea *
zone_alloc(
hwcContext * Context,
hwcArea * Slibing,
hwcRECT * Rect,
int Owner
)
{
hwcArea * area;
hwcAreaPool * pool = &Context->areaMem;
while(true)
{
if (pool->areas == NULL)
{
/* No areas allocated, allocate now. */
pool->areas = (hwcArea *) malloc(sizeof (hwcArea) * MEM_SIZE);
/* Get area. */
area = pool->areas;
/* Update freeNodes. */
pool->freeNodes = area + 1;
break;
}
else if (pool->freeNodes - pool->areas >= MEM_SIZE)
{
/* This pool is full. */
if (pool->next == NULL)
{
pool->next = (hwcAreaPool *) malloc(sizeof (hwcAreaPool));
pool = pool->next;
pool->areas = NULL;
pool->freeNodes = NULL;
pool->next = NULL;
}
else
{
pool = pool->next;
}
}
else
{
area = pool->freeNodes++;
break;
}
}
area->rect = *Rect;
area->owners = Owner;
//LOGD("area->rect.left=%d,top=%d,right=%d,bottom=%d,area->owners=%d",area->rect.left,area->rect.top,area->rect.right,area->rect.bottom,area->owners);
if (Slibing == NULL)
{
area->next = NULL;
}
else if (Slibing->next == NULL)
{
area->next = NULL;
Slibing->next = area;
}
else
{
area->next = Slibing->next;
Slibing->next = area;
}
return area;
}
void
ZoneFree(
hwcContext * Context,
hwcArea* Head
)
{
hwcAreaPool * pool = &Context->areaMem;
while (pool != NULL)
{
if (Head >= pool->areas && Head < pool->areas + MEM_SIZE)
{
if (Head < pool->freeNodes)
{
pool->freeNodes = Head;
while (pool->next != NULL)
{
pool = pool->next;
pool->freeNodes = pool->areas;
}
}
break;
}
else if (pool->freeNodes < pool->areas + MEM_SIZE)
{
break;
}
else
{
pool = pool->next;
}
}
}
void
DivArea(
hwcContext * Context,
hwcArea * Area,
hwcRECT * Rect,
int Owner
)
{
hwcRECT r0[4];
hwcRECT r1[4];
int i = 0;
int j = 0;
hwcRECT * rect;
while (true)
{
rect = &Area->rect;
if ((Rect->left < rect->right)
&& (Rect->top < rect->bottom)
&& (Rect->right > rect->left)
&& (Rect->bottom > rect->top)
)
{
/* Overlapped. */
break;
}
if (Area->next == NULL)
{
/* This rectangle is not overlapped with any area. */
zone_alloc(Context, Area, Rect, Owner);
return;
}
Area = Area->next;
}
if ((Rect->left <= rect->left)
&& (Rect->right >= rect->right)
)
{
if (Rect->left < rect->left)
{
r1[j].left = Rect->left;
r1[j].top = Rect->top;
r1[j].right = rect->left;
r1[j].bottom = Rect->bottom;
j++;
}
if (Rect->top < rect->top)
{
r1[j].left = rect->left;
r1[j].top = Rect->top;
r1[j].right = rect->right;
r1[j].bottom = rect->top;
j++;
}
else if (rect->top < Rect->top)
{
r0[i].left = rect->left;
r0[i].top = rect->top;
r0[i].right = rect->right;
r0[i].bottom = Rect->top;
i++;
}
if (Rect->right > rect->right)
{
r1[j].left = rect->right;
r1[j].top = Rect->top;
r1[j].right = Rect->right;
r1[j].bottom = Rect->bottom;
j++;
}
if (Rect->bottom > rect->bottom)
{
r1[j].left = rect->left;
r1[j].top = rect->bottom;
r1[j].right = rect->right;
r1[j].bottom = Rect->bottom;
j++;
}
else if (rect->bottom > Rect->bottom)
{
r0[i].left = rect->left;
r0[i].top = Rect->bottom;
r0[i].right = rect->right;
r0[i].bottom = rect->bottom;
i++;
}
}
else if (Rect->left <= rect->left)
{
if (Rect->left < rect->left)
{
r1[j].left = Rect->left;
r1[j].top = Rect->top;
r1[j].right = rect->left;
r1[j].bottom = Rect->bottom;
j++;
}
if (Rect->top < rect->top)
{
r1[j].left = rect->left;
r1[j].top = Rect->top;
r1[j].right = Rect->right;
r1[j].bottom = rect->top;
j++;
}
else if (rect->top < Rect->top)
{
r0[i].left = rect->left;
r0[i].top = rect->top;
r0[i].right = Rect->right;
r0[i].bottom = Rect->top;
i++;
}
r0[i].left = Rect->right;
r0[i].top = rect->top;
r0[i].right = rect->right;
r0[i].bottom = rect->bottom;
i++;
if (Rect->bottom > rect->bottom)
{
r1[j].left = rect->left;
r1[j].top = rect->bottom;
r1[j].right = Rect->right;
r1[j].bottom = Rect->bottom;
j++;
}
else if (rect->bottom > Rect->bottom)
{
r0[i].left = rect->left;
r0[i].top = Rect->bottom;
r0[i].right = Rect->right;
r0[i].bottom = rect->bottom;
i++;
}
}
else if (Rect->right >= rect->right)
{
r0[i].left = rect->left;
r0[i].top = rect->top;
r0[i].right = Rect->left;
r0[i].bottom = rect->bottom;
i++;
if (Rect->top < rect->top)
{
r1[j].left = Rect->left;
r1[j].top = Rect->top;
r1[j].right = rect->right;
r1[j].bottom = rect->top;
j++;
}
else if (rect->top < Rect->top)
{
r0[i].left = Rect->left;
r0[i].top = rect->top;
r0[i].right = rect->right;
r0[i].bottom = Rect->top;
i++;
}
if (Rect->right > rect->right)
{
r1[j].left = rect->right;
r1[j].top = Rect->top;
r1[j].right = Rect->right;
r1[j].bottom = Rect->bottom;
j++;
}
if (Rect->bottom > rect->bottom)
{
r1[j].left = Rect->left;
r1[j].top = rect->bottom;
r1[j].right = rect->right;
r1[j].bottom = Rect->bottom;
j++;
}
else if (rect->bottom > Rect->bottom)
{
r0[i].left = Rect->left;
r0[i].top = Rect->bottom;
r0[i].right = rect->right;
r0[i].bottom = rect->bottom;
i++;
}
}
else
{
r0[i].left = rect->left;
r0[i].top = rect->top;
r0[i].right = Rect->left;
r0[i].bottom = rect->bottom;
i++;
if (Rect->top < rect->top)
{
r1[j].left = Rect->left;
r1[j].top = Rect->top;
r1[j].right = Rect->right;
r1[j].bottom = rect->top;
j++;
}
else if (rect->top < Rect->top)
{
r0[i].left = Rect->left;
r0[i].top = rect->top;
r0[i].right = Rect->right;
r0[i].bottom = Rect->top;
i++;
}
r0[i].left = Rect->right;
r0[i].top = rect->top;
r0[i].right = rect->right;
r0[i].bottom = rect->bottom;
i++;
if (Rect->bottom > rect->bottom)
{
r1[j].left = Rect->left;
r1[j].top = rect->bottom;
r1[j].right = Rect->right;
r1[j].bottom = Rect->bottom;
j++;
}
else if (rect->bottom > Rect->bottom)
{
r0[i].left = Rect->left;
r0[i].top = Rect->bottom;
r0[i].right = Rect->right;
r0[i].bottom = rect->bottom;
i++;
}
}
if (j > 0)
{
if (Area->next == NULL)
{
for (int k = 0; k < j; k++)
{
zone_alloc(Context, Area, &r1[k], Owner);
}
}
else
{
for (int k = 0; k < j; k++)
{
DivArea(Context, Area, &r1[k], Owner);
}
}
}
if (i > 0)
{
for (int k = 0; k < i; k++)
{
zone_alloc(Context, Area, &r0[k], Area->owners);
}
if (rect->left < Rect->left) { rect->left = Rect->left; }
if (rect->top < Rect->top) { rect->top = Rect->top; }
if (rect->right > Rect->right) { rect->right = Rect->right; }
if (rect->bottom > Rect->bottom) { rect->bottom = Rect->bottom; }
}
Area->owners |= Owner;
}
#endif