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

Commit 1e0b563e authored by Oleg Petšjonkin's avatar Oleg Petšjonkin Committed by Android (Google) Code Review
Browse files

Merge "Adding SupportedModesVote" into main

parents b2e1acac 5b8b7f05
Loading
Loading
Loading
Loading
+59 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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 com.android.server.display.mode;

import java.util.Objects;

class BaseModeRefreshRateVote implements Vote {

    /**
     * The preferred refresh rate selected by the app. It is used to validate that the summary
     * refresh rate ranges include this value, and are not restricted by a lower priority vote.
     */
    final float mAppRequestBaseModeRefreshRate;

    BaseModeRefreshRateVote(float baseModeRefreshRate) {
        mAppRequestBaseModeRefreshRate = baseModeRefreshRate;
    }

    @Override
    public void updateSummary(DisplayModeDirector.VoteSummary summary) {
        if (summary.appRequestBaseModeRefreshRate == 0f
                && mAppRequestBaseModeRefreshRate > 0f) {
            summary.appRequestBaseModeRefreshRate = mAppRequestBaseModeRefreshRate;
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof BaseModeRefreshRateVote that)) return false;
        return Float.compare(that.mAppRequestBaseModeRefreshRate,
                mAppRequestBaseModeRefreshRate) == 0;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mAppRequestBaseModeRefreshRate);
    }

    @Override
    public String toString() {
        return "BaseModeRefreshRateVote{ mAppRequestBaseModeRefreshRate="
                + mAppRequestBaseModeRefreshRate + " }";
    }
}
+51 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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 com.android.server.display.mode;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

class CombinedVote implements Vote {
    final List<Vote> mVotes;

    CombinedVote(List<Vote> votes) {
        mVotes = Collections.unmodifiableList(votes);
    }

    @Override
    public void updateSummary(DisplayModeDirector.VoteSummary summary) {
        mVotes.forEach(vote -> vote.updateSummary(summary));
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof CombinedVote that)) return false;
        return Objects.equals(mVotes, that.mVotes);
    }

    @Override
    public int hashCode() {
        return Objects.hash(mVotes);
    }

    @Override
    public String toString() {
        return "CombinedVote{ mVotes=" + mVotes + " }";
    }
}
+56 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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 com.android.server.display.mode;

import java.util.Objects;

class DisableRefreshRateSwitchingVote implements Vote {

    /**
     * Whether refresh rate switching should be disabled (i.e. the refresh rate range is
     * a single value).
     */
    final boolean mDisableRefreshRateSwitching;

    DisableRefreshRateSwitchingVote(boolean disableRefreshRateSwitching) {
        mDisableRefreshRateSwitching = disableRefreshRateSwitching;
    }

