| 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 |  | 
|  | 17 | // #define LOG_NDEBUG 0 | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 18 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 19 |  | 
|  | 20 | #include "LayerInfoV2.h" | 
|  | 21 |  | 
|  | 22 | #include <algorithm> | 
|  | 23 | #include <utility> | 
|  | 24 |  | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 25 | #include <cutils/compiler.h> | 
|  | 26 | #include <cutils/trace.h> | 
|  | 27 |  | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 28 | #undef LOG_TAG | 
|  | 29 | #define LOG_TAG "LayerInfoV2" | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 30 |  | 
|  | 31 | namespace android::scheduler { | 
|  | 32 |  | 
| Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 33 | const RefreshRateConfigs* LayerInfoV2::sRefreshRateConfigs = nullptr; | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 34 | bool LayerInfoV2::sTraceEnabled = false; | 
| Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 35 |  | 
| Ady Abraham | a6b676e | 2020-05-27 14:29:09 -0700 | [diff] [blame] | 36 | LayerInfoV2::LayerInfoV2(const std::string& name, nsecs_t highRefreshRatePeriod, | 
|  | 37 | LayerHistory::LayerVoteType defaultVote) | 
|  | 38 | : mName(name), | 
|  | 39 | mHighRefreshRatePeriod(highRefreshRatePeriod), | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 40 | mDefaultVote(defaultVote), | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 41 | mLayerVote({defaultVote, 0.0f}), | 
|  | 42 | mRefreshRateHistory(name) {} | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 43 |  | 
| Ady Abraham | 32efd54 | 2020-05-19 17:49:26 -0700 | [diff] [blame] | 44 | void LayerInfoV2::setLastPresentTime(nsecs_t lastPresentTime, nsecs_t now, | 
| Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 45 | LayerUpdateType updateType, bool pendingConfigChange) { | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 46 | lastPresentTime = std::max(lastPresentTime, static_cast<nsecs_t>(0)); | 
|  | 47 |  | 
|  | 48 | mLastUpdatedTime = std::max(lastPresentTime, now); | 
| Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 49 | switch (updateType) { | 
|  | 50 | case LayerUpdateType::AnimationTX: | 
|  | 51 | mLastAnimationTime = std::max(lastPresentTime, now); | 
|  | 52 | break; | 
|  | 53 | case LayerUpdateType::SetFrameRate: | 
|  | 54 | case LayerUpdateType::Buffer: | 
|  | 55 | FrameTimeData frameTime = {.presetTime = lastPresentTime, | 
|  | 56 | .queueTime = mLastUpdatedTime, | 
|  | 57 | .pendingConfigChange = pendingConfigChange}; | 
|  | 58 | mFrameTimes.push_back(frameTime); | 
|  | 59 | if (mFrameTimes.size() > HISTORY_SIZE) { | 
|  | 60 | mFrameTimes.pop_front(); | 
|  | 61 | } | 
|  | 62 | break; | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 63 | } | 
|  | 64 | } | 
|  | 65 |  | 
| Ady Abraham | dfb63ba | 2020-05-27 20:05:05 +0000 | [diff] [blame] | 66 | bool LayerInfoV2::isFrameTimeValid(const FrameTimeData& frameTime) const { | 
|  | 67 | return frameTime.queueTime >= std::chrono::duration_cast<std::chrono::nanoseconds>( | 
|  | 68 | mFrameTimeValidSince.time_since_epoch()) | 
|  | 69 | .count(); | 
|  | 70 | } | 
| Ady Abraham | 1adbb72 | 2020-05-15 11:51:48 -0700 | [diff] [blame] | 71 |  | 
| Ady Abraham | dfb63ba | 2020-05-27 20:05:05 +0000 | [diff] [blame] | 72 | bool LayerInfoV2::isFrequent(nsecs_t now) const { | 
| Ady Abraham | dfb63ba | 2020-05-27 20:05:05 +0000 | [diff] [blame] | 73 | // If we know nothing about this layer we consider it as frequent as it might be the start | 
|  | 74 | // of an animation. | 
| Ady Abraham | 983e568 | 2020-05-28 16:49:18 -0700 | [diff] [blame] | 75 | if (mFrameTimes.size() < FREQUENT_LAYER_WINDOW_SIZE) { | 
| Ady Abraham | dfb63ba | 2020-05-27 20:05:05 +0000 | [diff] [blame] | 76 | return true; | 
|  | 77 | } | 
|  | 78 |  | 
|  | 79 | // Find the first active frame | 
| Ady Abraham | 983e568 | 2020-05-28 16:49:18 -0700 | [diff] [blame] | 80 | auto it = mFrameTimes.begin(); | 
| Ady Abraham | dfb63ba | 2020-05-27 20:05:05 +0000 | [diff] [blame] | 81 | for (; it != mFrameTimes.end(); ++it) { | 
|  | 82 | if (it->queueTime >= getActiveLayerThreshold(now)) { | 
|  | 83 | break; | 
|  | 84 | } | 
|  | 85 | } | 
|  | 86 |  | 
|  | 87 | const auto numFrames = std::distance(it, mFrameTimes.end()); | 
|  | 88 | if (numFrames < FREQUENT_LAYER_WINDOW_SIZE) { | 
|  | 89 | return false; | 
|  | 90 | } | 
|  | 91 |  | 
|  | 92 | // Layer is considered frequent if the average frame rate is higher than the threshold | 
|  | 93 | const auto totalTime = mFrameTimes.back().queueTime - it->queueTime; | 
|  | 94 | return (1e9f * (numFrames - 1)) / totalTime >= MIN_FPS_FOR_FREQUENT_LAYER; | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 95 | } | 
|  | 96 |  | 
| Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 97 | bool LayerInfoV2::isAnimating(nsecs_t now) const { | 
|  | 98 | return mLastAnimationTime >= getActiveLayerThreshold(now); | 
|  | 99 | } | 
|  | 100 |  | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 101 | bool LayerInfoV2::hasEnoughDataForHeuristic() const { | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 102 | // 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] | 103 | if (mFrameTimes.size() < 2) { | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 104 | ALOGV("fewer than 2 frames recorded: %zu", mFrameTimes.size()); | 
| Ady Abraham | a61edcb | 2020-01-30 18:32:03 -0800 | [diff] [blame] | 105 | return false; | 
|  | 106 | } | 
|  | 107 |  | 
| Ady Abraham | dfb63ba | 2020-05-27 20:05:05 +0000 | [diff] [blame] | 108 | if (!isFrameTimeValid(mFrameTimes.front())) { | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 109 | ALOGV("stale frames still captured"); | 
| Ady Abraham | dfb63ba | 2020-05-27 20:05:05 +0000 | [diff] [blame] | 110 | return false; | 
|  | 111 | } | 
|  | 112 |  | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 113 | const auto totalDuration = mFrameTimes.back().queueTime - mFrameTimes.front().queueTime; | 
|  | 114 | if (mFrameTimes.size() < HISTORY_SIZE && totalDuration < HISTORY_DURATION.count()) { | 
|  | 115 | ALOGV("not enough frames captured: %zu | %.2f seconds", mFrameTimes.size(), | 
|  | 116 | totalDuration / 1e9f); | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 117 | return false; | 
|  | 118 | } | 
|  | 119 |  | 
|  | 120 | return true; | 
|  | 121 | } | 
|  | 122 |  | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 123 | std::optional<nsecs_t> LayerInfoV2::calculateAverageFrameTime() const { | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 124 | nsecs_t totalPresentTimeDeltas = 0; | 
| Ady Abraham | c966483 | 2020-05-12 14:16:56 -0700 | [diff] [blame] | 125 | nsecs_t totalQueueTimeDeltas = 0; | 
| Ady Abraham | 32efd54 | 2020-05-19 17:49:26 -0700 | [diff] [blame] | 126 | bool missingPresentTime = false; | 
|  | 127 | int numFrames = 0; | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 128 | for (auto it = mFrameTimes.begin(); it != mFrameTimes.end() - 1; ++it) { | 
| Ady Abraham | 32efd54 | 2020-05-19 17:49:26 -0700 | [diff] [blame] | 129 | // Ignore frames captured during a config change | 
|  | 130 | if (it->pendingConfigChange || (it + 1)->pendingConfigChange) { | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 131 | return std::nullopt; | 
| Ady Abraham | 32efd54 | 2020-05-19 17:49:26 -0700 | [diff] [blame] | 132 | } | 
|  | 133 |  | 
| Ady Abraham | c966483 | 2020-05-12 14:16:56 -0700 | [diff] [blame] | 134 | totalQueueTimeDeltas += | 
|  | 135 | std::max(((it + 1)->queueTime - it->queueTime), mHighRefreshRatePeriod); | 
| Ady Abraham | 32efd54 | 2020-05-19 17:49:26 -0700 | [diff] [blame] | 136 | numFrames++; | 
| Ady Abraham | c966483 | 2020-05-12 14:16:56 -0700 | [diff] [blame] | 137 |  | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 138 | if (!missingPresentTime && (it->presetTime == 0 || (it + 1)->presetTime == 0)) { | 
| Ady Abraham | c966483 | 2020-05-12 14:16:56 -0700 | [diff] [blame] | 139 | missingPresentTime = true; | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 140 | // If there are no presentation timestamps and we haven't calculated | 
|  | 141 | // one in the past then we can't calculate the refresh rate | 
|  | 142 | if (mLastRefreshRate.reported == 0) { | 
|  | 143 | return std::nullopt; | 
|  | 144 | } | 
| Ady Abraham | c966483 | 2020-05-12 14:16:56 -0700 | [diff] [blame] | 145 | continue; | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 146 | } | 
|  | 147 |  | 
|  | 148 | totalPresentTimeDeltas += | 
|  | 149 | std::max(((it + 1)->presetTime - it->presetTime), mHighRefreshRatePeriod); | 
|  | 150 | } | 
| Ady Abraham | c966483 | 2020-05-12 14:16:56 -0700 | [diff] [blame] | 151 |  | 
| Ady Abraham | c966483 | 2020-05-12 14:16:56 -0700 | [diff] [blame] | 152 | // Calculate the average frame time based on presentation timestamps. If those | 
|  | 153 | // doesn't exist, we look at the time the buffer was queued only. We can do that only if | 
|  | 154 | // we calculated a refresh rate based on presentation timestamps in the past. The reason | 
|  | 155 | // we look at the queue time is to handle cases where hwui attaches presentation timestamps | 
|  | 156 | // when implementing render ahead for specific refresh rates. When hwui no longer provides | 
|  | 157 | // presentation timestamps we look at the queue time to see if the current refresh rate still | 
|  | 158 | // matches the content. | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 159 |  | 
| Ady Abraham | 32efd54 | 2020-05-19 17:49:26 -0700 | [diff] [blame] | 160 | const auto averageFrameTime = | 
| Ady Abraham | c966483 | 2020-05-12 14:16:56 -0700 | [diff] [blame] | 161 | static_cast<float>(missingPresentTime ? totalQueueTimeDeltas : totalPresentTimeDeltas) / | 
| Ady Abraham | 32efd54 | 2020-05-19 17:49:26 -0700 | [diff] [blame] | 162 | numFrames; | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 163 | return static_cast<nsecs_t>(averageFrameTime); | 
| Ady Abraham | 32efd54 | 2020-05-19 17:49:26 -0700 | [diff] [blame] | 164 | } | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 165 |  | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 166 | std::optional<float> LayerInfoV2::calculateRefreshRateIfPossible(nsecs_t now) { | 
| Ady Abraham | 32efd54 | 2020-05-19 17:49:26 -0700 | [diff] [blame] | 167 | static constexpr float MARGIN = 1.0f; // 1Hz | 
| Ady Abraham | 32efd54 | 2020-05-19 17:49:26 -0700 | [diff] [blame] | 168 | if (!hasEnoughDataForHeuristic()) { | 
|  | 169 | ALOGV("Not enough data"); | 
|  | 170 | return std::nullopt; | 
|  | 171 | } | 
|  | 172 |  | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 173 | const auto averageFrameTime = calculateAverageFrameTime(); | 
|  | 174 | if (averageFrameTime.has_value()) { | 
|  | 175 | const auto refreshRate = 1e9f / *averageFrameTime; | 
|  | 176 | const bool refreshRateConsistent = mRefreshRateHistory.add(refreshRate, now); | 
|  | 177 | if (refreshRateConsistent) { | 
|  | 178 | const auto knownRefreshRate = | 
|  | 179 | sRefreshRateConfigs->findClosestKnownFrameRate(refreshRate); | 
| Ady Abraham | 32efd54 | 2020-05-19 17:49:26 -0700 | [diff] [blame] | 180 |  | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 181 | // To avoid oscillation, use the last calculated refresh rate if it is | 
|  | 182 | // close enough | 
|  | 183 | if (std::abs(mLastRefreshRate.calculated - refreshRate) > MARGIN && | 
|  | 184 | mLastRefreshRate.reported != knownRefreshRate) { | 
|  | 185 | mLastRefreshRate.calculated = refreshRate; | 
|  | 186 | mLastRefreshRate.reported = knownRefreshRate; | 
|  | 187 | } | 
|  | 188 |  | 
|  | 189 | ALOGV("%s %.2fHz rounded to nearest known frame rate %.2fHz", mName.c_str(), | 
|  | 190 | refreshRate, mLastRefreshRate.reported); | 
|  | 191 | } else { | 
|  | 192 | ALOGV("%s Not stable (%.2fHz) returning last known frame rate %.2fHz", mName.c_str(), | 
|  | 193 | refreshRate, mLastRefreshRate.reported); | 
|  | 194 | } | 
| Ady Abraham | 32efd54 | 2020-05-19 17:49:26 -0700 | [diff] [blame] | 195 | } | 
|  | 196 |  | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 197 | return mLastRefreshRate.reported == 0 ? std::nullopt | 
|  | 198 | : std::make_optional(mLastRefreshRate.reported); | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 199 | } | 
|  | 200 |  | 
|  | 201 | std::pair<LayerHistory::LayerVoteType, float> LayerInfoV2::getRefreshRate(nsecs_t now) { | 
|  | 202 | if (mLayerVote.type != LayerHistory::LayerVoteType::Heuristic) { | 
| Ady Abraham | a6b676e | 2020-05-27 14:29:09 -0700 | [diff] [blame] | 203 | ALOGV("%s voted %d ", mName.c_str(), static_cast<int>(mLayerVote.type)); | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 204 | return {mLayerVote.type, mLayerVote.fps}; | 
|  | 205 | } | 
|  | 206 |  | 
| Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 207 | if (isAnimating(now)) { | 
|  | 208 | ALOGV("%s is animating", mName.c_str()); | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 209 | mLastRefreshRate.animatingOrInfrequent = true; | 
| Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 210 | return {LayerHistory::LayerVoteType::Max, 0}; | 
|  | 211 | } | 
|  | 212 |  | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 213 | if (!isFrequent(now)) { | 
| Ady Abraham | a6b676e | 2020-05-27 14:29:09 -0700 | [diff] [blame] | 214 | ALOGV("%s is infrequent", mName.c_str()); | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 215 | mLastRefreshRate.animatingOrInfrequent = true; | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 216 | return {LayerHistory::LayerVoteType::Min, 0}; | 
|  | 217 | } | 
|  | 218 |  | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 219 | // If the layer was previously tagged as animating or infrequent, we clear | 
|  | 220 | // the history as it is likely the layer just changed its behavior | 
|  | 221 | // and we should not look at stale data | 
|  | 222 | if (mLastRefreshRate.animatingOrInfrequent) { | 
|  | 223 | clearHistory(now); | 
|  | 224 | } | 
|  | 225 |  | 
|  | 226 | auto refreshRate = calculateRefreshRateIfPossible(now); | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 227 | if (refreshRate.has_value()) { | 
| Ady Abraham | a6b676e | 2020-05-27 14:29:09 -0700 | [diff] [blame] | 228 | ALOGV("%s calculated refresh rate: %.2f", mName.c_str(), refreshRate.value()); | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 229 | return {LayerHistory::LayerVoteType::Heuristic, refreshRate.value()}; | 
|  | 230 | } | 
|  | 231 |  | 
| Ady Abraham | a6b676e | 2020-05-27 14:29:09 -0700 | [diff] [blame] | 232 | ALOGV("%s Max (can't resolve refresh rate)", mName.c_str()); | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 233 | return {LayerHistory::LayerVoteType::Max, 0}; | 
|  | 234 | } | 
|  | 235 |  | 
| Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 236 | const char* LayerInfoV2::getTraceTag(android::scheduler::LayerHistory::LayerVoteType type) const { | 
|  | 237 | if (mTraceTags.count(type) == 0) { | 
|  | 238 | const auto tag = "LFPS " + mName + " " + RefreshRateConfigs::layerVoteTypeString(type); | 
|  | 239 | mTraceTags.emplace(type, tag); | 
|  | 240 | } | 
|  | 241 |  | 
|  | 242 | return mTraceTags.at(type).c_str(); | 
|  | 243 | } | 
|  | 244 |  | 
|  | 245 | LayerInfoV2::RefreshRateHistory::HeuristicTraceTagData | 
|  | 246 | LayerInfoV2::RefreshRateHistory::makeHeuristicTraceTagData() const { | 
|  | 247 | const std::string prefix = "LFPS "; | 
|  | 248 | const std::string suffix = "Heuristic "; | 
|  | 249 | return {.min = prefix + mName + suffix + "min", | 
|  | 250 | .max = prefix + mName + suffix + "max", | 
|  | 251 | .consistent = prefix + mName + suffix + "consistent", | 
|  | 252 | .average = prefix + mName + suffix + "average"}; | 
|  | 253 | } | 
|  | 254 |  | 
|  | 255 | void LayerInfoV2::RefreshRateHistory::clear() { | 
|  | 256 | mRefreshRates.clear(); | 
|  | 257 | } | 
|  | 258 |  | 
|  | 259 | bool LayerInfoV2::RefreshRateHistory::add(float refreshRate, nsecs_t now) { | 
|  | 260 | mRefreshRates.push_back({refreshRate, now}); | 
|  | 261 | while (mRefreshRates.size() >= HISTORY_SIZE || | 
|  | 262 | now - mRefreshRates.front().timestamp > HISTORY_DURATION.count()) { | 
|  | 263 | mRefreshRates.pop_front(); | 
|  | 264 | } | 
|  | 265 |  | 
|  | 266 | if (CC_UNLIKELY(sTraceEnabled)) { | 
|  | 267 | if (!mHeuristicTraceTagData.has_value()) { | 
|  | 268 | mHeuristicTraceTagData = makeHeuristicTraceTagData(); | 
|  | 269 | } | 
|  | 270 |  | 
|  | 271 | ATRACE_INT(mHeuristicTraceTagData->average.c_str(), static_cast<int>(refreshRate)); | 
|  | 272 | } | 
|  | 273 |  | 
|  | 274 | return isConsistent(); | 
|  | 275 | } | 
|  | 276 |  | 
|  | 277 | bool LayerInfoV2::RefreshRateHistory::isConsistent() const { | 
|  | 278 | if (mRefreshRates.empty()) return true; | 
|  | 279 |  | 
|  | 280 | const auto max = std::max_element(mRefreshRates.begin(), mRefreshRates.end()); | 
|  | 281 | const auto min = std::min_element(mRefreshRates.begin(), mRefreshRates.end()); | 
|  | 282 | const auto consistent = max->refreshRate - min->refreshRate <= MARGIN_FPS; | 
|  | 283 |  | 
|  | 284 | if (CC_UNLIKELY(sTraceEnabled)) { | 
|  | 285 | if (!mHeuristicTraceTagData.has_value()) { | 
|  | 286 | mHeuristicTraceTagData = makeHeuristicTraceTagData(); | 
|  | 287 | } | 
|  | 288 |  | 
|  | 289 | ATRACE_INT(mHeuristicTraceTagData->max.c_str(), static_cast<int>(max->refreshRate)); | 
|  | 290 | ATRACE_INT(mHeuristicTraceTagData->min.c_str(), static_cast<int>(min->refreshRate)); | 
|  | 291 | ATRACE_INT(mHeuristicTraceTagData->consistent.c_str(), consistent); | 
|  | 292 | } | 
|  | 293 |  | 
|  | 294 | return consistent; | 
|  | 295 | } | 
|  | 296 |  | 
| Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 297 | } // namespace android::scheduler |