LCD橫豎屏顯示
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
說明: fbcon=rotate:<n>
This option changes the orientation angle of the console display. The
value 'n' accepts the following:
0 - normal orientation (0 degree)
1 - clockwise orientation (90 degrees)
2 - upside down orientation (180 degrees)
3 - counterclockwise orientation (270 degrees)
2)Android OS 豎屏
檔案:./native/services/surfaceflinger/SurfaceFlinger.cpp
status_t SurfaceFlinger::getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info) {
...
738
// int displayOrientation = DisplayState::eOrientationDefault;
int displayOrientation = isplayState::eOrientation90; // 加上這行
740 char property[PROPERTY_VALUE_MAX];
741 if (type == DisplayDevice::DISPLAY_PRIMARY) {
742 if (property_get("ro.sf.hwrotation", property, NULL) > 0) {
743 switch (atoi(property)) {
744 case 90:
745 displayOrientation = DisplayState::eOrientation90;
746 break;
747 case 270:
748 displayOrientation = DisplayState::eOrientation270;
749 break;
750 }
751 }
752 }
753
754 if (displayOrientation & DisplayState::eOrientationSwapMask) {
755 swap(width, height);
756 }
757
758 info->w = width;
759 info->h = height;
760 info->xdpi = xdpi;
761 info->ydpi = ydpi;
762 info->fps = float(1e9 / hwc.getRefreshPeriod(type));
763
764 // All non-virtual displays are currently considered secure.
765 info->secure = true;
766
767 return NO_ERROR;
768 }
a: device 中init.rc修改 豎屏
#Define the config for dual camera
setprop camera.disable_zsl_mode 1
#For landscape mode, orient is 0
#For portrait mode, orient is 90
#the android before honycomb are all in portrait mode
setprop back_camera_name ov5640_mipi
setprop back_camera_orient 0
setprop front_camera_name uvc,ov5642_camera,ov5640_camera
setprop front_camera_orient 0
# Set OpenGLES version
setprop ro.opengles.version 196608
# Set rotation to 270 to cofigure as portrait mode
setprop ro.sf.hwrotation 0 #指定預設輸出不旋轉(我們預設輸出時豎屏)
#setprop ro.sf.hwrotation 270 指定旋轉270度輸出
# Set the density to 160dpi, default 128dpi is not good
setprop ro.sf.lcd_density 160
b: . 這個指定角度,Android預設只有0度和270度有效,180度無效,如果想使用180度,需要修改原始碼
修改檔案frameworks/native/services/surfaceflinger/SurfaceFlinger.cpp
if (type == DisplayDevice::DISPLAY_PRIMARY) {
if (property_get("ro.sf.hwrotation", property, NULL) > 0) {
switch (atoi(property)) {
case 90:
displayOrientation = DisplayState::eOrientation90;
break;
case 270:
displayOrientation = DisplayState::eOrientation270;
break;
case 180:
displayOrientation = DisplayState::eOrientation180;
break;
}
}
}
這樣子就支援了180度了在方法
3. 還有更詳細的 - Android 4.1 預設窗體旋轉180度
1).設定屬性值
在/out/target/product/sabresd_6dq/system/build.prop檔案中加入
ro.sf.hwrotation=180
2).設定窗體預設顯示方向
在frameworks/native/services/surfaceflinger/SurfaceFlinger.cpp檔案中找到方法
getDisplayInfo
switch (atoi(property)) 加入
case 180:
displayOrientation = DisplayState::eOrientation180;
break;
3).設定窗體動畫旋轉方向
a > 在frameworks/base/core/java/android/view/Surface.java 加入方法
public static int getDefaultRotation(){
return android.os.SystemProperties.getInt("ro.sf.hwrotation", 0);//180
}
/**
* @hide
*/
public static int getDefaultRotationIndex(){
int rotation = getDefaultRotation();
switch(rotation){
case 0:
return ROTATION_0;
case 90:
return ROTATION_90;
case 180:
return ROTATION_180;
case 270:
return ROTATION_270;
}
return ROTATION_0;
}
b > 在frameworks/base/services/java/com/android/server/vm/ScreenRotationAnimation.java 檔案中找到(android4.1) 方法setRotation
或(android4.2)方法setRotationInTransaction 修改 deltaRotation(rotation,Surface.ROTATION_0);
為deltaRotation(rotation,Surface. getDefaultRotationIndex());