Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b55db4a6 authored by Tom Giordano's avatar Tom Giordano Committed by Sam Mortimer
Browse files

framework: fix screenshot and rotation animation for devices with abnormal hw rotation

Change-Id: I42694931cb1a754aa6c7652c0a96304ef1f88492
parent cd2b8b2b
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -450,6 +450,7 @@ class GlobalScreenshot {

    private MediaActionSound mCameraSound;

    private final int mSfHwRotation;

    /**
     * @param context everything needs a context :(
@@ -519,6 +520,9 @@ class GlobalScreenshot {
        // Setup the Camera shutter sound
        mCameraSound = new MediaActionSound();
        mCameraSound.load(MediaActionSound.SHUTTER_CLICK);

        // Load hardware rotation from prop
        mSfHwRotation = android.os.SystemProperties.getInt("ro.sf.hwrotation", 0) / 90;
    }

    /**
@@ -563,7 +567,10 @@ class GlobalScreenshot {
        // only in the natural orientation of the device :!)
        mDisplay.getRealMetrics(mDisplayMetrics);
        float[] dims = {mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels};
        float degrees = getDegreesForRotation(mDisplay.getRotation());
        int rot = mDisplay.getRotation();
        // Allow for abnormal hardware orientation
        rot = (rot + mSfHwRotation) % 4;
        float degrees = getDegreesForRotation(rot);
        boolean requiresRotation = (degrees > 0);
        if (requiresRotation) {
            // Get the dimensions of the device in its native orientation
+7 −0
Original line number Diff line number Diff line
@@ -332,6 +332,8 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
    WallpaperController mWallpaperController;
    int mInputMethodAnimLayerAdjustment;

    private final int mSfHwRotation;

    private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
        WindowStateAnimator winAnimator = w.mWinAnimator;
        if (winAnimator.hasSurface()) {
@@ -762,6 +764,9 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        // Add itself as a child to the root container.
        mService.mRoot.addChild(this, null);

        // Load hardware rotation from prop
        mSfHwRotation = android.os.SystemProperties.getInt("ro.sf.hwrotation", 0) / 90;

        // TODO(b/62541591): evaluate whether this is the best spot to declare the
        // {@link DisplayContent} ready for use.
        mDisplayReady = true;
@@ -3106,6 +3111,8 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo

            // The screenshot API does not apply the current screen rotation.
            int rot = mDisplay.getRotation();
            // Allow for abnormal hardware orientation
            rot = (rot + mSfHwRotation) % 4;

            if (rot == ROTATION_90 || rot == ROTATION_270) {
                rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
+21 −7
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ class ScreenRotationAnimation {
    BlackFrame mExitingBlackFrame;
    BlackFrame mEnteringBlackFrame;
    int mWidth, mHeight;
    int mSnapshotRotation;

    int mOriginalRotation;
    int mOriginalWidth, mOriginalHeight;
@@ -240,6 +241,9 @@ class ScreenRotationAnimation {
            originalWidth = displayInfo.logicalWidth;
            originalHeight = displayInfo.logicalHeight;
        }
        // Allow for abnormal hardware orientation
        mSnapshotRotation = (4 - android.os.SystemProperties.getInt("ro.sf.hwrotation", 0) / 90) % 4;
        if (mSnapshotRotation == Surface.ROTATION_0 || mSnapshotRotation == Surface.ROTATION_180) {
            if (originalRotation == Surface.ROTATION_90
                 || originalRotation == Surface.ROTATION_270) {
                mWidth = originalHeight;
@@ -248,6 +252,16 @@ class ScreenRotationAnimation {
                mWidth = originalWidth;
                mHeight = originalHeight;
            }
        } else {
            if (originalRotation == Surface.ROTATION_90
                || originalRotation == Surface.ROTATION_270) {
                mWidth = originalWidth;
                mHeight = originalHeight;
            } else {
                mWidth = originalHeight;
                mHeight = originalWidth;
            }
        }

        mOriginalRotation = originalRotation;
        mOriginalWidth = originalWidth;
@@ -364,7 +378,7 @@ class ScreenRotationAnimation {
        // Compute the transformation matrix that must be applied
        // to the snapshot to make it stay in the same original position
        // with the current screen rotation.
        int delta = DisplayContent.deltaRotation(rotation, Surface.ROTATION_0);
        int delta = DisplayContent.deltaRotation(rotation, mSnapshotRotation);
        createRotationMatrix(delta, mWidth, mHeight, mSnapshotInitialMatrix);

        if (DEBUG_STATE) Slog.v(TAG, "**** ROTATION: " + delta);