-
Notifications
You must be signed in to change notification settings - Fork 4
/
rk_hwcomposer.cpp
executable file
·6300 lines (5610 loc) · 196 KB
/
rk_hwcomposer.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
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* rockchip hwcomposer( 2D graphic acceleration unit) .
*
* Copyright (C) 2015 Rockchip Electronics Co., Ltd.
*/
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include "rk_hwcomposer.h"
#include "version.h"
#include <hardware/hardware.h>
#include <sys/prctl.h>
#include <stdlib.h>
#include <errno.h>
#include <cutils/properties.h>
#include <fcntl.h>
#include <sync/sync.h>
#ifdef TARGET_BOARD_PLATFORM_RK30XXB
#include <hardware/hal_public.h>
#include <linux/fb.h>
#else
#include "gralloc_priv.h"
#endif
#include <time.h>
#include <poll.h>
#include "rk_hwcomposer_hdmi.h"
#include <ui/PixelFormat.h>
#include <sys/stat.h>
#include "hwc_ipp.h"
#include "hwc_rga.h"
#include <ui/PixelFormat.h>
#include "TVInfo.h"
#define MAX_DO_SPECIAL_COUNT 5
#define RK_FBIOSET_ROTATE 0x5003
#define FPS_NAME "com.aatt.fpsm"
#define BOTTOM_LAYER_NAME "NavigationBar"
#define TOP_LAYER_NAME "StatusBar"
#define WALLPAPER "ImageWallpaper"
#define INPUT "InputMethod"
#define PopWin "PopupWindow"
#define BOTTOM_LAYER_NAME1 "StatusBar"
#define USE_HWC_FENCE 1
#define RK_FBIOGET_DSP_ADDR 0x4630
#define RK_FBIOGET_DSP_FD 0x4630
#define RK_FBIOGET_LIST_STAT 0X4631
#define FB1_IOCTL_SET_YUV_ADDR 0x5002
#define RK_FBIOSET_DMABUF_FD 0x5004
#undef LOGV
#define LOGV(...)
static int SkipFrameCount = 0;
//static bool LastUseGpuCompose = false;
static hwcContext * gcontextAnchor[HWC_NUM_DISPLAY_TYPES] = {0};
static int skip_count = 0;
static int last_video_addr[2];
static char const* compositionModeName[] = {
"HWC_VOP",
"HWC_RGA",
"HWC_VOP_RGA",
"HWC_RGA_VOP",
"HWC_RGA_TRSM_VOP",
"HWC_RGA_TRSM_GPU_VOP",
"HWC_VOP_GPU",
"HWC_NODRAW_GPU_VOP",
"HWC_GPU_NODRAW_VOP",
"HWC_RGA_GPU_VOP",
"HWC_GPU_VOP",
"HWC_CP_FB",
"HWC_GPU",
};
static int hwc_blank(struct hwc_composer_device_1 *dev,int dpy,int blank);
static int hwc_query(struct hwc_composer_device_1* dev,int what,int* value);
static int hwc_event_control(struct hwc_composer_device_1* dev,int dpy,int event,int enabled);
static int hwc_prepare(hwc_composer_device_1_t * dev,size_t numDisplays,hwc_display_contents_1_t** displays);
static int hwc_set(hwc_composer_device_1_t * dev,size_t numDisplays,hwc_display_contents_1_t ** displays);
int hotplug_get_config(int flag);
int hotplug_set_config();
int hotplug_set_overscan(int flag);
int hotplug_reset_dstpos(struct rk_fb_win_cfg_data * fb_info,int flag);
void* hotplug_init_thread(void *arg);
void* hotplug_invalidate_refresh(void *arg);
int hotpulg_did_hdr_video(hwcContext *ctx,struct rk_fb_win_par *win_par, struct private_handle_t* src_handle);
static int hwc_device_close(struct hw_device_t * dev);
static int hwc_device_open(const struct hw_module_t * module,const char * name,struct hw_device_t ** device);
static int DetectValidData( hwcContext * context,int *data,int w,int h);
int getFbInfo(hwc_display_t dpy, hwc_surface_t surf, hwc_display_contents_1_t *list);
int init_tv_hdr_info(hwcContext *ctx)
{
int r = HdmiSupportedDataSpace();
ctx->hdrSupportType = r;
return 0;
}
int deinit_tv_hdr_info(hwcContext *ctx)
{
HdmiSetHDR(0);
HdmiSetColorimetry(HAL_DATASPACE_UNKNOWN);
ctx->hdrStatus = 0;
ctx->hdrFrameStatus = 0;
return 0;
}
static struct hw_module_methods_t hwc_module_methods =
{
open:
hwc_device_open
};
hwc_module_t HAL_MODULE_INFO_SYM =
{
common:
{
tag:
HARDWARE_MODULE_TAG,
version_major:
1,
version_minor:
2,
id:
HWC_HARDWARE_MODULE_ID,
name: "Hardware Composer Module"
,
author: "Rockchip Corporation"
,
methods:
&hwc_module_methods,
dso:
NULL,
reserved:
{
0,
}
}
};
void hwc_list_nodraw(hwc_display_contents_1_t *list)
{
if (list == NULL)
{
return;
}
for (unsigned int i = 0; i < list->numHwLayers - 1; i++)
{
list->hwLayers[i].compositionType = HWC_OVERLAY;
}
return;
}
//return property value of pcProperty
int hwc_get_int_property(const char* pcProperty, const char* default_value)
{
char value[PROPERTY_VALUE_MAX];
int new_value = 0;
if (pcProperty == NULL || default_value == NULL)
{
ALOGE("hwc_get_int_property: invalid param");
return -1;
}
property_get(pcProperty, value, default_value);
new_value = atoi(value);
return new_value;
}
static int hwc_get_string_property(const char* pcProperty, const char* default_value, char* retult)
{
if (pcProperty == NULL || default_value == NULL || retult == NULL)
{
ALOGE("hwc_get_string_property: invalid param");
return -1;
}
property_get(pcProperty, retult, default_value);
return 0;
}
void is_debug_log(void)
{
hwcContext * context = gcontextAnchor[HWC_DISPLAY_PRIMARY];
context->Is_debug = hwc_get_int_property("sys.hwc.log","0");
context->Is_noi = hwc_get_int_property("sys.hwc.noi","0");
}
int is_out_log( void )
{
hwcContext * context = gcontextAnchor[HWC_DISPLAY_PRIMARY];
return context->Is_debug;
}
bool is_suit_nodraw(hwc_layer_1_t * layer,hwcContext * context)
{
hwc_rect_t * DstRect = &layer->displayFrame;
hwc_region_t * Region = &layer->visibleRegionScreen;
int dst_width = DstRect->right - DstRect->left;
int dst_height = DstRect->bottom - DstRect->top;
int screen_area = context->fbWidth * context->fbHeight;
if(dst_height * dst_width < screen_area / 4)
return false;
if(Region->numRects > 1) return false;
return true;
}
bool is_not_suit_mix_policy(hwc_display_contents_1_t *list)
{
struct private_handle_t * handle = NULL;
hwc_layer_1_t * layer = NULL;
if (!list)
return true;
if (list->numHwLayers <= 0)
return true;
layer = &list->hwLayers[list->numHwLayers - 1];
if (layer)
handle = (struct private_handle_t *)layer->handle;
switch (handle && handle->format) {
case HAL_PIXEL_FORMAT_RGBA_8888:
case HAL_PIXEL_FORMAT_BGRA_8888:
return false;
default:
break;
}
return true;
}
bool is_same_rect(hwc_rect_t rs,hwc_rect_t ls)
{
bool res = true;
res &= rs.left == ls.left;
res &= rs.top == ls.top;
res &= rs.right == ls.right;
res &= rs.bottom == ls.bottom;
return res;
}
bool is_need_draw(hwcContext * context,hwc_display_contents_1_t *list,int index,int mode)
{
bool res = false;
hwc_rect_t * drest = NULL;
hwc_layer_1_t * layer = NULL;
struct private_handle_t * handle = NULL;
res = context->mLastStatus.ovleryLayer != index;
res = res || context->last_composer_mode != mode;
res = res || context->mLastStatus.numLayers != (int)(list->numHwLayers - 1);
LOGV("[%d,%d,%d]--[%d,%d,%d]",context->mLastStatus.ovleryLayer,context->last_composer_mode,
context->mLastStatus.numLayers,index,mode,list->numHwLayers - 1);
for(int i = 0;i < (int)(list->numHwLayers - 1);i++)
{
if(res) return res;
if(i == index) continue;
layer = &list->hwLayers[i];
drest = &layer->displayFrame;
handle = (struct private_handle_t *) layer->handle;
res = res || context->mLastStatus.fd[i] != ((handle != NULL) ? handle->share_fd:0);
res = res || context->mLastStatus.alpha[i] != (layer->blending) >> 16;
res = res || context->mLastStatus.drect[i].left != drest->left;
res = res || context->mLastStatus.drect[i].right != drest->right;
res = res || context->mLastStatus.drect[i].top != drest->top;
res = res || context->mLastStatus.drect[i].bottom != drest->bottom;
LOGV("I=%d,res=%d:[%d,%d,%d,%d,%d,%d],[%d,%d,%d,%d,%d,%d]",i,res,
context->mLastStatus.fd[i],context->mLastStatus.alpha[i],
context->mLastStatus.drect[i].left,context->mLastStatus.drect[i].right,
context->mLastStatus.drect[i].top,context->mLastStatus.drect[i].bottom,
(handle != NULL) ? handle->share_fd:0,
(layer->blending) >> 16,drest->left,drest->right,drest->top,drest->bottom );
}
return res;
}
bool is_displayframe_intersect(hwc_layer_1_t * rs,hwc_layer_1_t * ls)
{
bool xret = false;
bool yret = false;
hwc_rect_t * rDstRect = &rs->displayFrame;
hwc_rect_t * lDstRect = &ls->displayFrame;
xret = xret || (rDstRect->left >= lDstRect->left && rDstRect->left <= lDstRect->right);
LOGV("%d,%d",__LINE__,xret);
yret = yret || (rDstRect->top >= lDstRect->top && rDstRect->top <= lDstRect->bottom);
LOGV("%d,%d",__LINE__,yret);
xret = xret || (rDstRect->left <= lDstRect->left && rDstRect->right >= lDstRect->left);
LOGV("%d,%d",__LINE__,xret);
yret = yret || (rDstRect->top <= lDstRect->top && rDstRect->bottom >= lDstRect->top);
LOGV("%d,%d",__LINE__,yret);
LOGV("rs [%d,%d,%d,%d] ls[%d,%d,%d,%d]",rDstRect->left,rDstRect->top,rDstRect->right,rDstRect->bottom,
lDstRect->left,lDstRect->top,lDstRect->right,lDstRect->bottom);
return xret && yret;
}
int is_vop_yuv(int format)
{
int ret = 0;
switch(format){
case 0x20:
case 0x22:
ret = 1;
break;
default:
break;
}
return ret;
}
int type_of_android_format(int fmt)
{
//1:yuv,2:rgb
int ret = -1;
switch(fmt){
case HAL_PIXEL_FORMAT_YCrCb_NV12:
case HAL_PIXEL_FORMAT_YCrCb_NV12_VIDEO:
case HAL_PIXEL_FORMAT_YCrCb_NV12_10:
case HAL_PIXEL_FORMAT_YCbCr_422_SP:
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
case HAL_PIXEL_FORMAT_YCbCr_422_I:
case HAL_PIXEL_FORMAT_YCbCr_422_SP_10:
//case HAL_PIXEL_FORMAT_YCrCb_444_SP_10:
ret = 1;
break;
case HAL_PIXEL_FORMAT_RGBA_8888:
case HAL_PIXEL_FORMAT_RGBX_8888:
case HAL_PIXEL_FORMAT_RGB_888:
case HAL_PIXEL_FORMAT_RGB_565:
case HAL_PIXEL_FORMAT_BGRA_8888:
//case HAL_PIXEL_FORMAT_RGBA_5551:
//case HAL_PIXEL_FORMAT_RGBA_4444:
ret = 2;
break;
default:
ret = -1;
break;
}
return ret;
}
static int LayerZoneCheck(hwc_layer_1_t * Layer,hwcContext * Context)
{
hwc_region_t * Region = &(Layer->visibleRegionScreen);
hwc_rect_t const * rects = Region->rects;
hwc_rect_t * SrcRect = &Layer->sourceCrop;
hwc_rect_t * DstRect = &Layer->displayFrame;
hwc_rect_t rect_merge;
int left_min = 0;
int top_min = 0;
int right_max = 0;
int bottom_max = 0;
hwcRECT dstRects ;
hwcRECT srcRects ;
float hfactor = 1.0;
float vfactor = 1.0;
unsigned int i;
for (i = 0; i < (unsigned int) Region->numRects ;i++)
{
LOGV("checkzone=%s,[%d,%d,%d,%d]", \
Layer->LayerName, rects[i].left, rects[i].top, rects[i].right, rects[i].bottom);
if (rects[i].left < 0 || rects[i].top < 0
|| rects[i].right > Context->fbWidth
|| rects[i].bottom > Context->fbHeight)
{
return -1;
}
}
if(rects)
{
left_min = rects[0].left;
top_min = rects[0].top;
right_max = rects[0].right;
bottom_max = rects[0].bottom;
}
for (unsigned int r = 0; r < (unsigned int) Region->numRects ; r++)
{
int r_left;
int r_top;
int r_right;
int r_bottom;
r_left = hwcMAX(DstRect->left, rects[r].left);
left_min = hwcMIN(r_left,left_min);
r_top = hwcMAX(DstRect->top, rects[r].top);
top_min = hwcMIN(r_top,top_min);
r_right = hwcMIN(DstRect->right, rects[r].right);
right_max = hwcMAX(r_right,right_max);
r_bottom = hwcMIN(DstRect->bottom, rects[r].bottom);
bottom_max = hwcMAX(r_bottom,bottom_max);
}
rect_merge.left = left_min;
rect_merge.top = top_min;
rect_merge.right = right_max;
rect_merge.bottom = bottom_max;
dstRects.left = hwcMAX(DstRect->left, rect_merge.left);
dstRects.top = hwcMAX(DstRect->top, rect_merge.top);
dstRects.right = hwcMIN(DstRect->right, rect_merge.right);
dstRects.bottom = hwcMIN(DstRect->bottom, rect_merge.bottom);
if((dstRects.right - dstRects.left ) <= 2
|| (dstRects.bottom - dstRects.top) <= 2)
{
if(is_out_log())
ALOGW("zone is small ,LCDC can not support");
return -1;
}
hfactor = (float)(Layer->sourceCrop.right - Layer->sourceCrop.left)
/ (Layer->displayFrame.right - Layer->displayFrame.left);
vfactor = (float)(Layer->sourceCrop.bottom - Layer->sourceCrop.top)
/ (Layer->displayFrame.bottom - Layer->displayFrame.top);
srcRects.left = hwcMAX ((SrcRect->left \
- (int) ((DstRect->left - dstRects.left) * hfactor)),0);
srcRects.top = hwcMAX ((SrcRect->top \
- (int) ((DstRect->top - dstRects.top) * vfactor)),0);
srcRects.right = SrcRect->right \
- (int) ((DstRect->right - dstRects.right) * hfactor);
srcRects.bottom = SrcRect->bottom \
- (int) ((DstRect->bottom - dstRects.bottom) * vfactor);
if((srcRects.right - srcRects.left ) <= 16
|| (srcRects.bottom - srcRects.top) <= 16)
{
if(is_out_log())
ALOGW("source is too small ,LCDC can not support");
return -1;
}
hfactor = (float)(Layer->sourceCrop.right - Layer->sourceCrop.left)
/ (Layer->displayFrame.right - Layer->displayFrame.left);
vfactor = (float)(Layer->sourceCrop.bottom - Layer->sourceCrop.top)
/ (Layer->displayFrame.bottom - Layer->displayFrame.top);
if(hfactor >= 8 || hfactor <= 0.125 || vfactor >= 8 || vfactor <= 0.125)
{
if(is_out_log())
ALOGD("line=%d,scale over[%d,%d]",__LINE__,hfactor,vfactor);
return -1;
}
return 0;
}
int init_thread_pamaters(threadPamaters* mThreadPamaters)
{
if(mThreadPamaters) {
mThreadPamaters->count = 0;
pthread_mutex_init(&mThreadPamaters->mtx, NULL);
pthread_mutex_init(&mThreadPamaters->mlk, NULL);
pthread_cond_init(&mThreadPamaters->cond, NULL);
} else {
ALOGE("{%s}%d,mThreadPamaters is NULL",__FUNCTION__,__LINE__);
}
return 0;
}
int free_thread_pamaters(threadPamaters* mThreadPamaters)
{
if(mThreadPamaters) {
pthread_mutex_destroy(&mThreadPamaters->mtx);
pthread_mutex_destroy(&mThreadPamaters->mlk);
pthread_cond_destroy(&mThreadPamaters->cond);
} else {
ALOGE("{%s}%d,mThreadPamaters is NULL",__FUNCTION__,__LINE__);
}
return 0;
}
void dump_platform_info()
{
hwcContext * ctxp = gcontextAnchor[HWC_DISPLAY_PRIMARY];
hwcContext * ctxe = gcontextAnchor[HWC_DISPLAY_EXTERNAL];
if(ctxp && is_out_log() > 3)
ALOGI("Primary context:IsRk3188=%d,IsRk3126=%d,IsRk3128=%d,IsRk322x=%d,IsRkBox=%d",
ctxp->IsRk3188,ctxp->IsRk3126,ctxp->IsRk3128,ctxp->IsRk322x,ctxp->IsRkBox);
if(ctxp && ctxe && is_out_log() > 3)
ALOGI("Primary context:IsRk3188=%d,IsRk3126=%d,IsRk3128=%d,IsRk322x=%d,IsRkBox=%d",
ctxe->IsRk3188,ctxe->IsRk3126,ctxe->IsRk3128,ctxe->IsRk322x,ctxe->IsRkBox);
return;
}
void sort_fbinfo_by_winid(struct rk_fb_win_cfg_data* fb_info)
{
struct rk_fb_win_cfg_data fbinfo;
memcpy((void*)&fbinfo,(void*)fb_info,sizeof(struct rk_fb_win_cfg_data));
for(int i = 0;i<4;i++)
{
for(int j=0;j<4;j++)
{
if(fb_info->win_par[i].area_par[j].ion_fd || fb_info->win_par[i].area_par[j].phy_addr)
{
int win_id = fb_info->win_par[i].win_id;
memcpy(&(fbinfo.win_par[win_id]),&(fb_info->win_par[i]),sizeof(struct rk_fb_win_par));
}
}
}
memcpy((void*)fb_info,(void*)&fbinfo,sizeof(struct rk_fb_win_cfg_data));
return;
}
void dump_config_info(hwcContext * context,struct rk_fb_win_cfg_data fb_info)
{
for(int i = 0;i<4;i++)
{
for(int j=0;j<4;j++)
{
if(fb_info.win_par[i].area_par[j].ion_fd || fb_info.win_par[i].area_par[j].phy_addr)
{
if(is_out_log())
ALOGD("%s,par[%d],area[%d],z_win_galp[%d,%d,%x],[%d,%d,%d,%d]=>[%d,%d,%d,%d],w_h_f[%d,%d,%d],acq_fence_fd=%d,fd=%d,addr=%x",
context == gcontextAnchor[0] ? "primary:" : "external:",
i,j,
fb_info.win_par[i].z_order,
fb_info.win_par[i].win_id,
fb_info.win_par[i].g_alpha_val,
fb_info.win_par[i].area_par[j].x_offset,
fb_info.win_par[i].area_par[j].y_offset,
fb_info.win_par[i].area_par[j].xact,
fb_info.win_par[i].area_par[j].yact,
fb_info.win_par[i].area_par[j].xpos,
fb_info.win_par[i].area_par[j].ypos,
fb_info.win_par[i].area_par[j].xsize,
fb_info.win_par[i].area_par[j].ysize,
fb_info.win_par[i].area_par[j].xvir,
fb_info.win_par[i].area_par[j].yvir,
fb_info.win_par[i].area_par[j].data_format,
fb_info.win_par[i].area_par[j].acq_fence_fd,
fb_info.win_par[i].area_par[j].ion_fd,
fb_info.win_par[i].area_par[j].phy_addr);
}
}
}
return;
}
void handle_gpu_nodraw_optimazation(hwcContext* ctx,hwc_display_contents_1_t *list,int index,int mode)
{
unsigned int i ;
hwc_rect_t * drest = NULL;
int relOverlayLayer = index;
hwc_layer_1_t * layer = NULL;
struct private_handle_t * handle = NULL;
if(is_need_draw(ctx,list,relOverlayLayer,mode))
{
for (i = 0; i < (list->numHwLayers - 1); i++)
{
layer = &list->hwLayers[i];
if((int)i == relOverlayLayer)
continue;
else
{
layer->compositionType = HWC_FRAMEBUFFER;
drest = &layer->displayFrame;
handle = (struct private_handle_t *)layer->handle;
ctx->mLastStatus.fd[i] = handle?handle->share_fd:0;
ctx->mLastStatus.alpha[i] = (layer->blending) >> 16;
ctx->mLastStatus.drect[i].left = drest->left;
ctx->mLastStatus.drect[i].right = drest->right;
ctx->mLastStatus.drect[i].top = drest->top;
ctx->mLastStatus.drect[i].bottom = drest->bottom;
}
}
ctx->mLastStatus.ovleryLayer = relOverlayLayer;
ctx->mLastStatus.numLayers = list->numHwLayers - 1;
}
else
{
for (i = 0; i < (list->numHwLayers - 1); i++)
{
layer = &list->hwLayers[i];
if((int)i == relOverlayLayer)
continue;
else
layer->compositionType = HWC_NODRAW;
}
}
return;
}
int is_need_stereo(hwcContext* ctx, hwc_display_contents_1_t *list)
{
if(!ctx || !list)
return -1;
int needStereo = 0;
unsigned int numlayer = list->numHwLayers;
ctx->isStereo = 0;
for (unsigned int j = 0; j <(numlayer - 1); j++)
{
if(list->hwLayers[j].alreadyStereo)
{
needStereo = list->hwLayers[j].alreadyStereo;
break;
}
}
if (needStereo)
{
ctx->isStereo = needStereo;
for (unsigned int j = 0; j <(numlayer - 1); j++)
list->hwLayers[j].displayStereo = needStereo;
}
else
{
for (unsigned int j = 0; j <(numlayer - 1); j++)
list->hwLayers[j].displayStereo = needStereo;
}
return 0;
}
bool is_screen_changed(hwcContext* ctx, int dpyId)
{
if (!ctx)
return false;
if (ctx->dpyAttr[dpyId].xres != ctx->dpyAttr[dpyId].relxres) {
ctx->mScreenChanged = true;
return true;
}
if (ctx->dpyAttr[dpyId].yres != ctx->dpyAttr[dpyId].relyres) {
ctx->mScreenChanged = true;
return true;
}
return false;
}
bool is_boot_skip_platform(hwcContext * context)
{
bool skipPlatform = false;
skipPlatform = skipPlatform || context->IsRk3126;
skipPlatform = skipPlatform || context->IsRk3128;
skipPlatform = skipPlatform || (context->IsRk322x && !context->IsRk3328);
skipPlatform = skipPlatform || context->IsRk3036;
return skipPlatform;
}
void hwc_sync(hwc_display_contents_1_t *list)
{
if (list == NULL)
{
return ;
}
for (unsigned int i = 0; i < list->numHwLayers; i++)
{
if (list->hwLayers[i].acquireFenceFd > 0)
{
// if( i == 1)
// ALOGD("hwc_sync,name=%s",list->hwLayers[i].LayerName);
sync_wait(list->hwLayers[i].acquireFenceFd, 500);
ALOGV("fenceFd=%d,name=%s", list->hwLayers[i].acquireFenceFd, list->hwLayers[i].LayerName);
}
}
}
void hwc_sync_release(hwc_display_contents_1_t *list)
{
for (unsigned int i = 0; i < list->numHwLayers; i++)
{
hwc_layer_1_t* layer = &list->hwLayers[i];
if (layer == NULL)
{
return ;
}
if (layer->acquireFenceFd > 0)
{
ALOGV(">>>close acquireFenceFd:%d,layername=%s", layer->acquireFenceFd, layer->LayerName);
close(layer->acquireFenceFd);
list->hwLayers[i].acquireFenceFd = -1;
}
}
if (list->outbufAcquireFenceFd > 0)
{
ALOGV(">>>close outbufAcquireFenceFd:%d", list->outbufAcquireFenceFd);
close(list->outbufAcquireFenceFd);
list->outbufAcquireFenceFd = -1;
}
}
//static PFNEGLGETRENDERBUFFERANDROIDPROC _eglGetRenderBufferANDROID;
#ifndef TARGET_BOARD_PLATFORM_RK30XXB
//static PFNEGLRENDERBUFFERMODIFYEDANDROIDPROC _eglRenderBufferModifiedANDROID;
#endif
/*****************************************************************************/
#if hwcDEBUG
static void
_Dump(
hwc_display_contents_1_t* list
)
{
size_t i, j;
for (i = 0; list && (i < (list->numHwLayers - 1)); i++)
{
hwc_layer_1_t const * l = &list->hwLayers[i];
if (l->flags & HWC_SKIP_LAYER)
{
LOGD("layer %p skipped", l);
}
else
{
LOGD("layer=%p, "
"layer name=%s, "
"type=%d, "
"hints=%08x, "
"flags=%08x, "
"handle=%p, "
"tr=%02x, "
"blend=%04x, "
"{%d,%d,%d,%d}, "
"{%d,%d,%d,%d}",
l,
l->LayerName,
l->compositionType,
l->hints,
l->flags,
l->handle,
l->transform,
l->blending,
l->sourceCrop.left,
l->sourceCrop.top,
l->sourceCrop.right,
l->sourceCrop.bottom,
l->displayFrame.left,
l->displayFrame.top,
l->displayFrame.right,
l->displayFrame.bottom);
for (j = 0; j < l->visibleRegionScreen.numRects; j++)
{
LOGD("\trect%d: {%d,%d,%d,%d}", j,
l->visibleRegionScreen.rects[j].left,
l->visibleRegionScreen.rects[j].top,
l->visibleRegionScreen.rects[j].right,
l->visibleRegionScreen.rects[j].bottom);
}
}
}
}
#endif
void sync_fbinfo_fence(struct rk_fb_win_cfg_data* fb_info)
{
struct rk_fb_win_cfg_data fbinfo;
for(int i = 0;i<4;i++)
{
for(int j=0;j<4;j++)
{
if(fb_info->win_par[i].area_par[j].ion_fd || fb_info->win_par[i].area_par[j].phy_addr)
{
if(fb_info->win_par[i].area_par[j].acq_fence_fd > -1)
{
sync_wait(fb_info->win_par[i].area_par[j].acq_fence_fd,500);
fb_info->win_par[i].area_par[j].acq_fence_fd = -1;
if(is_out_log()) ALOGD("Sync fbinfo fence i=%d",i);
}
}
}
}
return;
}
int hwc_reset_fb_info(struct rk_fb_win_cfg_data *fb_info, hwcContext * context)
{
bool interleaveForVop = false;
float hfactor;
int scale = 1;
int ionFd, phy_addr;
int xact, yact, xsize, ysize, yvir, format;
int relxres, relyres, vsync_priod;
if (!context && context->Is_noi)
return -EINVAL;
#if 1
for (int i = 0; i < 4; i++) {
for (int j= 0; j < 4; j++) {
xact = fb_info->win_par[i].area_par[j].xact;
yact = fb_info->win_par[i].area_par[j].yact;
yvir = fb_info->win_par[i].area_par[j].yvir;
xsize = fb_info->win_par[i].area_par[j].xsize;
ysize = fb_info->win_par[i].area_par[j].ysize;
format = fb_info->win_par[i].area_par[j].data_format;
ionFd = fb_info->win_par[i].area_par[j].ion_fd;
phy_addr = fb_info->win_par[i].area_par[j].phy_addr;
hfactor = (float)ysize / (float)yact;
vsync_priod = context->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period;
relxres = context->dpyAttr[HWC_DISPLAY_PRIMARY].relxres;
relyres = context->dpyAttr[HWC_DISPLAY_PRIMARY].relyres;
interleaveForVop = ionFd || phy_addr;
interleaveForVop = interleaveForVop && is_vop_yuv(format);
interleaveForVop = interleaveForVop && (xact > MaxIForVop || yact > MaxIForVop);
interleaveForVop = interleaveForVop && (hfactor <= 0.95);
interleaveForVop = interleaveForVop && vsync_priod >= 50 && relxres >= 3840;
if (is_out_log())
ALOGD("[%d,%d]=>[%d,%d][%d,%d,%d]", xact,yact,xsize,ysize,relxres,relyres,vsync_priod);
if (is_out_log() && (yvir % 2) && interleaveForVop)
ALOGW("We need interleave for vop but yvir is not align to 2");
interleaveForVop = interleaveForVop && (yvir % 2 == 0);
if (interleaveForVop) {
fb_info->win_par[i].area_par[j].xvir *= 2;
fb_info->win_par[i].area_par[j].yvir /= 2;
fb_info->win_par[i].area_par[j].yact /= 2;
}
}
}
#else
scale = hwc_get_int_property("sys.wzq.test", "1");
for (int i = 0; i < 4; i++) {
for (int j= 0; j < 4; j++) {
if(fb_info->win_par[i].area_par[j].ion_fd ||
fb_info->win_par[i].area_par[j].phy_addr) {
fb_info->win_par[i].area_par[j].xact /= scale;
fb_info->win_par[i].area_par[j].yact /= scale;
fb_info->win_par[i].area_par[j].xsize /= scale;
fb_info->win_par[i].area_par[j].ysize /= scale;
}
}
}
#endif
return 0;
}
#if hwcDumpSurface
static void
_DumpSurface(
hwc_display_contents_1_t* list
)
{
size_t i;
static int DumpSurfaceCount = 0;
char pro_value[PROPERTY_VALUE_MAX];
property_get("sys.dump", pro_value, 0);
//LOGI(" sys.dump value :%s",pro_value);
if (!strcmp(pro_value, "true"))
{
for (i = 0; list && (i < (list->numHwLayers - 1)); i++)
{
hwc_layer_1_t const * l = &list->hwLayers[i];
if (l->flags & HWC_SKIP_LAYER)
{
LOGI("layer %p skipped", l);
}
else
{
struct private_handle_t * handle_pre = (struct private_handle_t *) l->handle;
int32_t SrcStride ;
int div = 1;
FILE * pfile = NULL;
char layername[100] ;
if (handle_pre == NULL)
continue;
if(handle_pre->format == HAL_PIXEL_FORMAT_YCrCb_NV12 )
{
SrcStride = 3;
div = 2;
}
else
SrcStride = android::bytesPerPixel(handle_pre->format);
memset(layername, 0, sizeof(layername));
system("mkdir /data/dump/ && chmod /data/dump/ 777 ");
//mkdir( "/data/dump/",777);
#ifndef TARGET_BOARD_PLATFORM_RK30XXB
sprintf(layername, "/data/dump/dmlayer%d_%d_%d_%d.bin", DumpSurfaceCount, handle_pre->stride, handle_pre->height, SrcStride);
#else
sprintf(layername, "/data/dump/dmlayer%d_%d_%d_%d.bin", DumpSurfaceCount, handle_pre->width, handle_pre->height, SrcStride);
#endif
DumpSurfaceCount ++;
pfile = fopen(layername, "wb");
if (pfile)
{
#ifndef TARGET_BOARD_PLATFORM_RK30XXB
fwrite((const void *)handle_pre->base, (size_t)(SrcStride * handle_pre->stride*handle_pre->height/div), 1, pfile);
#else
fwrite((const void *)handle_pre->iBase, (size_t)(SrcStride * handle_pre->width*handle_pre->height/div), 1, pfile);
#endif
fclose(pfile);
LOGI(" dump surface layername %s,w:%d,h:%d,formatsize :%d", layername, handle_pre->width, handle_pre->height, SrcStride);
}
}
}
}
property_set("sys.dump", "false");
}
#endif
void
hwcDumpArea(
IN hwcArea * Area
)
{
hwcArea * area = Area;
while (area != NULL)
{
char buf[128];
char digit[8];
bool first = true;
sprintf(buf,
"Area[%d,%d,%d,%d] owners=%08x:",
area->rect.left,
area->rect.top,
area->rect.right,
area->rect.bottom,
area->owners);
for (int i = 0; i < 32; i++)
{
/* Build decimal layer indices. */
if (area->owners & (1U << i))
{
if (first)
{
sprintf(digit, " %d", i);
strcat(buf, digit);
first = false;
}
else
{
sprintf(digit, ",%d", i);
strcat(buf, digit);
}
}
if ((unsigned int)area->owners < (1U << i))
{
break;
}
}
LOGD("%s", buf);
/* Advance to next area. */
area = area->next;
}
}
uint32_t hwc_get_vsync_period_from_fb_fps(int fbindex)
{
const char node[] = "/sys/class/graphics/fb%u/fps";
char nodeName[100] = {0};
char value[100] = {0};
int fps = 0;