blob: 726a42064922261251a721b55c9c8759790a4190 [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.
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
Rachel Lee6a9731d2022-06-06 17:08:14 -070076 /*
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
Ady Abraham8cb21882020-08-26 18:22:05 -070083 virtual void dump(std::string& result) const = 0;
84
85protected:
86 VsyncController() = default;
87 VsyncController(VsyncController const&) = delete;
88 VsyncController& operator=(VsyncController const&) = delete;
89};
90
91} // namespace android::scheduler