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