Display.getHdrCapabilities.getSupportedHdrTypes returns the current mode's supported HDR types

Bug: 241349060
Test: atest DisplayTest
Change-Id: Ie240873f6038600e4e00bce7c04710b4cd7fdcb7
This commit is contained in:
Marc Kassis
2023-03-31 10:28:04 +02:00
parent d0b9808b90
commit cd7c0ff42e
2 changed files with 51 additions and 22 deletions

View File

@@ -1218,47 +1218,51 @@ public final class Display {
}
/**
* Returns the display's HDR capabilities.
* Returns the current display mode's HDR capabilities.
*
* @see #isHdr()
*/
public HdrCapabilities getHdrCapabilities() {
synchronized (mLock) {
updateDisplayInfoLocked();
if (mDisplayInfo.userDisabledHdrTypes.length == 0) {
return mDisplayInfo.hdrCapabilities;
}
if (mDisplayInfo.hdrCapabilities == null) {
return null;
}
ArraySet<Integer> enabledTypesSet = new ArraySet<>();
for (int supportedType : mDisplayInfo.hdrCapabilities.getSupportedHdrTypes()) {
boolean typeDisabled = false;
for (int userDisabledType : mDisplayInfo.userDisabledHdrTypes) {
if (supportedType == userDisabledType) {
typeDisabled = true;
break;
int[] supportedHdrTypes;
if (mDisplayInfo.userDisabledHdrTypes.length == 0) {
int[] modeSupportedHdrTypes = getMode().getSupportedHdrTypes();
supportedHdrTypes = Arrays.copyOf(modeSupportedHdrTypes,
modeSupportedHdrTypes.length);
} else {
ArraySet<Integer> enabledTypesSet = new ArraySet<>();
for (int supportedType : getMode().getSupportedHdrTypes()) {
if (!contains(mDisplayInfo.userDisabledHdrTypes, supportedType)) {
enabledTypesSet.add(supportedType);
}
}
if (!typeDisabled) {
enabledTypesSet.add(supportedType);
supportedHdrTypes = new int[enabledTypesSet.size()];
int index = 0;
for (int enabledType : enabledTypesSet) {
supportedHdrTypes[index++] = enabledType;
}
}
int[] enabledTypes = new int[enabledTypesSet.size()];
int index = 0;
for (int enabledType : enabledTypesSet) {
enabledTypes[index++] = enabledType;
}
return new HdrCapabilities(enabledTypes,
return new HdrCapabilities(supportedHdrTypes,
mDisplayInfo.hdrCapabilities.mMaxLuminance,
mDisplayInfo.hdrCapabilities.mMaxAverageLuminance,
mDisplayInfo.hdrCapabilities.mMinLuminance);
}
}
private boolean contains(int[] disabledHdrTypes, int hdrType) {
for (Integer disabledHdrFormat : disabledHdrTypes) {
if (disabledHdrFormat == hdrType) {
return true;
}
}
return false;
}
/**
* @hide
* Returns the current mode's supported HDR types.

View File

@@ -141,6 +141,31 @@ public class DisplayTest {
assertArrayEquals(hdrTypesWithoutDv, display.getReportedHdrTypes());
}
@Test
public void testGetHdrCapabilities_getSupportedHdrTypes_returns_mode_specific_hdr_types() {
setDisplayInfoPortrait(mDisplayInfo);
float[] alternativeRefreshRates = new float[0];
int[] hdrTypesWithDv = new int[] {1, 2, 3, 4};
Display.Mode modeWithDv = new Display.Mode(/* modeId= */ 0, 0, 0, 0f,
alternativeRefreshRates, hdrTypesWithDv);
int[] hdrTypesWithoutDv = new int[]{2, 3, 4};
Display.Mode modeWithoutDv = new Display.Mode(/* modeId= */ 1, 0, 0, 0f,
alternativeRefreshRates, hdrTypesWithoutDv);
mDisplayInfo.supportedModes = new Display.Mode[] {modeWithoutDv, modeWithDv};
mDisplayInfo.hdrCapabilities = new Display.HdrCapabilities(hdrTypesWithDv, 0, 0, 0);
final Display display = new Display(mDisplayManagerGlobal, DEFAULT_DISPLAY, mDisplayInfo,
DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS);
mDisplayInfo.modeId = 0;
assertArrayEquals(hdrTypesWithDv, display.getHdrCapabilities().getSupportedHdrTypes());
mDisplayInfo.modeId = 1;
assertArrayEquals(hdrTypesWithoutDv, display.getHdrCapabilities().getSupportedHdrTypes());
}
@Test
public void testConstructor_defaultDisplayAdjustments_matchesDisplayInfo() {
setDisplayInfoPortrait(mDisplayInfo);