android 1.5 之前豎屏顯示

來源:互聯網
上載者:User

屏是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度)顯示了。

 

http://blog.csdn.net/knock/archive/2010/03/01/5335767.aspx

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.