• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 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 <cstddef>
20 
21 #include <utils/Mutex.h>
22 #include <utils/RefBase.h>
23 #include <utils/Timers.h>
24 
25 #include <ui/FenceTime.h>
26 
27 #include <memory>
28 
29 namespace android::scheduler {
30 
31 class FenceTime;
32 
33 class VsyncController {
34 public:
35     virtual ~VsyncController();
36 
37     /*
38      * Adds a present fence to the model. The controller will use the fence time as
39      * a vsync signal.
40      *
41      * \param [in] fence    The present fence given from the display
42      * \return              True if the model needs more vsync signals to make
43      *                      an accurate prediction,
44      *                      False otherwise
45      */
46     virtual bool addPresentFence(const std::shared_ptr<android::FenceTime>&) = 0;
47 
48     /*
49      * Adds a hw sync timestamp to the model. The controller will use the timestamp
50      * time as a vsync signal.
51      *
52      * \param [in] timestamp       The HW Vsync timestamp
53      * \param [in] hwcVsyncPeriod  The Vsync period reported by composer, if available
54      * \param [out] periodFlushed  True if the vsync period changed is completed
55      * \return                     True if the model needs more vsync signals to make
56      *                             an accurate prediction,
57      *                             False otherwise
58      */
59     virtual bool addHwVsyncTimestamp(nsecs_t timestamp, std::optional<nsecs_t> hwcVsyncPeriod,
60                                      bool* periodFlushed) = 0;
61 
62     /*
63      * Inform the controller that the period is changing and the controller needs to recalibrate
64      * itself. The controller will end the period transition internally.
65      *
66      * \param [in] period   The period that the system is changing into.
67      */
68     virtual void startPeriodTransition(nsecs_t period) = 0;
69 
70     /*
71      * Tells the tracker to stop using present fences to get a vsync signal.
72      *
73      * \param [in] ignore  Whether to ignore the present fences or not
74      */
75     virtual void setIgnorePresentFences(bool ignore) = 0;
76 
77     virtual void dump(std::string& result) const = 0;
78 
79 protected:
80     VsyncController() = default;
81     VsyncController(VsyncController const&) = delete;
82     VsyncController& operator=(VsyncController const&) = delete;
83 };
84 
85 } // namespace android::scheduler
86