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

Commit 5b20bbe4 authored by Ebru Kurnaz's avatar Ebru Kurnaz
Browse files

Update getLogicalDensity to return physical pixel density for external displays.

Flag: com.android.server.display.feature.flags.base_density_for_external_displays
Test: atest LocalDisplayAdapterTest
Bug: 382954433
Change-Id: I9f2dfb6a8eed2cd53093be06f04be318b6ddb40b
parent 878ba923
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -83,6 +83,8 @@ final class LocalDisplayAdapter extends DisplayAdapter {

    private static final String PROPERTY_EMULATOR_CIRCULAR = "ro.boot.emulator.circular";

    private static final double DEFAULT_DISPLAY_SIZE = 24.0;

    private final LongSparseArray<LocalDisplayDevice> mDevices = new LongSparseArray<>();

    private final Injector mInjector;
@@ -526,6 +528,21 @@ final class LocalDisplayAdapter extends DisplayAdapter {
        private int getLogicalDensity() {
            DensityMapping densityMapping = getDisplayDeviceConfig().getDensityMapping();
            if (densityMapping == null) {
                if (getFeatureFlags().isBaseDensityForExternalDisplaysEnabled()
                        && !mStaticDisplayInfo.isInternal) {
                    double dpi;

                    if (mActiveSfDisplayMode.xDpi > 0 && mActiveSfDisplayMode.yDpi > 0) {
                        dpi = Math.sqrt((Math.pow(mActiveSfDisplayMode.xDpi, 2)
                                + Math.pow(mActiveSfDisplayMode.yDpi, 2)) / 2);
                    } else {
                        // xDPI and yDPI is missing, calculate DPI from display resolution and
                        // default display size
                        dpi = Math.sqrt(Math.pow(mInfo.width, 2) + Math.pow(mInfo.height, 2))
                                / DEFAULT_DISPLAY_SIZE;
                    }
                    return (int) (dpi + 0.5);
                }
                return (int) (mStaticDisplayInfo.density * 160 + 0.5);
            }

+21 −1
Original line number Diff line number Diff line
@@ -455,8 +455,9 @@ public class LocalDisplayAdapterTest {
     * Confirm that external display uses physical density.
     */
    @Test
    public void testDpiValues() throws Exception {
    public void testDpiValues_baseDensityForExternalDisplaysDisabled() throws Exception {
        // needs default one always
        doReturn(false).when(mFlags).isBaseDensityForExternalDisplaysEnabled();
        setUpDisplay(new FakeDisplay(PORT_A));
        setUpDisplay(new FakeDisplay(PORT_B));
        updateAvailableDisplays();
@@ -472,6 +473,25 @@ public class LocalDisplayAdapterTest {
                16000);
    }

    @Test
    public void testDpiValues_baseDensityForExternalDisplaysEnabled() throws Exception {
        // needs default one always
        doReturn(true).when(mFlags).isBaseDensityForExternalDisplaysEnabled();
        setUpDisplay(new FakeDisplay(PORT_A));
        setUpDisplay(new FakeDisplay(PORT_B));
        updateAvailableDisplays();
        mAdapter.registerLocked();

        waitForHandlerToComplete(mHandler, HANDLER_WAIT_MS);

        assertDisplayDpi(
                mListener.addedDisplays.get(0).getDisplayDeviceInfoLocked(), PORT_A, 100, 100,
                100);
        assertDisplayDpi(
                mListener.addedDisplays.get(1).getDisplayDeviceInfoLocked(), PORT_B, 100, 100,
                100);
    }

    private static class DisplayModeWrapper {
        public SurfaceControl.DisplayMode mode;
        public float[] expectedAlternativeRefreshRates;