android屏幕旋转framework,android屏幕旋转在framework中的修改。

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就这么简单的一修改,就可以全程竖屏显示了!

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

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值