android4.4如何開機橫屏

來源:互聯網
上載者:User

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.bkjia.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的關卡可以一步屬性設定即可,只是本人沒有發現這道關,上述提供的方案僅供參考以及筆者作為記錄之用,穩定性還有待考究,本人未做全面的測試。有問題的同仁可以和我探討,有更好方案的朋友還望不吝賜教。謝謝~~~

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.