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

Commit f05ab200 authored by Oleg Blinnikov's avatar Oleg Blinnikov Committed by Android (Google) Code Review
Browse files

Merge "Fix user rotation of display devices" into main

parents 04864bd0 b84f973f
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -158,8 +158,6 @@ abstract class DisplayDevice {
    @Nullable
    public Point getDisplaySurfaceDefaultSizeLocked() {
        DisplayDeviceInfo displayDeviceInfo = getDisplayDeviceInfoLocked();
        final boolean isRotated = mCurrentOrientation == ROTATION_90
                || mCurrentOrientation == ROTATION_270;
        var width = displayDeviceInfo.width;
        var height = displayDeviceInfo.height;
        if (mIsAnisotropyCorrectionEnabled && displayDeviceInfo.yDpi > 0
@@ -170,7 +168,7 @@ abstract class DisplayDevice {
                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();
        }

        boolean isRotated = (mCurrentOrientation == Surface.ROTATION_90
                || mCurrentOrientation == ROTATION_270);
        final boolean isRotated = isRotatedLocked();
        DisplayDeviceInfo info = getDisplayDeviceInfoLocked();
        viewport.deviceWidth = isRotated ? info.height : info.width;
        viewport.deviceHeight = isRotated ? info.width : info.height;
@@ -425,6 +422,13 @@ abstract class DisplayDevice {
        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() {
        return DisplayDeviceConfig.create(mContext, /* useConfigXml= */ false,
                mDisplayAdapter.getFeatureFlags());
+16 −3
Original line number Diff line number Diff line
@@ -203,6 +203,13 @@ final class LogicalDisplay {
    private SparseArray<SurfaceControl.RefreshRateRange> mThermalRefreshRateThrottling =
            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
     * 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;

    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,
            boolean isAnisotropyCorrectionEnabled) {
            boolean isAnisotropyCorrectionEnabled, boolean isAlwaysRotateDisplayDeviceEnabled) {
        mDisplayId = displayId;
        mLayerStack = layerStack;
        mPrimaryDisplayDevice = primaryDisplayDevice;
@@ -236,6 +243,7 @@ final class LogicalDisplay {
        mPowerThrottlingDataId = DisplayDeviceConfig.DEFAULT_ID;
        mBaseDisplayInfo.thermalBrightnessThrottlingDataId = mThermalBrightnessThrottlingDataId;
        mIsAnisotropyCorrectionEnabled = isAnisotropyCorrectionEnabled;
        mAlwaysRotateDisplayDeviceEnabled = isAlwaysRotateDisplayDeviceEnabled;
    }

    public void setDevicePositionLocked(int position) {
@@ -672,7 +680,12 @@ final class LogicalDisplay {
        // The orientation specifies how the physical coordinate system of the display
        // is rotated when the contents of the logical display are rendered.
        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;
        }

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

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

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

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

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

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

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