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

Commit 1cd9dc53 authored by Marc Kassis's avatar Marc Kassis Committed by Automerger Merge Worker
Browse files

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

Merge "Display.getHdrCapabilities.getSupportedHdrTypes returns the current mode's supported HDR types" into udc-dev am: 7c41d8e4

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22100006



Change-Id: Iaa89fe5b98b2a3a6431585bde8df3f35685cc44c
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 22140b9d 7c41d8e4
Loading
Loading
Loading
Loading
+26 −22
Original line number Original line 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()
     * @see #isHdr()
     */
     */
    public HdrCapabilities getHdrCapabilities() {
    public HdrCapabilities getHdrCapabilities() {
        synchronized (mLock) {
        synchronized (mLock) {
            updateDisplayInfoLocked();
            updateDisplayInfoLocked();
            if (mDisplayInfo.userDisabledHdrTypes.length == 0) {
                return mDisplayInfo.hdrCapabilities;
            }

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


            int[] enabledTypes = new int[enabledTypesSet.size()];
                supportedHdrTypes = new int[enabledTypesSet.size()];
                int index = 0;
                int index = 0;
                for (int enabledType : enabledTypesSet) {
                for (int enabledType : enabledTypesSet) {
                enabledTypes[index++] = enabledType;
                    supportedHdrTypes[index++] = enabledType;
                }
            }
            }
            return new HdrCapabilities(enabledTypes,
            return new HdrCapabilities(supportedHdrTypes,
                    mDisplayInfo.hdrCapabilities.mMaxLuminance,
                    mDisplayInfo.hdrCapabilities.mMaxLuminance,
                    mDisplayInfo.hdrCapabilities.mMaxAverageLuminance,
                    mDisplayInfo.hdrCapabilities.mMaxAverageLuminance,
                    mDisplayInfo.hdrCapabilities.mMinLuminance);
                    mDisplayInfo.hdrCapabilities.mMinLuminance);
        }
        }
    }
    }


    private boolean contains(int[] disabledHdrTypes, int hdrType) {
        for (Integer disabledHdrFormat : disabledHdrTypes) {
            if (disabledHdrFormat == hdrType) {
                return true;
            }
        }
        return false;
    }

    /**
    /**
     * @hide
     * @hide
     * Returns the current mode's supported HDR types.
     * Returns the current mode's supported HDR types.
+25 −0
Original line number Original line Diff line number Diff line
@@ -141,6 +141,31 @@ public class DisplayTest {
        assertArrayEquals(hdrTypesWithoutDv, display.getReportedHdrTypes());
        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
    @Test
    public void testConstructor_defaultDisplayAdjustments_matchesDisplayInfo() {
    public void testConstructor_defaultDisplayAdjustments_matchesDisplayInfo() {
        setDisplayInfoPortrait(mDisplayInfo);
        setDisplayInfoPortrait(mDisplayInfo);