| Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 1 | /* | 
|  | 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 |  | 
|  | 19 | #include <cinttypes> | 
|  | 20 | #include <cstdint> | 
|  | 21 | #include <numeric> | 
|  | 22 | #include <string> | 
|  | 23 |  | 
|  | 24 | namespace android { | 
|  | 25 | namespace scheduler { | 
|  | 26 |  | 
|  | 27 | LayerInfo::LayerInfo(const std::string name, float maxRefreshRate) | 
|  | 28 | : mName(name), | 
|  | 29 | mMinRefreshDuration(1e9f / maxRefreshRate), | 
|  | 30 | mRefreshRateHistory(mMinRefreshDuration) {} | 
|  | 31 |  | 
|  | 32 | LayerInfo::~LayerInfo() = default; | 
|  | 33 |  | 
|  | 34 | void LayerInfo::setLastPresentTime(nsecs_t lastPresentTime) { | 
|  | 35 | std::lock_guard lock(mLock); | 
|  | 36 |  | 
|  | 37 | // Buffers can come with a present time far in the future. That keeps them relevant. | 
|  | 38 | mLastUpdatedTime = std::max(lastPresentTime, systemTime()); | 
|  | 39 | mPresentTimeHistory.insertPresentTime(mLastUpdatedTime); | 
|  | 40 |  | 
|  | 41 | const nsecs_t timeDiff = lastPresentTime - mLastPresentTime; | 
|  | 42 | mLastPresentTime = lastPresentTime; | 
|  | 43 | // Ignore time diff that are too high - those are stale values | 
|  | 44 | if (timeDiff > TIME_EPSILON_NS.count()) return; | 
|  | 45 | const nsecs_t refreshDuration = (timeDiff > 0) ? timeDiff : mMinRefreshDuration; | 
|  | 46 | mRefreshRateHistory.insertRefreshRate(refreshDuration); | 
|  | 47 | } | 
|  | 48 |  | 
|  | 49 | } // namespace scheduler | 
|  | 50 | } // namespace android |