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

Commit 1569bd0f authored by ramindani's avatar ramindani
Browse files

Adds support for getSuggestedFrameRate api

BUG: 361433796
Flag: com.android.server.display.feature.flags.enable_get_suggested_frame_rate
Test: atest android.display.cts.DisplayTest
Test: Check value of the frameRateCategoryRate in the `adb shell dumpsys display`
Change-Id: I017ae994312325df33ec75d4b2aa0187e9388ba8
parent 15a0bb22
Loading
Loading
Loading
Loading
+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
@@ -1811,6 +1811,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;
@@ -1829,6 +1830,7 @@ public final class SurfaceControl implements Parcelable {
                    + ", activeDisplayModeId=" + activeDisplayModeId
                    + ", renderFrameRate=" + renderFrameRate
                    + ", hasArrSupport=" + hasArrSupport
                    + ", frameRateCategoryRate=" + frameRateCategoryRate
                    + ", supportedColorModes=" + Arrays.toString(supportedColorModes)
                    + ", activeColorMode=" + activeColorMode
                    + ", hdrCapabilities=" + hdrCapabilities
@@ -1849,13 +1851,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);
        }
    }

+13 −0
Original line number Diff line number Diff line
@@ -45,6 +45,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.SurfaceControl;

@@ -247,6 +248,7 @@ final class LocalDisplayAdapter extends DisplayAdapter {
        private boolean mDisplayModeSpecsInvalid;
        private int mActiveColorMode;
        private boolean mHasArrSupport;
        private FrameRateCategoryRate mFrameRateCategoryRate;
        private Display.HdrCapabilities mHdrCapabilities;
        private boolean mAllmSupported;
        private boolean mGameContentTypeSupported;
@@ -313,6 +315,7 @@ final class LocalDisplayAdapter extends DisplayAdapter {
            changed |= updateAllmSupport(dynamicInfo.autoLowLatencyModeSupported);
            changed |= updateGameContentTypeSupport(dynamicInfo.gameContentTypeSupported);
            changed |= updateHasArrSupportLocked(dynamicInfo.hasArrSupport);
            changed |= updateFrameRateCategoryRatesLocked(dynamicInfo.frameRateCategoryRate);

            if (changed) {
                mHavePendingChanges = true;
@@ -604,6 +607,15 @@ final class LocalDisplayAdapter extends DisplayAdapter {
            return true;
        }

        private boolean updateFrameRateCategoryRatesLocked(
                FrameRateCategoryRate newFrameRateCategoryRate) {
            if (Objects.equals(mFrameRateCategoryRate, newFrameRateCategoryRate)) {
                return false;
            }
            mFrameRateCategoryRate = newFrameRateCategoryRate;
            return true;
        }

        private boolean updateHasArrSupportLocked(boolean newHasArrSupport) {
            if (mHasArrSupport == newHasArrSupport) {
                return false;
@@ -695,6 +707,7 @@ final class LocalDisplayAdapter extends DisplayAdapter {
                }
                mInfo.hdrCapabilities = mHdrCapabilities;
                mInfo.hasArrSupport = mHasArrSupport;
                mInfo.frameRateCategoryRate = mFrameRateCategoryRate;
                mInfo.appVsyncOffsetNanos = mActiveSfDisplayMode.appVsyncOffsetNanos;
                mInfo.presentationDeadlineNanos = mActiveSfDisplayMode.presentationDeadlineNanos;
                mInfo.state = mState;
+1 −0
Original line number Diff line number Diff line
@@ -507,6 +507,7 @@ final class LogicalDisplay {
            mBaseDisplayInfo.modeId = deviceInfo.modeId;
            mBaseDisplayInfo.renderFrameRate = deviceInfo.renderFrameRate;
            mBaseDisplayInfo.hasArrSupport = deviceInfo.hasArrSupport;
            mBaseDisplayInfo.frameRateCategoryRate = deviceInfo.frameRateCategoryRate;
            mBaseDisplayInfo.defaultModeId = deviceInfo.defaultModeId;
            mBaseDisplayInfo.userPreferredModeId = deviceInfo.userPreferredModeId;
            mBaseDisplayInfo.supportedModes = Arrays.copyOf(