android+4.4.2+横屏,android4.4如何开机横屏

软件环境:android4.4

硬件平台:marvell

之前调试过在android4.0上将屏幕开机旋转90度,找到了契合点,调整起来还是相对简单,只需设置一个名称为ro.sf.hwrotation = 90即可,android的surface系统显示的时候会读取该系统属性的值,从而将显示界面旋转,但是android4.4的surfaceflinger机制做了调整,自始至终没有发现对该属性的处理判断,可能有其他的暗门,我暂时没发现,因此就把4.0判断属性的那一套移植了过来,具体改动如下:

--- a/services/surfaceflinger/DisplayDevice.cpp

+++ b/services/surfaceflinger/DisplayDevice.cpp

@@ -384,6 +384,11 @@ status_t DisplayDevice::orientationToTransfrom(

int orientation, int w, int h, Transform* tr)

{

uint32_t flags = 0;

+ char property[PROPERTY_VALUE_MAX];

+ if (property_get("ro.sf.hwrotation", property, NULL) > 0) {

+ if (atoi(property) == 90)

+ orientation = DisplayState::eOrientation90;

+ }

switch (orientation) {

case DisplayState::eOrientationDefault:

flags = Transform::ROT_0;

@@ -411,6 +416,7 @@ void DisplayDevice::setProjection(int orientation,

const int w = mDisplayWidth;

const int h = mDisplayHeight;

+ char property[PROPERTY_VALUE_MAX];

Transform R;

DisplayDevice::orientationToTransfrom(orientation, w, h, &R);

@@ -418,7 +424,12 @@ void DisplayDevice::setProjection(int orientation,

if (!frame.isValid()) {

// the destination frame can be invalid if it has never been set,

// in that case we assume the whole display frame.

- frame = Rect(w, h);www.2cto.com

+ if (property_get("ro.sf.hwrotation", property, NULL) > 0) {

+ if (atoi(property) == 90)

+ frame = Rect(h, w);

+ } else {

+ frame = Rect(w, h);

+ }

}

--- a/services/surfaceflinger/SurfaceFlinger.cpp

+++ b/services/surfaceflinger/SurfaceFlinger.cpp

@@ -674,6 +674,7 @@ status_t SurfaceFlinger::getDisplayInfo(const sp& display, DisplayInfo*

const HWComposer& hwc(getHwComposer());

float xdpi = hwc.getDpiX(type);

float ydpi = hwc.getDpiY(type);

+ char property[PROPERTY_VALUE_MAX];

// TODO: Not sure if display density should handled by SF any longer

class Density {

@@ -718,8 +719,15 @@ status_t SurfaceFlinger::getDisplayInfo(const sp& display, DisplayInfo*

info->orientation = 0;

}

- info->w = hwc.getWidth(type);

- info->h = hwc.getHeight(type);

+ if (property_get("ro.sf.hwrotation", property, NULL) > 0) {

+ if (atoi(property) == 90) {

+ info->w = hwc.getHeight(type);

+ info->h = hwc.getWidth(type);

+ }

+ } else {

+ info->w = hwc.getWidth(type);

+ info->h = hwc.getHeight(type);

+ }

这两个文件做完相应的修改之后,问题来了,开机以及后续的一系列显示确实进入了横屏模式,但是触摸屏却依然没有旋转过来,上层对touch点位的处理还是按竖屏模式处理的。。。接着尝试修改了surface的不少地方企图扭转touch点位,均告失败,最终选择了一个能解决问题但未必最优的方案,修改Input系统的处理。改动如下:

--- a/services/input/InputReader.cpp

+++ b/services/input/InputReader.cpp

@@ -42,6 +42,7 @@

#include "InputReader.h"

#include

+#include

#include

#include

@@ -2954,6 +2955,12 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {

int32_t naturalPhysicalWidth, naturalPhysicalHeight;

int32_t naturalPhysicalLeft, naturalPhysicalTop;

int32_t naturalDeviceWidth, naturalDeviceHeight;

+

+ char property[PROPERTY_VALUE_MAX];

+ if (property_get("ro.sf.hwrotation", property, NULL) > 0) {

+ if (atoi(property) == 90)

+ mViewport.orientation = DISPLAY_ORIENTATION_90;

+ }

switch (mViewport.orientation) {

case DISPLAY_ORIENTATION_90:

naturalLogicalWidth = mViewport.logicalBottom - mViewport.logicalTop;

@@ -4246,6 +4253,11 @@ void TouchInputMapper::cookPointerData() {

// X, Y, and the bounding box for coverage information

// Adjust coords for surface orientation.

float x, y, left, top, right, bottom;

+ char property[PROPERTY_VALUE_MAX];

+ if (property_get("ro.sf.hwrotation", property, NULL) > 0) {

+ if (atoi(property) == 90)

+ mSurfaceOrientation = DISPLAY_ORIENTATION_90;

+ }

switch (mSurfaceOrientation) {

case DISPLAY_ORIENTATION_90:

至此,触摸屏旋转成功。

本人是本着遇到问题解决问题的原则,也许4.4有类似4.0的关卡可以一步属性设置即可,只是本人没有发现这道关,上述提供的方案仅供参考以及笔者作为记录之用,稳定性还有待考究,本人未做全面的测试。有问题的同仁可以和我探讨,有更好方案的朋友还望不吝赐教。谢谢~~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值