Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -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 | #pragma once |
| 18 | |
| 19 | #include <utils/Timers.h> |
| 20 | #include "VSyncDispatch.h" |
| 21 | |
| 22 | namespace android::scheduler { |
| 23 | /* |
| 24 | * VSyncTracker is an interface for providing estimates on future Vsync signal times based on |
| 25 | * historical vsync timing data. |
| 26 | */ |
| 27 | class VSyncTracker { |
| 28 | public: |
| 29 | virtual ~VSyncTracker(); |
| 30 | |
| 31 | /* |
| 32 | * Adds a known timestamp from a vsync timing source (HWVsync signal, present fence) |
| 33 | * to the model. |
| 34 | * |
| 35 | * \param [in] timestamp The timestamp when the vsync signal was. |
Kevin DuBois | 02d5ed9 | 2020-01-27 11:05:46 -0800 | [diff] [blame] | 36 | * \return True if the timestamp was consistent with the internal model, |
| 37 | * False otherwise |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 38 | */ |
Kevin DuBois | 02d5ed9 | 2020-01-27 11:05:46 -0800 | [diff] [blame] | 39 | virtual bool addVsyncTimestamp(nsecs_t timestamp) = 0; |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 40 | |
| 41 | /* |
| 42 | * Access the next anticipated vsync time such that the anticipated time >= timePoint. |
| 43 | * This will always give the best accurate at the time of calling; multiple |
| 44 | * calls with the same timePoint might give differing values if the internal model |
| 45 | * is updated. |
| 46 | * |
| 47 | * \param [in] timePoint The point in time after which to estimate a vsync event. |
| 48 | * \return A prediction of the timestamp of a vsync event. |
| 49 | */ |
| 50 | virtual nsecs_t nextAnticipatedVSyncTimeFrom(nsecs_t timePoint) const = 0; |
| 51 | |
Kevin DuBois | 2fd3cea | 2019-11-14 08:52:45 -0800 | [diff] [blame] | 52 | /* |
| 53 | * The current period of the vsync signal. |
| 54 | * |
| 55 | * \return The current period of the vsync signal |
| 56 | */ |
| 57 | virtual nsecs_t currentPeriod() const = 0; |
| 58 | |
Kevin DuBois | ee2ad9f | 2019-11-21 11:10:57 -0800 | [diff] [blame] | 59 | /* |
| 60 | * Inform the tracker that the period is changing and the tracker needs to recalibrate itself. |
| 61 | * |
| 62 | * \param [in] period The period that the system is changing into. |
| 63 | */ |
| 64 | virtual void setPeriod(nsecs_t period) = 0; |
| 65 | |
Kevin DuBois | c3e9e8e | 2020-01-07 09:06:52 -0800 | [diff] [blame] | 66 | /* Inform the tracker that the samples it has are not accurate for prediction. */ |
| 67 | virtual void resetModel() = 0; |
| 68 | |
Ady Abraham | 5e7371c | 2020-03-24 14:47:24 -0700 | [diff] [blame] | 69 | virtual void dump(std::string& result) const = 0; |
| 70 | |
Kevin DuBois | 305bef1 | 2019-10-09 13:23:27 -0700 | [diff] [blame] | 71 | protected: |
| 72 | VSyncTracker(VSyncTracker const&) = delete; |
| 73 | VSyncTracker& operator=(VSyncTracker const&) = delete; |
| 74 | VSyncTracker() = default; |
| 75 | }; |
| 76 | |
| 77 | } // namespace android::scheduler |