blob: f3b0d5630284224fdc633f441e4f9ffccf0e6abe [file] [log] [blame]
Ady Abraham09bd3922019-04-08 10:44:56 -07001/*
2 * Copyright 2019 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#include "LayerInfo.h"
18
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -070019#include <algorithm>
20#include <utility>
Ady Abraham09bd3922019-04-08 10:44:56 -070021
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -070022namespace android::scheduler {
Ady Abraham09bd3922019-04-08 10:44:56 -070023
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -070024LayerInfo::LayerInfo(float lowRefreshRate, float highRefreshRate)
25 : mLowRefreshRate(lowRefreshRate), mHighRefreshRate(highRefreshRate) {}
Ady Abraham09bd3922019-04-08 10:44:56 -070026
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -070027void LayerInfo::setLastPresentTime(nsecs_t lastPresentTime, nsecs_t now) {
Ady Abraham09bd3922019-04-08 10:44:56 -070028 // Buffers can come with a present time far in the future. That keeps them relevant.
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -070029 mLastUpdatedTime = std::max(lastPresentTime, now);
Ady Abraham09bd3922019-04-08 10:44:56 -070030 mPresentTimeHistory.insertPresentTime(mLastUpdatedTime);
31
Ady Abraham616b8322019-06-12 13:30:07 -070032 if (mLastPresentTime == 0) {
33 // First frame
34 mLastPresentTime = lastPresentTime;
35 return;
36 }
37
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -070038 const nsecs_t period = lastPresentTime - mLastPresentTime;
Ady Abraham09bd3922019-04-08 10:44:56 -070039 mLastPresentTime = lastPresentTime;
40 // Ignore time diff that are too high - those are stale values
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -070041 if (period > MAX_ACTIVE_LAYER_PERIOD_NS.count()) return;
42
43 const float fps = std::min(1e9f / period, mHighRefreshRate);
Ady Abraham187d2d82019-07-10 16:18:48 -070044 mRefreshRateHistory.insertRefreshRate(fps);
Ady Abraham09bd3922019-04-08 10:44:56 -070045}
46
Dominik Laskowskif7a09ed2019-10-07 13:54:18 -070047} // namespace android::scheduler