1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.display.mode; 18 19 import android.annotation.NonNull; 20 21 import java.util.Objects; 22 23 24 /** 25 * Information about the refresh rate frame rate ranges DM would like to set the display to. 26 */ 27 abstract class RefreshRateVote implements Vote { 28 final float mMinRefreshRate; 29 30 final float mMaxRefreshRate; 31 RefreshRateVote(float minRefreshRate, float maxRefreshRate)32 RefreshRateVote(float minRefreshRate, float maxRefreshRate) { 33 mMinRefreshRate = minRefreshRate; 34 mMaxRefreshRate = maxRefreshRate; 35 } 36 37 @Override equals(Object o)38 public boolean equals(Object o) { 39 if (this == o) return true; 40 if (!(o instanceof RefreshRateVote that)) return false; 41 return Float.compare(that.mMinRefreshRate, mMinRefreshRate) == 0 42 && Float.compare(that.mMaxRefreshRate, mMaxRefreshRate) == 0; 43 } 44 45 @Override hashCode()46 public int hashCode() { 47 return Objects.hash(mMinRefreshRate, mMaxRefreshRate); 48 } 49 50 @Override toString()51 public String toString() { 52 return "RefreshRateVote{ mMinRefreshRate=" + mMinRefreshRate 53 + ", mMaxRefreshRate=" + mMaxRefreshRate + " }"; 54 } 55 56 static class RenderVote extends RefreshRateVote { RenderVote(float minRefreshRate, float maxRefreshRate)57 RenderVote(float minRefreshRate, float maxRefreshRate) { 58 super(minRefreshRate, maxRefreshRate); 59 } 60 61 /** 62 * Summary: minRender minPhysical maxRender 63 * v v v 64 * -------------------|---------------------"-----------------------------|--------- 65 * ^ ^ ^* ^ ^ 66 * Vote: min(ignored) min(applied) min(applied+physical) max(applied) max(ignored) 67 */ 68 @Override updateSummary(@onNull VoteSummary summary)69 public void updateSummary(@NonNull VoteSummary summary) { 70 summary.minRenderFrameRate = Math.max(summary.minRenderFrameRate, mMinRefreshRate); 71 summary.maxRenderFrameRate = Math.min(summary.maxRenderFrameRate, mMaxRefreshRate); 72 // Physical refresh rate cannot be lower than the minimal render frame rate. 73 summary.minPhysicalRefreshRate = Math.max(summary.minPhysicalRefreshRate, 74 mMinRefreshRate); 75 } 76 77 @Override equals(Object o)78 public boolean equals(Object o) { 79 if (!(o instanceof RefreshRateVote.RenderVote)) return false; 80 return super.equals(o); 81 } 82 83 @Override toString()84 public String toString() { 85 return "RenderVote{ " + super.toString() + " }"; 86 } 87 } 88 89 static class PhysicalVote extends RefreshRateVote { PhysicalVote(float minRefreshRate, float maxRefreshRate)90 PhysicalVote(float minRefreshRate, float maxRefreshRate) { 91 super(minRefreshRate, maxRefreshRate); 92 } 93 94 /** 95 * Summary: minPhysical maxRender maxPhysical 96 * v v v 97 * -------------------"-----------------------------|----------------------"---------- 98 * ^ ^ ^* ^ ^ 99 * Vote: min(ignored) min(applied) max(applied+render) max(applied) max(ignored) 100 */ 101 @Override updateSummary(@onNull VoteSummary summary)102 public void updateSummary(@NonNull VoteSummary summary) { 103 summary.minPhysicalRefreshRate = Math.max(summary.minPhysicalRefreshRate, 104 mMinRefreshRate); 105 summary.maxPhysicalRefreshRate = Math.min(summary.maxPhysicalRefreshRate, 106 mMaxRefreshRate); 107 // Render frame rate cannot exceed the max physical refresh rate 108 summary.maxRenderFrameRate = Math.min(summary.maxRenderFrameRate, mMaxRefreshRate); 109 } 110 111 @Override equals(Object o)112 public boolean equals(Object o) { 113 if (!(o instanceof RefreshRateVote.PhysicalVote)) return false; 114 return super.equals(o); 115 } 116 117 @Override toString()118 public String toString() { 119 return "PhysicalVote{ " + super.toString() + " }"; 120 } 121 } 122 } 123