实战记录,我的芯片是rk3566。
1.修改屏幕方向:
打开 android-11.0/device/rockchip/rk356x/BoardConfig.mk配置文件,修改配置:
SF_PRIMARY_DISPLAY_ORIENTATION := 180
2.修改触摸的方向:
1)配置触摸方向:
在android-11.0/build/tools/buildinfo.sh的最后一行增加:echo “persist.sys.touch.rotation=90”
2)打开文件frameworks/native/services/inputflinger/reader/mapper/TouchInputMapper.cpp,找到方法:void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded)
if (mDeviceMode == DEVICE_MODE_DIRECT || mDeviceMode == DEVICE_MODE_POINTER) {
// Convert rotated viewport to natural surface coordinates.
int32_t naturalLogicalWidth, naturalLogicalHeight;
int32_t naturalPhysicalWidth, naturalPhysicalHeight;
int32_t naturalPhysicalLeft, naturalPhysicalTop;
int32_t naturalDeviceWidth, naturalDeviceHeight;
/新增代码
char value[PROPERTY_VALUE_MAX];// 使用PROPERTY_VALUE_MAX宏,需要引入头文件#include <cutils/properties.h>
int orientation = 0;
// 关键在这里,需要自己先行配置该属性
property_get("persist.sys.touch.rotation", value, "180");// 这里面的默认值,建议填自己需要旋转的角度
switch(atoi(value)){
case 90:
orientation = DISPLAY_ORIENTATION_90;
break;
case 180:
orientation = DISPLAY_ORIENTATION_180;
break;
case 270:
orientation = DISPLAY_ORIENTATION_270;
break;
case 0:
default:
orientation = DISPLAY_ORIENTATION_0;
break;
}
mViewport.orientation = (mViewport.orientation + orientation) % 4;
//
switch (mViewport.orientation) {
case DISPLAY_ORIENTATION_90:
naturalLogicalWidth = mViewport.logicalBottom - mViewport.logicalTop;
naturalLogicalHeight = mViewport.logicalRight - mViewport.logicalLeft;
naturalPhysicalWidth = mViewport.physicalBottom - mViewport.physicalTop;
naturalPhysicalHeight = mViewport.physicalRight - mViewport.physicalLeft;
naturalPhysicalLeft = mViewport.deviceHeight - mViewport.physicalBottom;
naturalPhysicalTop = mViewport.physicalLeft;
naturalDeviceWidth = mViewport.deviceHeight;
naturalDeviceHeight = mViewport.deviceWidth;
break;
case DISPLAY_ORIENTATION_180:
naturalLogicalWidth = mViewport.logicalRight - mViewport.logicalLeft;
naturalLogicalHeight = mViewport.logicalBottom - mViewport.logicalTop;
naturalPhysicalWidth = mViewport.physicalRight - mViewport.physicalLeft;
naturalPhysicalHeight = mViewport.physicalBottom - mViewport.physicalTop;
naturalPhysicalLeft = mViewport.deviceWidth - mViewport.physicalRight;
naturalPhysicalTop = mViewport.deviceHeight - mViewport.physicalBottom;
naturalDeviceWidth = mViewport.deviceWidth;
naturalDeviceHeight = mViewport.deviceHeight;
break;
case DISPLAY_ORIENTATION_270:
naturalLogicalWidth = mViewport.logicalBottom - mViewport.logicalTop;
naturalLogicalHeight = mViewport.logicalRight - mViewport.logicalLeft;
naturalPhysicalWidth = mViewport.physicalBottom - mViewport.physicalTop;
naturalPhysicalHeight = mViewport.physicalRight - mViewport.physicalLeft;
naturalPhysicalLeft = mViewport.physicalTop;
naturalPhysicalTop = mViewport.deviceWidth - mViewport.physicalRight;
naturalDeviceWidth = mViewport.deviceHeight;
naturalDeviceHeight = mViewport.deviceWidth;
break;
case DISPLAY_ORIENTATION_0:
default:
naturalLogicalWidth = mViewport.logicalRight - mViewport.logicalLeft;
naturalLogicalHeight = mViewport.logicalBottom - mViewport.logicalTop;
naturalPhysicalWidth = mViewport.physicalRight - mViewport.physicalLeft;
naturalPhysicalHeight = mViewport.physicalBottom - mViewport.physicalTop;
naturalPhysicalLeft = mViewport.physicalLeft;
naturalPhysicalTop = mViewport.physicalTop;
naturalDeviceWidth = mViewport.deviceWidth;
naturalDeviceHeight = mViewport.deviceHeight;
break;
}
if (naturalPhysicalHeight == 0 || naturalPhysicalWidth == 0) {
ALOGE("Viewport is not set properly: %s", mViewport.toString().c_str());
naturalPhysicalHeight = naturalPhysicalHeight == 0 ? 1 : naturalPhysicalHeight;
naturalPhysicalWidth = naturalPhysicalWidth == 0 ? 1 : naturalPhysicalWidth;
}
mPhysicalWidth = naturalPhysicalWidth;
mPhysicalHeight = naturalPhysicalHeight;
mPhysicalLeft = naturalPhysicalLeft;
mPhysicalTop = naturalPhysicalTop;
mRawSurfaceWidth = naturalLogicalWidth * naturalDeviceWidth / naturalPhysicalWidth;
mRawSurfaceHeight = naturalLogicalHeight * naturalDeviceHeight / naturalPhysicalHeight;
mSurfaceLeft = naturalPhysicalLeft * naturalLogicalWidth / naturalPhysicalWidth;
mSurfaceTop = naturalPhysicalTop * naturalLogicalHeight / naturalPhysicalHeight;
mSurfaceRight = mSurfaceLeft + naturalLogicalWidth;
mSurfaceBottom = mSurfaceTop + naturalLogicalHeight;
mSurfaceOrientation =
mParameters.orientationAware ? mViewport.orientation : DISPLAY_ORIENTATION_0;
} else {
mPhysicalWidth = rawWidth;
mPhysicalHeight = rawHeight;
mPhysicalLeft = 0;
mPhysicalTop = 0;
mRawSurfaceWidth = rawWidth;
mRawSurfaceHeight = rawHeight;
mSurfaceLeft = 0;
mSurfaceTop = 0;
mSurfaceOrientation = DISPLAY_ORIENTATION_0;
}
直接在设置触摸方向的switch前面设置旋转变量mViewport.orientation = DISPLAY_ORIENTATION_180;
结束:
这个方法,本人是亲自在公司的实际项目中验证通过的,希望能对阅读的你,有所帮助。