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

Commit b84f973f authored by Oleg Blinnikov's avatar Oleg Blinnikov
Browse files

Fix user rotation of display devices

Previously calling wm user-rotation adb command
for non-default display resulted into a
non-rotated shifted picture.

With this CL, DM will always take the rotation
supplied by WM and set it to the surface flinger
projection. Also to fix the shifted picture
after rotation, there is an additional call
to ContentRecorder.onConfigurationChanged.

VirtualDisplay surface size previously did
not take the possible rotation into account,
this CL fixes this - important for Chromecast.

Change-Id: I6f3a86a97ba81413aa480a763307ac9109585c6f
Bug: 302326003
Bug: 322480626
Test: adb shell setprop persist.demo.userrotation 1
Test: adb shell wm user-rotation -d ${DISPLAYID} lock 1
parent 670ec4a1
Loading
Loading
Loading
Loading
+9 −5
Original line number Original line Diff line number Diff line
@@ -158,8 +158,6 @@ abstract class DisplayDevice {
    @Nullable
    @Nullable
    public Point getDisplaySurfaceDefaultSizeLocked() {
    public Point getDisplaySurfaceDefaultSizeLocked() {
        DisplayDeviceInfo displayDeviceInfo = getDisplayDeviceInfoLocked();
        DisplayDeviceInfo displayDeviceInfo = getDisplayDeviceInfoLocked();
        final boolean isRotated = mCurrentOrientation == ROTATION_90
                || mCurrentOrientation == ROTATION_270;
        var width = displayDeviceInfo.width;
        var width = displayDeviceInfo.width;
        var height = displayDeviceInfo.height;
        var height = displayDeviceInfo.height;
        if (mIsAnisotropyCorrectionEnabled && displayDeviceInfo.yDpi > 0
        if (mIsAnisotropyCorrectionEnabled && displayDeviceInfo.yDpi > 0
@@ -170,7 +168,7 @@ abstract class DisplayDevice {
                width = (int) (width * displayDeviceInfo.yDpi / displayDeviceInfo.xDpi  + 0.5);
                width = (int) (width * displayDeviceInfo.yDpi / displayDeviceInfo.xDpi  + 0.5);
            }
            }
        }
        }
        return isRotated ? new Point(height, width) : new Point(width, height);
        return isRotatedLocked() ? new Point(height, width) : new Point(width, height);
    }
    }


    /**
    /**
@@ -394,8 +392,7 @@ abstract class DisplayDevice {
            viewport.physicalFrame.setEmpty();
            viewport.physicalFrame.setEmpty();
        }
        }


        boolean isRotated = (mCurrentOrientation == Surface.ROTATION_90
        final boolean isRotated = isRotatedLocked();
                || mCurrentOrientation == ROTATION_270);
        DisplayDeviceInfo info = getDisplayDeviceInfoLocked();
        DisplayDeviceInfo info = getDisplayDeviceInfoLocked();
        viewport.deviceWidth = isRotated ? info.height : info.width;
        viewport.deviceWidth = isRotated ? info.height : info.width;
        viewport.deviceHeight = isRotated ? info.width : info.height;
        viewport.deviceHeight = isRotated ? info.width : info.height;
@@ -425,6 +422,13 @@ abstract class DisplayDevice {
        pw.println("mCurrentSurface=" + mCurrentSurface);
        pw.println("mCurrentSurface=" + mCurrentSurface);
    }
    }


    /**
     * @return whether the orientation is {@link ROTATION_90} or {@link ROTATION_270}.
     */
    boolean isRotatedLocked() {
        return mCurrentOrientation == ROTATION_90 || mCurrentOrientation == ROTATION_270;
    }

    private DisplayDeviceConfig loadDisplayDeviceConfig() {
    private DisplayDeviceConfig loadDisplayDeviceConfig() {
        return DisplayDeviceConfig.create(mContext, /* useConfigXml= */ false,
        return DisplayDeviceConfig.create(mContext, /* useConfigXml= */ false,
                mDisplayAdapter.getFeatureFlags());
                mDisplayAdapter.getFeatureFlags());
+16 −3
Original line number Original line Diff line number Diff line
@@ -203,6 +203,13 @@ final class LogicalDisplay {
    private SparseArray<SurfaceControl.RefreshRateRange> mThermalRefreshRateThrottling =
    private SparseArray<SurfaceControl.RefreshRateRange> mThermalRefreshRateThrottling =
            new SparseArray<>();
            new SparseArray<>();


    /**
     * If enabled, will not check for {@link Display#FLAG_ROTATES_WITH_CONTENT} in LogicalDisplay
     * and simply use the {@link DisplayInfo#rotation} supplied by WindowManager via
     * {@link #setDisplayInfoOverrideFromWindowManagerLocked}
     */
    private boolean mAlwaysRotateDisplayDeviceEnabled;

    /**
    /**
     * If the aspect ratio of the resolution of the display does not match the physical aspect
     * If the aspect ratio of the resolution of the display does not match the physical aspect
     * ratio of the display, then without this feature enabled, picture would appear stretched to
     * ratio of the display, then without this feature enabled, picture would appear stretched to
@@ -220,11 +227,11 @@ final class LogicalDisplay {
    private final boolean mIsAnisotropyCorrectionEnabled;
    private final boolean mIsAnisotropyCorrectionEnabled;


    LogicalDisplay(int displayId, int layerStack, DisplayDevice primaryDisplayDevice) {
    LogicalDisplay(int displayId, int layerStack, DisplayDevice primaryDisplayDevice) {
        this(displayId, layerStack, primaryDisplayDevice, false);
        this(displayId, layerStack, primaryDisplayDevice, false, false);
    }
    }


    LogicalDisplay(int displayId, int layerStack, DisplayDevice primaryDisplayDevice,
    LogicalDisplay(int displayId, int layerStack, DisplayDevice primaryDisplayDevice,
            boolean isAnisotropyCorrectionEnabled) {
            boolean isAnisotropyCorrectionEnabled, boolean isAlwaysRotateDisplayDeviceEnabled) {
        mDisplayId = displayId;
        mDisplayId = displayId;
        mLayerStack = layerStack;
        mLayerStack = layerStack;
        mPrimaryDisplayDevice = primaryDisplayDevice;
        mPrimaryDisplayDevice = primaryDisplayDevice;
@@ -236,6 +243,7 @@ final class LogicalDisplay {
        mPowerThrottlingDataId = DisplayDeviceConfig.DEFAULT_ID;
        mPowerThrottlingDataId = DisplayDeviceConfig.DEFAULT_ID;
        mBaseDisplayInfo.thermalBrightnessThrottlingDataId = mThermalBrightnessThrottlingDataId;
        mBaseDisplayInfo.thermalBrightnessThrottlingDataId = mThermalBrightnessThrottlingDataId;
        mIsAnisotropyCorrectionEnabled = isAnisotropyCorrectionEnabled;
        mIsAnisotropyCorrectionEnabled = isAnisotropyCorrectionEnabled;
        mAlwaysRotateDisplayDeviceEnabled = isAlwaysRotateDisplayDeviceEnabled;
    }
    }


    public void setDevicePositionLocked(int position) {
    public void setDevicePositionLocked(int position) {
@@ -672,7 +680,12 @@ final class LogicalDisplay {
        // The orientation specifies how the physical coordinate system of the display
        // The orientation specifies how the physical coordinate system of the display
        // is rotated when the contents of the logical display are rendered.
        // is rotated when the contents of the logical display are rendered.
        int orientation = Surface.ROTATION_0;
        int orientation = Surface.ROTATION_0;
        if ((displayDeviceInfo.flags & DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT) != 0) {

        // FLAG_ROTATES_WITH_CONTENT is now handled in DisplayContent. When the flag
        // mAlwaysRotateDisplayDeviceEnabled is removed, we should also remove this check for
        // ROTATES_WITH_CONTENT here and always set the orientation.
        if ((displayDeviceInfo.flags & DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT) != 0
                    || mAlwaysRotateDisplayDeviceEnabled) {
            orientation = displayInfo.rotation;
            orientation = displayInfo.rotation;
        }
        }


+2 −1
Original line number Original line Diff line number Diff line
@@ -1152,7 +1152,8 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
    private LogicalDisplay createNewLogicalDisplayLocked(DisplayDevice device, int displayId) {
    private LogicalDisplay createNewLogicalDisplayLocked(DisplayDevice device, int displayId) {
        final int layerStack = assignLayerStackLocked(displayId);
        final int layerStack = assignLayerStackLocked(displayId);
        final LogicalDisplay display = new LogicalDisplay(displayId, layerStack, device,
        final LogicalDisplay display = new LogicalDisplay(displayId, layerStack, device,
                mFlags.isPixelAnisotropyCorrectionInLogicalDisplayEnabled());
                mFlags.isPixelAnisotropyCorrectionInLogicalDisplayEnabled(),
                mFlags.isAlwaysRotateDisplayDeviceEnabled());
        display.updateLocked(mDisplayDeviceRepo);
        display.updateLocked(mDisplayDeviceRepo);


        final DisplayInfo info = display.getDisplayInfoLocked();
        final DisplayInfo info = display.getDisplayInfoLocked();
+2 −1
Original line number Original line Diff line number Diff line
@@ -366,7 +366,8 @@ public class VirtualDisplayAdapter extends DisplayAdapter {
            if (mSurface == null) {
            if (mSurface == null) {
                return null;
                return null;
            }
            }
            return mSurface.getDefaultSize();
            final Point surfaceSize = mSurface.getDefaultSize();
            return isRotatedLocked() ? new Point(surfaceSize.y, surfaceSize.x) : surfaceSize;
        }
        }


        @VisibleForTesting
        @VisibleForTesting
+9 −0
Original line number Original line Diff line number Diff line
@@ -116,6 +116,10 @@ public class DisplayManagerFlags {
            Flags.FLAG_FAST_HDR_TRANSITIONS,
            Flags.FLAG_FAST_HDR_TRANSITIONS,
            Flags::fastHdrTransitions);
            Flags::fastHdrTransitions);


    private final FlagState mAlwaysRotateDisplayDevice = new FlagState(
            Flags.FLAG_ALWAYS_ROTATE_DISPLAY_DEVICE,
            Flags::alwaysRotateDisplayDevice);

    private final FlagState mRefreshRateVotingTelemetry = new FlagState(
    private final FlagState mRefreshRateVotingTelemetry = new FlagState(
            Flags.FLAG_REFRESH_RATE_VOTING_TELEMETRY,
            Flags.FLAG_REFRESH_RATE_VOTING_TELEMETRY,
            Flags::refreshRateVotingTelemetry
            Flags::refreshRateVotingTelemetry
@@ -260,6 +264,10 @@ public class DisplayManagerFlags {
        return mFastHdrTransitions.isEnabled();
        return mFastHdrTransitions.isEnabled();
    }
    }


    public boolean isAlwaysRotateDisplayDeviceEnabled() {
        return mAlwaysRotateDisplayDevice.isEnabled();
    }

    public boolean isRefreshRateVotingTelemetryEnabled() {
    public boolean isRefreshRateVotingTelemetryEnabled() {
        return mRefreshRateVotingTelemetry.isEnabled();
        return mRefreshRateVotingTelemetry.isEnabled();
    }
    }
@@ -298,6 +306,7 @@ public class DisplayManagerFlags {
        pw.println(" " + mBrightnessWearBedtimeModeClamperFlagState);
        pw.println(" " + mBrightnessWearBedtimeModeClamperFlagState);
        pw.println(" " + mAutoBrightnessModesFlagState);
        pw.println(" " + mAutoBrightnessModesFlagState);
        pw.println(" " + mFastHdrTransitions);
        pw.println(" " + mFastHdrTransitions);
        pw.println(" " + mAlwaysRotateDisplayDevice);
        pw.println(" " + mRefreshRateVotingTelemetry);
        pw.println(" " + mRefreshRateVotingTelemetry);
        pw.println(" " + mPixelAnisotropyCorrectionEnabled);
        pw.println(" " + mPixelAnisotropyCorrectionEnabled);
        pw.println(" " + mSensorBasedBrightnessThrottling);
        pw.println(" " + mSensorBasedBrightnessThrottling);
Loading