-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrk_hwcomposer_hdmi.cpp
executable file
·148 lines (132 loc) · 3.32 KB
/
rk_hwcomposer_hdmi.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
/*
* rockchip hwcomposer( 2D graphic acceleration unit) .
*
* Copyright (C) 2015 Rockchip Electronics Co., Ltd.
*/
#include <sys/prctl.h>
#include "rk_hwcomposer_hdmi.h"
#include <errno.h>
#include <malloc.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <poll.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <cutils/log.h>
#include <cutils/properties.h>
#include <hardware_legacy/uevent.h>
#include <hardware/hwcomposer.h>
int g_hdmi_mode;
void rk_parse_uevent_buf(const char *buf,int* type,int* flag,int* fbx, int len)
{
const char *str = buf;
while(*str){
sscanf(str,"SCREEN=%d,ENABLE=%d",type,flag);
sscanf(str,"FBDEV=%d",fbx);
str += strlen(str) + 1;
if (str - buf >= len){
break;
}
//ALOGI("line %d,buf[%s]",__LINE__,str);
}
ALOGI("SCREEN=%d ENABLE=%d,",*type,*flag);
}
void rk_check_hdmi_state()
{
//int fd = open("/sys/devices/virtual/switch/hdmi/state", O_RDONLY);
int fd = open("/sys/devices/virtual/display/HDMI/connect", O_RDONLY);
if (fd > 0)
{
char statebuf[100];
memset(statebuf, 0, sizeof(statebuf));
int err = read(fd, statebuf, sizeof(statebuf));
if (err < 0)
{
ALOGE("error reading vsync timestamp: %s", strerror(errno));
return;
}
close(fd);
g_hdmi_mode = atoi(statebuf);
/* if (g_hdmi_mode==0)
{
property_set("sys.hdmi.mode", "0");
}
else
{
property_set("sys.hdmi.mode", "1");
}*/
}
else
{
ALOGD("err=%s", strerror(errno));
}
}
//0,1,2
void rk_check_hdmi_uevents(const char *buf,int len)
{
//ALOGI("fun[%s],line[%d],buf is [%s]",__FUNCTION__,__LINE__,buf);
#ifdef USE_X86
if(!strcmp(buf, "change@/devices/soc0/e0000000.noc/ef010000.l2_noc/e1000000.ahb_per/vop0"))
#else
#ifdef RK322X_BOX
if (strstr(buf, "change@/devices/vop"))
#else
if (!strcmp(buf, "change@/devices/virtual/display/HDMI"))
#endif
#endif
{
int type,flag,fbx;
type = flag = fbx = -1;
rk_check_hdmi_state();
rk_parse_uevent_buf(buf,&type,&flag,&fbx,len);
#ifdef USE_X86
if(type == -1 && flag == -1)
handle_hotplug_event(g_hdmi_mode,1);
else
#endif
#ifdef RK322X_BOX
handle_hotplug_event(flag,0);
#else
handle_hotplug_event(g_hdmi_mode,0);
#endif
}
}
void rk_handle_uevents(const char *buff,int len)
{
// uint64_t timestamp = 0;
rk_check_hdmi_uevents(buff,len);
}
void *rk_hwc_hdmi_thread(void *arg)
{
static char uevent_desc[4096];
struct pollfd fds[1];
int timeout;
int err;
prctl(PR_SET_NAME,"HWC_htg");
HWC_UNREFERENCED_PARAMETER(arg);
uevent_init();
fds[0].fd = uevent_get_fd();
fds[0].events = POLLIN;
memset(uevent_desc, 0, sizeof(uevent_desc));
do
{
err = poll(fds, 1, -1);
if (err == -1)
{
if (errno != EINTR)
ALOGE("event error: %m");
continue;
}
if (fds[0].revents & POLLIN)
{
int len = uevent_next_event(uevent_desc, sizeof(uevent_desc) - 2);
rk_handle_uevents(uevent_desc,len);
}
}
while (1);
pthread_exit(NULL);
return NULL;
}