-
Notifications
You must be signed in to change notification settings - Fork 1
/
ScreenScaleManager.cpp
187 lines (168 loc) · 5.56 KB
/
ScreenScaleManager.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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <cutils/properties.h>
#define LOG_TAG "ScreenScaleManager"
#include <cutils/log.h>
#include "Config.h"
#include "ScreenScaleManager.h"
#define PROPETY_OVERSCAN_MAIN "persist.sys.overscan.main"
#define PROPETY_OVERSCAN_AUX "persist.sys.overscan.aux"
#define MAIN_DISPLAY_SCALE_FILE "/sys/class/graphics/fb0/scale"
#define AUX_DISPLAY_SCALE_FILE "/sys/class/graphics/fb2/scale"
#define PROPETY_OVERSCAN_MAX "sys.overscan.max"
ScreenScaleManager::ScreenScaleManager() {
InitSysNode();
char property[PROPERTY_VALUE_MAX];
char property_max[PROPERTY_VALUE_MAX];
int max = 0;
float default_scale;
if (property_get(PROPETY_OVERSCAN_MAX, property_max, 0) > 0)
max = atoi(property_max);
default_scale = max*0.95;
int fd = open(MainDisplaySysNode, O_RDWR, 0);
if(fd > 0) {
if (property_get(PROPETY_OVERSCAN_MAIN, property, NULL) > 0)
sscanf(property, "overscan %d,%d,%d,%d", &overscan_left, &overscan_top, &overscan_right, &overscan_bottom);
if(max != 0) {
if(overscan_left == 0)
overscan_left = (int)default_scale;
if(overscan_right == 0)
overscan_right = (int)default_scale;
if(overscan_top == 0)
overscan_top = (int)default_scale;
if(overscan_bottom == 0)
overscan_bottom = (int)default_scale;
} else {
if(overscan_left == 0)
overscan_left = DEFALUT_SCREEN_SCALE;
if(overscan_right == 0)
overscan_right = DEFALUT_SCREEN_SCALE;
if(overscan_top == 0)
overscan_top = DEFALUT_SCREEN_SCALE;
if(overscan_bottom == 0)
overscan_bottom = DEFALUT_SCREEN_SCALE;
}
memset(property, 0, PROPERTY_VALUE_MAX);
sprintf(property, "overscan %d,%d,%d,%d", overscan_left, overscan_top, overscan_right, overscan_bottom);
// write(fd, property, strlen(property));
close(fd);
property_set(PROPETY_OVERSCAN_MAIN, property);
}
fd = open(AuxDisplaySysNode, O_RDWR, 0);
if(fd > 0) {
if (property_get(PROPETY_OVERSCAN_AUX, property, NULL) > 0)
sscanf(property, "overscan %d,%d,%d,%d", &overscan_left, &overscan_top, &overscan_right, &overscan_bottom);
if(max != 0) {
if(overscan_left == 0)
overscan_left = (int)default_scale;
if(overscan_right == 0)
overscan_right = (int)default_scale;
if(overscan_top == 0)
overscan_top = (int)default_scale;
if(overscan_bottom == 0)
overscan_bottom = (int)default_scale;
} else {
if(overscan_left == 0)
overscan_left = DEFALUT_SCREEN_SCALE;
if(overscan_right == 0)
overscan_right = DEFALUT_SCREEN_SCALE;
if(overscan_top == 0)
overscan_top = DEFALUT_SCREEN_SCALE;
if(overscan_bottom == 0)
overscan_bottom = DEFALUT_SCREEN_SCALE;
}
memset(property, 0, PROPERTY_VALUE_MAX);
sprintf(property, "overscan %d,%d,%d,%d", overscan_left, overscan_top, overscan_right, overscan_bottom);
// write(fd, property, strlen(property));
close(fd);
property_set(PROPETY_OVERSCAN_AUX, property);
}
}
void ScreenScaleManager::InitSysNode(void) {
memset(MainDisplaySysNode, 0, 64);
memset(AuxDisplaySysNode, 0, 64);
char const * const device_template = "/sys/class/graphics/fb%u/lcdcid";
FILE *fd = NULL;
int i = 0, id = 0, id_fb0 = -1;
char name[64];
do
{
ALOGD("i is %d", i);
memset(name, 0, 64);
snprintf(name, 64, device_template, i);
fd = fopen(name, "r");
if(fd != NULL) {
memset(name, 0, 64);
fgets(name, 64, fd);
fclose(fd);
id = atoi(name);
if (id_fb0 < 0)
id_fb0 = id;
if(id == id_fb0 && strlen(MainDisplaySysNode) == 0) {
snprintf(MainDisplaySysNode, 64, "/sys/class/graphics/fb%u/scale", i);
}
else if(id != id_fb0 && strlen(AuxDisplaySysNode) == 0) {
snprintf(AuxDisplaySysNode, 64, "/sys/class/graphics/fb%u/scale", i);
}
}
i++;
} while (fd != NULL);
if(strlen(MainDisplaySysNode) == 0)
strcpy(MainDisplaySysNode, MAIN_DISPLAY_SCALE_FILE);
// if(strlen(AuxDisplaySysNode) == 0) {
// strcpy(AuxDisplaySysNode, AUX_DISPLAY_SCALE_FILE);
// }
ALOGD("MainDisplaySysNode is %s", MainDisplaySysNode);
ALOGD("AuxDisplaySysNode is %s", AuxDisplaySysNode);
}
int ScreenScaleManager::SSMReadCfg() {
return 0;
}
void ScreenScaleManager::SSMCtrl(int display, int direction, int scalevalue) {
int fd = -1;
char property[PROPERTY_VALUE_MAX];
ALOGD("[%s] display %d, direction %d rate %d\n", __FUNCTION__, display, direction, scalevalue);
if(display == 0)
fd = open(MainDisplaySysNode, O_RDWR, 0);
else
fd = open(AuxDisplaySysNode, O_RDWR, 0);
if(fd < 0) return;
if (direction == DISPLAY_OVERSCAN_X) {
overscan_left = scalevalue;
overscan_right = scalevalue;
} else if (direction == DISPLAY_OVERSCAN_Y) {
overscan_top = scalevalue;
overscan_bottom = scalevalue;
} else if (direction == DISPLAY_OVERSCAN_LEFT) {
overscan_left = scalevalue;
} else if (direction == DISPLAY_OVERSCAN_RIGHT) {
overscan_right = scalevalue;
} else if (direction == DISPLAY_OVERSCAN_TOP) {
overscan_top = scalevalue;
} else if (direction == DISPLAY_OVERSCAN_BOTTOM) {
overscan_bottom = scalevalue;
} else if (direction == DISPLAY_OVERSCAN_ALL) {
overscan_left = scalevalue;
overscan_right = scalevalue;
overscan_top = scalevalue;
overscan_bottom = scalevalue;
}
memset(property, 0, PROPERTY_VALUE_MAX);
sprintf(property, "overscan %d,%d,%d,%d", overscan_left, overscan_top, overscan_right, overscan_bottom);
#ifdef RK3228
//write(fd, property, strlen(property));
#else
write(fd, property, strlen(property));
#endif
close(fd);
if(display == 0)
property_set(PROPETY_OVERSCAN_MAIN, property);
else
property_set(PROPETY_OVERSCAN_AUX, property);
system("sync");
ALOGD("sync property scale\n");
}