Android 竖屏启动 


1)kernel 竖屏
选中:
make menuconfig ---> Device Drivers  ---> Graphics support  ---> Console display driver support  ---> Framebuffer Console Rotation


make menuconfig 
                ---> Boot options  启动参数修改为:console=ttySAC2,115200 init=/linuxrc fbcon=rotate:1


2)Android OS 竖屏
文件:frameworks/base/libs/surfaceflinger/SurfaceFlinger.cpp


void GraphicPlane::setDisplayHardware(DisplayHardware *hw)
{
    mHw = hw;


    // initialize the display orientation transform.
    // it's a constant that should come from the display driver.
    //int displayOrientation = ISurfaceComposer::eOrientationDefault;   // 这行被注释掉
    int displayOrientation = ISurfaceComposer::eOrientation90;          // 加上这行
    char property[PROPERTY_VALUE_MAX];
    if (property_get("ro.sf.hwrotation", property, NULL) > 0) {
        //displayOrientation
        switch (atoi(property)) {
        case 90:
            displayOrientation = ISurfaceComposer::eOrientation90;
            break;
        case 270:
            displayOrientation = ISurfaceComposer::eOrientation270;
            break;
        }
    }


    const float w = hw->getWidth();
    const float h = hw->getHeight();
    GraphicPlane::orientationToTransfrom(displayOrientation, w, h,
            &mDisplayTransform);
    if (displayOrientation & ISurfaceComposer::eOrientationSwapMask) {
        mDisplayWidth = h;
        mDisplayHeight = w;
    } else {
        mDisplayWidth = w;
        mDisplayHeight = h;
    }


    setOrientation(ISurfaceComposer::eOrientationDefault);
}


触摸:


#else /* !CONFIG_CPU_S5PV210_EVT1 */
ts->yp += S3C_ADCDAT0_XPDATA_MASK_12BIT - (data0 & S3C_ADCDAT0_XPDATA_MASK_12BIT);
#endif /* !CONFIG_CPU_S5PV210_EVT1 */
ts->xp += S3C_ADCDAT1_YPDATA_MASK_12BIT - (data1 & S3C_ADCDAT1_YPDATA_MASK_12BIT);
#endif /* CONFIG_TOUCHSCREEN_NEW */


下面的搞死我了,不知道怎么改,


----------------------------------------------------------------------------------------------------------------------------------------
平板电脑一般是默认横屏, 竖屏的APP程序, 会自动旋转90°, 由于是顺时针转90°, 需要改为逆时针转90°; 也就是要把portrait改逆时针转90°,修改点如下:

PhoneWindowManager.java(\\192.168.1.4\opt\android_froyo_smdk\frameworks\policies\base\phone\com\android\internal\policy\impl)


public int rotationForOrientationLw(int orientation, int lastRotation,


boolean displayEnabled) {



if (mPortraitRotation < 0) {


// Initialize the rotation angles for each orientation once.


Display d =((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))


.getDefaultDisplay();


if (d.getWidth() > d.getHeight()) {


mPortraitRotation = Surface.ROTATION_270;//Surface.ROTATION_90;


mLandscapeRotation =Surface.ROTATION_0;


} else {


mPortraitRotation =Surface.ROTATION_0;


mLandscapeRotation = Surface.ROTATION_270;//Surface.ROTATION_90;


}


}

一下是参考文章------------------------------------------------------------------------------------------------------

本行实现以后才发现,google在1.5到2.2这个过程中改进了很多,1.5修改竖屏比较麻烦,而2.2是相当的容易!
其实基本上google将之前版本的默认为竖屏的做法进行了改进,不需要再花费更多力气在屏幕的默认横竖切换上面。1.还是kernel竖屏,可以显示到屏幕出现"A N D R O I D"字样
  启动参数里加入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会传递给其他需要的结构。
要选上:Device Drivers -> Graphics support -> Console display driver support ->Framebuffer Console support -> Framebuffer Console Rotation
注意:参考$(kernel)/documentation/fb/fbcon.txt2.android OS旋转屏幕
froyo中已经相当容易,仅修改一处:
frameworks/base/libs/surfaceflinger/SurfaceFlinger.cpp
void GraphicPlane::setDisplayHardware(DisplayHardware *hw)
{
    mHw = hw;    // initialize the display orientation transform.
    // it's a constant that should come from the display driver.
//    int displayOrientation = ISurfaceComposer::eOrientationDefault;
    int displayOrientation = ISurfaceComposer::eOrientation90; //jeff.
    。。。
}
或者只在init.rc中增加一项:
setprop ro.sf.hwrotation 90就这么简单的一修改,就可以全程竖屏显示了!


本文原创,来自http://blog.csdn.net/knock,转载请保留本行

 -----------------------------------------------------------------------------------------------------------------

屏是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 (2011-04-27 17:51:45)
  • Android (2011-07-06 15:33:10)
  • android (2011-04-05 16:54:42)
  • android (2010-12-27 12:02:06)
  • Android (2011-04-26 15:13:53)

更多相关文章

  1. Android(安卓)BaseExpandableListAdapter 教程
  2. Android(安卓)BaseExpandableListAdapter 教程
  3. 如何修改android开机启动默认横竖屏
  4. android tabhost学习
  5. Android利用Ksoap2连接webservice 源码
  6. 启动 flutter项目时报Could not find com.android.tools.build:g
  7. android的ndk修改app_platform的方法,亲测绝对可行
  8. android调用NotificationManager.notify无效,通知栏不显示
  9. android隐藏以及显示软键盘以及不自动弹出键盘的方法

随机推荐

  1. c语言数据类型转换的方法
  2. c语言中“或”怎么表示?
  3. c语言怎么实现动态内存分配
  4. c语言二进制如何表示
  5. c语言中的关键字有哪些类型?
  6. c语言中long是什么意思
  7. c语言0x什么意思
  8. printf在c语言中什么意思
  9. c语言中void的含义
  10. c语言的基本组成单位是什么