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 | #pragma once |
| 18 | |
Dominik Laskowski | f6b4ba6 | 2021-11-09 12:46:10 -0800 | [diff] [blame] | 19 | #include <chrono> |
| 20 | #include <deque> |
| 21 | #include <optional> |
| 22 | #include <string> |
| 23 | #include <unordered_map> |
| 24 | |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 25 | #include <ui/Transform.h> |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 26 | #include <utils/Timers.h> |
| 27 | |
Dominik Laskowski | f6b4ba6 | 2021-11-09 12:46:10 -0800 | [diff] [blame] | 28 | #include <scheduler/Seamlessness.h> |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 29 | |
| 30 | #include "LayerHistory.h" |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 31 | #include "RefreshRateSelector.h" |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 32 | |
| 33 | namespace android { |
| 34 | |
| 35 | class Layer; |
| 36 | |
| 37 | namespace scheduler { |
| 38 | |
| 39 | using namespace std::chrono_literals; |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 40 | struct LayerProps; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 41 | // Maximum period between presents for a layer to be considered active. |
| 42 | constexpr std::chrono::nanoseconds MAX_ACTIVE_LAYER_PERIOD_NS = 1200ms; |
| 43 | |
| 44 | // Earliest present time for a layer to be considered active. |
| 45 | constexpr nsecs_t getActiveLayerThreshold(nsecs_t now) { |
| 46 | return now - MAX_ACTIVE_LAYER_PERIOD_NS.count(); |
| 47 | } |
| 48 | |
| 49 | // Stores history of present times and refresh rates for a layer. |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 50 | class LayerInfo { |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 51 | using LayerUpdateType = LayerHistory::LayerUpdateType; |
| 52 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 53 | // Layer is considered frequent if the earliest value in the window of most recent present times |
| 54 | // is within a threshold. If a layer is infrequent, its average refresh rate is disregarded in |
| 55 | // favor of a low refresh rate. |
Ady Abraham | 86ac5c5 | 2023-01-11 15:24:03 -0800 | [diff] [blame] | 56 | static constexpr size_t kFrequentLayerWindowSize = 4; |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 57 | static constexpr Fps kMinFpsForFrequentLayer = 10_Hz; |
Marin Shalamanov | 2045d5b | 2020-12-28 18:11:41 +0100 | [diff] [blame] | 58 | static constexpr auto kMaxPeriodForFrequentLayerNs = |
| 59 | std::chrono::nanoseconds(kMinFpsForFrequentLayer.getPeriodNsecs()) + 1ms; |
Arthur Hung | 0cc8a38 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 60 | static constexpr size_t kNumSmallDirtyThreshold = 2; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 61 | |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 62 | friend class LayerHistoryTest; |
Marin Shalamanov | 2045d5b | 2020-12-28 18:11:41 +0100 | [diff] [blame] | 63 | friend class LayerInfoTest; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 64 | |
| 65 | public: |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 66 | // Holds information about the layer vote |
| 67 | struct LayerVote { |
| 68 | LayerHistory::LayerVoteType type = LayerHistory::LayerVoteType::Heuristic; |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 69 | Fps fps; |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 70 | Seamlessness seamlessness = Seamlessness::Default; |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 71 | }; |
| 72 | |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 73 | // FrameRateCompatibility specifies how we should interpret the frame rate associated with |
| 74 | // the layer. |
| 75 | enum class FrameRateCompatibility { |
| 76 | Default, // Layer didn't specify any specific handling strategy |
| 77 | |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 78 | Min, // Layer needs the minimum frame rate. |
| 79 | |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 80 | Exact, // Layer needs the exact frame rate. |
| 81 | |
| 82 | ExactOrMultiple, // Layer needs the exact frame rate (or a multiple of it) to present the |
| 83 | // content properly. Any other value will result in a pull down. |
| 84 | |
| 85 | NoVote, // Layer doesn't have any requirements for the refresh rate and |
| 86 | // should not be considered when the display refresh rate is determined. |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 87 | |
| 88 | ftl_last = NoVote |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | // Encapsulates the frame rate and compatibility of the layer. This information will be used |
| 92 | // when the display refresh rate is determined. |
| 93 | struct FrameRate { |
| 94 | using Seamlessness = scheduler::Seamlessness; |
| 95 | |
| 96 | Fps rate; |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 97 | FrameRateCompatibility type = FrameRateCompatibility::Default; |
| 98 | Seamlessness seamlessness = Seamlessness::Default; |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 99 | |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 100 | FrameRate() = default; |
| 101 | |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 102 | FrameRate(Fps rate, FrameRateCompatibility type, |
| 103 | Seamlessness seamlessness = Seamlessness::OnlySeamless) |
| 104 | : rate(rate), type(type), seamlessness(getSeamlessness(rate, seamlessness)) {} |
| 105 | |
| 106 | bool operator==(const FrameRate& other) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 107 | return isApproxEqual(rate, other.rate) && type == other.type && |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 108 | seamlessness == other.seamlessness; |
| 109 | } |
| 110 | |
| 111 | bool operator!=(const FrameRate& other) const { return !(*this == other); } |
| 112 | |
| 113 | // Convert an ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_* value to a |
| 114 | // Layer::FrameRateCompatibility. Logs fatal if the compatibility value is invalid. |
| 115 | static FrameRateCompatibility convertCompatibility(int8_t compatibility); |
| 116 | static scheduler::Seamlessness convertChangeFrameRateStrategy(int8_t strategy); |
| 117 | |
| 118 | private: |
| 119 | static Seamlessness getSeamlessness(Fps rate, Seamlessness seamlessness) { |
| 120 | if (!rate.isValid()) { |
| 121 | // Refresh rate of 0 is a special value which should reset the vote to |
| 122 | // its default value. |
| 123 | return Seamlessness::Default; |
| 124 | } |
| 125 | return seamlessness; |
| 126 | } |
| 127 | }; |
| 128 | |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 129 | static void setTraceEnabled(bool enabled) { sTraceEnabled = enabled; } |
| 130 | |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 131 | LayerInfo(const std::string& name, uid_t ownerUid, LayerHistory::LayerVoteType defaultVote); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 132 | |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 133 | LayerInfo(const LayerInfo&) = delete; |
| 134 | LayerInfo& operator=(const LayerInfo&) = delete; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 135 | |
| 136 | // Records the last requested present time. It also stores information about when |
| 137 | // the layer was last updated. If the present time is farther in the future than the |
| 138 | // updated time, the updated time is the present time. |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 139 | void setLastPresentTime(nsecs_t lastPresentTime, nsecs_t now, LayerUpdateType updateType, |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 140 | bool pendingModeChange, const LayerProps& props); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 141 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 142 | // Sets an explicit layer vote. This usually comes directly from the application via |
| 143 | // ANativeWindow_setFrameRate API |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 144 | void setLayerVote(LayerVote vote) { mLayerVote = vote; } |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 145 | |
| 146 | // Sets the default layer vote. This will be the layer vote after calling to resetLayerVote(). |
| 147 | // This is used for layers that called to setLayerVote() and then removed the vote, so that the |
| 148 | // layer can go back to whatever vote it had before the app voted for it. |
| 149 | void setDefaultLayerVote(LayerHistory::LayerVoteType type) { mDefaultVote = type; } |
| 150 | |
| 151 | // Resets the layer vote to its default. |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 152 | void resetLayerVote() { mLayerVote = {mDefaultVote, Fps(), Seamlessness::Default}; } |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 153 | |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 154 | std::string getName() const { return mName; } |
| 155 | |
| 156 | uid_t getOwnerUid() const { return mOwnerUid; } |
| 157 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 158 | LayerVote getRefreshRateVote(const RefreshRateSelector&, nsecs_t now); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 159 | |
| 160 | // Return the last updated time. If the present time is farther in the future than the |
| 161 | // updated time, the updated time is the present time. |
| 162 | nsecs_t getLastUpdatedTime() const { return mLastUpdatedTime; } |
| 163 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 164 | FrameRate getSetFrameRateVote() const; |
| 165 | bool isVisible() const; |
| 166 | int32_t getFrameRateSelectionPriority() const; |
| 167 | FloatRect getBounds() const; |
| 168 | ui::Transform getTransform() const; |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 169 | |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 170 | // Returns a C string for tracing a vote |
| 171 | const char* getTraceTag(LayerHistory::LayerVoteType type) const; |
| 172 | |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 173 | // Return the framerate of this layer. |
| 174 | Fps getFps(nsecs_t now) const; |
| 175 | |
Ady Abraham | 983e568 | 2020-05-28 16:49:18 -0700 | [diff] [blame] | 176 | void onLayerInactive(nsecs_t now) { |
Ady Abraham | dfb63ba | 2020-05-27 20:05:05 +0000 | [diff] [blame] | 177 | // Mark mFrameTimeValidSince to now to ignore all previous frame times. |
| 178 | // We are not deleting the old frame to keep track of whether we should treat the first |
| 179 | // buffer as Max as we don't know anything about this layer or Min as this layer is |
| 180 | // posting infrequent updates. |
Ady Abraham | 983e568 | 2020-05-28 16:49:18 -0700 | [diff] [blame] | 181 | const auto timePoint = std::chrono::nanoseconds(now); |
| 182 | mFrameTimeValidSince = std::chrono::time_point<std::chrono::steady_clock>(timePoint); |
Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 183 | mLastRefreshRate = {}; |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 184 | mRefreshRateHistory.clear(); |
ramindani | 63db24e | 2023-04-03 10:56:05 -0700 | [diff] [blame] | 185 | mIsFrequencyConclusive = true; |
Ady Abraham | a61edcb | 2020-01-30 18:32:03 -0800 | [diff] [blame] | 186 | } |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 187 | |
Ady Abraham | 983e568 | 2020-05-28 16:49:18 -0700 | [diff] [blame] | 188 | void clearHistory(nsecs_t now) { |
| 189 | onLayerInactive(now); |
| 190 | mFrameTimes.clear(); |
| 191 | } |
| 192 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 193 | private: |
Ady Abraham | a61edcb | 2020-01-30 18:32:03 -0800 | [diff] [blame] | 194 | // Used to store the layer timestamps |
| 195 | struct FrameTimeData { |
Marin Shalamanov | 2045d5b | 2020-12-28 18:11:41 +0100 | [diff] [blame] | 196 | nsecs_t presentTime; // desiredPresentTime, if provided |
Ady Abraham | a61edcb | 2020-01-30 18:32:03 -0800 | [diff] [blame] | 197 | nsecs_t queueTime; // buffer queue time |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 198 | bool pendingModeChange; |
Arthur Hung | 0cc8a38 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 199 | bool isSmallDirty; |
Ady Abraham | a61edcb | 2020-01-30 18:32:03 -0800 | [diff] [blame] | 200 | }; |
| 201 | |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 202 | // Holds information about the calculated and reported refresh rate |
| 203 | struct RefreshRateHeuristicData { |
| 204 | // Rate calculated on the layer |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 205 | Fps calculated; |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 206 | // Last reported rate for LayerInfo::getRefreshRate() |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 207 | Fps reported; |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 208 | // Whether the last reported rate for LayerInfo::getRefreshRate() |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 209 | // was due to animation or infrequent updates |
Ady Abraham | 86ac5c5 | 2023-01-11 15:24:03 -0800 | [diff] [blame] | 210 | bool animating = false; |
| 211 | // Whether the last reported rate for LayerInfo::getRefreshRate() |
| 212 | // was due to infrequent updates |
| 213 | bool infrequent = false; |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 214 | }; |
| 215 | |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 216 | // Class to store past calculated refresh rate and determine whether |
| 217 | // the refresh rate calculated is consistent with past values |
| 218 | class RefreshRateHistory { |
| 219 | public: |
| 220 | static constexpr auto HISTORY_SIZE = 90; |
| 221 | static constexpr std::chrono::nanoseconds HISTORY_DURATION = 2s; |
| 222 | |
| 223 | RefreshRateHistory(const std::string& name) : mName(name) {} |
| 224 | |
| 225 | // Clears History |
| 226 | void clear(); |
| 227 | |
| 228 | // Adds a new refresh rate and returns true if it is consistent |
Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 229 | bool add(Fps refreshRate, nsecs_t now); |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 230 | |
| 231 | private: |
Marin Shalamanov | 1bc43ee | 2020-11-20 16:56:52 +0100 | [diff] [blame] | 232 | friend class LayerHistoryTest; |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 233 | |
| 234 | // Holds the refresh rate when it was calculated |
| 235 | struct RefreshRateData { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 236 | Fps refreshRate; |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 237 | nsecs_t timestamp = 0; |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 238 | }; |
| 239 | |
| 240 | // Holds tracing strings |
| 241 | struct HeuristicTraceTagData { |
| 242 | std::string min; |
| 243 | std::string max; |
| 244 | std::string consistent; |
| 245 | std::string average; |
| 246 | }; |
| 247 | |
| 248 | bool isConsistent() const; |
| 249 | HeuristicTraceTagData makeHeuristicTraceTagData() const; |
| 250 | |
| 251 | const std::string mName; |
| 252 | mutable std::optional<HeuristicTraceTagData> mHeuristicTraceTagData; |
| 253 | std::deque<RefreshRateData> mRefreshRates; |
Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 254 | static constexpr float MARGIN_CONSISTENT_FPS = 1.0; |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 255 | }; |
| 256 | |
ramindani | 63db24e | 2023-04-03 10:56:05 -0700 | [diff] [blame] | 257 | // Represents whether we were able to determine either layer is frequent or infrequent |
| 258 | bool mIsFrequencyConclusive = true; |
| 259 | struct Frequent { |
| 260 | bool isFrequent; |
| 261 | bool clearHistory; |
| 262 | // Represents whether we were able to determine isFrequent conclusively |
| 263 | bool isConclusive; |
Arthur Hung | 0cc8a38 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 264 | // Represents whether the latest frames are small dirty. |
| 265 | bool isSmallDirty = false; |
ramindani | 63db24e | 2023-04-03 10:56:05 -0700 | [diff] [blame] | 266 | }; |
| 267 | Frequent isFrequent(nsecs_t now) const; |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 268 | bool isAnimating(nsecs_t now) const; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 269 | bool hasEnoughDataForHeuristic() const; |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 270 | std::optional<Fps> calculateRefreshRateIfPossible(const RefreshRateSelector&, nsecs_t now); |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 271 | std::optional<nsecs_t> calculateAverageFrameTime() const; |
Ady Abraham | dfb63ba | 2020-05-27 20:05:05 +0000 | [diff] [blame] | 272 | bool isFrameTimeValid(const FrameTimeData&) const; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 273 | |
Ady Abraham | a6b676e | 2020-05-27 14:29:09 -0700 | [diff] [blame] | 274 | const std::string mName; |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 275 | const uid_t mOwnerUid; |
Ady Abraham | a6b676e | 2020-05-27 14:29:09 -0700 | [diff] [blame] | 276 | |
Marin Shalamanov | 4ad8b30 | 2020-12-11 15:50:08 +0100 | [diff] [blame] | 277 | // Used for sanitizing the heuristic data. If two frames are less than |
| 278 | // this period apart from each other they'll be considered as duplicates. |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 279 | static constexpr nsecs_t kMinPeriodBetweenFrames = (240_Hz).getPeriodNsecs(); |
Marin Shalamanov | 2045d5b | 2020-12-28 18:11:41 +0100 | [diff] [blame] | 280 | // Used for sanitizing the heuristic data. If two frames are more than |
| 281 | // this period apart from each other, the interval between them won't be |
| 282 | // taken into account when calculating average frame rate. |
| 283 | static constexpr nsecs_t kMaxPeriodBetweenFrames = kMinFpsForFrequentLayer.getPeriodNsecs(); |
Arthur Hung | 0cc8a38 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 284 | // Used for sanitizing the heuristic data. If frames are small dirty updating and are less |
| 285 | // than this period apart from each other, the interval between them won't be |
| 286 | // taken into account when calculating average frame rate. |
| 287 | static constexpr nsecs_t kMinPeriodBetweenSmallDirtyFrames = (60_Hz).getPeriodNsecs(); |
| 288 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 289 | LayerHistory::LayerVoteType mDefaultVote; |
| 290 | |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 291 | LayerVote mLayerVote; |
| 292 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 293 | nsecs_t mLastUpdatedTime = 0; |
| 294 | |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 295 | nsecs_t mLastAnimationTime = 0; |
| 296 | |
Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 297 | RefreshRateHeuristicData mLastRefreshRate; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 298 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 299 | std::deque<FrameTimeData> mFrameTimes; |
Ady Abraham | dfb63ba | 2020-05-27 20:05:05 +0000 | [diff] [blame] | 300 | std::chrono::time_point<std::chrono::steady_clock> mFrameTimeValidSince = |
| 301 | std::chrono::steady_clock::now(); |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 302 | static constexpr size_t HISTORY_SIZE = RefreshRateHistory::HISTORY_SIZE; |
Arthur Hung | 0cc8a38 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 303 | static constexpr std::chrono::nanoseconds HISTORY_DURATION = LayerHistory::kMaxPeriodForHistory; |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 304 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 305 | std::unique_ptr<LayerProps> mLayerProps; |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 306 | |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 307 | RefreshRateHistory mRefreshRateHistory; |
| 308 | |
Arthur Hung | 8144e02 | 2023-09-08 10:26:23 +0000 | [diff] [blame^] | 309 | // This will be accessed from only one thread when counting a layer is frequent or infrequent, |
| 310 | // and to determine whether a layer is in small dirty updating. |
| 311 | mutable int32_t mLastSmallDirtyCount = 0; |
| 312 | |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 313 | mutable std::unordered_map<LayerHistory::LayerVoteType, std::string> mTraceTags; |
Ady Abraham | b1b9d41 | 2020-06-01 19:53:52 -0700 | [diff] [blame] | 314 | |
| 315 | // Shared for all LayerInfo instances |
Ady Abraham | 0ccd79b | 2020-06-10 10:11:17 -0700 | [diff] [blame] | 316 | static bool sTraceEnabled; |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 317 | }; |
| 318 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 319 | struct LayerProps { |
| 320 | bool visible = false; |
| 321 | FloatRect bounds; |
| 322 | ui::Transform transform; |
| 323 | LayerInfo::FrameRate setFrameRateVote; |
| 324 | int32_t frameRateSelectionPriority = -1; |
Arthur Hung | 0cc8a38 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 325 | bool isSmallDirty = false; |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 326 | }; |
| 327 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 328 | } // namespace scheduler |
| 329 | } // namespace android |