blob: 95750ad5cc84afc59fd231b684accf43fb0af8bb [file] [log] [blame]
Kevin DuBois305bef12019-10-09 13:23:27 -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#pragma once
18
19#include <utils/Timers.h>
Ady Abraham5cc2e262021-03-25 13:09:17 -070020#include "Fps.h"
Kevin DuBois305bef12019-10-09 13:23:27 -070021#include "VSyncDispatch.h"
22
23namespace android::scheduler {
24/*
25 * VSyncTracker is an interface for providing estimates on future Vsync signal times based on
26 * historical vsync timing data.
27 */
28class VSyncTracker {
29public:
30 virtual ~VSyncTracker();
31
32 /*
33 * Adds a known timestamp from a vsync timing source (HWVsync signal, present fence)
34 * to the model.
35 *
36 * \param [in] timestamp The timestamp when the vsync signal was.
Kevin DuBois02d5ed92020-01-27 11:05:46 -080037 * \return True if the timestamp was consistent with the internal model,
38 * False otherwise
Kevin DuBois305bef12019-10-09 13:23:27 -070039 */
Kevin DuBois02d5ed92020-01-27 11:05:46 -080040 virtual bool addVsyncTimestamp(nsecs_t timestamp) = 0;
Kevin DuBois305bef12019-10-09 13:23:27 -070041
42 /*
43 * Access the next anticipated vsync time such that the anticipated time >= timePoint.
44 * This will always give the best accurate at the time of calling; multiple
45 * calls with the same timePoint might give differing values if the internal model
46 * is updated.
47 *
48 * \param [in] timePoint The point in time after which to estimate a vsync event.
49 * \return A prediction of the timestamp of a vsync event.
50 */
51 virtual nsecs_t nextAnticipatedVSyncTimeFrom(nsecs_t timePoint) const = 0;
52
Kevin DuBois2fd3cea2019-11-14 08:52:45 -080053 /*
54 * The current period of the vsync signal.
55 *
56 * \return The current period of the vsync signal
57 */
58 virtual nsecs_t currentPeriod() const = 0;
59
Kevin DuBoisee2ad9f2019-11-21 11:10:57 -080060 /*
61 * Inform the tracker that the period is changing and the tracker needs to recalibrate itself.
62 *
63 * \param [in] period The period that the system is changing into.
64 */
65 virtual void setPeriod(nsecs_t period) = 0;
66
Kevin DuBoisc3e9e8e2020-01-07 09:06:52 -080067 /* Inform the tracker that the samples it has are not accurate for prediction. */
68 virtual void resetModel() = 0;
69
Kevin DuBoisb818bfa2020-07-10 14:29:36 -070070 virtual bool needsMoreSamples() const = 0;
71
Ady Abraham0bb6a472020-10-12 10:22:13 -070072 /*
Ady Abraham5cc2e262021-03-25 13:09:17 -070073 * Checks if a vsync timestamp is in phase for a frame rate
Ady Abraham0bb6a472020-10-12 10:22:13 -070074 *
75 * \param [in] timePoint A vsync timestamp
Ady Abraham5cc2e262021-03-25 13:09:17 -070076 * \param [in] frameRate The frame rate to check for
Ady Abraham0bb6a472020-10-12 10:22:13 -070077 */
Ady Abraham5cc2e262021-03-25 13:09:17 -070078 virtual bool isVSyncInPhase(nsecs_t timePoint, Fps frameRate) const = 0;
Ady Abraham0bb6a472020-10-12 10:22:13 -070079
Ady Abraham5e7371c2020-03-24 14:47:24 -070080 virtual void dump(std::string& result) const = 0;
81
Kevin DuBois305bef12019-10-09 13:23:27 -070082protected:
83 VSyncTracker(VSyncTracker const&) = delete;
84 VSyncTracker& operator=(VSyncTracker const&) = delete;
85 VSyncTracker() = default;
86};
87
88} // namespace android::scheduler