| 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 |  | 
| Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 19 | #include <algorithm> | 
|  | 20 | #include <utility> | 
| Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 21 |  | 
| Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 22 | namespace android::scheduler { | 
| Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 23 |  | 
| Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 24 | LayerInfo::LayerInfo(float lowRefreshRate, float highRefreshRate) | 
|  | 25 | : mLowRefreshRate(lowRefreshRate), mHighRefreshRate(highRefreshRate) {} | 
| Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 26 |  | 
| Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 27 | void LayerInfo::setLastPresentTime(nsecs_t lastPresentTime, nsecs_t now) { | 
| Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame] | 28 | lastPresentTime = std::max(lastPresentTime, static_cast<nsecs_t>(0)); | 
|  | 29 |  | 
| Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 30 | // Buffers can come with a present time far in the future. That keeps them relevant. | 
| Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 31 | mLastUpdatedTime = std::max(lastPresentTime, now); | 
| Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 32 | mPresentTimeHistory.insertPresentTime(mLastUpdatedTime); | 
|  | 33 |  | 
| Ady Abraham | 616b832 | 2019-06-12 13:30:07 -0700 | [diff] [blame] | 34 | if (mLastPresentTime == 0) { | 
|  | 35 | // First frame | 
|  | 36 | mLastPresentTime = lastPresentTime; | 
|  | 37 | return; | 
|  | 38 | } | 
|  | 39 |  | 
| Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 40 | const nsecs_t period = lastPresentTime - mLastPresentTime; | 
| Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 41 | mLastPresentTime = lastPresentTime; | 
|  | 42 | // Ignore time diff that are too high - those are stale values | 
| Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 43 | if (period > MAX_ACTIVE_LAYER_PERIOD_NS.count()) return; | 
|  | 44 |  | 
|  | 45 | const float fps = std::min(1e9f / period, mHighRefreshRate); | 
| Ady Abraham | 187d2d8 | 2019-07-10 16:18:48 -0700 | [diff] [blame] | 46 | mRefreshRateHistory.insertRefreshRate(fps); | 
| Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 47 | } | 
|  | 48 |  | 
| Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 49 | } // namespace android::scheduler |