Merge "Display.getHdrCapabilities.getSupportedHdrTypes returns the current mode's supported HDR types" into udc-dev
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user