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

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

Merge "Each Display Mode now has an array of supported HDR types"

parents f21acd4b 643cd12a
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -48751,7 +48751,7 @@ package android.view {
    method public float getDesiredMaxAverageLuminance();
    method public float getDesiredMaxLuminance();
    method public float getDesiredMinLuminance();
    method public int[] getSupportedHdrTypes();
    method @Deprecated public int[] getSupportedHdrTypes();
    method public void writeToParcel(android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.view.Display.HdrCapabilities> CREATOR;
    field public static final int HDR_TYPE_DOLBY_VISION = 1; // 0x1
@@ -48768,6 +48768,7 @@ package android.view {
    method public int getPhysicalHeight();
    method public int getPhysicalWidth();
    method public float getRefreshRate();
    method @NonNull public int[] getSupportedHdrTypes();
    method public void writeToParcel(android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.view.Display.Mode> CREATOR;
  }
+28 −5
Original line number Diff line number Diff line
@@ -1942,13 +1942,16 @@ public final class Display {
        private final float mRefreshRate;
        @NonNull
        private final float[] mAlternativeRefreshRates;
        @NonNull
        @HdrCapabilities.HdrType
        private final int[] mSupportedHdrTypes;

        /**
         * @hide
         */
        @TestApi
        public Mode(int width, int height, float refreshRate) {
            this(INVALID_MODE_ID, width, height, refreshRate, new float[0]);
            this(INVALID_MODE_ID, width, height, refreshRate, new float[0], new int[0]);
        }

        /**
@@ -1956,14 +1959,14 @@ public final class Display {
         */
        @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
        public Mode(int modeId, int width, int height, float refreshRate) {
            this(modeId, width, height, refreshRate, new float[0]);
            this(modeId, width, height, refreshRate, new float[0], new int[0]);
        }

        /**
         * @hide
         */
        public Mode(int modeId, int width, int height, float refreshRate,
                float[] alternativeRefreshRates) {
                float[] alternativeRefreshRates, @HdrCapabilities.HdrType int[] supportedHdrTypes) {
            mModeId = modeId;
            mWidth = width;
            mHeight = height;
@@ -1971,6 +1974,8 @@ public final class Display {
            mAlternativeRefreshRates =
                    Arrays.copyOf(alternativeRefreshRates, alternativeRefreshRates.length);
            Arrays.sort(mAlternativeRefreshRates);
            mSupportedHdrTypes = Arrays.copyOf(supportedHdrTypes, supportedHdrTypes.length);
            Arrays.sort(mSupportedHdrTypes);
        }

        /**
@@ -2044,6 +2049,15 @@ public final class Display {
            return mAlternativeRefreshRates;
        }

        /**
         * Returns the supported {@link HdrCapabilities} HDR_TYPE_* for this specific mode
         */
        @NonNull
        @HdrCapabilities.HdrType
        public int[] getSupportedHdrTypes() {
            return mSupportedHdrTypes;
        }

        /**
         * Returns {@code true} if this mode matches the given parameters.
         *
@@ -2118,7 +2132,8 @@ public final class Display {
            }
            Mode that = (Mode) other;
            return mModeId == that.mModeId && matches(that.mWidth, that.mHeight, that.mRefreshRate)
                    && Arrays.equals(mAlternativeRefreshRates, that.mAlternativeRefreshRates);
                    && Arrays.equals(mAlternativeRefreshRates, that.mAlternativeRefreshRates)
                    && Arrays.equals(mSupportedHdrTypes, that.mSupportedHdrTypes);
        }

        @Override
@@ -2129,6 +2144,7 @@ public final class Display {
            hash = hash * 17 + mHeight;
            hash = hash * 17 + Float.floatToIntBits(mRefreshRate);
            hash = hash * 17 + Arrays.hashCode(mAlternativeRefreshRates);
            hash = hash * 17 + Arrays.hashCode(mSupportedHdrTypes);
            return hash;
        }

@@ -2141,6 +2157,8 @@ public final class Display {
                    .append(", fps=").append(mRefreshRate)
                    .append(", alternativeRefreshRates=")
                    .append(Arrays.toString(mAlternativeRefreshRates))
                    .append(", supportedHdrTypes=")
                    .append(Arrays.toString(mSupportedHdrTypes))
                    .append("}")
                    .toString();
        }
@@ -2151,7 +2169,8 @@ public final class Display {
        }

        private Mode(Parcel in) {
            this(in.readInt(), in.readInt(), in.readInt(), in.readFloat(), in.createFloatArray());
            this(in.readInt(), in.readInt(), in.readInt(), in.readFloat(), in.createFloatArray(),
                    in.createIntArray());
        }

        @Override
@@ -2161,6 +2180,7 @@ public final class Display {
            out.writeInt(mHeight);
            out.writeFloat(mRefreshRate);
            out.writeFloatArray(mAlternativeRefreshRates);
            out.writeIntArray(mSupportedHdrTypes);
        }

        @SuppressWarnings("hiding")
@@ -2326,6 +2346,9 @@ public final class Display {
        /**
         * Gets the supported HDR types of this display.
         * Returns empty array if HDR is not supported by the display.
         *
         * @deprecated use {@link Display#getMode()}
         * and {@link Mode#getSupportedHdrTypes()} instead
         */
        public @HdrType int[] getSupportedHdrTypes() {
            return mSupportedHdrTypes;
+4 −1
Original line number Diff line number Diff line
@@ -1563,6 +1563,7 @@ public final class SurfaceControl implements Parcelable {
        public float refreshRate;
        public long appVsyncOffsetNanos;
        public long presentationDeadlineNanos;
        public int[] supportedHdrTypes;

        /**
         * The config group ID this config is associated to.
@@ -1582,6 +1583,7 @@ public final class SurfaceControl implements Parcelable {
                    + ", refreshRate=" + refreshRate
                    + ", appVsyncOffsetNanos=" + appVsyncOffsetNanos
                    + ", presentationDeadlineNanos=" + presentationDeadlineNanos
                    + ", supportedHdrTypes=" + Arrays.toString(supportedHdrTypes)
                    + ", group=" + group + "}";
        }

@@ -1598,13 +1600,14 @@ public final class SurfaceControl implements Parcelable {
                    && Float.compare(that.refreshRate, refreshRate) == 0
                    && appVsyncOffsetNanos == that.appVsyncOffsetNanos
                    && presentationDeadlineNanos == that.presentationDeadlineNanos
                    && Arrays.equals(supportedHdrTypes, that.supportedHdrTypes)
                    && group == that.group;
        }

        @Override
        public int hashCode() {
            return Objects.hash(id, width, height, xDpi, yDpi, refreshRate, appVsyncOffsetNanos,
                    presentationDeadlineNanos, group);
                    presentationDeadlineNanos, group, Arrays.hashCode(supportedHdrTypes));
        }
    }

+13 −0
Original line number Diff line number Diff line
@@ -129,6 +129,7 @@ static struct {
    jfieldID appVsyncOffsetNanos;
    jfieldID presentationDeadlineNanos;
    jfieldID group;
    jfieldID supportedHdrTypes;
} gDisplayModeClassInfo;

// Implements SkMallocPixelRef::ReleaseProc, to delete the screenshot on unref.
@@ -1130,6 +1131,16 @@ static jobject convertDisplayModeToJavaObject(JNIEnv* env, const ui::DisplayMode
    env->SetLongField(object, gDisplayModeClassInfo.presentationDeadlineNanos,
                      config.presentationDeadline);
    env->SetIntField(object, gDisplayModeClassInfo.group, config.group);

    const auto& types = config.supportedHdrTypes;
    std::vector<jint> intTypes;
    for (auto type : types) {
        intTypes.push_back(static_cast<jint>(type));
    }
    auto typesArray = env->NewIntArray(types.size());
    env->SetIntArrayRegion(typesArray, 0, intTypes.size(), intTypes.data());
    env->SetObjectField(object, gDisplayModeClassInfo.supportedHdrTypes, typesArray);

    return object;
}

@@ -2191,6 +2202,8 @@ int register_android_view_SurfaceControl(JNIEnv* env)
    gDisplayModeClassInfo.presentationDeadlineNanos =
            GetFieldIDOrDie(env, modeClazz, "presentationDeadlineNanos", "J");
    gDisplayModeClassInfo.group = GetFieldIDOrDie(env, modeClazz, "group", "I");
    gDisplayModeClassInfo.supportedHdrTypes =
            GetFieldIDOrDie(env, modeClazz, "supportedHdrTypes", "[I");

    jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
    jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
+11 −0
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSess

import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.assertArrayEquals;

import android.app.WindowConfiguration;
import android.content.Context;
import android.content.res.Resources;
@@ -399,6 +401,15 @@ public class DisplayTest {
        verifyRealMetricsMatchesBounds(display, sDeviceBoundsLandscape);
    }

    @Test
    public void testSupportedHdrTypesForDisplayModeAreSorted() {
        int[] nonSortedHdrTypes = new int[]{3, 2, 1};
        Display.Mode displayMode = new Display.Mode(0, 0, 0, 0, new float[0], nonSortedHdrTypes);

        int[] sortedHdrTypes = new int[]{1, 2, 3};
        assertArrayEquals(sortedHdrTypes, displayMode.getSupportedHdrTypes());
    }

    // Given rotated display dimensions, calculate the letterboxed app bounds.
    private static Rect buildAppBounds(int displayWidth, int displayHeight) {
        final int midWidth = displayWidth / 2;
Loading