Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 17 | #undef LOG_TAG |
| 18 | #define LOG_TAG "Scheduler" |
Ana Krulec | 7ab5603 | 2018-11-02 20:51:06 +0100 | [diff] [blame] | 19 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 20 | |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 21 | #include "Scheduler.h" |
| 22 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 23 | #include <android-base/properties.h> |
Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame] | 24 | #include <android-base/stringprintf.h> |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 25 | #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> |
| 26 | #include <android/hardware/configstore/1.1/ISurfaceFlingerConfigs.h> |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 27 | #include <configstore/Utils.h> |
Ady Abraham | 8f1ee7f | 2019-04-05 10:32:50 -0700 | [diff] [blame] | 28 | #include <input/InputWindow.h> |
Ana Krulec | fefd6ae | 2019-02-13 17:53:08 -0800 | [diff] [blame] | 29 | #include <system/window.h> |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 30 | #include <ui/DisplayStatInfo.h> |
Ana Krulec | 3084c05 | 2018-11-21 20:27:17 +0100 | [diff] [blame] | 31 | #include <utils/Timers.h> |
Ana Krulec | 7ab5603 | 2018-11-02 20:51:06 +0100 | [diff] [blame] | 32 | #include <utils/Trace.h> |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 33 | |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame^] | 34 | #include <FrameTimeline/FrameTimeline.h> |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 35 | #include <algorithm> |
| 36 | #include <cinttypes> |
| 37 | #include <cstdint> |
| 38 | #include <functional> |
| 39 | #include <memory> |
| 40 | #include <numeric> |
| 41 | |
| 42 | #include "../Layer.h" |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 43 | #include "DispSyncSource.h" |
| 44 | #include "EventThread.h" |
Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 45 | #include "InjectVSyncSource.h" |
Ana Krulec | f2c006d | 2019-06-21 15:37:07 -0700 | [diff] [blame] | 46 | #include "OneShotTimer.h" |
Ana Krulec | 434c22d | 2018-11-28 13:48:36 +0100 | [diff] [blame] | 47 | #include "SchedulerUtils.h" |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 48 | #include "SurfaceFlingerProperties.h" |
Kevin DuBois | 0028738 | 2019-11-19 15:11:55 -0800 | [diff] [blame] | 49 | #include "Timer.h" |
| 50 | #include "VSyncDispatchTimerQueue.h" |
| 51 | #include "VSyncPredictor.h" |
| 52 | #include "VSyncReactor.h" |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 53 | #include "VsyncController.h" |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 54 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 55 | #define RETURN_IF_INVALID_HANDLE(handle, ...) \ |
| 56 | do { \ |
| 57 | if (mConnections.count(handle) == 0) { \ |
| 58 | ALOGE("Invalid connection handle %" PRIuPTR, handle.id); \ |
| 59 | return __VA_ARGS__; \ |
| 60 | } \ |
| 61 | } while (false) |
| 62 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 63 | using namespace std::string_literals; |
| 64 | |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 65 | namespace android { |
Ady Abraham | 5a85855 | 2020-03-31 17:54:56 -0700 | [diff] [blame] | 66 | |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 67 | namespace { |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 68 | |
Ady Abraham | 5a85855 | 2020-03-31 17:54:56 -0700 | [diff] [blame] | 69 | std::unique_ptr<scheduler::VSyncTracker> createVSyncTracker() { |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 70 | // TODO(b/144707443): Tune constants. |
| 71 | constexpr int kDefaultRate = 60; |
| 72 | constexpr auto initialPeriod = std::chrono::duration<nsecs_t, std::ratio<1, kDefaultRate>>(1); |
| 73 | constexpr nsecs_t idealPeriod = |
| 74 | std::chrono::duration_cast<std::chrono::nanoseconds>(initialPeriod).count(); |
| 75 | constexpr size_t vsyncTimestampHistorySize = 20; |
| 76 | constexpr size_t minimumSamplesForPrediction = 6; |
| 77 | constexpr uint32_t discardOutlierPercent = 20; |
| 78 | return std::make_unique<scheduler::VSyncPredictor>(idealPeriod, vsyncTimestampHistorySize, |
| 79 | minimumSamplesForPrediction, |
| 80 | discardOutlierPercent); |
Ady Abraham | 5a85855 | 2020-03-31 17:54:56 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 83 | std::unique_ptr<scheduler::VSyncDispatch> createVSyncDispatch(scheduler::VSyncTracker& tracker) { |
| 84 | // TODO(b/144707443): Tune constants. |
| 85 | constexpr std::chrono::nanoseconds vsyncMoveThreshold = 3ms; |
| 86 | constexpr std::chrono::nanoseconds timerSlack = 500us; |
Ady Abraham | 5a85855 | 2020-03-31 17:54:56 -0700 | [diff] [blame] | 87 | return std::make_unique< |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 88 | scheduler::VSyncDispatchTimerQueue>(std::make_unique<scheduler::Timer>(), tracker, |
Ady Abraham | 5a85855 | 2020-03-31 17:54:56 -0700 | [diff] [blame] | 89 | timerSlack.count(), vsyncMoveThreshold.count()); |
| 90 | } |
| 91 | |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 92 | const char* toContentDetectionString(bool useContentDetection, bool useContentDetectionV2) { |
| 93 | if (!useContentDetection) return "off"; |
| 94 | return useContentDetectionV2 ? "V2" : "V1"; |
| 95 | } |
| 96 | |
| 97 | } // namespace |
| 98 | |
Ady Abraham | 8735eac | 2020-08-12 16:35:04 -0700 | [diff] [blame] | 99 | class PredictedVsyncTracer { |
| 100 | public: |
| 101 | PredictedVsyncTracer(scheduler::VSyncDispatch& dispatch) |
| 102 | : mRegistration(dispatch, std::bind(&PredictedVsyncTracer::callback, this), |
| 103 | "PredictedVsyncTracer") { |
| 104 | scheduleRegistration(); |
| 105 | } |
| 106 | |
| 107 | private: |
| 108 | TracedOrdinal<bool> mParity = {"VSYNC-predicted", 0}; |
| 109 | scheduler::VSyncCallbackRegistration mRegistration; |
| 110 | |
| 111 | void scheduleRegistration() { mRegistration.schedule({0, 0, 0}); } |
| 112 | |
| 113 | void callback() { |
| 114 | mParity = !mParity; |
| 115 | scheduleRegistration(); |
| 116 | } |
| 117 | }; |
| 118 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 119 | Scheduler::Scheduler(const scheduler::RefreshRateConfigs& configs, ISchedulerCallback& callback) |
| 120 | : Scheduler(configs, callback, |
| 121 | {.supportKernelTimer = sysprop::support_kernel_idle_timer(false), |
| 122 | .useContentDetection = sysprop::use_content_detection_for_refresh_rate(false), |
| 123 | .useContentDetectionV2 = |
Ady Abraham | 49cb7d5 | 2020-07-22 18:37:07 -0700 | [diff] [blame] | 124 | base::GetBoolProperty("debug.sf.use_content_detection_v2"s, true)}) {} |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 125 | |
| 126 | Scheduler::Scheduler(const scheduler::RefreshRateConfigs& configs, ISchedulerCallback& callback, |
| 127 | Options options) |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 128 | : Scheduler(createVsyncSchedule(options.supportKernelTimer), configs, callback, |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 129 | createLayerHistory(configs, options.useContentDetectionV2), options) { |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 130 | using namespace sysprop; |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 131 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 132 | const int setIdleTimerMs = base::GetIntProperty("debug.sf.set_idle_timer_ms"s, 0); |
Ana Krulec | fb77282 | 2018-11-30 10:44:07 +0100 | [diff] [blame] | 133 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 134 | if (const auto millis = setIdleTimerMs ? setIdleTimerMs : set_idle_timer_ms(0); millis > 0) { |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 135 | const auto callback = mOptions.supportKernelTimer ? &Scheduler::kernelIdleTimerCallback |
| 136 | : &Scheduler::idleTimerCallback; |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 137 | mIdleTimer.emplace( |
| 138 | std::chrono::milliseconds(millis), |
| 139 | [this, callback] { std::invoke(callback, this, TimerState::Reset); }, |
| 140 | [this, callback] { std::invoke(callback, this, TimerState::Expired); }); |
Ana Krulec | fb77282 | 2018-11-30 10:44:07 +0100 | [diff] [blame] | 141 | mIdleTimer->start(); |
| 142 | } |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 143 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 144 | if (const int64_t millis = set_touch_timer_ms(0); millis > 0) { |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 145 | // Touch events are coming to SF every 100ms, so the timer needs to be higher than that |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 146 | mTouchTimer.emplace( |
| 147 | std::chrono::milliseconds(millis), |
Dominik Laskowski | dd252cd | 2019-07-26 09:10:16 -0700 | [diff] [blame] | 148 | [this] { touchTimerCallback(TimerState::Reset); }, |
| 149 | [this] { touchTimerCallback(TimerState::Expired); }); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 150 | mTouchTimer->start(); |
| 151 | } |
Ady Abraham | 6fe2c17 | 2019-07-12 12:37:57 -0700 | [diff] [blame] | 152 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 153 | if (const int64_t millis = set_display_power_timer_ms(0); millis > 0) { |
| 154 | mDisplayPowerTimer.emplace( |
| 155 | std::chrono::milliseconds(millis), |
Dominik Laskowski | dd252cd | 2019-07-26 09:10:16 -0700 | [diff] [blame] | 156 | [this] { displayPowerTimerCallback(TimerState::Reset); }, |
| 157 | [this] { displayPowerTimerCallback(TimerState::Expired); }); |
Ady Abraham | 6fe2c17 | 2019-07-12 12:37:57 -0700 | [diff] [blame] | 158 | mDisplayPowerTimer->start(); |
| 159 | } |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 162 | Scheduler::Scheduler(VsyncSchedule schedule, const scheduler::RefreshRateConfigs& configs, |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 163 | ISchedulerCallback& schedulerCallback, |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 164 | std::unique_ptr<LayerHistory> layerHistory, Options options) |
| 165 | : mOptions(options), |
| 166 | mVsyncSchedule(std::move(schedule)), |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 167 | mLayerHistory(std::move(layerHistory)), |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 168 | mSchedulerCallback(schedulerCallback), |
Ady Abraham | 8735eac | 2020-08-12 16:35:04 -0700 | [diff] [blame] | 169 | mRefreshRateConfigs(configs), |
| 170 | mPredictedVsyncTracer( |
| 171 | base::GetBoolProperty("debug.sf.show_predicted_vsync", false) |
| 172 | ? std::make_unique<PredictedVsyncTracer>(*mVsyncSchedule.dispatch) |
| 173 | : nullptr) { |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 174 | mSchedulerCallback.setVsyncEnabled(false); |
| 175 | } |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 176 | |
Lloyd Pique | 1f9f1a4 | 2019-01-31 13:04:00 -0800 | [diff] [blame] | 177 | Scheduler::~Scheduler() { |
Ana Krulec | f2c006d | 2019-06-21 15:37:07 -0700 | [diff] [blame] | 178 | // Ensure the OneShotTimer threads are joined before we start destroying state. |
Ady Abraham | 6fe2c17 | 2019-07-12 12:37:57 -0700 | [diff] [blame] | 179 | mDisplayPowerTimer.reset(); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 180 | mTouchTimer.reset(); |
Lloyd Pique | 1f9f1a4 | 2019-01-31 13:04:00 -0800 | [diff] [blame] | 181 | mIdleTimer.reset(); |
| 182 | } |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 183 | |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 184 | Scheduler::VsyncSchedule Scheduler::createVsyncSchedule(bool supportKernelTimer) { |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 185 | auto clock = std::make_unique<scheduler::SystemClock>(); |
| 186 | auto tracker = createVSyncTracker(); |
| 187 | auto dispatch = createVSyncDispatch(*tracker); |
| 188 | |
| 189 | // TODO(b/144707443): Tune constants. |
| 190 | constexpr size_t pendingFenceLimit = 20; |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 191 | auto controller = |
Ady Abraham | 8735eac | 2020-08-12 16:35:04 -0700 | [diff] [blame] | 192 | std::make_unique<scheduler::VSyncReactor>(std::move(clock), *tracker, pendingFenceLimit, |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 193 | supportKernelTimer); |
| 194 | return {std::move(controller), std::move(tracker), std::move(dispatch)}; |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 197 | std::unique_ptr<LayerHistory> Scheduler::createLayerHistory( |
| 198 | const scheduler::RefreshRateConfigs& configs, bool useContentDetectionV2) { |
| 199 | if (!configs.canSwitch()) return nullptr; |
| 200 | |
| 201 | if (useContentDetectionV2) { |
| 202 | return std::make_unique<scheduler::impl::LayerHistoryV2>(configs); |
| 203 | } |
| 204 | |
| 205 | return std::make_unique<scheduler::impl::LayerHistory>(); |
| 206 | } |
| 207 | |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 208 | std::unique_ptr<VSyncSource> Scheduler::makePrimaryDispSyncSource( |
| 209 | const char* name, std::chrono::nanoseconds workDuration, |
| 210 | std::chrono::nanoseconds readyDuration, bool traceVsync) { |
| 211 | return std::make_unique<scheduler::DispSyncSource>(*mVsyncSchedule.dispatch, workDuration, |
| 212 | readyDuration, traceVsync, name); |
Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 215 | Scheduler::ConnectionHandle Scheduler::createConnection( |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame^] | 216 | const char* connectionName, frametimeline::TokenManager* tokenManager, |
| 217 | std::chrono::nanoseconds workDuration, std::chrono::nanoseconds readyDuration, |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 218 | impl::EventThread::InterceptVSyncsCallback interceptCallback) { |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 219 | auto vsyncSource = makePrimaryDispSyncSource(connectionName, workDuration, readyDuration); |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame^] | 220 | auto eventThread = std::make_unique<impl::EventThread>(std::move(vsyncSource), tokenManager, |
Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 221 | std::move(interceptCallback)); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 222 | return createConnection(std::move(eventThread)); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 223 | } |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 224 | |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 225 | Scheduler::ConnectionHandle Scheduler::createConnection(std::unique_ptr<EventThread> eventThread) { |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 226 | const ConnectionHandle handle = ConnectionHandle{mNextConnectionHandleId++}; |
| 227 | ALOGV("Creating a connection handle with ID %" PRIuPTR, handle.id); |
Dominik Laskowski | f654d57 | 2018-12-20 11:03:06 -0800 | [diff] [blame] | 228 | |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 229 | auto connection = |
| 230 | createConnectionInternal(eventThread.get(), ISurfaceComposer::eConfigChangedSuppress); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 231 | |
| 232 | mConnections.emplace(handle, Connection{connection, std::move(eventThread)}); |
| 233 | return handle; |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 236 | sp<EventThreadConnection> Scheduler::createConnectionInternal( |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 237 | EventThread* eventThread, ISurfaceComposer::ConfigChanged configChanged) { |
| 238 | return eventThread->createEventConnection([&] { resync(); }, configChanged); |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 241 | sp<IDisplayEventConnection> Scheduler::createDisplayEventConnection( |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 242 | ConnectionHandle handle, ISurfaceComposer::ConfigChanged configChanged) { |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 243 | RETURN_IF_INVALID_HANDLE(handle, nullptr); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 244 | return createConnectionInternal(mConnections[handle].thread.get(), configChanged); |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 247 | sp<EventThreadConnection> Scheduler::getEventConnection(ConnectionHandle handle) { |
| 248 | RETURN_IF_INVALID_HANDLE(handle, nullptr); |
| 249 | return mConnections[handle].connection; |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 252 | void Scheduler::onHotplugReceived(ConnectionHandle handle, PhysicalDisplayId displayId, |
| 253 | bool connected) { |
| 254 | RETURN_IF_INVALID_HANDLE(handle); |
| 255 | mConnections[handle].thread->onHotplugReceived(displayId, connected); |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 258 | void Scheduler::onScreenAcquired(ConnectionHandle handle) { |
| 259 | RETURN_IF_INVALID_HANDLE(handle); |
| 260 | mConnections[handle].thread->onScreenAcquired(); |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 263 | void Scheduler::onScreenReleased(ConnectionHandle handle) { |
| 264 | RETURN_IF_INVALID_HANDLE(handle); |
| 265 | mConnections[handle].thread->onScreenReleased(); |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame] | 268 | void Scheduler::onPrimaryDisplayConfigChanged(ConnectionHandle handle, PhysicalDisplayId displayId, |
| 269 | HwcConfigIndexType configId, nsecs_t vsyncPeriod) { |
| 270 | std::lock_guard<std::mutex> lock(mFeatureStateLock); |
| 271 | // Cache the last reported config for primary display. |
| 272 | mFeatures.cachedConfigChangedParams = {handle, displayId, configId, vsyncPeriod}; |
| 273 | onNonPrimaryDisplayConfigChanged(handle, displayId, configId, vsyncPeriod); |
| 274 | } |
| 275 | |
| 276 | void Scheduler::dispatchCachedReportedConfig() { |
| 277 | const auto configId = *mFeatures.configId; |
| 278 | const auto vsyncPeriod = |
| 279 | mRefreshRateConfigs.getRefreshRateFromConfigId(configId).getVsyncPeriod(); |
| 280 | |
| 281 | // If there is no change from cached config, there is no need to dispatch an event |
| 282 | if (configId == mFeatures.cachedConfigChangedParams->configId && |
| 283 | vsyncPeriod == mFeatures.cachedConfigChangedParams->vsyncPeriod) { |
| 284 | return; |
| 285 | } |
| 286 | |
| 287 | mFeatures.cachedConfigChangedParams->configId = configId; |
| 288 | mFeatures.cachedConfigChangedParams->vsyncPeriod = vsyncPeriod; |
| 289 | onNonPrimaryDisplayConfigChanged(mFeatures.cachedConfigChangedParams->handle, |
| 290 | mFeatures.cachedConfigChangedParams->displayId, |
| 291 | mFeatures.cachedConfigChangedParams->configId, |
| 292 | mFeatures.cachedConfigChangedParams->vsyncPeriod); |
| 293 | } |
| 294 | |
| 295 | void Scheduler::onNonPrimaryDisplayConfigChanged(ConnectionHandle handle, |
| 296 | PhysicalDisplayId displayId, |
| 297 | HwcConfigIndexType configId, nsecs_t vsyncPeriod) { |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 298 | RETURN_IF_INVALID_HANDLE(handle); |
Alec Mouri | 60aee1c | 2019-10-28 16:18:59 -0700 | [diff] [blame] | 299 | mConnections[handle].thread->onConfigChanged(displayId, configId, vsyncPeriod); |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 300 | } |
| 301 | |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 302 | size_t Scheduler::getEventThreadConnectionCount(ConnectionHandle handle) { |
| 303 | RETURN_IF_INVALID_HANDLE(handle, 0); |
| 304 | return mConnections[handle].thread->getEventThreadConnectionCount(); |
| 305 | } |
| 306 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 307 | void Scheduler::dump(ConnectionHandle handle, std::string& result) const { |
| 308 | RETURN_IF_INVALID_HANDLE(handle); |
| 309 | mConnections.at(handle).thread->dump(result); |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 312 | void Scheduler::setDuration(ConnectionHandle handle, std::chrono::nanoseconds workDuration, |
| 313 | std::chrono::nanoseconds readyDuration) { |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 314 | RETURN_IF_INVALID_HANDLE(handle); |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 315 | mConnections[handle].thread->setDuration(workDuration, readyDuration); |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 316 | } |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 317 | |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 318 | void Scheduler::getDisplayStatInfo(DisplayStatInfo* stats, nsecs_t now) { |
| 319 | stats->vsyncTime = mVsyncSchedule.tracker->nextAnticipatedVSyncTimeFrom(now); |
| 320 | stats->vsyncPeriod = mVsyncSchedule.tracker->currentPeriod(); |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 323 | Scheduler::ConnectionHandle Scheduler::enableVSyncInjection(bool enable) { |
| 324 | if (mInjectVSyncs == enable) { |
| 325 | return {}; |
| 326 | } |
| 327 | |
| 328 | ALOGV("%s VSYNC injection", enable ? "Enabling" : "Disabling"); |
| 329 | |
| 330 | if (!mInjectorConnectionHandle) { |
| 331 | auto vsyncSource = std::make_unique<InjectVSyncSource>(); |
| 332 | mVSyncInjector = vsyncSource.get(); |
| 333 | |
| 334 | auto eventThread = |
| 335 | std::make_unique<impl::EventThread>(std::move(vsyncSource), |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame^] | 336 | /*tokenManager=*/nullptr, |
Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 337 | impl::EventThread::InterceptVSyncsCallback()); |
| 338 | |
| 339 | mInjectorConnectionHandle = createConnection(std::move(eventThread)); |
| 340 | } |
| 341 | |
| 342 | mInjectVSyncs = enable; |
| 343 | return mInjectorConnectionHandle; |
| 344 | } |
| 345 | |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 346 | bool Scheduler::injectVSync(nsecs_t when, nsecs_t expectedVSyncTime, nsecs_t deadlineTimestamp) { |
Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 347 | if (!mInjectVSyncs || !mVSyncInjector) { |
| 348 | return false; |
| 349 | } |
| 350 | |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 351 | mVSyncInjector->onInjectSyncEvent(when, expectedVSyncTime, deadlineTimestamp); |
Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 352 | return true; |
| 353 | } |
| 354 | |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 355 | void Scheduler::enableHardwareVsync() { |
| 356 | std::lock_guard<std::mutex> lock(mHWVsyncLock); |
| 357 | if (!mPrimaryHWVsyncEnabled && mHWVsyncAvailable) { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 358 | mVsyncSchedule.tracker->resetModel(); |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 359 | mSchedulerCallback.setVsyncEnabled(true); |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 360 | mPrimaryHWVsyncEnabled = true; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | void Scheduler::disableHardwareVsync(bool makeUnavailable) { |
| 365 | std::lock_guard<std::mutex> lock(mHWVsyncLock); |
| 366 | if (mPrimaryHWVsyncEnabled) { |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 367 | mSchedulerCallback.setVsyncEnabled(false); |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 368 | mPrimaryHWVsyncEnabled = false; |
| 369 | } |
| 370 | if (makeUnavailable) { |
| 371 | mHWVsyncAvailable = false; |
| 372 | } |
| 373 | } |
| 374 | |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 375 | void Scheduler::resyncToHardwareVsync(bool makeAvailable, nsecs_t period) { |
| 376 | { |
| 377 | std::lock_guard<std::mutex> lock(mHWVsyncLock); |
| 378 | if (makeAvailable) { |
| 379 | mHWVsyncAvailable = makeAvailable; |
| 380 | } else if (!mHWVsyncAvailable) { |
| 381 | // Hardware vsync is not currently available, so abort the resync |
| 382 | // attempt for now |
| 383 | return; |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | if (period <= 0) { |
| 388 | return; |
| 389 | } |
| 390 | |
| 391 | setVsyncPeriod(period); |
| 392 | } |
| 393 | |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 394 | void Scheduler::resync() { |
Long Ling | 457bef9 | 2019-09-11 14:43:11 -0700 | [diff] [blame] | 395 | static constexpr nsecs_t kIgnoreDelay = ms2ns(750); |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 396 | |
| 397 | const nsecs_t now = systemTime(); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 398 | const nsecs_t last = mLastResyncTime.exchange(now); |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 399 | |
| 400 | if (now - last > kIgnoreDelay) { |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 401 | resyncToHardwareVsync(false, mRefreshRateConfigs.getCurrentRefreshRate().getVsyncPeriod()); |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 405 | void Scheduler::setVsyncPeriod(nsecs_t period) { |
Ady Abraham | 3aff917 | 2019-02-07 19:10:26 -0800 | [diff] [blame] | 406 | std::lock_guard<std::mutex> lock(mHWVsyncLock); |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 407 | mVsyncSchedule.controller->startPeriodTransition(period); |
Ady Abraham | 3aff917 | 2019-02-07 19:10:26 -0800 | [diff] [blame] | 408 | |
| 409 | if (!mPrimaryHWVsyncEnabled) { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 410 | mVsyncSchedule.tracker->resetModel(); |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 411 | mSchedulerCallback.setVsyncEnabled(true); |
Ady Abraham | 3aff917 | 2019-02-07 19:10:26 -0800 | [diff] [blame] | 412 | mPrimaryHWVsyncEnabled = true; |
| 413 | } |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Ady Abraham | 5dee2f1 | 2020-02-05 17:49:47 -0800 | [diff] [blame] | 416 | void Scheduler::addResyncSample(nsecs_t timestamp, std::optional<nsecs_t> hwcVsyncPeriod, |
| 417 | bool* periodFlushed) { |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 418 | bool needsHwVsync = false; |
Alec Mouri | f8e689c | 2019-05-20 18:32:22 -0700 | [diff] [blame] | 419 | *periodFlushed = false; |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 420 | { // Scope for the lock |
| 421 | std::lock_guard<std::mutex> lock(mHWVsyncLock); |
| 422 | if (mPrimaryHWVsyncEnabled) { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 423 | needsHwVsync = mVsyncSchedule.controller->addHwVsyncTimestamp(timestamp, hwcVsyncPeriod, |
| 424 | periodFlushed); |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | |
| 428 | if (needsHwVsync) { |
| 429 | enableHardwareVsync(); |
| 430 | } else { |
| 431 | disableHardwareVsync(false); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | void Scheduler::addPresentFence(const std::shared_ptr<FenceTime>& fenceTime) { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 436 | if (mVsyncSchedule.controller->addPresentFence(fenceTime)) { |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 437 | enableHardwareVsync(); |
| 438 | } else { |
| 439 | disableHardwareVsync(false); |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | void Scheduler::setIgnorePresentFences(bool ignore) { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 444 | mVsyncSchedule.controller->setIgnorePresentFences(ignore); |
Ady Abraham | c3e2131 | 2019-02-07 14:30:23 -0800 | [diff] [blame] | 445 | } |
| 446 | |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 447 | void Scheduler::registerLayer(Layer* layer) { |
Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame] | 448 | if (!mLayerHistory) return; |
| 449 | |
Steven Thomas | debafed | 2020-05-18 17:30:35 -0700 | [diff] [blame] | 450 | const auto minFps = mRefreshRateConfigs.getMinRefreshRate().getFps(); |
| 451 | const auto maxFps = mRefreshRateConfigs.getMaxRefreshRate().getFps(); |
| 452 | |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 453 | if (layer->getWindowType() == InputWindowInfo::Type::STATUS_BAR) { |
Steven Thomas | debafed | 2020-05-18 17:30:35 -0700 | [diff] [blame] | 454 | mLayerHistory->registerLayer(layer, minFps, maxFps, |
Ana Krulec | 3d367c8 | 2020-02-25 15:02:01 -0800 | [diff] [blame] | 455 | scheduler::LayerHistory::LayerVoteType::NoVote); |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 456 | } else if (!mOptions.useContentDetection) { |
Steven Thomas | debafed | 2020-05-18 17:30:35 -0700 | [diff] [blame] | 457 | // If the content detection feature is off, all layers are registered at Max. We still keep |
| 458 | // the layer history, since we use it for other features (like Frame Rate API), so layers |
| 459 | // still need to be registered. |
| 460 | mLayerHistory->registerLayer(layer, minFps, maxFps, |
| 461 | scheduler::LayerHistory::LayerVoteType::Max); |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 462 | } else if (!mOptions.useContentDetectionV2) { |
Steven Thomas | debafed | 2020-05-18 17:30:35 -0700 | [diff] [blame] | 463 | // In V1 of content detection, all layers are registered as Heuristic (unless it's |
| 464 | // wallpaper). |
| 465 | const auto highFps = |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 466 | layer->getWindowType() == InputWindowInfo::Type::WALLPAPER ? minFps : maxFps; |
Ana Krulec | 3d367c8 | 2020-02-25 15:02:01 -0800 | [diff] [blame] | 467 | |
Steven Thomas | debafed | 2020-05-18 17:30:35 -0700 | [diff] [blame] | 468 | mLayerHistory->registerLayer(layer, minFps, highFps, |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 469 | scheduler::LayerHistory::LayerVoteType::Heuristic); |
| 470 | } else { |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 471 | if (layer->getWindowType() == InputWindowInfo::Type::WALLPAPER) { |
Ana Krulec | 3d367c8 | 2020-02-25 15:02:01 -0800 | [diff] [blame] | 472 | // Running Wallpaper at Min is considered as part of content detection. |
Steven Thomas | debafed | 2020-05-18 17:30:35 -0700 | [diff] [blame] | 473 | mLayerHistory->registerLayer(layer, minFps, maxFps, |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 474 | scheduler::LayerHistory::LayerVoteType::Min); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 475 | } else { |
Steven Thomas | debafed | 2020-05-18 17:30:35 -0700 | [diff] [blame] | 476 | mLayerHistory->registerLayer(layer, minFps, maxFps, |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 477 | scheduler::LayerHistory::LayerVoteType::Heuristic); |
| 478 | } |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 479 | } |
Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 482 | void Scheduler::recordLayerHistory(Layer* layer, nsecs_t presentTime, |
| 483 | LayerHistory::LayerUpdateType updateType) { |
Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame] | 484 | if (mLayerHistory) { |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 485 | mLayerHistory->record(layer, presentTime, systemTime(), updateType); |
Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame] | 486 | } |
Ana Krulec | 3084c05 | 2018-11-21 20:27:17 +0100 | [diff] [blame] | 487 | } |
| 488 | |
Ady Abraham | 32efd54 | 2020-05-19 17:49:26 -0700 | [diff] [blame] | 489 | void Scheduler::setConfigChangePending(bool pending) { |
| 490 | if (mLayerHistory) { |
| 491 | mLayerHistory->setConfigChangePending(pending); |
| 492 | } |
| 493 | } |
| 494 | |
Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame] | 495 | void Scheduler::chooseRefreshRateForContent() { |
| 496 | if (!mLayerHistory) return; |
| 497 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 498 | ATRACE_CALL(); |
| 499 | |
| 500 | scheduler::LayerHistory::Summary summary = mLayerHistory->summarize(systemTime()); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 501 | HwcConfigIndexType newConfigId; |
Ady Abraham | 6398a0a | 2019-04-18 19:30:44 -0700 | [diff] [blame] | 502 | { |
| 503 | std::lock_guard<std::mutex> lock(mFeatureStateLock); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 504 | if (mFeatures.contentRequirements == summary) { |
Ady Abraham | 6398a0a | 2019-04-18 19:30:44 -0700 | [diff] [blame] | 505 | return; |
| 506 | } |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 507 | mFeatures.contentRequirements = summary; |
Ady Abraham | 4ccdcb4 | 2020-02-11 17:34:34 -0800 | [diff] [blame] | 508 | mFeatures.contentDetectionV1 = |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 509 | !summary.empty() ? ContentDetectionState::On : ContentDetectionState::Off; |
| 510 | |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame] | 511 | scheduler::RefreshRateConfigs::GlobalSignals consideredSignals; |
| 512 | newConfigId = calculateRefreshRateConfigIndexType(&consideredSignals); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 513 | if (mFeatures.configId == newConfigId) { |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame] | 514 | // We don't need to change the config, but we might need to send an event |
| 515 | // about a config change, since it was suppressed due to a previous idleConsidered |
| 516 | if (!consideredSignals.idle) { |
| 517 | dispatchCachedReportedConfig(); |
| 518 | } |
Ady Abraham | 6398a0a | 2019-04-18 19:30:44 -0700 | [diff] [blame] | 519 | return; |
| 520 | } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 521 | mFeatures.configId = newConfigId; |
Ady Abraham | 2e1dd89 | 2020-03-05 13:48:36 -0800 | [diff] [blame] | 522 | auto& newRefreshRate = mRefreshRateConfigs.getRefreshRateFromConfigId(newConfigId); |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame] | 523 | mSchedulerCallback.changeRefreshRate(newRefreshRate, |
| 524 | consideredSignals.idle ? ConfigEvent::None |
| 525 | : ConfigEvent::Changed); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 526 | } |
Ady Abraham | a1a49af | 2019-02-07 14:36:55 -0800 | [diff] [blame] | 527 | } |
| 528 | |
Ana Krulec | fb77282 | 2018-11-30 10:44:07 +0100 | [diff] [blame] | 529 | void Scheduler::resetIdleTimer() { |
| 530 | if (mIdleTimer) { |
| 531 | mIdleTimer->reset(); |
Ady Abraham | a1a49af | 2019-02-07 14:36:55 -0800 | [diff] [blame] | 532 | } |
| 533 | } |
| 534 | |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 535 | void Scheduler::notifyTouchEvent() { |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 536 | if (mTouchTimer) { |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 537 | mTouchTimer->reset(); |
Steven Thomas | 540730a | 2020-01-08 20:12:42 -0800 | [diff] [blame] | 538 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 539 | if (mOptions.supportKernelTimer && mIdleTimer) { |
Steven Thomas | 540730a | 2020-01-08 20:12:42 -0800 | [diff] [blame] | 540 | mIdleTimer->reset(); |
| 541 | } |
Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame] | 542 | } |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Ady Abraham | 6fe2c17 | 2019-07-12 12:37:57 -0700 | [diff] [blame] | 545 | void Scheduler::setDisplayPowerState(bool normal) { |
| 546 | { |
| 547 | std::lock_guard<std::mutex> lock(mFeatureStateLock); |
Dominik Laskowski | dd252cd | 2019-07-26 09:10:16 -0700 | [diff] [blame] | 548 | mFeatures.isDisplayPowerStateNormal = normal; |
Ady Abraham | 6fe2c17 | 2019-07-12 12:37:57 -0700 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | if (mDisplayPowerTimer) { |
| 552 | mDisplayPowerTimer->reset(); |
| 553 | } |
| 554 | |
| 555 | // Display Power event will boost the refresh rate to performance. |
| 556 | // Clear Layer History to get fresh FPS detection |
Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame] | 557 | if (mLayerHistory) { |
| 558 | mLayerHistory->clear(); |
| 559 | } |
Ady Abraham | 6fe2c17 | 2019-07-12 12:37:57 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Dominik Laskowski | 3a80a38 | 2019-07-25 11:16:07 -0700 | [diff] [blame] | 562 | void Scheduler::kernelIdleTimerCallback(TimerState state) { |
| 563 | ATRACE_INT("ExpiredKernelIdleTimer", static_cast<int>(state)); |
Ana Krulec | fb77282 | 2018-11-30 10:44:07 +0100 | [diff] [blame] | 564 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 565 | // TODO(145561154): cleanup the kernel idle timer implementation and the refresh rate |
| 566 | // magic number |
Ady Abraham | 2e1dd89 | 2020-03-05 13:48:36 -0800 | [diff] [blame] | 567 | const auto& refreshRate = mRefreshRateConfigs.getCurrentRefreshRate(); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 568 | constexpr float FPS_THRESHOLD_FOR_KERNEL_TIMER = 65.0f; |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 569 | if (state == TimerState::Reset && refreshRate.getFps() > FPS_THRESHOLD_FOR_KERNEL_TIMER) { |
Alec Mouri | 7f01518 | 2019-07-11 13:56:22 -0700 | [diff] [blame] | 570 | // If we're not in performance mode then the kernel timer shouldn't do |
| 571 | // anything, as the refresh rate during DPU power collapse will be the |
| 572 | // same. |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 573 | resyncToHardwareVsync(true /* makeAvailable */, refreshRate.getVsyncPeriod()); |
| 574 | } else if (state == TimerState::Expired && |
| 575 | refreshRate.getFps() <= FPS_THRESHOLD_FOR_KERNEL_TIMER) { |
Dominik Laskowski | 3a80a38 | 2019-07-25 11:16:07 -0700 | [diff] [blame] | 576 | // Disable HW VSYNC if the timer expired, as we don't need it enabled if |
| 577 | // we're not pushing frames, and if we're in PERFORMANCE mode then we'll |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 578 | // need to update the VsyncController model anyway. |
Dominik Laskowski | 3a80a38 | 2019-07-25 11:16:07 -0700 | [diff] [blame] | 579 | disableHardwareVsync(false /* makeUnavailable */); |
Alec Mouri | dc28b37 | 2019-04-18 21:17:13 -0700 | [diff] [blame] | 580 | } |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 581 | |
| 582 | mSchedulerCallback.kernelTimerChanged(state == TimerState::Expired); |
Alec Mouri | dc28b37 | 2019-04-18 21:17:13 -0700 | [diff] [blame] | 583 | } |
| 584 | |
Dominik Laskowski | 3a80a38 | 2019-07-25 11:16:07 -0700 | [diff] [blame] | 585 | void Scheduler::idleTimerCallback(TimerState state) { |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame] | 586 | handleTimerStateChanged(&mFeatures.idleTimer, state); |
Dominik Laskowski | 3a80a38 | 2019-07-25 11:16:07 -0700 | [diff] [blame] | 587 | ATRACE_INT("ExpiredIdleTimer", static_cast<int>(state)); |
Ana Krulec | fb77282 | 2018-11-30 10:44:07 +0100 | [diff] [blame] | 588 | } |
| 589 | |
Dominik Laskowski | 3a80a38 | 2019-07-25 11:16:07 -0700 | [diff] [blame] | 590 | void Scheduler::touchTimerCallback(TimerState state) { |
Dominik Laskowski | dd252cd | 2019-07-26 09:10:16 -0700 | [diff] [blame] | 591 | const TouchState touch = state == TimerState::Reset ? TouchState::Active : TouchState::Inactive; |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 592 | // Touch event will boost the refresh rate to performance. |
| 593 | // Clear layer history to get fresh FPS detection. |
| 594 | // NOTE: Instead of checking all the layers, we should be checking the layer |
| 595 | // that is currently on top. b/142507166 will give us this capability. |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame] | 596 | if (handleTimerStateChanged(&mFeatures.touch, touch)) { |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 597 | if (mLayerHistory) { |
| 598 | mLayerHistory->clear(); |
| 599 | } |
Ady Abraham | 1adbb72 | 2020-05-15 11:51:48 -0700 | [diff] [blame] | 600 | } |
Dominik Laskowski | 3a80a38 | 2019-07-25 11:16:07 -0700 | [diff] [blame] | 601 | ATRACE_INT("TouchState", static_cast<int>(touch)); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Dominik Laskowski | 3a80a38 | 2019-07-25 11:16:07 -0700 | [diff] [blame] | 604 | void Scheduler::displayPowerTimerCallback(TimerState state) { |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame] | 605 | handleTimerStateChanged(&mFeatures.displayPowerTimer, state); |
Dominik Laskowski | 3a80a38 | 2019-07-25 11:16:07 -0700 | [diff] [blame] | 606 | ATRACE_INT("ExpiredDisplayPowerTimer", static_cast<int>(state)); |
Alec Mouri | dc28b37 | 2019-04-18 21:17:13 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 609 | void Scheduler::dump(std::string& result) const { |
Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame] | 610 | using base::StringAppendF; |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 611 | |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 612 | StringAppendF(&result, "+ Idle timer: %s\n", mIdleTimer ? mIdleTimer->dump().c_str() : "off"); |
Ana Krulec | 3d367c8 | 2020-02-25 15:02:01 -0800 | [diff] [blame] | 613 | StringAppendF(&result, "+ Touch timer: %s\n", |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 614 | mTouchTimer ? mTouchTimer->dump().c_str() : "off"); |
| 615 | StringAppendF(&result, "+ Content detection: %s %s\n\n", |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 616 | toContentDetectionString(mOptions.useContentDetection, |
| 617 | mOptions.useContentDetectionV2), |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 618 | mLayerHistory ? mLayerHistory->dump().c_str() : "(no layer history)"); |
Ana Krulec | b43429d | 2019-01-09 14:28:51 -0800 | [diff] [blame] | 619 | } |
| 620 | |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 621 | void Scheduler::dumpVsync(std::string& s) const { |
Ady Abraham | 8735eac | 2020-08-12 16:35:04 -0700 | [diff] [blame] | 622 | using base::StringAppendF; |
| 623 | |
| 624 | StringAppendF(&s, "VSyncReactor:\n"); |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 625 | mVsyncSchedule.controller->dump(s); |
Ady Abraham | 8735eac | 2020-08-12 16:35:04 -0700 | [diff] [blame] | 626 | StringAppendF(&s, "VSyncDispatch:\n"); |
| 627 | mVsyncSchedule.dispatch->dump(s); |
| 628 | } |
| 629 | |
Ady Abraham | 6fe2c17 | 2019-07-12 12:37:57 -0700 | [diff] [blame] | 630 | template <class T> |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame] | 631 | bool Scheduler::handleTimerStateChanged(T* currentState, T newState) { |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 632 | HwcConfigIndexType newConfigId; |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame] | 633 | scheduler::RefreshRateConfigs::GlobalSignals consideredSignals; |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 634 | { |
| 635 | std::lock_guard<std::mutex> lock(mFeatureStateLock); |
Ady Abraham | 6fe2c17 | 2019-07-12 12:37:57 -0700 | [diff] [blame] | 636 | if (*currentState == newState) { |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame] | 637 | return false; |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 638 | } |
Ady Abraham | 6fe2c17 | 2019-07-12 12:37:57 -0700 | [diff] [blame] | 639 | *currentState = newState; |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame] | 640 | newConfigId = calculateRefreshRateConfigIndexType(&consideredSignals); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 641 | if (mFeatures.configId == newConfigId) { |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame] | 642 | // We don't need to change the config, but we might need to send an event |
| 643 | // about a config change, since it was suppressed due to a previous idleConsidered |
| 644 | if (!consideredSignals.idle) { |
| 645 | dispatchCachedReportedConfig(); |
| 646 | } |
| 647 | return consideredSignals.touch; |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 648 | } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 649 | mFeatures.configId = newConfigId; |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 650 | } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 651 | const RefreshRate& newRefreshRate = mRefreshRateConfigs.getRefreshRateFromConfigId(newConfigId); |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame] | 652 | mSchedulerCallback.changeRefreshRate(newRefreshRate, |
| 653 | consideredSignals.idle ? ConfigEvent::None |
| 654 | : ConfigEvent::Changed); |
| 655 | return consideredSignals.touch; |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 656 | } |
| 657 | |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame] | 658 | HwcConfigIndexType Scheduler::calculateRefreshRateConfigIndexType( |
| 659 | scheduler::RefreshRateConfigs::GlobalSignals* consideredSignals) { |
Ady Abraham | 4ccdcb4 | 2020-02-11 17:34:34 -0800 | [diff] [blame] | 660 | ATRACE_CALL(); |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame] | 661 | if (consideredSignals) *consideredSignals = {}; |
Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 662 | |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 663 | // If Display Power is not in normal operation we want to be in performance mode. When coming |
| 664 | // back to normal mode, a grace period is given with DisplayPowerTimer. |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 665 | if (mDisplayPowerTimer && |
| 666 | (!mFeatures.isDisplayPowerStateNormal || |
| 667 | mFeatures.displayPowerTimer == TimerState::Reset)) { |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 668 | return mRefreshRateConfigs.getMaxRefreshRateByPolicy().getConfigId(); |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 669 | } |
Ady Abraham | 6fe2c17 | 2019-07-12 12:37:57 -0700 | [diff] [blame] | 670 | |
Steven Thomas | bb37432 | 2020-04-28 22:47:16 -0700 | [diff] [blame] | 671 | const bool touchActive = mTouchTimer && mFeatures.touch == TouchState::Active; |
| 672 | const bool idle = mIdleTimer && mFeatures.idleTimer == TimerState::Expired; |
| 673 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 674 | if (!mOptions.useContentDetectionV2) { |
Ady Abraham | 4ccdcb4 | 2020-02-11 17:34:34 -0800 | [diff] [blame] | 675 | // As long as touch is active we want to be in performance mode. |
Steven Thomas | bb37432 | 2020-04-28 22:47:16 -0700 | [diff] [blame] | 676 | if (touchActive) { |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 677 | return mRefreshRateConfigs.getMaxRefreshRateByPolicy().getConfigId(); |
Ady Abraham | 4ccdcb4 | 2020-02-11 17:34:34 -0800 | [diff] [blame] | 678 | } |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 679 | |
Steven Thomas | bb37432 | 2020-04-28 22:47:16 -0700 | [diff] [blame] | 680 | // If timer has expired as it means there is no new content on the screen. |
| 681 | if (idle) { |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame] | 682 | if (consideredSignals) consideredSignals->idle = true; |
Steven Thomas | bb37432 | 2020-04-28 22:47:16 -0700 | [diff] [blame] | 683 | return mRefreshRateConfigs.getMinRefreshRateByPolicy().getConfigId(); |
| 684 | } |
Ady Abraham | a315ce7 | 2019-04-24 14:35:20 -0700 | [diff] [blame] | 685 | |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 686 | // If content detection is off we choose performance as we don't know the content fps. |
Ady Abraham | 4ccdcb4 | 2020-02-11 17:34:34 -0800 | [diff] [blame] | 687 | if (mFeatures.contentDetectionV1 == ContentDetectionState::Off) { |
Ana Krulec | 3803b8d | 2020-02-03 16:35:46 -0800 | [diff] [blame] | 688 | // NOTE: V1 always calls this, but this is not a default behavior for V2. |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 689 | return mRefreshRateConfigs.getMaxRefreshRateByPolicy().getConfigId(); |
Steven Thomas | 540730a | 2020-01-08 20:12:42 -0800 | [diff] [blame] | 690 | } |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 691 | |
| 692 | // Content detection is on, find the appropriate refresh rate with minimal error |
Ady Abraham | abc2760 | 2020-04-08 17:20:29 -0700 | [diff] [blame] | 693 | return mRefreshRateConfigs.getRefreshRateForContent(mFeatures.contentRequirements) |
| 694 | .getConfigId(); |
Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 695 | } |
| 696 | |
Ady Abraham | 1adbb72 | 2020-05-15 11:51:48 -0700 | [diff] [blame] | 697 | return mRefreshRateConfigs |
Ady Abraham | dfd6216 | 2020-06-10 16:11:56 -0700 | [diff] [blame] | 698 | .getBestRefreshRate(mFeatures.contentRequirements, {.touch = touchActive, .idle = idle}, |
| 699 | consideredSignals) |
Ady Abraham | 1adbb72 | 2020-05-15 11:51:48 -0700 | [diff] [blame] | 700 | .getConfigId(); |
Ana Krulec | fefd6ae | 2019-02-13 17:53:08 -0800 | [diff] [blame] | 701 | } |
| 702 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 703 | std::optional<HwcConfigIndexType> Scheduler::getPreferredConfigId() { |
Daniel Solomon | 0f0ddc1 | 2019-08-19 19:31:09 -0700 | [diff] [blame] | 704 | std::lock_guard<std::mutex> lock(mFeatureStateLock); |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 705 | // Make sure that the default config ID is first updated, before returned. |
| 706 | if (mFeatures.configId.has_value()) { |
Ana Krulec | 3803b8d | 2020-02-03 16:35:46 -0800 | [diff] [blame] | 707 | mFeatures.configId = calculateRefreshRateConfigIndexType(); |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 708 | } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 709 | return mFeatures.configId; |
Daniel Solomon | 0f0ddc1 | 2019-08-19 19:31:09 -0700 | [diff] [blame] | 710 | } |
| 711 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 712 | void Scheduler::onNewVsyncPeriodChangeTimeline(const hal::VsyncPeriodChangeTimeline& timeline) { |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 713 | if (timeline.refreshRequired) { |
| 714 | mSchedulerCallback.repaintEverythingForHWC(); |
| 715 | } |
| 716 | |
| 717 | std::lock_guard<std::mutex> lock(mVsyncTimelineLock); |
| 718 | mLastVsyncPeriodChangeTimeline = std::make_optional(timeline); |
| 719 | |
| 720 | const auto maxAppliedTime = systemTime() + MAX_VSYNC_APPLIED_TIME.count(); |
| 721 | if (timeline.newVsyncAppliedTimeNanos > maxAppliedTime) { |
| 722 | mLastVsyncPeriodChangeTimeline->newVsyncAppliedTimeNanos = maxAppliedTime; |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | void Scheduler::onDisplayRefreshed(nsecs_t timestamp) { |
| 727 | bool callRepaint = false; |
| 728 | { |
| 729 | std::lock_guard<std::mutex> lock(mVsyncTimelineLock); |
| 730 | if (mLastVsyncPeriodChangeTimeline && mLastVsyncPeriodChangeTimeline->refreshRequired) { |
| 731 | if (mLastVsyncPeriodChangeTimeline->refreshTimeNanos < timestamp) { |
| 732 | mLastVsyncPeriodChangeTimeline->refreshRequired = false; |
| 733 | } else { |
| 734 | // We need to send another refresh as refreshTimeNanos is still in the future |
| 735 | callRepaint = true; |
| 736 | } |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | if (callRepaint) { |
| 741 | mSchedulerCallback.repaintEverythingForHWC(); |
Ana Krulec | fefd6ae | 2019-02-13 17:53:08 -0800 | [diff] [blame] | 742 | } |
| 743 | } |
| 744 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 745 | void Scheduler::onPrimaryDisplayAreaChanged(uint32_t displayArea) { |
| 746 | if (mLayerHistory) { |
| 747 | mLayerHistory->setDisplayArea(displayArea); |
| 748 | } |
| 749 | } |
| 750 | |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 751 | } // namespace android |