blob: e05c985e47f345106f1fc4661c5287c97cf4355a [file] [log] [blame]
Ana Krulec98b5b242018-08-10 15:03:23 -07001/*
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
Ana Krulec7ab56032018-11-02 20:51:06 +010017#define ATRACE_TAG ATRACE_TAG_GRAPHICS
18
Ana Krulec98b5b242018-08-10 15:03:23 -070019#include "Scheduler.h"
20
Ana Krulec434c22d2018-11-28 13:48:36 +010021#include <algorithm>
Ana Krulec98b5b242018-08-10 15:03:23 -070022#include <cinttypes>
23#include <cstdint>
24#include <memory>
Ana Krulec7ab56032018-11-02 20:51:06 +010025#include <numeric>
Ana Krulec98b5b242018-08-10 15:03:23 -070026
Ana Krulece588e312018-09-18 12:32:24 -070027#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
28#include <android/hardware/configstore/1.1/ISurfaceFlingerConfigs.h>
Ana Krulece588e312018-09-18 12:32:24 -070029#include <configstore/Utils.h>
Ana Krulecfb772822018-11-30 10:44:07 +010030#include <cutils/properties.h>
Ana Krulece588e312018-09-18 12:32:24 -070031#include <ui/DisplayStatInfo.h>
Ana Krulec3084c052018-11-21 20:27:17 +010032#include <utils/Timers.h>
Ana Krulec7ab56032018-11-02 20:51:06 +010033#include <utils/Trace.h>
Ana Krulec98b5b242018-08-10 15:03:23 -070034
35#include "DispSync.h"
36#include "DispSyncSource.h"
Ana Krulece588e312018-09-18 12:32:24 -070037#include "EventControlThread.h"
Ana Krulec98b5b242018-08-10 15:03:23 -070038#include "EventThread.h"
Ana Krulecfb772822018-11-30 10:44:07 +010039#include "IdleTimer.h"
Ana Krulec98b5b242018-08-10 15:03:23 -070040#include "InjectVSyncSource.h"
Ana Krulec434c22d2018-11-28 13:48:36 +010041#include "SchedulerUtils.h"
Sundong Ahnd5e08f62018-12-12 20:27:28 +090042#include "SurfaceFlingerProperties.h"
Ana Krulec98b5b242018-08-10 15:03:23 -070043
44namespace android {
45
Ana Krulece588e312018-09-18 12:32:24 -070046using namespace android::hardware::configstore;
47using namespace android::hardware::configstore::V1_0;
Sundong Ahnd5e08f62018-12-12 20:27:28 +090048using namespace android::sysprop;
Ana Krulece588e312018-09-18 12:32:24 -070049
Ana Krulec0c8cd522018-08-31 12:27:28 -070050#define RETURN_VALUE_IF_INVALID(value) \
51 if (handle == nullptr || mConnections.count(handle->id) == 0) return value
52#define RETURN_IF_INVALID() \
53 if (handle == nullptr || mConnections.count(handle->id) == 0) return
54
Ana Krulec98b5b242018-08-10 15:03:23 -070055std::atomic<int64_t> Scheduler::sNextId = 0;
56
Ana Krulece588e312018-09-18 12:32:24 -070057Scheduler::Scheduler(impl::EventControlThread::SetVSyncEnabledFunction function)
Sundong Ahnd5e08f62018-12-12 20:27:28 +090058 : mHasSyncFramework(running_without_sync_framework(true)),
59 mDispSyncPresentTimeOffset(present_time_offset_from_vsync_ns(0)),
Ana Krulece588e312018-09-18 12:32:24 -070060 mPrimaryHWVsyncEnabled(false),
61 mHWVsyncAvailable(false) {
62 // Note: We create a local temporary with the real DispSync implementation
63 // type temporarily so we can initialize it with the configured values,
64 // before storing it for more generic use using the interface type.
65 auto primaryDispSync = std::make_unique<impl::DispSync>("SchedulerDispSync");
66 primaryDispSync->init(mHasSyncFramework, mDispSyncPresentTimeOffset);
67 mPrimaryDispSync = std::move(primaryDispSync);
68 mEventControlThread = std::make_unique<impl::EventControlThread>(function);
Ana Krulecfb772822018-11-30 10:44:07 +010069
70 char value[PROPERTY_VALUE_MAX];
Ana Kruleca5bdd9d2019-01-29 19:00:58 -080071 property_get("debug.sf.set_idle_timer_ms", value, "0");
Ana Krulecfb772822018-11-30 10:44:07 +010072 mSetIdleTimerMs = atoi(value);
73
74 if (mSetIdleTimerMs > 0) {
75 mIdleTimer =
76 std::make_unique<scheduler::IdleTimer>(std::chrono::milliseconds(mSetIdleTimerMs),
Ady Abrahama1a49af2019-02-07 14:36:55 -080077 [this] { resetTimerCallback(); },
Ana Krulecfb772822018-11-30 10:44:07 +010078 [this] { expiredTimerCallback(); });
79 mIdleTimer->start();
80 }
Ana Krulece588e312018-09-18 12:32:24 -070081}
82
Lloyd Pique1f9f1a42019-01-31 13:04:00 -080083Scheduler::~Scheduler() {
84 // Ensure the IdleTimer thread is joined before we start destroying state.
85 mIdleTimer.reset();
86}
Ana Krulec0c8cd522018-08-31 12:27:28 -070087
Ana Krulec98b5b242018-08-10 15:03:23 -070088sp<Scheduler::ConnectionHandle> Scheduler::createConnection(
Dominik Laskowskibd52c842019-01-28 18:11:23 -080089 const char* connectionName, int64_t phaseOffsetNs, ResyncCallback resyncCallback,
Ana Krulec98b5b242018-08-10 15:03:23 -070090 impl::EventThread::InterceptVSyncsCallback interceptCallback) {
91 const int64_t id = sNextId++;
92 ALOGV("Creating a connection handle with ID: %" PRId64 "\n", id);
93
Ana Krulec98b5b242018-08-10 15:03:23 -070094 std::unique_ptr<EventThread> eventThread =
Dominik Laskowskif654d572018-12-20 11:03:06 -080095 makeEventThread(connectionName, mPrimaryDispSync.get(), phaseOffsetNs,
Dominik Laskowskibd52c842019-01-28 18:11:23 -080096 std::move(interceptCallback));
Dominik Laskowskif654d572018-12-20 11:03:06 -080097
Dominik Laskowskiccf37d72019-02-01 16:47:58 -080098 auto eventThreadConnection =
Ady Abrahama1a49af2019-02-07 14:36:55 -080099 createConnectionInternal(eventThread.get(), std::move(resyncCallback));
Dominik Laskowskiccf37d72019-02-01 16:47:58 -0800100 mConnections.emplace(id,
101 std::make_unique<Connection>(new ConnectionHandle(id),
102 eventThreadConnection,
103 std::move(eventThread)));
Ana Krulec98b5b242018-08-10 15:03:23 -0700104 return mConnections[id]->handle;
105}
106
Ana Krulec0c8cd522018-08-31 12:27:28 -0700107std::unique_ptr<EventThread> Scheduler::makeEventThread(
Dominik Laskowskibd52c842019-01-28 18:11:23 -0800108 const char* connectionName, DispSync* dispSync, int64_t phaseOffsetNs,
Ana Krulec0c8cd522018-08-31 12:27:28 -0700109 impl::EventThread::InterceptVSyncsCallback interceptCallback) {
110 std::unique_ptr<VSyncSource> eventThreadSource =
Dominik Laskowskibd52c842019-01-28 18:11:23 -0800111 std::make_unique<DispSyncSource>(dispSync, phaseOffsetNs, true, connectionName);
112 return std::make_unique<impl::EventThread>(std::move(eventThreadSource),
Dominik Laskowskiccf37d72019-02-01 16:47:58 -0800113 std::move(interceptCallback), connectionName);
114}
115
Ady Abrahama1a49af2019-02-07 14:36:55 -0800116sp<EventThreadConnection> Scheduler::createConnectionInternal(EventThread* eventThread,
117 ResyncCallback&& resyncCallback) {
Dominik Laskowskiccf37d72019-02-01 16:47:58 -0800118 return eventThread->createEventConnection(std::move(resyncCallback),
Ady Abrahama1a49af2019-02-07 14:36:55 -0800119 [this] { resetIdleTimer(); });
Ana Krulec0c8cd522018-08-31 12:27:28 -0700120}
121
Ana Krulec98b5b242018-08-10 15:03:23 -0700122sp<IDisplayEventConnection> Scheduler::createDisplayEventConnection(
Ady Abrahama1a49af2019-02-07 14:36:55 -0800123 const sp<Scheduler::ConnectionHandle>& handle, ResyncCallback resyncCallback) {
Ana Krulec0c8cd522018-08-31 12:27:28 -0700124 RETURN_VALUE_IF_INVALID(nullptr);
Dominik Laskowskiccf37d72019-02-01 16:47:58 -0800125 return createConnectionInternal(mConnections[handle->id]->thread.get(),
Ady Abrahama1a49af2019-02-07 14:36:55 -0800126 std::move(resyncCallback));
Ana Krulec98b5b242018-08-10 15:03:23 -0700127}
128
129EventThread* Scheduler::getEventThread(const sp<Scheduler::ConnectionHandle>& handle) {
Ana Krulec0c8cd522018-08-31 12:27:28 -0700130 RETURN_VALUE_IF_INVALID(nullptr);
131 return mConnections[handle->id]->thread.get();
Ana Krulec98b5b242018-08-10 15:03:23 -0700132}
133
Ana Krulec85c39af2018-12-26 17:29:57 -0800134sp<EventThreadConnection> Scheduler::getEventConnection(const sp<ConnectionHandle>& handle) {
Ana Krulec0c8cd522018-08-31 12:27:28 -0700135 RETURN_VALUE_IF_INVALID(nullptr);
136 return mConnections[handle->id]->eventConnection;
Ana Krulec98b5b242018-08-10 15:03:23 -0700137}
138
139void Scheduler::hotplugReceived(const sp<Scheduler::ConnectionHandle>& handle,
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800140 PhysicalDisplayId displayId, bool connected) {
Ana Krulec0c8cd522018-08-31 12:27:28 -0700141 RETURN_IF_INVALID();
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800142 mConnections[handle->id]->thread->onHotplugReceived(displayId, connected);
Ana Krulec98b5b242018-08-10 15:03:23 -0700143}
144
145void Scheduler::onScreenAcquired(const sp<Scheduler::ConnectionHandle>& handle) {
Ana Krulec0c8cd522018-08-31 12:27:28 -0700146 RETURN_IF_INVALID();
147 mConnections[handle->id]->thread->onScreenAcquired();
Ana Krulec98b5b242018-08-10 15:03:23 -0700148}
149
150void Scheduler::onScreenReleased(const sp<Scheduler::ConnectionHandle>& handle) {
Ana Krulec0c8cd522018-08-31 12:27:28 -0700151 RETURN_IF_INVALID();
152 mConnections[handle->id]->thread->onScreenReleased();
Ana Krulec98b5b242018-08-10 15:03:23 -0700153}
154
Ady Abraham447052e2019-02-13 16:07:27 -0800155void Scheduler::onConfigChanged(const sp<ConnectionHandle>& handle, PhysicalDisplayId displayId,
156 int32_t configId) {
157 RETURN_IF_INVALID();
158 mConnections[handle->id]->thread->onConfigChanged(displayId, configId);
159}
160
Yiwei Zhang5434a782018-12-05 18:06:32 -0800161void Scheduler::dump(const sp<Scheduler::ConnectionHandle>& handle, std::string& result) const {
Ana Krulec0c8cd522018-08-31 12:27:28 -0700162 RETURN_IF_INVALID();
163 mConnections.at(handle->id)->thread->dump(result);
Ana Krulec98b5b242018-08-10 15:03:23 -0700164}
165
166void Scheduler::setPhaseOffset(const sp<Scheduler::ConnectionHandle>& handle, nsecs_t phaseOffset) {
Ana Krulec0c8cd522018-08-31 12:27:28 -0700167 RETURN_IF_INVALID();
168 mConnections[handle->id]->thread->setPhaseOffset(phaseOffset);
Ana Krulec98b5b242018-08-10 15:03:23 -0700169}
Ana Krulece588e312018-09-18 12:32:24 -0700170
Ady Abrahamb838aed2019-02-12 15:30:16 -0800171void Scheduler::pauseVsyncCallback(const android::sp<android::Scheduler::ConnectionHandle>& handle,
172 bool pause) {
173 RETURN_IF_INVALID();
174 mConnections[handle->id]->thread->pauseVsyncCallback(pause);
175}
176
Ana Krulece588e312018-09-18 12:32:24 -0700177void Scheduler::getDisplayStatInfo(DisplayStatInfo* stats) {
178 stats->vsyncTime = mPrimaryDispSync->computeNextRefresh(0);
179 stats->vsyncPeriod = mPrimaryDispSync->getPeriod();
180}
181
182void Scheduler::enableHardwareVsync() {
183 std::lock_guard<std::mutex> lock(mHWVsyncLock);
184 if (!mPrimaryHWVsyncEnabled && mHWVsyncAvailable) {
185 mPrimaryDispSync->beginResync();
186 mEventControlThread->setVsyncEnabled(true);
187 mPrimaryHWVsyncEnabled = true;
188 }
189}
190
191void Scheduler::disableHardwareVsync(bool makeUnavailable) {
192 std::lock_guard<std::mutex> lock(mHWVsyncLock);
193 if (mPrimaryHWVsyncEnabled) {
194 mEventControlThread->setVsyncEnabled(false);
195 mPrimaryDispSync->endResync();
196 mPrimaryHWVsyncEnabled = false;
197 }
198 if (makeUnavailable) {
199 mHWVsyncAvailable = false;
200 }
201}
202
Ana Krulecc2870422019-01-29 19:00:58 -0800203void Scheduler::resyncToHardwareVsync(bool makeAvailable, nsecs_t period) {
204 {
205 std::lock_guard<std::mutex> lock(mHWVsyncLock);
206 if (makeAvailable) {
207 mHWVsyncAvailable = makeAvailable;
208 } else if (!mHWVsyncAvailable) {
209 // Hardware vsync is not currently available, so abort the resync
210 // attempt for now
211 return;
212 }
213 }
214
215 if (period <= 0) {
216 return;
217 }
218
219 setVsyncPeriod(period);
220}
221
222ResyncCallback Scheduler::makeResyncCallback(GetVsyncPeriod&& getVsyncPeriod) {
223 std::weak_ptr<VsyncState> ptr = mPrimaryVsyncState;
224 return [ptr, getVsyncPeriod = std::move(getVsyncPeriod)]() {
225 if (const auto vsync = ptr.lock()) {
226 vsync->resync(getVsyncPeriod);
227 }
228 };
229}
230
231void Scheduler::VsyncState::resync(const GetVsyncPeriod& getVsyncPeriod) {
232 static constexpr nsecs_t kIgnoreDelay = ms2ns(500);
233
234 const nsecs_t now = systemTime();
235 const nsecs_t last = lastResyncTime.exchange(now);
236
237 if (now - last > kIgnoreDelay) {
238 scheduler.resyncToHardwareVsync(false, getVsyncPeriod());
239 }
240}
241
242void Scheduler::setRefreshSkipCount(int count) {
243 mPrimaryDispSync->setRefreshSkipCount(count);
244}
245
Ana Krulece588e312018-09-18 12:32:24 -0700246void Scheduler::setVsyncPeriod(const nsecs_t period) {
Ady Abraham3aff9172019-02-07 19:10:26 -0800247 std::lock_guard<std::mutex> lock(mHWVsyncLock);
Ana Krulece588e312018-09-18 12:32:24 -0700248 mPrimaryDispSync->reset();
249 mPrimaryDispSync->setPeriod(period);
Ady Abraham3aff9172019-02-07 19:10:26 -0800250
251 if (!mPrimaryHWVsyncEnabled) {
252 mPrimaryDispSync->beginResync();
253 mEventControlThread->setVsyncEnabled(true);
254 mPrimaryHWVsyncEnabled = true;
255 }
Ana Krulece588e312018-09-18 12:32:24 -0700256}
257
258void Scheduler::addResyncSample(const nsecs_t timestamp) {
259 bool needsHwVsync = false;
260 { // Scope for the lock
261 std::lock_guard<std::mutex> lock(mHWVsyncLock);
262 if (mPrimaryHWVsyncEnabled) {
263 needsHwVsync = mPrimaryDispSync->addResyncSample(timestamp);
264 }
265 }
266
267 if (needsHwVsync) {
268 enableHardwareVsync();
269 } else {
270 disableHardwareVsync(false);
271 }
272}
273
274void Scheduler::addPresentFence(const std::shared_ptr<FenceTime>& fenceTime) {
275 if (mPrimaryDispSync->addPresentFence(fenceTime)) {
276 enableHardwareVsync();
277 } else {
278 disableHardwareVsync(false);
279 }
280}
281
282void Scheduler::setIgnorePresentFences(bool ignore) {
283 mPrimaryDispSync->setIgnorePresentFences(ignore);
284}
285
Ady Abrahamc3e21312019-02-07 14:30:23 -0800286nsecs_t Scheduler::expectedPresentTime() {
287 return mPrimaryDispSync->expectedPresentTime();
288}
289
Ady Abraham3aff9172019-02-07 19:10:26 -0800290void Scheduler::dumpPrimaryDispSync(std::string& result) const {
291 mPrimaryDispSync->dump(result);
292}
293
Ana Krulec3084c052018-11-21 20:27:17 +0100294void Scheduler::addFramePresentTimeForLayer(const nsecs_t framePresentTime, bool isAutoTimestamp,
295 const std::string layerName) {
296 // This is V1 logic. It calculates the average FPS based on the timestamp frequency
297 // regardless of which layer the timestamp came from.
298 // For now, the averages and FPS are recorded in the systrace.
299 determineTimestampAverage(isAutoTimestamp, framePresentTime);
300
301 // This is V2 logic. It calculates the average and median timestamp difference based on the
302 // individual layer history. The results are recorded in the systrace.
303 determineLayerTimestampStats(layerName, framePresentTime);
304}
305
306void Scheduler::incrementFrameCounter() {
Ana Krulec6da0e492019-02-19 14:46:01 -0800307 std::lock_guard<std::mutex> lock(mLayerHistoryLock);
Ana Krulec3084c052018-11-21 20:27:17 +0100308 mLayerHistory.incrementCounter();
309}
310
Ana Krulec8d3e4f32019-03-05 10:40:33 -0800311void Scheduler::setChangeRefreshRateCallback(
312 const ChangeRefreshRateCallback& changeRefreshRateCallback) {
Ana Krulec7d1d6832018-12-27 11:10:09 -0800313 std::lock_guard<std::mutex> lock(mCallbackLock);
Ana Krulec8d3e4f32019-03-05 10:40:33 -0800314 mChangeRefreshRateCallback = changeRefreshRateCallback;
Ady Abrahama1a49af2019-02-07 14:36:55 -0800315}
316
Ana Krulec3084c052018-11-21 20:27:17 +0100317void Scheduler::updateFrameSkipping(const int64_t skipCount) {
318 ATRACE_INT("FrameSkipCount", skipCount);
319 if (mSkipCount != skipCount) {
320 // Only update DispSync if it hasn't been updated yet.
321 mPrimaryDispSync->setRefreshSkipCount(skipCount);
322 mSkipCount = skipCount;
323 }
324}
325
326void Scheduler::determineLayerTimestampStats(const std::string layerName,
327 const nsecs_t framePresentTime) {
Ana Krulec3084c052018-11-21 20:27:17 +0100328 std::vector<int64_t> differencesMs;
Ana Krulec434c22d2018-11-28 13:48:36 +0100329 std::string differencesText = "";
Ana Krulec6da0e492019-02-19 14:46:01 -0800330 {
331 std::lock_guard<std::mutex> lock(mLayerHistoryLock);
332 mLayerHistory.insert(layerName, framePresentTime);
333
334 // Traverse through the layer history, and determine the differences in present times.
335 nsecs_t newestPresentTime = framePresentTime;
336 for (int i = 1; i < mLayerHistory.getSize(); i++) {
337 std::unordered_map<std::string, nsecs_t> layers = mLayerHistory.get(i);
338 for (auto layer : layers) {
339 if (layer.first != layerName) {
340 continue;
341 }
342 int64_t differenceMs = (newestPresentTime - layer.second) / 1000000;
343 // Dismiss noise.
344 if (differenceMs > 10 && differenceMs < 60) {
345 differencesMs.push_back(differenceMs);
346 }
347 IF_ALOGV() { differencesText += (std::to_string(differenceMs) + " "); }
348 newestPresentTime = layer.second;
Ana Krulec3084c052018-11-21 20:27:17 +0100349 }
Ana Krulec3084c052018-11-21 20:27:17 +0100350 }
351 }
Ana Krulec434c22d2018-11-28 13:48:36 +0100352 ALOGV("Layer %s timestamp intervals: %s", layerName.c_str(), differencesText.c_str());
Ana Krulec3084c052018-11-21 20:27:17 +0100353
Ana Krulec434c22d2018-11-28 13:48:36 +0100354 if (!differencesMs.empty()) {
355 // Mean/Average is a good indicator for when 24fps videos are playing, because the frames
356 // come in 33, and 49 ms intervals with occasional 41ms.
357 const int64_t meanMs = scheduler::calculate_mean(differencesMs);
358 const auto tagMean = "TimestampMean_" + layerName;
359 ATRACE_INT(tagMean.c_str(), meanMs);
360
361 // Mode and median are good indicators for 30 and 60 fps videos, because the majority of
362 // frames come in 16, or 33 ms intervals.
Ana Krulec3084c052018-11-21 20:27:17 +0100363 const auto tagMedian = "TimestampMedian_" + layerName;
Ana Krulec434c22d2018-11-28 13:48:36 +0100364 ATRACE_INT(tagMedian.c_str(), scheduler::calculate_median(&differencesMs));
Ana Krulec3084c052018-11-21 20:27:17 +0100365
Ana Krulec434c22d2018-11-28 13:48:36 +0100366 const auto tagMode = "TimestampMode_" + layerName;
367 ATRACE_INT(tagMode.c_str(), scheduler::calculate_mode(differencesMs));
Ana Krulec3084c052018-11-21 20:27:17 +0100368 }
Ana Krulec3084c052018-11-21 20:27:17 +0100369}
370
371void Scheduler::determineTimestampAverage(bool isAutoTimestamp, const nsecs_t framePresentTime) {
Ana Krulec7ab56032018-11-02 20:51:06 +0100372 ATRACE_INT("AutoTimestamp", isAutoTimestamp);
Ana Krulec3084c052018-11-21 20:27:17 +0100373
Ana Krulec7ab56032018-11-02 20:51:06 +0100374 // Video does not have timestamp automatically set, so we discard timestamps that are
375 // coming in from other sources for now.
376 if (isAutoTimestamp) {
377 return;
378 }
Ana Krulec3084c052018-11-21 20:27:17 +0100379 int64_t differenceMs = (framePresentTime - mPreviousFrameTimestamp) / 1000000;
380 mPreviousFrameTimestamp = framePresentTime;
Ana Krulec7ab56032018-11-02 20:51:06 +0100381
382 if (differenceMs < 10 || differenceMs > 100) {
383 // Dismiss noise.
384 return;
385 }
386 ATRACE_INT("TimestampDiff", differenceMs);
387
Ana Krulec434c22d2018-11-28 13:48:36 +0100388 mTimeDifferences[mCounter % scheduler::ARRAY_SIZE] = differenceMs;
Ana Krulec7ab56032018-11-02 20:51:06 +0100389 mCounter++;
Ana Krulec434c22d2018-11-28 13:48:36 +0100390 int64_t mean = scheduler::calculate_mean(mTimeDifferences);
391 ATRACE_INT("AutoTimestampMean", mean);
Ana Krulec7ab56032018-11-02 20:51:06 +0100392
393 // TODO(b/113612090): This are current numbers from trial and error while running videos
394 // from YouTube at 24, 30, and 60 fps.
Ana Krulec434c22d2018-11-28 13:48:36 +0100395 if (mean > 14 && mean < 18) {
Ana Krulec7d1d6832018-12-27 11:10:09 -0800396 ATRACE_INT("MediaFPS", 60);
Ana Krulec434c22d2018-11-28 13:48:36 +0100397 } else if (mean > 31 && mean < 34) {
Ana Krulec7d1d6832018-12-27 11:10:09 -0800398 ATRACE_INT("MediaFPS", 30);
Ana Krulec7ab56032018-11-02 20:51:06 +0100399 return;
Ana Krulec434c22d2018-11-28 13:48:36 +0100400 } else if (mean > 39 && mean < 42) {
Ana Krulec7d1d6832018-12-27 11:10:09 -0800401 ATRACE_INT("MediaFPS", 24);
Ana Krulec7ab56032018-11-02 20:51:06 +0100402 }
Ana Krulec7ab56032018-11-02 20:51:06 +0100403}
404
Ana Krulecfb772822018-11-30 10:44:07 +0100405void Scheduler::resetIdleTimer() {
406 if (mIdleTimer) {
407 mIdleTimer->reset();
Ady Abrahama1a49af2019-02-07 14:36:55 -0800408 }
409}
410
411void Scheduler::resetTimerCallback() {
412 std::lock_guard<std::mutex> lock(mCallbackLock);
Ana Krulec8d3e4f32019-03-05 10:40:33 -0800413 if (mChangeRefreshRateCallback) {
414 // We do not notify the applications about config changes when idle timer is reset.
415 mChangeRefreshRateCallback(RefreshRateType::PERFORMANCE, ConfigEvent::None);
Ana Krulecfb772822018-11-30 10:44:07 +0100416 ATRACE_INT("ExpiredIdleTimer", 0);
417 }
418}
419
420void Scheduler::expiredTimerCallback() {
Ana Krulec7d1d6832018-12-27 11:10:09 -0800421 std::lock_guard<std::mutex> lock(mCallbackLock);
Ana Krulec8d3e4f32019-03-05 10:40:33 -0800422 if (mChangeRefreshRateCallback) {
423 // We do not notify the applications about config changes when idle timer expires.
424 mChangeRefreshRateCallback(RefreshRateType::DEFAULT, ConfigEvent::None);
Ana Krulec7d1d6832018-12-27 11:10:09 -0800425 ATRACE_INT("ExpiredIdleTimer", 1);
426 }
Ana Krulecfb772822018-11-30 10:44:07 +0100427}
428
Ana Krulecb43429d2019-01-09 14:28:51 -0800429std::string Scheduler::doDump() {
430 std::ostringstream stream;
431 stream << "+ Idle timer interval: " << mSetIdleTimerMs << " ms" << std::endl;
432 return stream.str();
433}
434
Ana Krulec98b5b242018-08-10 15:03:23 -0700435} // namespace android