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 | #undef LOG_TAG |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 18 | #define LOG_TAG "LayerHistory" |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 19 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 20 | |
| 21 | #include "LayerHistory.h" |
| 22 | |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 23 | #include <android-base/stringprintf.h> |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 24 | #include <cutils/properties.h> |
Ady Abraham | 73c3df5 | 2023-01-12 18:09:31 -0800 | [diff] [blame] | 25 | #include <gui/TraceUtils.h> |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 26 | #include <utils/Log.h> |
| 27 | #include <utils/Timers.h> |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 28 | |
| 29 | #include <algorithm> |
| 30 | #include <cmath> |
| 31 | #include <string> |
| 32 | #include <utility> |
| 33 | |
| 34 | #include "../Layer.h" |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 35 | #include "EventThread.h" |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 36 | #include "FlagManager.h" |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 37 | #include "LayerInfo.h" |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 38 | |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 39 | namespace android::scheduler { |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 40 | |
| 41 | namespace { |
| 42 | |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 43 | bool isLayerActive(const LayerInfo& info, nsecs_t threshold) { |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 44 | if (FlagManager::getInstance().misc1() && !info.isVisible()) { |
Rachel Lee | 414f408 | 2023-10-23 14:48:44 -0700 | [diff] [blame] | 45 | return false; |
| 46 | } |
| 47 | |
| 48 | // Layers with an explicit frame rate or frame rate category are kept active, |
Rachel Lee | d0694bc | 2023-09-12 14:57:58 -0700 | [diff] [blame] | 49 | // but ignore NoVote. |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 50 | if (info.getSetFrameRateVote().isValid() && !info.getSetFrameRateVote().isNoVote()) { |
Ady Abraham | 89089c9 | 2020-04-15 18:24:41 -0700 | [diff] [blame] | 51 | return true; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 52 | } |
Ady Abraham | 89089c9 | 2020-04-15 18:24:41 -0700 | [diff] [blame] | 53 | |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 54 | return info.isVisible() && info.getLastUpdatedTime() >= threshold; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | bool traceEnabled() { |
| 58 | return property_get_bool("debug.sf.layer_history_trace", false); |
| 59 | } |
| 60 | |
| 61 | bool useFrameRatePriority() { |
| 62 | char value[PROPERTY_VALUE_MAX]; |
| 63 | property_get("debug.sf.use_frame_rate_priority", value, "1"); |
| 64 | return atoi(value); |
| 65 | } |
| 66 | |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 67 | void trace(const LayerInfo& info, LayerHistory::LayerVoteType type, int fps) { |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 68 | const auto traceType = [&](LayerHistory::LayerVoteType checkedType, int value) { |
| 69 | ATRACE_INT(info.getTraceTag(checkedType), type == checkedType ? value : 0); |
Ady Abraham | a6b676e | 2020-05-27 14:29:09 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 72 | traceType(LayerHistory::LayerVoteType::NoVote, 1); |
| 73 | traceType(LayerHistory::LayerVoteType::Heuristic, fps); |
| 74 | traceType(LayerHistory::LayerVoteType::ExplicitDefault, fps); |
| 75 | traceType(LayerHistory::LayerVoteType::ExplicitExactOrMultiple, fps); |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 76 | traceType(LayerHistory::LayerVoteType::ExplicitExact, fps); |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 77 | traceType(LayerHistory::LayerVoteType::Min, 1); |
| 78 | traceType(LayerHistory::LayerVoteType::Max, 1); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 79 | traceType(LayerHistory::LayerVoteType::ExplicitCategory, 1); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 80 | |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 81 | ALOGD("%s: %s @ %d Hz", __FUNCTION__, info.getName().c_str(), fps); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 82 | } |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 83 | |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 84 | LayerHistory::LayerVoteType getVoteType(FrameRateCompatibility compatibility, |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 85 | bool contentDetectionEnabled) { |
| 86 | LayerHistory::LayerVoteType voteType; |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 87 | if (!contentDetectionEnabled || compatibility == FrameRateCompatibility::NoVote) { |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 88 | voteType = LayerHistory::LayerVoteType::NoVote; |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 89 | } else if (compatibility == FrameRateCompatibility::Min) { |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 90 | voteType = LayerHistory::LayerVoteType::Min; |
| 91 | } else { |
| 92 | voteType = LayerHistory::LayerVoteType::Heuristic; |
| 93 | } |
| 94 | return voteType; |
| 95 | } |
| 96 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 97 | } // namespace |
| 98 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 99 | LayerHistory::LayerHistory() |
Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 100 | : mTraceEnabled(traceEnabled()), mUseFrameRatePriority(useFrameRatePriority()) { |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 101 | LayerInfo::setTraceEnabled(mTraceEnabled); |
Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 104 | LayerHistory::~LayerHistory() = default; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 105 | |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 106 | void LayerHistory::registerLayer(Layer* layer, bool contentDetectionEnabled) { |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 107 | std::lock_guard lock(mLock); |
Dominik Laskowski | 0c41ffa | 2021-12-24 16:45:12 -0800 | [diff] [blame] | 108 | LOG_ALWAYS_FATAL_IF(findLayer(layer->getSequence()).first != LayerStatus::NotFound, |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 109 | "%s already registered", layer->getName().c_str()); |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 110 | LayerVoteType type = |
| 111 | getVoteType(layer->getDefaultFrameRateCompatibility(), contentDetectionEnabled); |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 112 | auto info = std::make_unique<LayerInfo>(layer->getName(), layer->getOwnerUid(), type); |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 113 | |
| 114 | // The layer can be placed on either map, it is assumed that partitionLayers() will be called |
| 115 | // to correct them. |
| 116 | mInactiveLayerInfos.insert({layer->getSequence(), std::make_pair(layer, std::move(info))}); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 117 | } |
| 118 | |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 119 | void LayerHistory::deregisterLayer(Layer* layer) { |
| 120 | std::lock_guard lock(mLock); |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 121 | if (!mActiveLayerInfos.erase(layer->getSequence())) { |
| 122 | if (!mInactiveLayerInfos.erase(layer->getSequence())) { |
| 123 | LOG_ALWAYS_FATAL("%s: unknown layer %p", __FUNCTION__, layer); |
| 124 | } |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 125 | } |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 128 | void LayerHistory::record(int32_t id, const LayerProps& layerProps, nsecs_t presentTime, |
| 129 | nsecs_t now, LayerUpdateType updateType) { |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 130 | std::lock_guard lock(mLock); |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 131 | auto [found, layerPair] = findLayer(id); |
Dominik Laskowski | 0c41ffa | 2021-12-24 16:45:12 -0800 | [diff] [blame] | 132 | if (found == LayerStatus::NotFound) { |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 133 | // Offscreen layer |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 134 | ALOGV("%s: %d not registered", __func__, id); |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 135 | return; |
| 136 | } |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 137 | |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 138 | const auto& info = layerPair->second; |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 139 | info->setLastPresentTime(presentTime, now, updateType, mModeChangePending, layerProps); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 140 | |
| 141 | // Activate layer if inactive. |
Dominik Laskowski | 0c41ffa | 2021-12-24 16:45:12 -0800 | [diff] [blame] | 142 | if (found == LayerStatus::LayerInInactiveMap) { |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 143 | mActiveLayerInfos.insert( |
| 144 | {id, std::make_pair(layerPair->first, std::move(layerPair->second))}); |
| 145 | mInactiveLayerInfos.erase(id); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
Vishnu Nair | 80e8cfe | 2023-09-29 17:03:45 -0700 | [diff] [blame] | 149 | void LayerHistory::setDefaultFrameRateCompatibility(int32_t id, |
| 150 | FrameRateCompatibility frameRateCompatibility, |
| 151 | bool contentDetectionEnabled) { |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 152 | std::lock_guard lock(mLock); |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 153 | |
| 154 | auto [found, layerPair] = findLayer(id); |
| 155 | if (found == LayerStatus::NotFound) { |
| 156 | // Offscreen layer |
Vishnu Nair | 80e8cfe | 2023-09-29 17:03:45 -0700 | [diff] [blame] | 157 | ALOGV("%s: %d not registered", __func__, id); |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 158 | return; |
| 159 | } |
| 160 | |
| 161 | const auto& info = layerPair->second; |
Vishnu Nair | 80e8cfe | 2023-09-29 17:03:45 -0700 | [diff] [blame] | 162 | info->setDefaultLayerVote(getVoteType(frameRateCompatibility, contentDetectionEnabled)); |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 165 | auto LayerHistory::summarize(const RefreshRateSelector& selector, nsecs_t now) -> Summary { |
Ady Abraham | 73c3df5 | 2023-01-12 18:09:31 -0800 | [diff] [blame] | 166 | ATRACE_CALL(); |
Dominik Laskowski | 0c41ffa | 2021-12-24 16:45:12 -0800 | [diff] [blame] | 167 | Summary summary; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 168 | |
| 169 | std::lock_guard lock(mLock); |
| 170 | |
| 171 | partitionLayers(now); |
| 172 | |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 173 | for (const auto& [key, value] : mActiveLayerInfos) { |
| 174 | auto& info = value.second; |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 175 | const auto frameRateSelectionPriority = info->getFrameRateSelectionPriority(); |
Ady Abraham | aae5ed5 | 2020-06-26 09:32:43 -0700 | [diff] [blame] | 176 | const auto layerFocused = Layer::isLayerFocusedBasedOnPriority(frameRateSelectionPriority); |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 177 | ALOGV("%s has priority: %d %s focused", info->getName().c_str(), frameRateSelectionPriority, |
| 178 | layerFocused ? "" : "not"); |
Ana Krulec | 3803b8d | 2020-02-03 16:35:46 -0800 | [diff] [blame] | 179 | |
Ady Abraham | 73c3df5 | 2023-01-12 18:09:31 -0800 | [diff] [blame] | 180 | ATRACE_FORMAT("%s", info->getName().c_str()); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 181 | const auto votes = info->getRefreshRateVote(selector, now); |
| 182 | for (LayerInfo::LayerVote vote : votes) { |
| 183 | if (vote.isNoVote()) { |
| 184 | continue; |
| 185 | } |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 186 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 187 | // Compute the layer's position on the screen |
| 188 | const Rect bounds = Rect(info->getBounds()); |
| 189 | const ui::Transform transform = info->getTransform(); |
| 190 | constexpr bool roundOutwards = true; |
| 191 | Rect transformed = transform.transform(bounds, roundOutwards); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 192 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 193 | const float layerArea = transformed.getWidth() * transformed.getHeight(); |
| 194 | float weight = mDisplayArea ? layerArea / mDisplayArea : 0.0f; |
| 195 | const std::string categoryString = vote.category == FrameRateCategory::Default |
Rachel Lee | 94ff799 | 2023-08-31 15:15:22 -0700 | [diff] [blame] | 196 | ? "" |
| 197 | : base::StringPrintf("category=%s", ftl::enum_string(vote.category).c_str()); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 198 | ATRACE_FORMAT_INSTANT("%s %s %s (%d%)", ftl::enum_string(vote.type).c_str(), |
| 199 | to_string(vote.fps).c_str(), categoryString.c_str(), |
| 200 | weight * 100); |
| 201 | summary.push_back({info->getName(), info->getOwnerUid(), vote.type, vote.fps, |
Rachel Lee | 67afbea | 2023-09-28 15:35:07 -0700 | [diff] [blame] | 202 | vote.seamlessness, vote.category, vote.categorySmoothSwitchOnly, |
| 203 | weight, layerFocused}); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 204 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 205 | if (CC_UNLIKELY(mTraceEnabled)) { |
| 206 | trace(*info, vote.type, vote.fps.getIntValue()); |
| 207 | } |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | |
| 211 | return summary; |
| 212 | } |
| 213 | |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 214 | void LayerHistory::partitionLayers(nsecs_t now) { |
Ady Abraham | 73c3df5 | 2023-01-12 18:09:31 -0800 | [diff] [blame] | 215 | ATRACE_CALL(); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 216 | const nsecs_t threshold = getActiveLayerThreshold(now); |
| 217 | |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 218 | // iterate over inactive map |
| 219 | LayerInfos::iterator it = mInactiveLayerInfos.begin(); |
| 220 | while (it != mInactiveLayerInfos.end()) { |
| 221 | auto& [layerUnsafe, info] = it->second; |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 222 | if (isLayerActive(*info, threshold)) { |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 223 | // move this to the active map |
| 224 | |
| 225 | mActiveLayerInfos.insert({it->first, std::move(it->second)}); |
| 226 | it = mInactiveLayerInfos.erase(it); |
| 227 | } else { |
| 228 | if (CC_UNLIKELY(mTraceEnabled)) { |
Dominik Laskowski | 0c41ffa | 2021-12-24 16:45:12 -0800 | [diff] [blame] | 229 | trace(*info, LayerVoteType::NoVote, 0); |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 230 | } |
| 231 | info->onLayerInactive(now); |
| 232 | it++; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | // iterate over active map |
| 237 | it = mActiveLayerInfos.begin(); |
| 238 | while (it != mActiveLayerInfos.end()) { |
| 239 | auto& [layerUnsafe, info] = it->second; |
| 240 | if (isLayerActive(*info, threshold)) { |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 241 | // Set layer vote if set |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 242 | const auto frameRate = info->getSetFrameRateVote(); |
Ady Abraham | 71c437d | 2020-01-31 15:56:57 -0800 | [diff] [blame] | 243 | const auto voteType = [&]() { |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 244 | switch (frameRate.vote.type) { |
Ady Abraham | 71c437d | 2020-01-31 15:56:57 -0800 | [diff] [blame] | 245 | case Layer::FrameRateCompatibility::Default: |
| 246 | return LayerVoteType::ExplicitDefault; |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 247 | case Layer::FrameRateCompatibility::Min: |
| 248 | return LayerVoteType::Min; |
Ady Abraham | 71c437d | 2020-01-31 15:56:57 -0800 | [diff] [blame] | 249 | case Layer::FrameRateCompatibility::ExactOrMultiple: |
| 250 | return LayerVoteType::ExplicitExactOrMultiple; |
| 251 | case Layer::FrameRateCompatibility::NoVote: |
| 252 | return LayerVoteType::NoVote; |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 253 | case Layer::FrameRateCompatibility::Exact: |
| 254 | return LayerVoteType::ExplicitExact; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 255 | } |
Ady Abraham | 71c437d | 2020-01-31 15:56:57 -0800 | [diff] [blame] | 256 | }(); |
Ady Abraham | 5dde597 | 2020-05-13 10:50:54 -0700 | [diff] [blame] | 257 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 258 | if (frameRate.isValid()) { |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 259 | const auto type = info->isVisible() ? voteType : LayerVoteType::NoVote; |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 260 | info->setLayerVote({type, frameRate.vote.rate, frameRate.vote.seamlessness, |
| 261 | frameRate.category}); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 262 | } else { |
| 263 | info->resetLayerVote(); |
| 264 | } |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 265 | |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 266 | it++; |
| 267 | } else { |
| 268 | if (CC_UNLIKELY(mTraceEnabled)) { |
Dominik Laskowski | 0c41ffa | 2021-12-24 16:45:12 -0800 | [diff] [blame] | 269 | trace(*info, LayerVoteType::NoVote, 0); |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 270 | } |
| 271 | info->onLayerInactive(now); |
| 272 | // move this to the inactive map |
| 273 | mInactiveLayerInfos.insert({it->first, std::move(it->second)}); |
| 274 | it = mActiveLayerInfos.erase(it); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 275 | } |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 276 | } |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 277 | } |
| 278 | |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 279 | void LayerHistory::clear() { |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 280 | std::lock_guard lock(mLock); |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 281 | for (const auto& [key, value] : mActiveLayerInfos) { |
| 282 | value.second->clearHistory(systemTime()); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 283 | } |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 284 | } |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 285 | |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 286 | std::string LayerHistory::dump() const { |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 287 | std::lock_guard lock(mLock); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 288 | return base::StringPrintf("{size=%zu, active=%zu}", |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 289 | mActiveLayerInfos.size() + mInactiveLayerInfos.size(), |
| 290 | mActiveLayerInfos.size()); |
| 291 | } |
| 292 | |
| 293 | float LayerHistory::getLayerFramerate(nsecs_t now, int32_t id) const { |
| 294 | std::lock_guard lock(mLock); |
| 295 | auto [found, layerPair] = findLayer(id); |
Dominik Laskowski | 0c41ffa | 2021-12-24 16:45:12 -0800 | [diff] [blame] | 296 | if (found != LayerStatus::NotFound) { |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 297 | return layerPair->second->getFps(now).getValue(); |
| 298 | } |
| 299 | return 0.f; |
| 300 | } |
| 301 | |
Dominik Laskowski | 0c41ffa | 2021-12-24 16:45:12 -0800 | [diff] [blame] | 302 | auto LayerHistory::findLayer(int32_t id) -> std::pair<LayerStatus, LayerPair*> { |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 303 | // the layer could be in either the active or inactive map, try both |
| 304 | auto it = mActiveLayerInfos.find(id); |
| 305 | if (it != mActiveLayerInfos.end()) { |
Dominik Laskowski | 0c41ffa | 2021-12-24 16:45:12 -0800 | [diff] [blame] | 306 | return {LayerStatus::LayerInActiveMap, &(it->second)}; |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 307 | } |
| 308 | it = mInactiveLayerInfos.find(id); |
| 309 | if (it != mInactiveLayerInfos.end()) { |
Dominik Laskowski | 0c41ffa | 2021-12-24 16:45:12 -0800 | [diff] [blame] | 310 | return {LayerStatus::LayerInInactiveMap, &(it->second)}; |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 311 | } |
Dominik Laskowski | 0c41ffa | 2021-12-24 16:45:12 -0800 | [diff] [blame] | 312 | return {LayerStatus::NotFound, nullptr}; |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 315 | bool LayerHistory::isSmallDirtyArea(uint32_t dirtyArea, float threshold) const { |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 316 | const float ratio = (float)dirtyArea / mDisplayArea; |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 317 | const bool isSmallDirty = ratio <= threshold; |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 318 | ATRACE_FORMAT_INSTANT("small dirty=%s, ratio=%.3f", isSmallDirty ? "true" : "false", ratio); |
| 319 | return isSmallDirty; |
| 320 | } |
| 321 | |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 322 | } // namespace android::scheduler |