Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 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> |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 20 | #include <memory> |
Rachel Lee | 6a9731d | 2022-06-06 17:08:14 -0700 | [diff] [blame^] | 21 | #include <mutex> |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 22 | |
Rachel Lee | 6a9731d | 2022-06-06 17:08:14 -0700 | [diff] [blame^] | 23 | #include <DisplayHardware/HWComposer.h> |
| 24 | #include <DisplayHardware/Hal.h> |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 25 | #include <ui/FenceTime.h> |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 26 | #include <utils/Mutex.h> |
| 27 | #include <utils/RefBase.h> |
| 28 | #include <utils/Timers.h> |
| 29 | |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 30 | namespace android::scheduler { |
| 31 | |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 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 | */ |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 45 | virtual bool addPresentFence(std::shared_ptr<FenceTime>) = 0; |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 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 | |
Rachel Lee | 6a9731d | 2022-06-06 17:08:14 -0700 | [diff] [blame^] | 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 | |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 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 |