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 <scheduler/FrameRateMode.h> 26 #include <ui/FenceTime.h> 27 #include <utils/Mutex.h> 28 #include <utils/RefBase.h> 29 #include <utils/Timers.h> 30 31 namespace android::scheduler { 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(std::shared_ptr<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 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. 66 * 67 * \param [in] DisplayModePtr The new mode the display is changing to. 68 * \param [in] force True to recalibrate even if period matches the existing period. 69 */ 70 virtual void onDisplayModeChanged(ftl::NonNull<DisplayModePtr>, bool force) = 0; 71 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 79 /* 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 86 virtual void dump(std::string& result) const = 0; 87 88 protected: 89 VsyncController() = default; 90 VsyncController(VsyncController const&) = delete; 91 VsyncController& operator=(VsyncController const&) = delete; 92 }; 93 94 } // namespace android::scheduler 95