android屏幕方向调整

屏是LANDSCAPE的,要让它默认显示为PORTRAIT.

1.kernel里要旋转FrameBuffer.
  启动参数里加入fbcon=rotate:1    (0:正常屏; 1:顺时钟转90度; 2:转180度; 3:顺时钟转270度;)
最后生成的autoconf.h里有类似项:
#define CONFIG_CMDLINE "console=ttySAC0,115200 fbcon=rotate:1"

此项的解析在$(kernel)/drivers/video/console/fbcon.c
static int __init fb_console_setup(char *this_opt);
只是去初始化变量initial_rotation,然后initial_rotation会传递给其他需要的结构。
注意:参考$(kernel)/documentation/fb/fbcon.txt

2.android OS旋转屏幕
系统默认是针对竖屏的,而MID使用的是横屏,所以需要做一个转换的动作。
PORTRAIT               LANDSCAPE         <------屏幕显示方式
ROTATION_0             ROTATION_90
ROTATION_90        ROTATION_180
ROTATION_180        ROTATION_270
ROTATION_270        ROTATION_0

而source code里对ROTATION_180和ROTATION_270的处理比较少,只在sensor和KeyQueue部分,所以如果只是要让系统显示为竖屏,将android中的Surface.ROTATION_0改为Surface.ROTATION_90,而Surface.ROTATION_90改为Surface.ROTATION_0。 这样,启动后的屏幕就是竖屏的了。
改动后,启动时还是LANDSCAPE显示的,进入HOME也是,很快就会自动旋转到PORTRAIT模式,这是由于
$(cupcake)/frameworks/base/services/java/com/android/server/WindowManagerService.java
中enableScreenAfterBoot()->performEnableScreen()->mPolicy.enableScreenAfterBoot(), mPolicy为父类指针,可以指向
PhoneWindowManager或者MidWindowManager,由配置文件$(cupcake)/build/target/product/core.mk中
PRODUCT_POLICY := android.policy_phone
//PRODUCT_POLICY := android.policy_mid
来指定。
PhoneWindowManager::enableScreenAfterBoot()->updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)->mWindowManager.setRotation()完成设置旋转并清除LOGO.

3.启动过程中竖屏
启动过程中,默认是按照屏的width和height显示的,不会旋转,要使它显示logo时就是竖屏的,也就是旋转90度,需要做如下工作:
$(cupcake)/frameworks/base/libs/surfaceflinger/SurfaceFlinger.cpp
status_t SurfaceFlinger::readyToRun()中
    //const uint32_t w = hw.getWidth();
    //const uint32_t h = hw.getHeight();
//swap w&h for portrait display in landscape panel. jeff.
    const uint32_t h = hw.getWidth();  
    const uint32_t w = hw.getHeight();
交换一下width和height,这样后面用OpenGL创建的ViewPort形状就是竖的了。修改后面的函数参数也可以,不过太多了,交换一下省事。但是怎么让这个竖的viewport旋转90度呢?这里就要用到GraphicPlane::mGlobalTransform这个Transform了。它指示当前最终要旋转的结果。 所以要在创建GraphicPlane时初始化mGlobalTransform为旋转90度。
GraphicPlane::GraphicPlane()
    : mHw(0)
{
//add by jeff. for default rotate angel 90 
 mOrientationTransform.reset();
 mOrientation = ISurfaceComposer::eOrientation90;
 mGlobalTransform = mOrientationTransform * mTransform; 
}
此段从status_t GraphicPlane::setOrientation(int orientation)复制过来,注意修改mGlobalTransform:
    if (orientation == ISurfaceComposer::eOrientation90) { //ISurfaceComposer::eOrientationDefault //jeff
        // make sure the default orientation is optimal
        mOrientationTransform.reset();
        mOrientation = orientation;
        //mGlobalTransform = mTransform;
        mGlobalTransform = mOrientationTransform * mTransform; //jeff
        return NO_ERROR;
    }
注意mOrientationTransform.reset();要修改为默认旋转90度。参照status_t GraphicPlane::orientationToTransfrom
中的设置,修改为:
void Transform::reset() { 
    mTransform.reset();
    mType = 0;
 set(0,-1,1,0);  //jeff
 set(800,0);
}
参考:
status_t GraphicPlane::orientationToTransfrom(
        int orientation, int w, int h, Transform* tr)
{    
    float a, b, c, d, x, y;
    switch (orientation) {
    case ISurfaceComposer::eOrientationDefault:
        a=1; b=0; c=0; d=1; x=0; y=0;
        break;
    case ISurfaceComposer::eOrientation90:
        a=0; b=-1; c=1; d=0; x=w; y=0;
        break;
    case ISurfaceComposer::eOrientation180:
        a=-1; b=0; c=0; d=-1; x=w; y=h;
        break;
    case ISurfaceComposer::eOrientation270:
        a=0; b=1; c=-1; d=0; x=0; y=h;
        break;
    default:
        return BAD_VALUE;
    }
    tr->set(a, b, c, d);
    tr->set(x, y);
    return NO_ERROR;
}
修改之后,默认就是竖屏(旋转90度)显示了。

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

