Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 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 | |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wextra" |
| 20 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 21 | // #define LOG_NDEBUG 0 |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 22 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 23 | |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 24 | #include "LayerInfo.h" |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 25 | |
| 26 | #include <algorithm> |
| 27 | #include <utility> |
| 28 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 29 | #include <android/native_window.h> |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 30 | #include <cutils/compiler.h> |
| 31 | #include <cutils/trace.h> |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 32 | #include <ftl/enum.h> |
Ady Abraham | 73c3df5 | 2023-01-12 18:09:31 -0800 | [diff] [blame] | 33 | #include <gui/TraceUtils.h> |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 34 | #include <system/window.h> |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 35 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 36 | #undef LOG_TAG |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 37 | #define LOG_TAG "LayerInfo" |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 38 | |
| 39 | namespace android::scheduler { |
| 40 | |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 41 | bool LayerInfo::sTraceEnabled = false; |
Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 42 | |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 43 | LayerInfo::LayerInfo(const std::string& name, uid_t ownerUid, |
| 44 | LayerHistory::LayerVoteType defaultVote) |
Ady Abraham | a6b676e | 2020-05-27 14:29:09 -0700 | [diff] [blame] | 45 | : mName(name), |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 46 | mOwnerUid(ownerUid), |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 47 | mDefaultVote(defaultVote), |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 48 | mLayerVote({defaultVote, Fps()}), |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 49 | mLayerProps(std::make_unique<LayerProps>()), |
| 50 | mRefreshRateHistory(name) { |
| 51 | ; |
| 52 | } |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 53 | |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 54 | void LayerInfo::setLastPresentTime(nsecs_t lastPresentTime, nsecs_t now, LayerUpdateType updateType, |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 55 | bool pendingModeChange, const LayerProps& props) { |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 56 | lastPresentTime = std::max(lastPresentTime, static_cast<nsecs_t>(0)); |
| 57 | |
| 58 | mLastUpdatedTime = std::max(lastPresentTime, now); |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 59 | *mLayerProps = props; |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 60 | switch (updateType) { |
| 61 | case LayerUpdateType::AnimationTX: |
| 62 | mLastAnimationTime = std::max(lastPresentTime, now); |
| 63 | break; |
| 64 | case LayerUpdateType::SetFrameRate: |
Ady Abraham | ae93c35 | 2023-12-20 23:38:55 +0000 | [diff] [blame^] | 65 | if (FlagManager::getInstance().vrr_config()) { |
| 66 | break; |
| 67 | } |
| 68 | FALLTHROUGH_INTENDED; |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 69 | case LayerUpdateType::Buffer: |
Marin Shalamanov | 2045d5b | 2020-12-28 18:11:41 +0100 | [diff] [blame] | 70 | FrameTimeData frameTime = {.presentTime = lastPresentTime, |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 71 | .queueTime = mLastUpdatedTime, |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 72 | .pendingModeChange = pendingModeChange, |
| 73 | .isSmallDirty = props.isSmallDirty}; |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 74 | mFrameTimes.push_back(frameTime); |
| 75 | if (mFrameTimes.size() > HISTORY_SIZE) { |
| 76 | mFrameTimes.pop_front(); |
| 77 | } |
| 78 | break; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 82 | void LayerInfo::setProperties(const android::scheduler::LayerProps& properties) { |
| 83 | *mLayerProps = properties; |
| 84 | } |
| 85 | |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 86 | bool LayerInfo::isFrameTimeValid(const FrameTimeData& frameTime) const { |
Ady Abraham | dfb63ba | 2020-05-27 20:05:05 +0000 | [diff] [blame] | 87 | return frameTime.queueTime >= std::chrono::duration_cast<std::chrono::nanoseconds>( |
| 88 | mFrameTimeValidSince.time_since_epoch()) |
| 89 | .count(); |
| 90 | } |
Ady Abraham | 1adbb72 | 2020-05-15 11:51:48 -0700 | [diff] [blame] | 91 | |
ramindani | 63db24e | 2023-04-03 10:56:05 -0700 | [diff] [blame] | 92 | LayerInfo::Frequent LayerInfo::isFrequent(nsecs_t now) const { |
Ady Abraham | 86ac5c5 | 2023-01-11 15:24:03 -0800 | [diff] [blame] | 93 | // If we know nothing about this layer (e.g. after touch event), |
| 94 | // we consider it as frequent as it might be the start of an animation. |
Marin Shalamanov | 2045d5b | 2020-12-28 18:11:41 +0100 | [diff] [blame] | 95 | if (mFrameTimes.size() < kFrequentLayerWindowSize) { |
ramindani | 63db24e | 2023-04-03 10:56:05 -0700 | [diff] [blame] | 96 | return {/* isFrequent */ true, /* clearHistory */ false, /* isConclusive */ true}; |
Ady Abraham | dfb63ba | 2020-05-27 20:05:05 +0000 | [diff] [blame] | 97 | } |
Ady Abraham | 86ac5c5 | 2023-01-11 15:24:03 -0800 | [diff] [blame] | 98 | |
| 99 | // Non-active layers are also infrequent |
| 100 | if (mLastUpdatedTime < getActiveLayerThreshold(now)) { |
ramindani | 63db24e | 2023-04-03 10:56:05 -0700 | [diff] [blame] | 101 | return {/* isFrequent */ false, /* clearHistory */ false, /* isConclusive */ true}; |
Ady Abraham | 86ac5c5 | 2023-01-11 15:24:03 -0800 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | // We check whether we can classify this layer as frequent or infrequent: |
| 105 | // - frequent: a layer posted kFrequentLayerWindowSize within |
| 106 | // kMaxPeriodForFrequentLayerNs of each other. |
| 107 | // - infrequent: a layer posted kFrequentLayerWindowSize with longer |
| 108 | // gaps than kFrequentLayerWindowSize. |
| 109 | // If we can't determine the layer classification yet, we return the last |
| 110 | // classification. |
| 111 | bool isFrequent = true; |
| 112 | bool isInfrequent = true; |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 113 | int32_t smallDirtyCount = 0; |
Ady Abraham | 86ac5c5 | 2023-01-11 15:24:03 -0800 | [diff] [blame] | 114 | const auto n = mFrameTimes.size() - 1; |
| 115 | for (size_t i = 0; i < kFrequentLayerWindowSize - 1; i++) { |
| 116 | if (mFrameTimes[n - i].queueTime - mFrameTimes[n - i - 1].queueTime < |
| 117 | kMaxPeriodForFrequentLayerNs.count()) { |
| 118 | isInfrequent = false; |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 119 | if (mFrameTimes[n - i].presentTime == 0 && mFrameTimes[n - i].isSmallDirty) { |
| 120 | smallDirtyCount++; |
| 121 | } |
Ady Abraham | 86ac5c5 | 2023-01-11 15:24:03 -0800 | [diff] [blame] | 122 | } else { |
| 123 | isFrequent = false; |
| 124 | } |
| 125 | } |
| 126 | |
Arthur Hung | 8144e02 | 2023-09-08 10:26:23 +0000 | [diff] [blame] | 127 | // Vote the small dirty when a layer contains at least HISTORY_SIZE of small dirty updates. |
| 128 | bool isSmallDirty = false; |
| 129 | if (smallDirtyCount >= kNumSmallDirtyThreshold) { |
| 130 | if (mLastSmallDirtyCount >= HISTORY_SIZE) { |
| 131 | isSmallDirty = true; |
| 132 | } else { |
| 133 | mLastSmallDirtyCount++; |
| 134 | } |
| 135 | } else { |
| 136 | mLastSmallDirtyCount = 0; |
| 137 | } |
| 138 | |
Ady Abraham | 86ac5c5 | 2023-01-11 15:24:03 -0800 | [diff] [blame] | 139 | if (isFrequent || isInfrequent) { |
ramindani | 63db24e | 2023-04-03 10:56:05 -0700 | [diff] [blame] | 140 | // If the layer was previously inconclusive, we clear |
| 141 | // the history as indeterminate layers changed to frequent, |
| 142 | // and we should not look at the stale data. |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 143 | return {isFrequent, isFrequent && !mIsFrequencyConclusive, /* isConclusive */ true, |
Arthur Hung | 8144e02 | 2023-09-08 10:26:23 +0000 | [diff] [blame] | 144 | isSmallDirty}; |
Ady Abraham | 86ac5c5 | 2023-01-11 15:24:03 -0800 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | // If we can't determine whether the layer is frequent or not, we return |
ramindani | 63db24e | 2023-04-03 10:56:05 -0700 | [diff] [blame] | 148 | // the last known classification and mark the layer frequency as inconclusive. |
| 149 | isFrequent = !mLastRefreshRate.infrequent; |
| 150 | |
| 151 | // If the layer was previously tagged as animating, we clear |
| 152 | // the history as it is likely the layer just changed its behavior, |
| 153 | // and we should not look at stale data. |
| 154 | return {isFrequent, isFrequent && mLastRefreshRate.animating, /* isConclusive */ false}; |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 155 | } |
Ady Abraham | dfb63ba | 2020-05-27 20:05:05 +0000 | [diff] [blame] | 156 | |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 157 | Fps LayerInfo::getFps(nsecs_t now) const { |
Ady Abraham | dfb63ba | 2020-05-27 20:05:05 +0000 | [diff] [blame] | 158 | // Find the first active frame |
Ady Abraham | 983e568 | 2020-05-28 16:49:18 -0700 | [diff] [blame] | 159 | auto it = mFrameTimes.begin(); |
Ady Abraham | dfb63ba | 2020-05-27 20:05:05 +0000 | [diff] [blame] | 160 | for (; it != mFrameTimes.end(); ++it) { |
| 161 | if (it->queueTime >= getActiveLayerThreshold(now)) { |
| 162 | break; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | const auto numFrames = std::distance(it, mFrameTimes.end()); |
Marin Shalamanov | 2045d5b | 2020-12-28 18:11:41 +0100 | [diff] [blame] | 167 | if (numFrames < kFrequentLayerWindowSize) { |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 168 | return Fps(); |
Ady Abraham | dfb63ba | 2020-05-27 20:05:05 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | // Layer is considered frequent if the average frame rate is higher than the threshold |
| 172 | const auto totalTime = mFrameTimes.back().queueTime - it->queueTime; |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 173 | return Fps::fromPeriodNsecs(totalTime / (numFrames - 1)); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 174 | } |
| 175 | |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 176 | bool LayerInfo::isAnimating(nsecs_t now) const { |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 177 | return mLastAnimationTime >= getActiveLayerThreshold(now); |
| 178 | } |
| 179 | |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 180 | bool LayerInfo::hasEnoughDataForHeuristic() const { |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 181 | // The layer had to publish at least HISTORY_SIZE or HISTORY_DURATION of updates |
Ady Abraham | a61edcb | 2020-01-30 18:32:03 -0800 | [diff] [blame] | 182 | if (mFrameTimes.size() < 2) { |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 183 | ALOGV("fewer than 2 frames recorded: %zu", mFrameTimes.size()); |
Ady Abraham | a61edcb | 2020-01-30 18:32:03 -0800 | [diff] [blame] | 184 | return false; |
| 185 | } |
| 186 | |
Ady Abraham | dfb63ba | 2020-05-27 20:05:05 +0000 | [diff] [blame] | 187 | if (!isFrameTimeValid(mFrameTimes.front())) { |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 188 | ALOGV("stale frames still captured"); |
Ady Abraham | dfb63ba | 2020-05-27 20:05:05 +0000 | [diff] [blame] | 189 | return false; |
| 190 | } |
| 191 | |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 192 | const auto totalDuration = mFrameTimes.back().queueTime - mFrameTimes.front().queueTime; |
| 193 | if (mFrameTimes.size() < HISTORY_SIZE && totalDuration < HISTORY_DURATION.count()) { |
| 194 | ALOGV("not enough frames captured: %zu | %.2f seconds", mFrameTimes.size(), |
| 195 | totalDuration / 1e9f); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 196 | return false; |
| 197 | } |
| 198 | |
| 199 | return true; |
| 200 | } |
| 201 | |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 202 | std::optional<nsecs_t> LayerInfo::calculateAverageFrameTime() const { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 203 | // Ignore frames captured during a mode change |
| 204 | const bool isDuringModeChange = |
Marin Shalamanov | 2045d5b | 2020-12-28 18:11:41 +0100 | [diff] [blame] | 205 | std::any_of(mFrameTimes.begin(), mFrameTimes.end(), |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 206 | [](const auto& frame) { return frame.pendingModeChange; }); |
| 207 | if (isDuringModeChange) { |
Marin Shalamanov | 2045d5b | 2020-12-28 18:11:41 +0100 | [diff] [blame] | 208 | return std::nullopt; |
| 209 | } |
Ady Abraham | 32efd54 | 2020-05-19 17:49:26 -0700 | [diff] [blame] | 210 | |
Marin Shalamanov | 2045d5b | 2020-12-28 18:11:41 +0100 | [diff] [blame] | 211 | const bool isMissingPresentTime = |
| 212 | std::any_of(mFrameTimes.begin(), mFrameTimes.end(), |
| 213 | [](auto frame) { return frame.presentTime == 0; }); |
| 214 | if (isMissingPresentTime && !mLastRefreshRate.reported.isValid()) { |
| 215 | // If there are no presentation timestamps and we haven't calculated |
| 216 | // one in the past then we can't calculate the refresh rate |
| 217 | return std::nullopt; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 218 | } |
Ady Abraham | c966483 | 2020-05-12 14:16:56 -0700 | [diff] [blame] | 219 | |
Ady Abraham | c966483 | 2020-05-12 14:16:56 -0700 | [diff] [blame] | 220 | // Calculate the average frame time based on presentation timestamps. If those |
| 221 | // doesn't exist, we look at the time the buffer was queued only. We can do that only if |
| 222 | // we calculated a refresh rate based on presentation timestamps in the past. The reason |
| 223 | // we look at the queue time is to handle cases where hwui attaches presentation timestamps |
| 224 | // when implementing render ahead for specific refresh rates. When hwui no longer provides |
| 225 | // presentation timestamps we look at the queue time to see if the current refresh rate still |
| 226 | // matches the content. |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 227 | |
Marin Shalamanov | 2045d5b | 2020-12-28 18:11:41 +0100 | [diff] [blame] | 228 | auto getFrameTime = isMissingPresentTime ? [](FrameTimeData data) { return data.queueTime; } |
| 229 | : [](FrameTimeData data) { return data.presentTime; }; |
| 230 | |
| 231 | nsecs_t totalDeltas = 0; |
| 232 | int numDeltas = 0; |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 233 | int32_t smallDirtyCount = 0; |
Marin Shalamanov | 2045d5b | 2020-12-28 18:11:41 +0100 | [diff] [blame] | 234 | auto prevFrame = mFrameTimes.begin(); |
| 235 | for (auto it = mFrameTimes.begin() + 1; it != mFrameTimes.end(); ++it) { |
| 236 | const auto currDelta = getFrameTime(*it) - getFrameTime(*prevFrame); |
| 237 | if (currDelta < kMinPeriodBetweenFrames) { |
| 238 | // Skip this frame, but count the delta into the next frame |
| 239 | continue; |
| 240 | } |
| 241 | |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 242 | // If this is a small area update, we don't want to consider it for calculating the average |
| 243 | // frame time. Instead, we let the bigger frame updates to drive the calculation. |
| 244 | if (it->isSmallDirty && currDelta < kMinPeriodBetweenSmallDirtyFrames) { |
| 245 | smallDirtyCount++; |
| 246 | continue; |
| 247 | } |
| 248 | |
Marin Shalamanov | 2045d5b | 2020-12-28 18:11:41 +0100 | [diff] [blame] | 249 | prevFrame = it; |
| 250 | |
| 251 | if (currDelta > kMaxPeriodBetweenFrames) { |
| 252 | // Skip this frame and the current delta. |
| 253 | continue; |
| 254 | } |
| 255 | |
| 256 | totalDeltas += currDelta; |
| 257 | numDeltas++; |
| 258 | } |
| 259 | |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 260 | if (smallDirtyCount > 0) { |
| 261 | ATRACE_FORMAT_INSTANT("small dirty = %" PRIu32, smallDirtyCount); |
| 262 | } |
| 263 | |
Marin Shalamanov | 2045d5b | 2020-12-28 18:11:41 +0100 | [diff] [blame] | 264 | if (numDeltas == 0) { |
| 265 | return std::nullopt; |
| 266 | } |
| 267 | |
| 268 | const auto averageFrameTime = static_cast<double>(totalDeltas) / static_cast<double>(numDeltas); |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 269 | return static_cast<nsecs_t>(averageFrameTime); |
Ady Abraham | 32efd54 | 2020-05-19 17:49:26 -0700 | [diff] [blame] | 270 | } |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 271 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 272 | std::optional<Fps> LayerInfo::calculateRefreshRateIfPossible(const RefreshRateSelector& selector, |
| 273 | nsecs_t now) { |
Ady Abraham | 73c3df5 | 2023-01-12 18:09:31 -0800 | [diff] [blame] | 274 | ATRACE_CALL(); |
Ady Abraham | 32efd54 | 2020-05-19 17:49:26 -0700 | [diff] [blame] | 275 | static constexpr float MARGIN = 1.0f; // 1Hz |
Ady Abraham | 32efd54 | 2020-05-19 17:49:26 -0700 | [diff] [blame] | 276 | if (!hasEnoughDataForHeuristic()) { |
| 277 | ALOGV("Not enough data"); |
| 278 | return std::nullopt; |
| 279 | } |
| 280 | |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 281 | if (const auto averageFrameTime = calculateAverageFrameTime()) { |
Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 282 | const auto refreshRate = Fps::fromPeriodNsecs(*averageFrameTime); |
Jerry Chang | 04eb8e0 | 2023-11-15 08:06:07 +0000 | [diff] [blame] | 283 | const auto closestKnownRefreshRate = mRefreshRateHistory.add(refreshRate, now, selector); |
| 284 | if (closestKnownRefreshRate.isValid()) { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 285 | using fps_approx_ops::operator!=; |
| 286 | |
| 287 | // To avoid oscillation, use the last calculated refresh rate if it is close enough. |
Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 288 | if (std::abs(mLastRefreshRate.calculated.getValue() - refreshRate.getValue()) > |
| 289 | MARGIN && |
Jerry Chang | 04eb8e0 | 2023-11-15 08:06:07 +0000 | [diff] [blame] | 290 | mLastRefreshRate.reported != closestKnownRefreshRate) { |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 291 | mLastRefreshRate.calculated = refreshRate; |
Jerry Chang | 04eb8e0 | 2023-11-15 08:06:07 +0000 | [diff] [blame] | 292 | mLastRefreshRate.reported = closestKnownRefreshRate; |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 295 | ALOGV("%s %s rounded to nearest known frame rate %s", mName.c_str(), |
| 296 | to_string(refreshRate).c_str(), to_string(mLastRefreshRate.reported).c_str()); |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 297 | } else { |
Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 298 | ALOGV("%s Not stable (%s) returning last known frame rate %s", mName.c_str(), |
| 299 | to_string(refreshRate).c_str(), to_string(mLastRefreshRate.reported).c_str()); |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 300 | } |
Ady Abraham | 32efd54 | 2020-05-19 17:49:26 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 303 | return mLastRefreshRate.reported.isValid() ? std::make_optional(mLastRefreshRate.reported) |
| 304 | : std::nullopt; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 305 | } |
| 306 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 307 | LayerInfo::RefreshRateVotes LayerInfo::getRefreshRateVote(const RefreshRateSelector& selector, |
| 308 | nsecs_t now) { |
Ady Abraham | 73c3df5 | 2023-01-12 18:09:31 -0800 | [diff] [blame] | 309 | ATRACE_CALL(); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 310 | LayerInfo::RefreshRateVotes votes; |
| 311 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 312 | if (mLayerVote.type != LayerHistory::LayerVoteType::Heuristic) { |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 313 | if (mLayerVote.category != FrameRateCategory::Default) { |
Rachel Lee | 414f408 | 2023-10-23 14:48:44 -0700 | [diff] [blame] | 314 | const auto voteType = mLayerVote.type == LayerHistory::LayerVoteType::NoVote |
| 315 | ? LayerHistory::LayerVoteType::NoVote |
| 316 | : LayerHistory::LayerVoteType::ExplicitCategory; |
| 317 | ATRACE_FORMAT_INSTANT("Vote %s (category=%s)", ftl::enum_string(voteType).c_str(), |
Rachel Lee | c0e40bc | 2023-09-12 13:41:15 -0700 | [diff] [blame] | 318 | ftl::enum_string(mLayerVote.category).c_str()); |
Rachel Lee | 414f408 | 2023-10-23 14:48:44 -0700 | [diff] [blame] | 319 | ALOGV("%s voted %s with category: %s", mName.c_str(), |
| 320 | ftl::enum_string(voteType).c_str(), |
| 321 | ftl::enum_string(mLayerVote.category).c_str()); |
| 322 | votes.push_back({voteType, Fps(), Seamlessness::Default, mLayerVote.category, |
Rachel Lee | 67afbea | 2023-09-28 15:35:07 -0700 | [diff] [blame] | 323 | mLayerVote.categorySmoothSwitchOnly}); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | if (mLayerVote.fps.isValid() || |
| 327 | mLayerVote.type != LayerHistory::LayerVoteType::ExplicitDefault) { |
Rachel Lee | c0e40bc | 2023-09-12 13:41:15 -0700 | [diff] [blame] | 328 | ATRACE_FORMAT_INSTANT("Vote %s", ftl::enum_string(mLayerVote.type).c_str()); |
Rachel Lee | 414f408 | 2023-10-23 14:48:44 -0700 | [diff] [blame] | 329 | ALOGV("%s voted %d", mName.c_str(), static_cast<int>(mLayerVote.type)); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 330 | votes.push_back(mLayerVote); |
| 331 | } |
| 332 | |
| 333 | return votes; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 334 | } |
| 335 | |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 336 | if (isAnimating(now)) { |
Ady Abraham | 73c3df5 | 2023-01-12 18:09:31 -0800 | [diff] [blame] | 337 | ATRACE_FORMAT_INSTANT("animating"); |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 338 | ALOGV("%s is animating", mName.c_str()); |
Ady Abraham | 86ac5c5 | 2023-01-11 15:24:03 -0800 | [diff] [blame] | 339 | mLastRefreshRate.animating = true; |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 340 | votes.push_back({LayerHistory::LayerVoteType::Max, Fps()}); |
| 341 | return votes; |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Alec Mouri | 89f5d4e | 2023-10-20 17:12:49 +0000 | [diff] [blame] | 344 | // Vote for max refresh rate whenever we're front-buffered. |
| 345 | if (FlagManager::getInstance().vrr_config() && isFrontBuffered()) { |
| 346 | ATRACE_FORMAT_INSTANT("front buffered"); |
| 347 | ALOGV("%s is front-buffered", mName.c_str()); |
| 348 | votes.push_back({LayerHistory::LayerVoteType::Max, Fps()}); |
| 349 | return votes; |
| 350 | } |
| 351 | |
ramindani | 63db24e | 2023-04-03 10:56:05 -0700 | [diff] [blame] | 352 | const LayerInfo::Frequent frequent = isFrequent(now); |
| 353 | mIsFrequencyConclusive = frequent.isConclusive; |
| 354 | if (!frequent.isFrequent) { |
Ady Abraham | 73c3df5 | 2023-01-12 18:09:31 -0800 | [diff] [blame] | 355 | ATRACE_FORMAT_INSTANT("infrequent"); |
Ady Abraham | a6b676e | 2020-05-27 14:29:09 -0700 | [diff] [blame] | 356 | ALOGV("%s is infrequent", mName.c_str()); |
Ady Abraham | 86ac5c5 | 2023-01-11 15:24:03 -0800 | [diff] [blame] | 357 | mLastRefreshRate.infrequent = true; |
Arthur Hung | 8144e02 | 2023-09-08 10:26:23 +0000 | [diff] [blame] | 358 | mLastSmallDirtyCount = 0; |
ramindani | 63db24e | 2023-04-03 10:56:05 -0700 | [diff] [blame] | 359 | // Infrequent layers vote for minimal refresh rate for |
Marin Shalamanov | 29e2540 | 2021-04-07 21:09:58 +0200 | [diff] [blame] | 360 | // battery saving purposes and also to prevent b/135718869. |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 361 | votes.push_back({LayerHistory::LayerVoteType::Min, Fps()}); |
| 362 | return votes; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 363 | } |
| 364 | |
ramindani | 63db24e | 2023-04-03 10:56:05 -0700 | [diff] [blame] | 365 | if (frequent.clearHistory) { |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 366 | clearHistory(now); |
| 367 | } |
| 368 | |
Arthur Hung | 8144e02 | 2023-09-08 10:26:23 +0000 | [diff] [blame] | 369 | // Return no vote if the recent frames are small dirty. |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 370 | if (frequent.isSmallDirty && !mLastRefreshRate.reported.isValid()) { |
| 371 | ATRACE_FORMAT_INSTANT("NoVote (small dirty)"); |
| 372 | ALOGV("%s is small dirty", mName.c_str()); |
| 373 | votes.push_back({LayerHistory::LayerVoteType::NoVote, Fps()}); |
| 374 | return votes; |
| 375 | } |
| 376 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 377 | auto refreshRate = calculateRefreshRateIfPossible(selector, now); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 378 | if (refreshRate.has_value()) { |
Rachel Lee | c0e40bc | 2023-09-12 13:41:15 -0700 | [diff] [blame] | 379 | ATRACE_FORMAT_INSTANT("calculated (%s)", to_string(*refreshRate).c_str()); |
Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 380 | ALOGV("%s calculated refresh rate: %s", mName.c_str(), to_string(*refreshRate).c_str()); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 381 | votes.push_back({LayerHistory::LayerVoteType::Heuristic, refreshRate.value()}); |
| 382 | return votes; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 383 | } |
| 384 | |
Rachel Lee | c0e40bc | 2023-09-12 13:41:15 -0700 | [diff] [blame] | 385 | ATRACE_FORMAT_INSTANT("Max (can't resolve refresh rate)"); |
Ady Abraham | a6b676e | 2020-05-27 14:29:09 -0700 | [diff] [blame] | 386 | ALOGV("%s Max (can't resolve refresh rate)", mName.c_str()); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 387 | votes.push_back({LayerHistory::LayerVoteType::Max, Fps()}); |
| 388 | return votes; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 389 | } |
| 390 | |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 391 | const char* LayerInfo::getTraceTag(LayerHistory::LayerVoteType type) const { |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 392 | if (mTraceTags.count(type) == 0) { |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 393 | auto tag = "LFPS " + mName + " " + ftl::enum_string(type); |
| 394 | mTraceTags.emplace(type, std::move(tag)); |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | return mTraceTags.at(type).c_str(); |
| 398 | } |
| 399 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 400 | LayerInfo::FrameRate LayerInfo::getSetFrameRateVote() const { |
| 401 | return mLayerProps->setFrameRateVote; |
| 402 | } |
| 403 | |
| 404 | bool LayerInfo::isVisible() const { |
| 405 | return mLayerProps->visible; |
| 406 | } |
| 407 | |
| 408 | int32_t LayerInfo::getFrameRateSelectionPriority() const { |
| 409 | return mLayerProps->frameRateSelectionPriority; |
| 410 | } |
| 411 | |
Alec Mouri | 89f5d4e | 2023-10-20 17:12:49 +0000 | [diff] [blame] | 412 | bool LayerInfo::isFrontBuffered() const { |
| 413 | return mLayerProps->isFrontBuffered; |
| 414 | } |
| 415 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 416 | FloatRect LayerInfo::getBounds() const { |
| 417 | return mLayerProps->bounds; |
| 418 | } |
| 419 | |
| 420 | ui::Transform LayerInfo::getTransform() const { |
| 421 | return mLayerProps->transform; |
| 422 | } |
| 423 | |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 424 | LayerInfo::RefreshRateHistory::HeuristicTraceTagData |
| 425 | LayerInfo::RefreshRateHistory::makeHeuristicTraceTagData() const { |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 426 | const std::string prefix = "LFPS "; |
| 427 | const std::string suffix = "Heuristic "; |
| 428 | return {.min = prefix + mName + suffix + "min", |
| 429 | .max = prefix + mName + suffix + "max", |
| 430 | .consistent = prefix + mName + suffix + "consistent", |
| 431 | .average = prefix + mName + suffix + "average"}; |
| 432 | } |
| 433 | |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 434 | void LayerInfo::RefreshRateHistory::clear() { |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 435 | mRefreshRates.clear(); |
| 436 | } |
| 437 | |
Jerry Chang | 04eb8e0 | 2023-11-15 08:06:07 +0000 | [diff] [blame] | 438 | Fps LayerInfo::RefreshRateHistory::add(Fps refreshRate, nsecs_t now, |
| 439 | const RefreshRateSelector& selector) { |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 440 | mRefreshRates.push_back({refreshRate, now}); |
| 441 | while (mRefreshRates.size() >= HISTORY_SIZE || |
| 442 | now - mRefreshRates.front().timestamp > HISTORY_DURATION.count()) { |
| 443 | mRefreshRates.pop_front(); |
| 444 | } |
| 445 | |
| 446 | if (CC_UNLIKELY(sTraceEnabled)) { |
| 447 | if (!mHeuristicTraceTagData.has_value()) { |
| 448 | mHeuristicTraceTagData = makeHeuristicTraceTagData(); |
| 449 | } |
| 450 | |
Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 451 | ATRACE_INT(mHeuristicTraceTagData->average.c_str(), refreshRate.getIntValue()); |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Jerry Chang | 04eb8e0 | 2023-11-15 08:06:07 +0000 | [diff] [blame] | 454 | return selectRefreshRate(selector); |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Jerry Chang | 04eb8e0 | 2023-11-15 08:06:07 +0000 | [diff] [blame] | 457 | Fps LayerInfo::RefreshRateHistory::selectRefreshRate(const RefreshRateSelector& selector) const { |
| 458 | if (mRefreshRates.empty()) return Fps(); |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 459 | |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 460 | const auto [min, max] = |
| 461 | std::minmax_element(mRefreshRates.begin(), mRefreshRates.end(), |
| 462 | [](const auto& lhs, const auto& rhs) { |
| 463 | return isStrictlyLess(lhs.refreshRate, rhs.refreshRate); |
| 464 | }); |
| 465 | |
Jerry Chang | 04eb8e0 | 2023-11-15 08:06:07 +0000 | [diff] [blame] | 466 | const auto maxClosestRate = selector.findClosestKnownFrameRate(max->refreshRate); |
| 467 | const bool consistent = [&](Fps maxFps, Fps minFps) { |
| 468 | if (FlagManager::getInstance().use_known_refresh_rate_for_fps_consistency()) { |
| 469 | if (maxFps.getValue() - minFps.getValue() < |
| 470 | MARGIN_CONSISTENT_FPS_FOR_CLOSEST_REFRESH_RATE) { |
| 471 | const auto minClosestRate = selector.findClosestKnownFrameRate(minFps); |
| 472 | using fps_approx_ops::operator==; |
| 473 | return maxClosestRate == minClosestRate; |
| 474 | } |
| 475 | return false; |
| 476 | } |
| 477 | return maxFps.getValue() - minFps.getValue() < MARGIN_CONSISTENT_FPS; |
| 478 | }(max->refreshRate, min->refreshRate); |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 479 | |
| 480 | if (CC_UNLIKELY(sTraceEnabled)) { |
| 481 | if (!mHeuristicTraceTagData.has_value()) { |
| 482 | mHeuristicTraceTagData = makeHeuristicTraceTagData(); |
| 483 | } |
| 484 | |
Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 485 | ATRACE_INT(mHeuristicTraceTagData->max.c_str(), max->refreshRate.getIntValue()); |
| 486 | ATRACE_INT(mHeuristicTraceTagData->min.c_str(), min->refreshRate.getIntValue()); |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 487 | ATRACE_INT(mHeuristicTraceTagData->consistent.c_str(), consistent); |
| 488 | } |
| 489 | |
Jerry Chang | 04eb8e0 | 2023-11-15 08:06:07 +0000 | [diff] [blame] | 490 | return consistent ? maxClosestRate : Fps(); |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 493 | FrameRateCompatibility LayerInfo::FrameRate::convertCompatibility(int8_t compatibility) { |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 494 | switch (compatibility) { |
| 495 | case ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT: |
| 496 | return FrameRateCompatibility::Default; |
| 497 | case ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE: |
| 498 | return FrameRateCompatibility::ExactOrMultiple; |
| 499 | case ANATIVEWINDOW_FRAME_RATE_EXACT: |
| 500 | return FrameRateCompatibility::Exact; |
| 501 | case ANATIVEWINDOW_FRAME_RATE_MIN: |
| 502 | return FrameRateCompatibility::Min; |
Rachel Lee | e5514a7 | 2023-10-25 16:20:29 -0700 | [diff] [blame] | 503 | case ANATIVEWINDOW_FRAME_RATE_GTE: |
| 504 | return FrameRateCompatibility::Gte; |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 505 | case ANATIVEWINDOW_FRAME_RATE_NO_VOTE: |
| 506 | return FrameRateCompatibility::NoVote; |
| 507 | default: |
| 508 | LOG_ALWAYS_FATAL("Invalid frame rate compatibility value %d", compatibility); |
| 509 | return FrameRateCompatibility::Default; |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | Seamlessness LayerInfo::FrameRate::convertChangeFrameRateStrategy(int8_t strategy) { |
| 514 | switch (strategy) { |
| 515 | case ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS: |
| 516 | return Seamlessness::OnlySeamless; |
| 517 | case ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS: |
| 518 | return Seamlessness::SeamedAndSeamless; |
| 519 | default: |
| 520 | LOG_ALWAYS_FATAL("Invalid change frame sate strategy value %d", strategy); |
| 521 | return Seamlessness::Default; |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | FrameRateCategory LayerInfo::FrameRate::convertCategory(int8_t category) { |
| 526 | switch (category) { |
| 527 | case ANATIVEWINDOW_FRAME_RATE_CATEGORY_DEFAULT: |
| 528 | return FrameRateCategory::Default; |
| 529 | case ANATIVEWINDOW_FRAME_RATE_CATEGORY_NO_PREFERENCE: |
| 530 | return FrameRateCategory::NoPreference; |
| 531 | case ANATIVEWINDOW_FRAME_RATE_CATEGORY_LOW: |
| 532 | return FrameRateCategory::Low; |
| 533 | case ANATIVEWINDOW_FRAME_RATE_CATEGORY_NORMAL: |
| 534 | return FrameRateCategory::Normal; |
| 535 | case ANATIVEWINDOW_FRAME_RATE_CATEGORY_HIGH: |
| 536 | return FrameRateCategory::High; |
| 537 | default: |
| 538 | LOG_ALWAYS_FATAL("Invalid frame rate category value %d", category); |
| 539 | return FrameRateCategory::Default; |
| 540 | } |
| 541 | } |
| 542 | |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 543 | LayerInfo::FrameRateSelectionStrategy LayerInfo::convertFrameRateSelectionStrategy( |
| 544 | int8_t strategy) { |
| 545 | switch (strategy) { |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 546 | case ANATIVEWINDOW_FRAME_RATE_SELECTION_STRATEGY_PROPAGATE: |
| 547 | return FrameRateSelectionStrategy::Propagate; |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 548 | case ANATIVEWINDOW_FRAME_RATE_SELECTION_STRATEGY_OVERRIDE_CHILDREN: |
| 549 | return FrameRateSelectionStrategy::OverrideChildren; |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 550 | case ANATIVEWINDOW_FRAME_RATE_SELECTION_STRATEGY_SELF: |
| 551 | return FrameRateSelectionStrategy::Self; |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 552 | default: |
| 553 | LOG_ALWAYS_FATAL("Invalid frame rate selection strategy value %d", strategy); |
| 554 | return FrameRateSelectionStrategy::Self; |
| 555 | } |
| 556 | } |
| 557 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 558 | bool LayerInfo::FrameRate::isNoVote() const { |
Rachel Lee | d0694bc | 2023-09-12 14:57:58 -0700 | [diff] [blame] | 559 | return vote.type == FrameRateCompatibility::NoVote; |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | bool LayerInfo::FrameRate::isValid() const { |
| 563 | return isNoVote() || vote.rate.isValid() || category != FrameRateCategory::Default; |
| 564 | } |
| 565 | |
| 566 | std::ostream& operator<<(std::ostream& stream, const LayerInfo::FrameRate& rate) { |
| 567 | return stream << "{rate=" << rate.vote.rate << " type=" << ftl::enum_string(rate.vote.type) |
| 568 | << " seamlessness=" << ftl::enum_string(rate.vote.seamlessness) << '}'; |
| 569 | } |
| 570 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 571 | } // namespace android::scheduler |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 572 | |
| 573 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 574 | #pragma clang diagnostic pop // ignored "-Wextra" |