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

Commit 0587fa4a authored by ramindani's avatar ramindani
Browse files

Adds getSuggestedFrameRate api

This api returns the suggested frame rate for the provided categories.
The suggested rate can be used further to build the FrameRateParams for setFrameRate call or call
the setFrameRate using the FrameRateParams.

BUG: 361433796
Flag: com.android.server.display.feature.flags.enable_get_suggested_frame_rate
Test: atest android.display.cts.DisplayTest
Change-Id: Ic566c77e9e7eae0a4c6a687a9a176e0ea7a4a5ea
parent 1569bd0f
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -51013,6 +51013,7 @@ package android.view {
    method @NonNull public android.view.DisplayShape getShape();
    method @Deprecated public void getSize(android.graphics.Point);
    method public int getState();
    method @FlaggedApi("com.android.server.display.feature.flags.enable_get_suggested_frame_rate") public float getSuggestedFrameRate(int);
    method public android.view.Display.Mode[] getSupportedModes();
    method @Deprecated public float[] getSupportedRefreshRates();
    method @Deprecated public int getWidth();
@@ -51030,6 +51031,8 @@ package android.view {
    field public static final int FLAG_ROUND = 16; // 0x10
    field public static final int FLAG_SECURE = 2; // 0x2
    field public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 1; // 0x1
    field @FlaggedApi("com.android.server.display.feature.flags.enable_get_suggested_frame_rate") public static final int FRAME_RATE_CATEGORY_HIGH = 1; // 0x1
    field @FlaggedApi("com.android.server.display.feature.flags.enable_get_suggested_frame_rate") public static final int FRAME_RATE_CATEGORY_NORMAL = 0; // 0x0
    field public static final int INVALID_DISPLAY = -1; // 0xffffffff
    field public static final int STATE_DOZE = 3; // 0x3
    field public static final int STATE_DOZE_SUSPEND = 4; // 0x4
+55 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.hardware.flags.Flags.FLAG_OVERLAYPROPERTIES_CLASS_API;

import static com.android.server.display.feature.flags.Flags.FLAG_HIGHEST_HDR_SDR_RATIO_API;
import static com.android.server.display.feature.flags.Flags.FLAG_ENABLE_HAS_ARR_SUPPORT;
import static com.android.server.display.feature.flags.Flags.FLAG_ENABLE_GET_SUGGESTED_FRAME_RATE;

import android.Manifest;
import android.annotation.FlaggedApi;
@@ -1278,6 +1279,60 @@ public final class Display {
        }
    }

    @FlaggedApi(FLAG_ENABLE_GET_SUGGESTED_FRAME_RATE)
    public static final int FRAME_RATE_CATEGORY_NORMAL = 0;
    @FlaggedApi(FLAG_ENABLE_GET_SUGGESTED_FRAME_RATE)
    public static final int FRAME_RATE_CATEGORY_HIGH = 1;

    /**
     * @hide
     */
    @IntDef(prefix = {"FRAME_RATE_CATEGORY_"},
            value = {
                FRAME_RATE_CATEGORY_NORMAL,
                FRAME_RATE_CATEGORY_HIGH
            })
    @Retention(RetentionPolicy.SOURCE)
    public @interface FrameRateCategory {}

    /**
     * <p> Gets the display-defined frame rate given a descriptive frame rate category. </p>
     *
     * <p> For example, an animation that does not require fast render rates can use
     * the {@link #FRAME_RATE_CATEGORY_NORMAL} to get the suggested frame rate.
     * The suggested frame rate then can be used in the
     * {@link Surface.FrameRateParams.Builder#setDesiredRateRange} for desiredMinRate.
     *
     * <pre>{@code
     *  float desiredMinRate = display.getSuggestedFrameRate(FRAME_RATE_CATEGORY_NORMAL);
     *  Surface.FrameRateParams params = new Surface.FrameRateParams.Builder().
     *                                      setDesiredRateRange(desiredMinRate, Float.MAX).build();
     *  surface.setFrameRate(params);
     * }</pre>
     * </p>
     *
     * @param category either {@link #FRAME_RATE_CATEGORY_NORMAL}
     *                 or {@link #FRAME_RATE_CATEGORY_HIGH}
     *
     * @see Surface#setFrameRate(Surface.FrameRateParams)
     * @see SurfaceControl.Transaction#setFrameRate(SurfaceControl, Surface.FrameRateParams)
     * @throws IllegalArgumentException when category is not {@link #FRAME_RATE_CATEGORY_NORMAL}
     * or {@link #FRAME_RATE_CATEGORY_HIGH}
     */
    @FlaggedApi(FLAG_ENABLE_GET_SUGGESTED_FRAME_RATE)
    public float getSuggestedFrameRate(@FrameRateCategory int category) {
        synchronized (mLock) {
            updateDisplayInfoLocked();
            if (category == FRAME_RATE_CATEGORY_HIGH) {
                return mDisplayInfo.frameRateCategoryRate.getHigh();
            } else if (category == FRAME_RATE_CATEGORY_NORMAL) {
                return mDisplayInfo.frameRateCategoryRate.getNormal();
            } else {
                throw new IllegalArgumentException("Invalid FrameRateCategory provided");
            }
        }
    }

    /**
     * <p> Returns true if the connected display can be switched into a mode with minimal
     * post processing. </p>
+13 −0
Original line number Diff line number Diff line
@@ -203,6 +203,12 @@ public final class DisplayInfo implements Parcelable {
     */
    public boolean hasArrSupport;

    /**
     * Represents frame rate for the FrameRateCategory Normal and High.
     * @see android.view.Display#getSuggestedFrameRate(int) for more details.
     */
    public FrameRateCategoryRate frameRateCategoryRate;

    /**
     * The default display mode.
     */
@@ -443,6 +449,7 @@ public final class DisplayInfo implements Parcelable {
                && modeId == other.modeId
                && renderFrameRate == other.renderFrameRate
                && hasArrSupport == other.hasArrSupport
                && Objects.equals(frameRateCategoryRate, other.frameRateCategoryRate)
                && defaultModeId == other.defaultModeId
                && userPreferredModeId == other.userPreferredModeId
                && Arrays.equals(supportedModes, other.supportedModes)
@@ -505,6 +512,7 @@ public final class DisplayInfo implements Parcelable {
        modeId = other.modeId;
        renderFrameRate = other.renderFrameRate;
        hasArrSupport = other.hasArrSupport;
        frameRateCategoryRate = other.frameRateCategoryRate;
        defaultModeId = other.defaultModeId;
        userPreferredModeId = other.userPreferredModeId;
        supportedModes = Arrays.copyOf(other.supportedModes, other.supportedModes.length);
@@ -562,6 +570,8 @@ public final class DisplayInfo implements Parcelable {
        modeId = source.readInt();
        renderFrameRate = source.readFloat();
        hasArrSupport = source.readBoolean();
        frameRateCategoryRate = source.readParcelable(null,
                android.view.FrameRateCategoryRate.class);
        defaultModeId = source.readInt();
        userPreferredModeId = source.readInt();
        int nModes = source.readInt();
@@ -636,6 +646,7 @@ public final class DisplayInfo implements Parcelable {
        dest.writeInt(modeId);
        dest.writeFloat(renderFrameRate);
        dest.writeBoolean(hasArrSupport);
        dest.writeParcelable(frameRateCategoryRate, flags);
        dest.writeInt(defaultModeId);
        dest.writeInt(userPreferredModeId);
        dest.writeInt(supportedModes.length);
@@ -883,6 +894,8 @@ public final class DisplayInfo implements Parcelable {
        sb.append(renderFrameRate);
        sb.append(", hasArrSupport ");
        sb.append(hasArrSupport);
        sb.append(", frameRateCategoryRate ");
        sb.append(frameRateCategoryRate);
        sb.append(", defaultMode ");
        sb.append(defaultModeId);
        sb.append(", userPreferredModeId ");
+24 −0
Original line number Diff line number Diff line
@@ -116,6 +116,7 @@ static struct {
    jfieldID activeDisplayModeId;
    jfieldID renderFrameRate;
    jfieldID hasArrSupport;
    jfieldID frameRateCategoryRate;
    jfieldID supportedColorModes;
    jfieldID activeColorMode;
    jfieldID hdrCapabilities;
@@ -291,6 +292,11 @@ static struct {
    jfieldID frameNumber;
} gStalledTransactionInfoClassInfo;

static struct {
    jclass clazz;
    jmethodID ctor;
} gFrameRateCategoryRateClassInfo;

constexpr ui::Dataspace pickDataspaceFromColorMode(const ui::ColorMode colorMode) {
    switch (colorMode) {
        case ui::ColorMode::DISPLAY_P3:
@@ -1387,6 +1393,13 @@ static jobject nativeGetStaticDisplayInfo(JNIEnv* env, jclass clazz, jlong id) {
    return object;
}

static jobject convertFrameRateCategoryRateToJavaObject(
        JNIEnv* env, const ui::FrameRateCategoryRate& frameRateCategoryRate) {
    return env->NewObject(gFrameRateCategoryRateClassInfo.clazz,
                          gFrameRateCategoryRateClassInfo.ctor, frameRateCategoryRate.getNormal(),
                          frameRateCategoryRate.getHigh());
}

static jobject convertDisplayModeToJavaObject(JNIEnv* env, const ui::DisplayMode& config) {
    jobject object = env->NewObject(gDisplayModeClassInfo.clazz, gDisplayModeClassInfo.ctor);
    env->SetIntField(object, gDisplayModeClassInfo.id, config.id);
@@ -1455,6 +1468,8 @@ static jobject nativeGetDynamicDisplayInfo(JNIEnv* env, jclass clazz, jlong disp
                     info.activeDisplayModeId);
    env->SetFloatField(object, gDynamicDisplayInfoClassInfo.renderFrameRate, info.renderFrameRate);
    env->SetBooleanField(object, gDynamicDisplayInfoClassInfo.hasArrSupport, info.hasArrSupport);
    env->SetObjectField(object, gDynamicDisplayInfoClassInfo.frameRateCategoryRate,
                        convertFrameRateCategoryRateToJavaObject(env, info.frameRateCategoryRate));
    jintArray colorModesArray = env->NewIntArray(info.supportedColorModes.size());
    if (colorModesArray == NULL) {
        jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
@@ -2644,6 +2659,15 @@ int register_android_view_SurfaceControl(JNIEnv* env)
            GetFieldIDOrDie(env, dynamicInfoClazz, "renderFrameRate", "F");
    gDynamicDisplayInfoClassInfo.hasArrSupport =
            GetFieldIDOrDie(env, dynamicInfoClazz, "hasArrSupport", "Z");

    gDynamicDisplayInfoClassInfo.frameRateCategoryRate =
            GetFieldIDOrDie(env, dynamicInfoClazz, "frameRateCategoryRate",
                            "Landroid/view/FrameRateCategoryRate;");
    jclass frameRateCategoryRateClazz = FindClassOrDie(env, "android/view/FrameRateCategoryRate");
    gFrameRateCategoryRateClassInfo.clazz = MakeGlobalRefOrDie(env, frameRateCategoryRateClazz);
    gFrameRateCategoryRateClassInfo.ctor =
            GetMethodIDOrDie(env, frameRateCategoryRateClazz, "<init>", "(FF)V");

    gDynamicDisplayInfoClassInfo.supportedColorModes =
            GetFieldIDOrDie(env, dynamicInfoClazz, "supportedColorModes", "[I");
    gDynamicDisplayInfoClassInfo.activeColorMode =
+10 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.view.DisplayAddress;
import android.view.DisplayCutout;
import android.view.DisplayEventReceiver;
import android.view.DisplayShape;
import android.view.FrameRateCategoryRate;
import android.view.RoundedCorners;
import android.view.Surface;

@@ -299,6 +300,11 @@ final class DisplayDeviceInfo {
     */
    public boolean hasArrSupport;

    /**
     * Represents frame rate for the FrameRateCategory Normal and High.
     * @see android.view.Display#getSuggestedFrameRate(int) for more details.
     */
    public FrameRateCategoryRate frameRateCategoryRate;
    /**
     * The default mode of the display.
     */
@@ -548,7 +554,8 @@ final class DisplayDeviceInfo {
                || !Objects.equals(roundedCorners, other.roundedCorners)
                || installOrientation != other.installOrientation
                || !Objects.equals(displayShape, other.displayShape)
                || hasArrSupport != other.hasArrSupport) {
                || hasArrSupport != other.hasArrSupport
                || !Objects.equals(frameRateCategoryRate, other.frameRateCategoryRate)) {
            diff |= DIFF_OTHER;
        }
        return diff;
@@ -567,6 +574,7 @@ final class DisplayDeviceInfo {
        modeId = other.modeId;
        renderFrameRate = other.renderFrameRate;
        hasArrSupport = other.hasArrSupport;
        frameRateCategoryRate = other.frameRateCategoryRate;
        defaultModeId = other.defaultModeId;
        userPreferredModeId = other.userPreferredModeId;
        supportedModes = other.supportedModes;
@@ -612,6 +620,7 @@ final class DisplayDeviceInfo {
        sb.append(", modeId ").append(modeId);
        sb.append(", renderFrameRate ").append(renderFrameRate);
        sb.append(", hasArrSupport ").append(hasArrSupport);
        sb.append(", frameRateCategoryRate ").append(frameRateCategoryRate);
        sb.append(", defaultModeId ").append(defaultModeId);
        sb.append(", userPreferredModeId ").append(userPreferredModeId);
        sb.append(", supportedModes ").append(Arrays.toString(supportedModes));
Loading