android屏幕显示之《动画方向》

Android开机的时候根据product.sensors.x属性的值来动态地改变开机动画的方向。 步骤:
 1. 修改frameworks/base/libs/surfaceflinger/SurfaceFlinger.cpp:1)GraphicPlane::mGlobalTransform指示了当前最终要旋转的结果,所以要在创建GraphicPlane时初始化mGlobalTransform为需要旋转的角度:

GraphicPlane::GraphicPlane()
     : mHw(0)
 {
+ char value[PROPERTY_VALUE_MAX];
+ property_get("product.sensors.x", value, "1");
+ product_sensors_x = atoi(value);
+ switch (product_sensors_x) {
+ case 1: // Default rotate 90

+ mOrientationTransform.reset();
+ mOrientation = ISurfaceComposer::eOrientation90;
+ mGlobalTransform = mOrientationTransform * mTransform;
+ break;
+ case 2: // Default rotate 180

+ mOrientationTransform.reset();
+ mOrientation = ISurfaceComposer::eOrientation180;
+ mGlobalTransform = mOrientationTransform * mTransform;
+ break;
+ case 3: // Default rotate 270

+ mOrientationTransform.reset();
+ mOrientation = ISurfaceComposer::eOrientation270;
+ mGlobalTransform = mOrientationTransform * mTransform;
+ break;
+ }
 }
 


注意:上面用到的reset函数也要相应地修改。

2)GraphicPlane::mGlobalTransform指示了当前最终要旋转的结果,同样地,需要修改GraphicPlane::setOrientation函数:

 

status_t GraphicPlane::setOrientation(int orientation)
     const DisplayHardware& hw(displayHardware());
     const float w = hw.getWidth();
     const float h = hw.getHeight();
- if (orientation == ISurfaceComposer::eOrientationDefault) {
- // make sure the default orientation is optimal

- mOrientationTransform.reset();
- mOrientation = orientation;
- mGlobalTransform = mTransform;
- return NO_ERROR;
+ char value[PROPERTY_VALUE_MAX];
+ property_get("product.sensors.x", value, "1");
+ product_sensors_x = atoi(value);
+ if (product_sensors_x != 0) {
+ if (orientation == product_sensors_x) {
+ // make sure the default orientation is optimal

+ mOrientationTransform.reset();
+ mOrientation = orientation;
+ mGlobalTransform = mOrientationTransform * mTransform;
+ return NO_ERROR;
+ }
+ } else {
+ if (orientation == ISurfaceComposer::eOrientationDefault) {
+ // make sure the default orientation is optimal

+ mOrientationTransform.reset();
+ mOrientation = orientation;
+ mGlobalTransform = mTransform;
+ return NO_ERROR;
+ }
     }
 


注意:上面用到的reset函数也要相应地修改。
 2. 修改frameworks/base/libs/surfaceflinger/Transform.cpp:修改上面用到的reset函数:

 

void Transform::reset() {
     mTransform.reset();
     mType = 0;
+ char value[PROPERTY_VALUE_MAX];
+ property_get("product.sensors.x", value, "1");
+ int product_sensors_x = atoi(value);
+ switch (product_sensors_x) {
+ case 1: // Default rotate 90

+ set(0,-1,1,0); set(1024,0); break;
+ case 2: // Default rotate 180

+ set(-1,0,0,-1); set(1024,768); break;
+ case 3: // Default rotate 270

+ set(0,1,-1,0); set(0,768); break;
+ }
 }
 

上面用到的set函数里面的参数值的设置参考的是GraphicPlane::orientationToTransfrom函数:

 

status_t GraphicPlane::orientationToTransfrom(
        int orientation, int w, int h, Transform* tr)
{ 
    float a, b, c, d, x, y;
    switch (orientation) {
    case ISurfaceComposer::eOrientationDefault:
        a=1; b=0; c=0; d=1; x=0; y=0;
        break;
    case ISurfaceComposer::eOrientation90:
        a=0; b=-1; c=1; d=0; x=w; y=0;
        break;
    case ISurfaceComposer::eOrientation180:
        a=-1; b=0; c=0; d=-1; x=w; y=h;
        break;
    case ISurfaceComposer::eOrientation270:
        a=0; b=1; c=-1; d=0; x=0; y=h;
        break;
    default:
        return BAD_VALUE;
    }
    tr->set(a, b, c, d);
    tr->set(x, y);
    return NO_ERROR;
}

 


  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值