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