Android4.4 how to enable landscape Screen
Software environment: android4.4
Hardware Platform: marvell
I have previously debugged rotating the screen at 90 degrees on android4.0, and found the matching point. It is relatively simple to adjust it. You only need to set a name named ro. sf. hwrotation = 90. android's surface system reads the value of this system attribute and rotates the display interface. However, the surfaceflinger mechanism of android4.4 has been adjusted, I have not found any judgment on this attribute from start to end. There may be other secrets. I have not found it for the time being. Therefore, I transplanted the 4.0 judgment attribute set. The specific changes are as follows:
--- 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 + response, 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 shold 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 );
+}
After the two files have been modified, the problem arises. the boot and subsequent displays have indeed entered the Landscape mode, but the touch screen is still not rotated, the upper layer still processes touch points in portrait mode... Then I tried to modify many places on the surface and tried to reverse the touch point. All of them failed. Finally, I chose a solution that could solve the problem but not necessarily the best, and modified the processing of the Input system. The changes are as follows:
--- 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;
@-Route 6, 6 + Route 3, 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:
At this point, the touch screen is rotated successfully.
I am in line with the principle of solving problems, maybe 4.4 has a level similar to 4.0, you can set the attribute step by step, but I did not find this level, the above solution is for reference only and the author's use as a record. The stability remains to be studied. I have not conducted a comprehensive test. If you have any questions, you can discuss them with me. If you have any better solutions, please kindly advise me. Thank you ~~~