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> |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 21 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 22 | #include <ui/FenceTime.h> |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 23 | #include <utils/Mutex.h> |
| 24 | #include <utils/RefBase.h> |
| 25 | #include <utils/Timers.h> |
| 26 | |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 27 | namespace android::scheduler { |
| 28 | |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 29 | class VsyncController { |
| 30 | public: |
| 31 | virtual ~VsyncController(); |
| 32 | |
| 33 | /* |
| 34 | * Adds a present fence to the model. The controller will use the fence time as |
| 35 | * a vsync signal. |
| 36 | * |
| 37 | * \param [in] fence The present fence given from the display |
| 38 | * \return True if the model needs more vsync signals to make |
| 39 | * an accurate prediction, |
| 40 | * False otherwise |
| 41 | */ |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 42 | virtual bool addPresentFence(std::shared_ptr<FenceTime>) = 0; |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 43 | |
| 44 | /* |
| 45 | * Adds a hw sync timestamp to the model. The controller will use the timestamp |
| 46 | * time as a vsync signal. |
| 47 | * |
| 48 | * \param [in] timestamp The HW Vsync timestamp |
| 49 | * \param [in] hwcVsyncPeriod The Vsync period reported by composer, if available |
| 50 | * \param [out] periodFlushed True if the vsync period changed is completed |
| 51 | * \return True if the model needs more vsync signals to make |
| 52 | * an accurate prediction, |
| 53 | * False otherwise |
| 54 | */ |
| 55 | virtual bool addHwVsyncTimestamp(nsecs_t timestamp, std::optional<nsecs_t> hwcVsyncPeriod, |
| 56 | bool* periodFlushed) = 0; |
| 57 | |
| 58 | /* |
| 59 | * Inform the controller that the period is changing and the controller needs to recalibrate |
| 60 | * itself. The controller will end the period transition internally. |
| 61 | * |
| 62 | * \param [in] period The period that the system is changing into. |
| 63 | */ |
| 64 | virtual void startPeriodTransition(nsecs_t period) = 0; |
| 65 | |
| 66 | /* |
| 67 | * Tells the tracker to stop using present fences to get a vsync signal. |
| 68 | * |
| 69 | * \param [in] ignore Whether to ignore the present fences or not |
| 70 | */ |
| 71 | virtual void setIgnorePresentFences(bool ignore) = 0; |
| 72 | |
| 73 | virtual void dump(std::string& result) const = 0; |
| 74 | |
| 75 | protected: |
| 76 | VsyncController() = default; |
| 77 | VsyncController(VsyncController const&) = delete; |
| 78 | VsyncController& operator=(VsyncController const&) = delete; |
| 79 | }; |
| 80 | |
| 81 | } // namespace android::scheduler |