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