1 修改旋转方向
项目中用到了三个不同尺寸的屏幕,其中有两块屏幕是横屏另一块是竖屏,所以需要根据屏幕尺寸来决定是否旋转显示方向
在kernel中获取屏幕的尺寸类型,将屏幕类型写进eeprom中,并在上层读取eeprom然后判断是否旋转屏幕的显示方向,修改路径:
frameworks/native / services/surfaceflinger/SurfaceFlingerProperties.cpp中的SurfaceFlingerProperties::primary_display_orientation_values primary_display_orientation函数
#define EEPROM_PATH "/sys/bus/i2c/devices/i2c-0/0-0050/eeprom"
#define LCD_INDEX_OFFSET 200
int read_eeprom_rotation(void)
{
int ret = 0;
unsigned char buf;
int eeprom_fd;
eeprom_fd = open(EEPROM_PATH, O_RDONLY);
if (eeprom_fd < 0) {
ALOGD("Open EEPROM error %s !\n" ,EEPROM_PATH);
return -1;
}
else
{
lseek(eeprom_fd, LCD_INDEX_OFFSET, SEEK_SET);
ret = read(eeprom_fd, &buf, 1);
if(ret < 0)
{
ALOGD("%s: read eeprom error",__FUNCTION__);
return -1;
}
else
ALOGD("%s: read eeprom --------[%d]",__FUNCTION__,buf);
}
return buf;
}
SurfaceFlingerProperties::primary_display_orientation_values primary_display_orientation(
SurfaceFlingerProperties::primary_display_orientation_values defaultValue) {
if(read_eeprom_rotation() == 5){
ALOGD("vtlk:force to set rotation 270 for 10 inch panel");
return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270;
}
auto temp = SurfaceFlingerProperties::primary_display_orientation();
if (temp.has_value()) {
return *temp;
}
auto configDefault = DisplayOrientation::ORIENTATION_0;
switch (defaultValue) {
case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90:
configDefault = DisplayOrientation::ORIENTATION_90;
break;
case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180:
configDefault = DisplayOrientation::ORIENTATION_180;
break;
case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270:
configDefault = DisplayOrientation::ORIENTATION_270;
break;
default:
configDefault = DisplayOrientation::ORIENTATION_0;
break;
}
DisplayOrientation result =
getDisplayOrientation<V1_1::ISurfaceFlingerConfigs,
&V1_1::ISurfaceFlingerConfigs::primaryDisplayOrientation>(
configDefault);
switch (result) {
case DisplayOrientation::ORIENTATION_90:
return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90;
case DisplayOrientation::ORIENTATION_180:
return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180;
case DisplayOrientation::ORIENTATION_270:
return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270;
default:
break;
}
return SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_0;
}
添加了read_eeprom_rotation函数,在该函数中去读取eeprom中存储的屏幕尺寸信息,根据返回类型来决定屏幕的方向
2 修改屏幕密度
由于客户APP的布局在较小的屏幕上出现重叠现象,修改屏幕密度后正常,所以和上面一样读取屏幕类型修改屏幕密度
修改路径:frameworks/native / services/surfaceflinger/SurfaceFlinger.cpp
#define EEPROM_PATH "/sys/bus/i2c/devices/i2c-0/0-0050/eeprom"
#define LCD_INDEX_OFFSET 200
int read_eeprom_rotation(void)
{
int ret = 0;
unsigned char macaddr;
int eeprom_fd;
eeprom_fd = open(EEPROM_PATH, O_RDONLY);
if (eeprom_fd < 0) {
ALOGD("Open MAC EEPROM error %s !\n" ,EEPROM_PATH);
return -1;
}
else
{
lseek(eeprom_fd, LCD_INDEX_OFFSET, SEEK_SET);
ret = read(eeprom_fd, &macaddr, 1);
if(ret < 0)
{
ALOGD("%s: read eeprom error",__FUNCTION__);
close(eeprom_fd);
return -1;
}
else {
ALOGD("%s: read eeprom --------[%d]",__FUNCTION__,macaddr);
close(eeprom_fd);
return macaddr;
}
}
}
// TODO(b/141333600): Consolidate with HWC2::Display::Config::Builder::getDefaultDensity.
constexpr float FALLBACK_DENSITY = ACONFIGURATION_DENSITY_TV;
float getDensityFromProperty(const char* property, bool required) {
char value[PROPERTY_VALUE_MAX];
const float density = property_get(property, value, nullptr) > 0 ? std::atof(value) : 0.f;
if (!density && required) {
ALOGE("%s must be defined as a build property", property);
return FALLBACK_DENSITY;
}
if(strcmp(property,"ro.sf.lcd_density") == 0)
{
if(read_eeprom_rotation() == 2){ //7inch
ALOGD("vantron -->> :set density to 120");
return 120.000;
}
}
ALOGD("vantron -->> getDensityFromProperty density = %f \n",density);
return density;
}
在添加了getDensityFromProperty中添加了如下内容:
if(strcmp(property,"ro.sf.lcd_density") == 0)
{
if(read_eeprom_rotation() == 2){ //7inch
ALOGD("vantron -->> :set density to 120");
return 120.000;
}
}
ALOGD("vantron -->> getDensityFromProperty density = %f \n",density);