From 1eb2a91aa0d66df8a8b1979386f71dbbb526df82 Mon Sep 17 00:00:00 2001 From: Daichi Hirono Date: Thu, 14 Nov 2019 16:23:15 +0900 Subject: [PATCH] Use physical density for external displays The CL has LocalDisplayAdapter use physical density from surface flinger. Previously LocalDisplayAdapter always uses fake density for external displays. The fake density is no longer needed because surface flinger fills density always now. Bug: 144066777 Test: LocalDisplayAdapterTest Change-Id: I105de4f6ded17c6882d98e60e8c7d7c027299f56 --- .../server/display/LocalDisplayAdapter.java | 7 ++- .../display/LocalDisplayAdapterTest.java | 52 ++++++++++++++++--- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/services/core/java/com/android/server/display/LocalDisplayAdapter.java b/services/core/java/com/android/server/display/LocalDisplayAdapter.java index 1d7c942e8224c..308c755a08680 100644 --- a/services/core/java/com/android/server/display/LocalDisplayAdapter.java +++ b/services/core/java/com/android/server/display/LocalDisplayAdapter.java @@ -410,6 +410,9 @@ final class LocalDisplayAdapter extends DisplayAdapter { final DisplayAddress.Physical physicalAddress = DisplayAddress.fromPhysicalDisplayId(mPhysicalDisplayId); mInfo.address = physicalAddress; + mInfo.densityDpi = (int) (phys.density * 160 + 0.5f); + mInfo.xDpi = phys.xDpi; + mInfo.yDpi = phys.yDpi; // Assume that all built-in displays that have secure output (eg. HDCP) also // support compositing from gralloc protected buffers. @@ -436,9 +439,6 @@ final class LocalDisplayAdapter extends DisplayAdapter { mInfo.displayCutout = DisplayCutout.fromResourcesRectApproximation(res, mInfo.width, mInfo.height); mInfo.type = Display.TYPE_BUILT_IN; - mInfo.densityDpi = (int)(phys.density * 160 + 0.5f); - mInfo.xDpi = phys.xDpi; - mInfo.yDpi = phys.yDpi; mInfo.touch = DisplayDeviceInfo.TOUCH_INTERNAL; } else { mInfo.displayCutout = null; @@ -447,7 +447,6 @@ final class LocalDisplayAdapter extends DisplayAdapter { mInfo.name = getContext().getResources().getString( com.android.internal.R.string.display_manager_hdmi_display_name); mInfo.touch = DisplayDeviceInfo.TOUCH_EXTERNAL; - mInfo.setAssumedDensityForExternalDisplay(phys.width, phys.height); // For demonstration purposes, allow rotation of the external display. // In the future we might allow the user to configure this directly. diff --git a/services/tests/mockingservicestests/src/com/android/server/display/LocalDisplayAdapterTest.java b/services/tests/mockingservicestests/src/com/android/server/display/LocalDisplayAdapterTest.java index 3518dc599cefd..05b655af65ed3 100644 --- a/services/tests/mockingservicestests/src/com/android/server/display/LocalDisplayAdapterTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/display/LocalDisplayAdapterTest.java @@ -120,11 +120,14 @@ public class LocalDisplayAdapterTest { waitForHandlerToComplete(mHandler, HANDLER_WAIT_MS); // This should be public - assertDisplay(mListener.addedDisplays.get(0).getDisplayDeviceInfoLocked(), PORT_A, false); - // This should be private - assertDisplay(mListener.addedDisplays.get(1).getDisplayDeviceInfoLocked(), PORT_B, true); + assertDisplayPrivateFlag(mListener.addedDisplays.get(0).getDisplayDeviceInfoLocked(), + PORT_A, false); // This should be public - assertDisplay(mListener.addedDisplays.get(2).getDisplayDeviceInfoLocked(), PORT_C, false); + assertDisplayPrivateFlag(mListener.addedDisplays.get(1).getDisplayDeviceInfoLocked(), + PORT_B, true); + // This should be public + assertDisplayPrivateFlag(mListener.addedDisplays.get(2).getDisplayDeviceInfoLocked(), + PORT_C, false); } /** @@ -141,12 +144,14 @@ public class LocalDisplayAdapterTest { waitForHandlerToComplete(mHandler, HANDLER_WAIT_MS); // This should be public - assertDisplay(mListener.addedDisplays.get(0).getDisplayDeviceInfoLocked(), PORT_A, false); + assertDisplayPrivateFlag(mListener.addedDisplays.get(0).getDisplayDeviceInfoLocked(), + PORT_A, false); // This should be public - assertDisplay(mListener.addedDisplays.get(1).getDisplayDeviceInfoLocked(), PORT_C, false); + assertDisplayPrivateFlag(mListener.addedDisplays.get(1).getDisplayDeviceInfoLocked(), + PORT_C, false); } - private static void assertDisplay( + private static void assertDisplayPrivateFlag( DisplayDeviceInfo info, int expectedPort, boolean shouldBePrivate) { final DisplayAddress.Physical address = (DisplayAddress.Physical) info.address; assertNotNull(address); @@ -155,6 +160,39 @@ public class LocalDisplayAdapterTest { assertEquals(shouldBePrivate, (info.flags & DisplayDeviceInfo.FLAG_PRIVATE) != 0); } + /** + * Confirm that external display uses physical density. + */ + @Test + public void testDpiValues() throws Exception { + // needs default one always + setUpDisplay(new DisplayConfig(createDisplayAddress(PORT_A), createDummyDisplayInfo())); + setUpDisplay(new DisplayConfig(createDisplayAddress(PORT_B), createDummyDisplayInfo())); + updateAvailableDisplays(); + mAdapter.registerLocked(); + + waitForHandlerToComplete(mHandler, HANDLER_WAIT_MS); + + assertDisplayDpi( + mListener.addedDisplays.get(0).getDisplayDeviceInfoLocked(), PORT_A, 100, 100, + 16000); + assertDisplayDpi( + mListener.addedDisplays.get(1).getDisplayDeviceInfoLocked(), PORT_B, 100, 100, + 16000); + } + + private void assertDisplayDpi(DisplayDeviceInfo info, int expectedPort, + float expectedXdpi, + float expectedYDpi, + int expectedDensityDpi) { + final DisplayAddress.Physical physical = (DisplayAddress.Physical) info.address; + assertNotNull(physical); + assertEquals((byte) expectedPort, physical.getPort()); + assertEquals(expectedXdpi, info.xDpi, 0.01); + assertEquals(expectedYDpi, info.yDpi, 0.01); + assertEquals(expectedDensityDpi, info.densityDpi); + } + private class DisplayConfig { public final DisplayAddress.Physical address; public final IBinder displayToken = new Binder();