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

Commit 7c41d8e4 authored by Marc Kassis's avatar Marc Kassis Committed by Android (Google) Code Review
Browse files

Merge "Display.getHdrCapabilities.getSupportedHdrTypes returns the current...

Merge "Display.getHdrCapabilities.getSupportedHdrTypes returns the current mode's supported HDR types" into udc-dev
parents e044f614 cd7c0ff4
Loading
Loading
Loading
Loading
+26 −22
Original line number Diff line number Diff line
@@ -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;
            }

            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 : mDisplayInfo.hdrCapabilities.getSupportedHdrTypes()) {
                boolean typeDisabled = false;
                for (int userDisabledType : mDisplayInfo.userDisabledHdrTypes) {
                    if (supportedType == userDisabledType) {
                        typeDisabled = true;
                        break;
                    }
                }
                if (!typeDisabled) {
                for (int supportedType : getMode().getSupportedHdrTypes()) {
                    if (!contains(mDisplayInfo.userDisabledHdrTypes, supportedType)) {
                        enabledTypesSet.add(supportedType);
                    }
                }

            int[] enabledTypes = new int[enabledTypesSet.size()];
                supportedHdrTypes = new int[enabledTypesSet.size()];
                int index = 0;
                for (int enabledType : enabledTypesSet) {
                enabledTypes[index++] = enabledType;
                    supportedHdrTypes[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.
+25 −0
Original line number Diff line number Diff line
@@ -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);