blob: 807a7fba5351f2834897ad2a2132fc843bb915f6 [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>
Ady Abrahamc585dba2023-11-15 18:41:35 -080025#include <scheduler/FrameRateMode.h>
Dominik Laskowski068173d2021-08-11 17:22:59 -070026#include <ui/FenceTime.h>
Ady Abraham8cb21882020-08-26 18:22:05 -070027#include <utils/Mutex.h>
28#include <utils/RefBase.h>
29#include <utils/Timers.h>
30
Ady Abraham8cb21882020-08-26 18:22:05 -070031namespace android::scheduler {
32
Ady Abraham8cb21882020-08-26 18:22:05 -070033class VsyncController {
34public:
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 */
Dominik Laskowski068173d2021-08-11 17:22:59 -070046 virtual bool addPresentFence(std::shared_ptr<FenceTime>) = 0;
Ady Abraham8cb21882020-08-26 18:22:05 -070047
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 /*
Ady Abrahamc585dba2023-11-15 18:41:35 -080063 * Inform the controller that the display mode is changing and the controller needs to
64 * recalibrate itself to the new vsync period. The controller will end the period transition
65 * internally.
Ady Abraham8cb21882020-08-26 18:22:05 -070066 *
Ady Abrahamc585dba2023-11-15 18:41:35 -080067 * \param [in] DisplayModePtr The new mode the display is changing to.
Leon Scroggins III67388622023-02-06 20:36:20 -050068 * \param [in] force True to recalibrate even if period matches the existing period.
Ady Abraham8cb21882020-08-26 18:22:05 -070069 */
Ady Abrahamc585dba2023-11-15 18:41:35 -080070 virtual void onDisplayModeChanged(ftl::NonNull<DisplayModePtr>, bool force) = 0;
Ady Abraham8cb21882020-08-26 18:22:05 -070071
72 /*
73 * Tells the tracker to stop using present fences to get a vsync signal.
74 *
75 * \param [in] ignore Whether to ignore the present fences or not
76 */
77 virtual void setIgnorePresentFences(bool ignore) = 0;
78
Rachel Lee6a9731d2022-06-06 17:08:14 -070079 /*
80 * Sets the primary display power mode to the controller.
81 *
82 * \param [in] powerMode
83 */
84 virtual void setDisplayPowerMode(hal::PowerMode powerMode) = 0;
85
Ady Abraham8cb21882020-08-26 18:22:05 -070086 virtual void dump(std::string& result) const = 0;
87
88protected:
89 VsyncController() = default;
90 VsyncController(VsyncController const&) = delete;
91 VsyncController& operator=(VsyncController const&) = delete;
92};
93
94} // namespace android::scheduler