码迷,mamicode.com
首页 > 移动开发 > 详细

android4.4如何开机横屏

时间:2015-02-26 16:44:50      阅读:611      评论:0      收藏:0      [点我收藏+]

标签:android4.4   开机横屏   surface   屏幕旋转   surfaceflinger   

软件环境: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);
+        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<IBinder>& 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<IBinder>& 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 <cutils/log.h>
+#include <cutils/properties.h>
 #include <input/Keyboard.h>
 #include <input/VirtualKeyMap.h>
 
@@ -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的关卡可以一步属性设置即可,只是本人没有发现这道关,上述提供的方案仅供参考以及笔者作为记录之用,稳定性还有待考究,本人未做全面的测试。有问题的同仁可以和我探讨,有更好方案的朋友还望不吝赐教。谢谢~~~


android4.4如何开机横屏

标签:android4.4   开机横屏   surface   屏幕旋转   surfaceflinger   

原文地址:http://blog.csdn.net/dkbdkbdkb/article/details/43953199

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!