Android4.4 增加屏幕旋转功能

由于Android4.4系统上去掉了ro.sf.hwrotation属性的支持,因为不能使用之前的方法进行屏幕旋转了。暂时没有找到相应的属性和后门,于是自己写了一个屏幕旋转的临时代码,后面找到更好的方法后再替换。具体代码如下:

 

~/framework/native/services/surfaceflinger/DisplayDevice.cpp

uint32_t DisplayDevice::getOrientationTransform() const {

    ...


    if (property_get("persist.sys.hwrotation", property, NULL) > 0) { 
        switch (atoi(property)) {
            case 90:
                transform = Transform::ROT_90;
                break;
            case 270:
                transform = Transform::ROT_270;
                break;
         }
     }
     return transform;

}

 

status_t DisplayDevice::orientationToTransfrom(
        int orientation, int w, int h, Transform* tr)
{
    ...


    if (property_get("persist.sys.hwrotation", property, NULL) > 0) { 
        switch (atoi(property)) {
            case 90:
                flags = Transform::ROT_90;
                break;
            case 270:
                flags = Transform::ROT_270;
                break;
         }
    }

    tr->set(flags, w, h);
    return NO_ERROR;
}

void DisplayDevice::setProjection(int orientation,
        const Rect& newViewport, const Rect& newFrame) {

    ...

    if (!frame.isValid()) {
        if (property_get("persist.sys.hwrotation", property, NULL) > 0) { 
            switch (atoi(property)) {
                case 90:
                case 270:
                    frame = Rect(h, w);
                    break;
                default:
                    frame = Rect(w, h);
                    break;
            }
        } else
            frame = Rect(w, h);
    } else {

        ...

    }

}

 

~/framework/base/services/input/InputReader.cpp

void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {

    ...

    if (property_get("persist.sys.hwrotation", property, NULL) > 0) { 
        switch (atoi(property)) {
            case 90:
                mSurfaceOrientation = DISPLAY_ORIENTATION_90;
                break;
            case 270:
                mSurfaceOrientation = DISPLAY_ORIENTATION_270;
                break;
         }
    }

        switch (mSurfaceOrientation) {
        case DISPLAY_ORIENTATION_90:
        case DISPLAY_ORIENTATION_270:

}

 

~/framework/native/services/surfaceflinger/SurfaceFlinger.cpp

status_t SurfaceFlinger::getDisplayInfo(const sp& display, DisplayInfo* info) {

    ...

    info->w = hwc.getWidth(type);
    info->h = hwc.getHeight(type);
    
    if (property_get("persist.sys.hwrotation", property, NULL) > 0) {
        switch (atoi(property)) {
            case 90:
            case 270:
                if (type != DisplayDevice::DISPLAY_EXTERNAL) {
                    info->w = hwc.getHeight(type);
                    info->h = hwc.getWidth(type);
                }
                break;
            default:
                break;
        }
    }

    info->xdpi = xdpi;
    info->ydpi = ydpi;
    info->fps = float(1e9 / hwc.getRefreshPeriod(type));

    ...

}

 

void SurfaceFlinger::onInitializeDisplays() {

    ...

    d.orientation = DisplayState::eOrientationDefault;
 
    char property[PROPERTY_VALUE_MAX];
    if (property_get("persist.sys.hwrotation", property, NULL) > 0){
        switch (atoi(property)) {
            case 0:
                d.orientation = DisplayState::eOrientationDefault;
                break;
            case 90:
                d.orientation = DisplayState::eOrientation90;
                break;
            case 180:
                d.orientation = DisplayState::eOrientation180;
                break;
            case 270:
                d.orientation = DisplayState::eOrientation270;
                break;
            default:
                d.orientation = DisplayState::eOrientationDefault;
                break;
         }
    } else {
         d.orientation = DisplayState::eOrientationDefault;
    }
 
    d.frame.makeInvalid();
    d.viewport.makeInvalid();

}

 

~/framework/base/services/java/com/android/server/wm/WindowManagerService.java

boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {

    ...

    if (req != mForcedAppOrientation) {
          if ("0".equals(SystemProperties.get("persist.sys.hwrotation", "0")))
              req = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
          else if ("90".equals(SystemProperties.get("persist.sys.hwrotation", "0")))
              req = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
          else if ("180".equals(SystemProperties.get("persist.sys.hwrotation", "0")))
              req = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
          else if ("270".equals(SystemProperties.get("persist.sys.hwrotation", "0")))
              req = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
          else
              req = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
      }

    ...

}

 

 

你可能感兴趣的:(图像/显示)