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

Commit 2df95c98 authored by Ram Indani's avatar Ram Indani Committed by Android (Google) Code Review
Browse files

Merge changes from topic "getsuggestedframerate" into main

* changes:
  Adds getSuggestedFrameRate api
  Adds support for getSuggestedFrameRate api
  adds a flag for getSuggestedFrameRates api
parents 025a1051 0587fa4a
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -51080,6 +51080,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();
@@ -51097,6 +51098,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 ");
+113 −0
Original line number Diff line number Diff line
/*
 * Copyright 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.view;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * A class to create and manage FrameRateCategoryRate for
 * categories Normal and High.
 * @hide
 */
public class FrameRateCategoryRate implements Parcelable {

    private final float mNormal;
    private final float mHigh;

    /**
     * Creates a FrameRateCategoryRate with the provided rates
     * for the categories Normal and High respectively;
     *
     * @param normal rate for the category Normal.
     * @param high rate for the category High.
     * @hide
     */
    public FrameRateCategoryRate(float normal, float high) {
        this.mNormal = normal;
        this.mHigh = high;
    }

    /**
     * @return the value for the category normal;
     * @hide
     */
    public float getNormal() {
        return mNormal;
    }

    /**
     * @return the value for the category high;
     * @hide
     */
    public float getHigh() {
        return mHigh;
    }

    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof FrameRateCategoryRate)) {
            return false;
        }
        FrameRateCategoryRate that = (FrameRateCategoryRate) o;
        return mNormal == that.mNormal && mHigh == that.mHigh;

    }

    @Override
    public int hashCode() {
        int result = 1;
        result = 31 * result + Float.hashCode(mNormal);
        result = 31 * result + Float.hashCode(mHigh);
        return result;
    }

    @Override
    public String toString() {
        return "FrameRateCategoryRate {"
                + "normal=" + mNormal
                + ", high=" + mHigh
                + '}';
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeFloat(mNormal);
        dest.writeFloat(mHigh);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<FrameRateCategoryRate> CREATOR =
            new Creator<>() {
                @Override
                public FrameRateCategoryRate createFromParcel(Parcel in) {
                    return new FrameRateCategoryRate(in.readFloat(), in.readFloat());
                }

                @Override
                public FrameRateCategoryRate[] newArray(int size) {
                    return new FrameRateCategoryRate[size];
                }
            };
}
+6 −2
Original line number Diff line number Diff line
@@ -1798,6 +1798,7 @@ public final class SurfaceControl implements Parcelable {
        public int activeDisplayModeId;
        public float renderFrameRate;
        public boolean hasArrSupport;
        public FrameRateCategoryRate frameRateCategoryRate;

        public int[] supportedColorModes;
        public int activeColorMode;
@@ -1816,6 +1817,7 @@ public final class SurfaceControl implements Parcelable {
                    + ", activeDisplayModeId=" + activeDisplayModeId
                    + ", renderFrameRate=" + renderFrameRate
                    + ", hasArrSupport=" + hasArrSupport
                    + ", frameRateCategoryRate=" + frameRateCategoryRate
                    + ", supportedColorModes=" + Arrays.toString(supportedColorModes)
                    + ", activeColorMode=" + activeColorMode
                    + ", hdrCapabilities=" + hdrCapabilities
@@ -1836,13 +1838,15 @@ public final class SurfaceControl implements Parcelable {
                && activeColorMode == that.activeColorMode
                && Objects.equals(hdrCapabilities, that.hdrCapabilities)
                && preferredBootDisplayMode == that.preferredBootDisplayMode
                && hasArrSupport == that.hasArrSupport;
                && hasArrSupport == that.hasArrSupport
                && Objects.equals(frameRateCategoryRate, that.frameRateCategoryRate);
        }

        @Override
        public int hashCode() {
            return Objects.hash(Arrays.hashCode(supportedDisplayModes), activeDisplayModeId,
                    renderFrameRate, activeColorMode, hdrCapabilities, hasArrSupport);
                    renderFrameRate, activeColorMode, hdrCapabilities, hasArrSupport,
                    frameRateCategoryRate);
        }
    }

Loading