blob: 917789934a8498f3a4a6e0b4690d618ba338419e [file] [log] [blame]
Ady Abraham8cb21882020-08-26 18:22:05 -07001/*
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>
Dominik Laskowski068173d2021-08-11 17:22:59 -070020#include <memory>
Rachel Lee6a9731d2022-06-06 17:08:14 -070021#include <mutex>
Ady Abraham8cb21882020-08-26 18:22:05 -070022
Rachel Lee6a9731d2022-06-06 17:08:14 -070023#include <DisplayHardware/HWComposer.h>
24#include <DisplayHardware/Hal.h>
Dominik Laskowski068173d2021-08-11 17:22:59 -070025#include <ui/FenceTime.h>
Ady Abraham8cb21882020-08-26 18:22:05 -070026#include <utils/Mutex.h>
27#include <utils/RefBase.h>
28#include <utils/Timers.h>
29
Ady Abraham8cb21882020-08-26 18:22:05 -070030namespace android::scheduler {
31
Ady Abraham8cb21882020-08-26 18:22:05 -070032class VsyncController {
33public:
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 */
Dominik Laskowski068173d2021-08-11 17:22:59 -070045 virtual bool addPresentFence(std::shared_ptr<FenceTime>) = 0;
Ady Abraham8cb21882020-08-26 18:22:05 -070046
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.
Leon Scroggins III31d41412022-11-18 16:42:53 -050066 * \param [in] force True to recalibrate even if period matches the existing period.
Ady Abraham8cb21882020-08-26 18:22:05 -070067 */
Leon Scroggins III31d41412022-11-18 16:42:53 -050068 virtual void startPeriodTransition(nsecs_t period, bool force) = 0;
Ady Abraham8cb21882020-08-26 18:22:05 -070069
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
Rachel Lee6a9731d2022-06-06 17:08:14 -070077 /*
78 * Sets the primary display power mode to the controller.
79 *
80 * \param [in] powerMode
81 */
82 virtual void setDisplayPowerMode(hal::PowerMode powerMode) = 0;
83
Ady Abraham8cb21882020-08-26 18:22:05 -070084 virtual void dump(std::string& result) const = 0;
85
86protected:
87 VsyncController() = default;
88 VsyncController(VsyncController const&) = delete;
89 VsyncController& operator=(VsyncController const&) = delete;
90};
91
92} // namespace android::scheduler