Rename DensityMap to DensityMapping per API review
Test: build and presubmit passes
Test: atest DensityMappingTest
Bug: 215434050
Fixes: 215434050
Merged-In: Id54d23c088e98c6e629b62ccb74c9b1cd751615e
Change-Id: Id54d23c088e98c6e629b62ccb74c9b1cd751615e
(cherry picked from commit 140a80e4be)
This commit is contained in:
@@ -23,31 +23,32 @@ import java.util.Comparator;
|
||||
* Class which can compute the logical density for a display resolution. It holds a collection
|
||||
* of pre-configured densities, which are used for look-up and interpolation.
|
||||
*/
|
||||
public class DensityMap {
|
||||
public class DensityMapping {
|
||||
|
||||
// Instead of resolutions we store the squared diagonal size. Diagonals make the map
|
||||
// keys invariant to rotations and are useful for interpolation because they're scalars.
|
||||
// Squared diagonals have the same properties as diagonals (the square function is monotonic)
|
||||
// but also allow us to use integer types and avoid floating point arithmetics.
|
||||
private final Entry[] mSortedDensityMapEntries;
|
||||
private final Entry[] mSortedDensityMappingEntries;
|
||||
|
||||
/**
|
||||
* Creates a density map. The newly created object takes ownership of the passed array.
|
||||
* Creates a density mapping. The newly created object takes ownership of the passed array.
|
||||
*/
|
||||
static DensityMap createByOwning(Entry[] densityMapEntries) {
|
||||
return new DensityMap(densityMapEntries);
|
||||
static DensityMapping createByOwning(Entry[] densityMappingEntries) {
|
||||
return new DensityMapping(densityMappingEntries);
|
||||
}
|
||||
|
||||
private DensityMap(Entry[] densityMapEntries) {
|
||||
Arrays.sort(densityMapEntries, Comparator.comparingInt(entry -> entry.squaredDiagonal));
|
||||
mSortedDensityMapEntries = densityMapEntries;
|
||||
verifyDensityMap(mSortedDensityMapEntries);
|
||||
private DensityMapping(Entry[] densityMappingEntries) {
|
||||
Arrays.sort(densityMappingEntries, Comparator.comparingInt(
|
||||
entry -> entry.squaredDiagonal));
|
||||
mSortedDensityMappingEntries = densityMappingEntries;
|
||||
verifyDensityMapping(mSortedDensityMappingEntries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the logical density for the given resolution.
|
||||
*
|
||||
* If the resolution matches one of the entries in the map, the corresponding density is
|
||||
* If the resolution matches one of the entries in the mapping, the corresponding density is
|
||||
* returned. Otherwise the return value is interpolated using the closest entries in the map.
|
||||
*/
|
||||
public int getDensityForResolution(int width, int height) {
|
||||
@@ -61,7 +62,7 @@ public class DensityMap {
|
||||
Entry left = Entry.ZEROES;
|
||||
Entry right = null;
|
||||
|
||||
for (Entry entry : mSortedDensityMapEntries) {
|
||||
for (Entry entry : mSortedDensityMappingEntries) {
|
||||
if (entry.squaredDiagonal <= squaredDiagonal) {
|
||||
left = entry;
|
||||
} else {
|
||||
@@ -90,7 +91,7 @@ public class DensityMap {
|
||||
/ (rightDiagonal - leftDiagonal) + left.density);
|
||||
}
|
||||
|
||||
private static void verifyDensityMap(Entry[] sortedEntries) {
|
||||
private static void verifyDensityMapping(Entry[] sortedEntries) {
|
||||
for (int i = 1; i < sortedEntries.length; i++) {
|
||||
Entry prev = sortedEntries[i - 1];
|
||||
Entry curr = sortedEntries[i];
|
||||
@@ -100,10 +101,10 @@ public class DensityMap {
|
||||
// resolution (AxB and AxB) or rotated resolution (AxB and BxA), but it can also
|
||||
// happen in the very rare cases when two different resolutions happen to have
|
||||
// the same diagonal (e.g. 100x700 and 500x500).
|
||||
throw new IllegalStateException("Found two entries in the density map with"
|
||||
throw new IllegalStateException("Found two entries in the density mapping with"
|
||||
+ " the same diagonal: " + prev + ", " + curr);
|
||||
} else if (prev.density > curr.density) {
|
||||
throw new IllegalStateException("Found two entries in the density map with"
|
||||
throw new IllegalStateException("Found two entries in the density mapping with"
|
||||
+ " increasing diagonal but decreasing density: " + prev + ", " + curr);
|
||||
}
|
||||
}
|
||||
@@ -111,8 +112,8 @@ public class DensityMap {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DensityMap{"
|
||||
+ "mDensityMapEntries=" + Arrays.toString(mSortedDensityMapEntries)
|
||||
return "DensityMapping{"
|
||||
+ "mDensityMappingEntries=" + Arrays.toString(mSortedDensityMappingEntries)
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@@ -129,7 +130,7 @@ public class DensityMap {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DensityMapEntry{"
|
||||
return "DensityMappingEntry{"
|
||||
+ "squaredDiagonal=" + squaredDiagonal
|
||||
+ ", density=" + density + '}';
|
||||
}
|
||||
@@ -272,7 +272,7 @@ public class DisplayDeviceConfig {
|
||||
private List<String> mQuirks;
|
||||
private boolean mIsHighBrightnessModeEnabled = false;
|
||||
private HighBrightnessModeData mHbmData;
|
||||
private DensityMap mDensityMap;
|
||||
private DensityMapping mDensityMapping;
|
||||
private String mLoadedFrom = null;
|
||||
|
||||
private BrightnessThrottlingData mBrightnessThrottlingData;
|
||||
@@ -592,8 +592,8 @@ public class DisplayDeviceConfig {
|
||||
return mRefreshRateLimitations;
|
||||
}
|
||||
|
||||
public DensityMap getDensityMap() {
|
||||
return mDensityMap;
|
||||
public DensityMapping getDensityMapping() {
|
||||
return mDensityMapping;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -637,7 +637,7 @@ public class DisplayDeviceConfig {
|
||||
+ ", mAmbientLightSensor=" + mAmbientLightSensor
|
||||
+ ", mProximitySensor=" + mProximitySensor
|
||||
+ ", mRefreshRateLimitations= " + Arrays.toString(mRefreshRateLimitations.toArray())
|
||||
+ ", mDensityMap= " + mDensityMap
|
||||
+ ", mDensityMapping= " + mDensityMapping
|
||||
+ "}";
|
||||
}
|
||||
|
||||
@@ -681,7 +681,7 @@ public class DisplayDeviceConfig {
|
||||
try (InputStream in = new BufferedInputStream(new FileInputStream(configFile))) {
|
||||
final DisplayConfiguration config = XmlParser.read(in);
|
||||
if (config != null) {
|
||||
loadDensityMap(config);
|
||||
loadDensityMapping(config);
|
||||
loadBrightnessDefaultFromDdcXml(config);
|
||||
loadBrightnessConstraintsFromConfigXml();
|
||||
loadBrightnessMap(config);
|
||||
@@ -735,28 +735,28 @@ public class DisplayDeviceConfig {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mDensityMap == null) {
|
||||
loadDensityMap(defaultConfig);
|
||||
if (mDensityMapping == null) {
|
||||
loadDensityMapping(defaultConfig);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadDensityMap(DisplayConfiguration config) {
|
||||
private void loadDensityMapping(DisplayConfiguration config) {
|
||||
if (config.getDensityMap() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Density> entriesFromXml = config.getDensityMap().getDensity();
|
||||
|
||||
final DensityMap.Entry[] entries =
|
||||
new DensityMap.Entry[entriesFromXml.size()];
|
||||
final DensityMapping.Entry[] entries =
|
||||
new DensityMapping.Entry[entriesFromXml.size()];
|
||||
for (int i = 0; i < entriesFromXml.size(); i++) {
|
||||
final Density density = entriesFromXml.get(i);
|
||||
entries[i] = new DensityMap.Entry(
|
||||
entries[i] = new DensityMapping.Entry(
|
||||
density.getWidth().intValue(),
|
||||
density.getHeight().intValue(),
|
||||
density.getDensity().intValue());
|
||||
}
|
||||
mDensityMap = DensityMap.createByOwning(entries);
|
||||
mDensityMapping = DensityMapping.createByOwning(entries);
|
||||
}
|
||||
|
||||
private void loadBrightnessDefaultFromDdcXml(DisplayConfiguration config) {
|
||||
|
||||
@@ -469,12 +469,12 @@ final class LocalDisplayAdapter extends DisplayAdapter {
|
||||
}
|
||||
|
||||
private int getLogicalDensity() {
|
||||
DensityMap densityMap = getDisplayDeviceConfig().getDensityMap();
|
||||
if (densityMap == null) {
|
||||
DensityMapping densityMapping = getDisplayDeviceConfig().getDensityMapping();
|
||||
if (densityMapping == null) {
|
||||
return (int) (mStaticDisplayInfo.density * 160 + 0.5);
|
||||
}
|
||||
|
||||
return densityMap.getDensityForResolution(mInfo.width, mInfo.height);
|
||||
return densityMapping.getDensityForResolution(mInfo.width, mInfo.height);
|
||||
}
|
||||
|
||||
private void loadDisplayDeviceConfig() {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.android.server.display;
|
||||
|
||||
import static com.android.server.display.DensityMap.Entry;
|
||||
import static com.android.server.display.DensityMapping.Entry;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
@@ -29,37 +29,37 @@ import org.junit.runner.RunWith;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class DensityMapTest {
|
||||
public class DensityMappingTest {
|
||||
|
||||
@Test
|
||||
public void testConstructor_withBadConfig_throwsException() {
|
||||
assertThrows(IllegalStateException.class, () ->
|
||||
DensityMap.createByOwning(new Entry[]{
|
||||
DensityMapping.createByOwning(new Entry[]{
|
||||
new Entry(1080, 1920, 320),
|
||||
new Entry(1080, 1920, 320)})
|
||||
);
|
||||
|
||||
assertThrows(IllegalStateException.class, () ->
|
||||
DensityMap.createByOwning(new Entry[]{
|
||||
DensityMapping.createByOwning(new Entry[]{
|
||||
new Entry(1080, 1920, 320),
|
||||
new Entry(1920, 1080, 120)})
|
||||
);
|
||||
|
||||
assertThrows(IllegalStateException.class, () ->
|
||||
DensityMap.createByOwning(new Entry[]{
|
||||
DensityMapping.createByOwning(new Entry[]{
|
||||
new Entry(1080, 1920, 320),
|
||||
new Entry(2160, 3840, 120)})
|
||||
);
|
||||
|
||||
assertThrows(IllegalStateException.class, () ->
|
||||
DensityMap.createByOwning(new Entry[]{
|
||||
DensityMapping.createByOwning(new Entry[]{
|
||||
new Entry(1080, 1920, 320),
|
||||
new Entry(3840, 2160, 120)})
|
||||
);
|
||||
|
||||
// Two entries with the same diagonal
|
||||
assertThrows(IllegalStateException.class, () ->
|
||||
DensityMap.createByOwning(new Entry[]{
|
||||
DensityMapping.createByOwning(new Entry[]{
|
||||
new Entry(500, 500, 123),
|
||||
new Entry(100, 700, 456)})
|
||||
);
|
||||
@@ -67,77 +67,77 @@ public class DensityMapTest {
|
||||
|
||||
@Test
|
||||
public void testGetDensityForResolution_withResolutionMatch_returnsDensityFromConfig() {
|
||||
DensityMap densityMap = DensityMap.createByOwning(new Entry[]{
|
||||
DensityMapping densityMapping = DensityMapping.createByOwning(new Entry[]{
|
||||
new Entry(720, 1280, 213),
|
||||
new Entry(1080, 1920, 320),
|
||||
new Entry(2160, 3840, 640)});
|
||||
|
||||
assertEquals(213, densityMap.getDensityForResolution(720, 1280));
|
||||
assertEquals(213, densityMap.getDensityForResolution(1280, 720));
|
||||
assertEquals(213, densityMapping.getDensityForResolution(720, 1280));
|
||||
assertEquals(213, densityMapping.getDensityForResolution(1280, 720));
|
||||
|
||||
assertEquals(320, densityMap.getDensityForResolution(1080, 1920));
|
||||
assertEquals(320, densityMap.getDensityForResolution(1920, 1080));
|
||||
assertEquals(320, densityMapping.getDensityForResolution(1080, 1920));
|
||||
assertEquals(320, densityMapping.getDensityForResolution(1920, 1080));
|
||||
|
||||
assertEquals(640, densityMap.getDensityForResolution(2160, 3840));
|
||||
assertEquals(640, densityMap.getDensityForResolution(3840, 2160));
|
||||
assertEquals(640, densityMapping.getDensityForResolution(2160, 3840));
|
||||
assertEquals(640, densityMapping.getDensityForResolution(3840, 2160));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDensityForResolution_withDiagonalMatch_returnsDensityFromConfig() {
|
||||
DensityMap densityMap = DensityMap.createByOwning(
|
||||
DensityMapping densityMapping = DensityMapping.createByOwning(
|
||||
new Entry[]{ new Entry(500, 500, 123)});
|
||||
|
||||
// 500x500 has the same diagonal as 100x700
|
||||
assertEquals(123, densityMap.getDensityForResolution(100, 700));
|
||||
assertEquals(123, densityMapping.getDensityForResolution(100, 700));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDensityForResolution_withOneEntry_withNoMatch_returnsExtrapolatedDensity() {
|
||||
DensityMap densityMap = DensityMap.createByOwning(
|
||||
DensityMapping densityMapping = DensityMapping.createByOwning(
|
||||
new Entry[]{ new Entry(1080, 1920, 320)});
|
||||
|
||||
assertEquals(320, densityMap.getDensityForResolution(1081, 1920));
|
||||
assertEquals(320, densityMap.getDensityForResolution(1080, 1921));
|
||||
assertEquals(320, densityMapping.getDensityForResolution(1081, 1920));
|
||||
assertEquals(320, densityMapping.getDensityForResolution(1080, 1921));
|
||||
|
||||
assertEquals(640, densityMap.getDensityForResolution(2160, 3840));
|
||||
assertEquals(640, densityMap.getDensityForResolution(3840, 2160));
|
||||
assertEquals(640, densityMapping.getDensityForResolution(2160, 3840));
|
||||
assertEquals(640, densityMapping.getDensityForResolution(3840, 2160));
|
||||
|
||||
assertEquals(213, densityMap.getDensityForResolution(720, 1280));
|
||||
assertEquals(213, densityMap.getDensityForResolution(1280, 720));
|
||||
assertEquals(213, densityMapping.getDensityForResolution(720, 1280));
|
||||
assertEquals(213, densityMapping.getDensityForResolution(1280, 720));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDensityForResolution_withTwoEntries_withNoMatch_returnExtrapolatedDensity() {
|
||||
DensityMap densityMap = DensityMap.createByOwning(new Entry[]{
|
||||
DensityMapping densityMapping = DensityMapping.createByOwning(new Entry[]{
|
||||
new Entry(1080, 1920, 320),
|
||||
new Entry(2160, 3840, 320)});
|
||||
|
||||
// Resolution is smaller than all entries
|
||||
assertEquals(213, densityMap.getDensityForResolution(720, 1280));
|
||||
assertEquals(213, densityMap.getDensityForResolution(1280, 720));
|
||||
assertEquals(213, densityMapping.getDensityForResolution(720, 1280));
|
||||
assertEquals(213, densityMapping.getDensityForResolution(1280, 720));
|
||||
|
||||
// Resolution is bigger than all entries
|
||||
assertEquals(320 * 2, densityMap.getDensityForResolution(2160 * 2, 3840 * 2));
|
||||
assertEquals(320 * 2, densityMap.getDensityForResolution(3840 * 2, 2160 * 2));
|
||||
assertEquals(320 * 2, densityMapping.getDensityForResolution(2160 * 2, 3840 * 2));
|
||||
assertEquals(320 * 2, densityMapping.getDensityForResolution(3840 * 2, 2160 * 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDensityForResolution_withNoMatch_returnsInterpolatedDensity() {
|
||||
{
|
||||
DensityMap densityMap = DensityMap.createByOwning(new Entry[]{
|
||||
DensityMapping densityMapping = DensityMapping.createByOwning(new Entry[]{
|
||||
new Entry(1080, 1920, 320),
|
||||
new Entry(2160, 3840, 320)});
|
||||
|
||||
assertEquals(320, densityMap.getDensityForResolution(2000, 2000));
|
||||
assertEquals(320, densityMapping.getDensityForResolution(2000, 2000));
|
||||
}
|
||||
|
||||
{
|
||||
DensityMap densityMap = DensityMap.createByOwning(new Entry[]{
|
||||
DensityMapping densityMapping = DensityMapping.createByOwning(new Entry[]{
|
||||
new Entry(720, 1280, 213),
|
||||
new Entry(2160, 3840, 640)});
|
||||
|
||||
assertEquals(320, densityMap.getDensityForResolution(1080, 1920));
|
||||
assertEquals(320, densityMap.getDensityForResolution(1920, 1080));
|
||||
assertEquals(320, densityMapping.getDensityForResolution(1080, 1920));
|
||||
assertEquals(320, densityMapping.getDensityForResolution(1920, 1080));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user