平台
RK3288 + Android 7.1
1
概述
固定了屏幕方向后, 默认不旋转时, 所有的显示都正常, 但是, 在旋转后, 开机动画显示的方向要么不准确, 要么会跳变.
前提
屏幕旋转方向有四个值, 分别为
Surface.ROTATION_0 (默认)
Surface.ROTATION_90
Surface.ROTATION_180
Surface.ROTATION_270
分析
|-- frameworks/base/cmds/bootanimation/BootAnimation.cpp
BootAnimation::BootAnimation(bool shutdown) : Thread(false), mClockEnabled(true), mTimeIsAccurate(false),
mTimeFormat12Hour(false), mTimeCheckThread(NULL) {
mSession = new SurfaceComposerClient();
// If the system has already booted, the animation is not being used for a boot.
mSystemBoot = !property_get_bool(BOOT_COMPLETED_PROP_NAME, 0);
mShutdown = shutdown;
mReverseAxis = false;
mVideoFile = NULL;
mVideoAnimation = false;
if(mShutdown){
sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(
ISurfaceComposer::eDisplayIdMain)); // primary_display_token
DisplayInfo dinfo;
status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &dinfo);
if (status == OK) {
ALOGD("DISPLAY,W-H: %d-%d, ori: %d", dinfo.w, dinfo.h, dinfo.orientation);
if(dinfo.orientation==1 || dinfo.orientation==3 )
mReverseAxis=true;
else
mReverseAxis=false;
}
}
}
初步怀疑是屏幕旋转导致了问题存在, 于是, 从上面的代码中, 抽取了读取屏幕信息的方法, 并打印出信息.
代码到动画绘制的循环中
bool BootAnimation::android()
{
//...
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
//加入打印显示信息代码
sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(
ISurfaceComposer::eDisplayIdMain)); // primary_display_token
DisplayInfo dinfo;
const nsecs_t startTime = systemTime();
do {
//加入打印显示信息代码.
status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &dinfo);
if (status == OK) {
ALOGD("DISPLAY,W-H: %d-%d, ori: %d", dinfo.w, dinfo.h, dinfo.orientation);
}
//...
checkExit();
} while (!exitPending());
}
LOG内容如下:
01-03 01:17:31.965 327-376/? D/