    @Override
    public void updateSummary(DisplayModeDirector.VoteSummary summary) {
        summary.disableRefreshRateSwitching =
                summary.disableRefreshRateSwitching || mDisableRefreshRateSwitching;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof DisableRefreshRateSwitchingVote that)) return false;
        return mDisableRefreshRateSwitching == that.mDisableRefreshRateSwitching;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mDisableRefreshRateSwitching);
    }

    @Override
    public String toString() {
        return "DisableRefreshRateSwitchingVote{ mDisableRefreshRateSwitching="
                + mDisableRefreshRateSwitching + " }";
    }
}
+10 −44
Original line number Diff line number Diff line
@@ -262,7 +262,7 @@ public class DisplayModeDirector {
        mVotesStorage.setLoggingEnabled(loggingEnabled);
    }

    private static final class VoteSummary {
    static final class VoteSummary {
        public float minPhysicalRefreshRate;
        public float maxPhysicalRefreshRate;
        public float minRenderFrameRate;
@@ -274,7 +274,12 @@ public class DisplayModeDirector {
        public boolean disableRefreshRateSwitching;
        public float appRequestBaseModeRefreshRate;

        VoteSummary() {
        public List<SupportedModesVote.SupportedMode> supportedModes;

        final boolean mIsDisplayResolutionRangeVotingEnabled;

        VoteSummary(boolean isDisplayResolutionRangeVotingEnabled) {
            mIsDisplayResolutionRangeVotingEnabled = isDisplayResolutionRangeVotingEnabled;
            reset();
        }

@@ -322,46 +327,7 @@ public class DisplayModeDirector {
                continue;
            }

            // For physical refresh rates, just use the tightest bounds of all the votes.
            // The refresh rate cannot be lower than the minimal render frame rate.
            final float minPhysicalRefreshRate = Math.max(vote.refreshRateRanges.physical.min,
                    vote.refreshRateRanges.render.min);
            summary.minPhysicalRefreshRate = Math.max(summary.minPhysicalRefreshRate,
                    minPhysicalRefreshRate);
            summary.maxPhysicalRefreshRate = Math.min(summary.maxPhysicalRefreshRate,
                    vote.refreshRateRanges.physical.max);

            // Same goes to render frame rate, but frame rate cannot exceed the max physical
            // refresh rate
            final float maxRenderFrameRate = Math.min(vote.refreshRateRanges.render.max,
                    vote.refreshRateRanges.physical.max);
            summary.minRenderFrameRate = Math.max(summary.minRenderFrameRate,
                    vote.refreshRateRanges.render.min);
            summary.maxRenderFrameRate = Math.min(summary.maxRenderFrameRate, maxRenderFrameRate);

            // For display size, disable refresh rate switching and base mode refresh rate use only
            // the first vote we come across (i.e. the highest priority vote that includes the
            // attribute).
            if (vote.height > 0 && vote.width > 0) {
                if (summary.width == Vote.INVALID_SIZE && summary.height == Vote.INVALID_SIZE) {
                    summary.width = vote.width;
                    summary.height = vote.height;
                    summary.minWidth = vote.minWidth;
                    summary.minHeight = vote.minHeight;
                } else if (mIsDisplayResolutionRangeVotingEnabled) {
                    summary.width = Math.min(summary.width, vote.width);
                    summary.height = Math.min(summary.height, vote.height);
                    summary.minWidth = Math.max(summary.minWidth, vote.minWidth);
                    summary.minHeight = Math.max(summary.minHeight, vote.minHeight);
                }
            }
            if (!summary.disableRefreshRateSwitching && vote.disableRefreshRateSwitching) {
                summary.disableRefreshRateSwitching = true;
            }
            if (summary.appRequestBaseModeRefreshRate == 0f
                    && vote.appRequestBaseModeRefreshRate > 0f) {
                summary.appRequestBaseModeRefreshRate = vote.appRequestBaseModeRefreshRate;
            }
            vote.updateSummary(summary);

            if (mLoggingEnabled) {
                Slog.w(TAG, "Vote summary for priority " + Vote.priorityToString(priority)
@@ -443,7 +409,7 @@ public class DisplayModeDirector {

            ArrayList<Display.Mode> availableModes = new ArrayList<>();
            availableModes.add(defaultMode);
            VoteSummary primarySummary = new VoteSummary();
            VoteSummary primarySummary = new VoteSummary(mIsDisplayResolutionRangeVotingEnabled);
            int lowestConsideredPriority = Vote.MIN_PRIORITY;
            int highestConsideredPriority = Vote.MAX_PRIORITY;

@@ -526,7 +492,7 @@ public class DisplayModeDirector {
                                + "]");
            }

            VoteSummary appRequestSummary = new VoteSummary();
            VoteSummary appRequestSummary = new VoteSummary(mIsDisplayResolutionRangeVotingEnabled);
            summarizeVotes(
                    votes,
                    Vote.APP_REQUEST_REFRESH_RATE_RANGE_PRIORITY_CUTOFF,
+120 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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 com.android.server.display.mode;

import java.util.Objects;


/**
 * Information about the refresh rate frame rate ranges DM would like to set the display to.
 */
abstract class RefreshRateVote implements Vote {
    final float mMinRefreshRate;

    final float mMaxRefreshRate;

    RefreshRateVote(float minRefreshRate, float maxRefreshRate) {
        mMinRefreshRate = minRefreshRate;
        mMaxRefreshRate = maxRefreshRate;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof RefreshRateVote that)) return false;
        return Float.compare(that.mMinRefreshRate, mMinRefreshRate) == 0
                && Float.compare(that.mMaxRefreshRate, mMaxRefreshRate) == 0;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mMinRefreshRate, mMaxRefreshRate);
    }

    @Override
    public String toString() {
        return "RefreshRateVote{  mMinRefreshRate=" + mMinRefreshRate
                + ", mMaxRefreshRate=" + mMaxRefreshRate + " }";
    }

    static class RenderVote extends RefreshRateVote {
        RenderVote(float minRefreshRate, float maxRefreshRate) {
            super(minRefreshRate, maxRefreshRate);
        }

        /**
         * Summary:        minRender            minPhysical                    maxRender
         *                    v                     v                             v
         * -------------------|---------------------"-----------------------------|---------
         *             ^                ^                   ^*             ^           ^
         *  Vote: min(ignored)     min(applied)  min(applied+physical)  max(applied)  max(ignored)
         */
        @Override
        public void updateSummary(DisplayModeDirector.VoteSummary summary) {
            summary.minRenderFrameRate = Math.max(summary.minRenderFrameRate, mMinRefreshRate);
            summary.maxRenderFrameRate = Math.min(summary.maxRenderFrameRate, mMaxRefreshRate);
            // Physical refresh rate cannot be lower than the minimal render frame rate.
            summary.minPhysicalRefreshRate = Math.max(summary.minPhysicalRefreshRate,
                    mMinRefreshRate);
        }

        @Override
        public boolean equals(Object o) {
            if (!(o instanceof RefreshRateVote.RenderVote)) return false;
            return super.equals(o);
        }

        @Override
        public String toString() {
            return "RenderVote{ " + super.toString() + " }";
        }
    }

    static class PhysicalVote extends RefreshRateVote {
        PhysicalVote(float minRefreshRate, float maxRefreshRate) {
            super(minRefreshRate, maxRefreshRate);
        }

        /**
         * Summary:        minPhysical                   maxRender               maxPhysical
         *                    v                             v                        v
         * -------------------"-----------------------------|----------------------"----------
         *             ^             ^             ^*                 ^                   ^
         *  Vote: min(ignored) min(applied)  max(applied+render)     max(applied)  max(ignored)
         */
        @Override
        public void updateSummary(DisplayModeDirector.VoteSummary summary) {
            summary.minPhysicalRefreshRate = Math.max(summary.minPhysicalRefreshRate,
                    mMinRefreshRate);
            summary.maxPhysicalRefreshRate = Math.min(summary.maxPhysicalRefreshRate,
                    mMaxRefreshRate);
            // Render frame rate cannot exceed the max physical refresh rate
            summary.maxRenderFrameRate = Math.min(summary.maxRenderFrameRate, mMaxRefreshRate);
        }

        @Override
        public boolean equals(Object o) {
            if (!(o instanceof RefreshRateVote.PhysicalVote)) return false;
            return super.equals(o);
        }

        @Override
        public String toString() {
            return "PhysicalVote{ " + super.toString() + " }";
        }
    }
}
Loading