Kevin DuBois | b2501ba | 2019-11-12 14:20:29 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 | |
Kevin DuBois | b2501ba | 2019-11-12 14:20:29 -0800 | [diff] [blame] | 19 | #include <memory> |
| 20 | #include <mutex> |
Kevin DuBois | f91e923 | 2019-11-21 10:51:23 -0800 | [diff] [blame] | 21 | #include <unordered_map> |
Kevin DuBois | b2501ba | 2019-11-12 14:20:29 -0800 | [diff] [blame] | 22 | #include <vector> |
Dominik Laskowski | 4e0d20d | 2021-12-06 11:31:02 -0800 | [diff] [blame] | 23 | |
| 24 | #include <android-base/thread_annotations.h> |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 25 | #include <ui/DisplayId.h> |
Dominik Laskowski | 4e0d20d | 2021-12-06 11:31:02 -0800 | [diff] [blame] | 26 | #include <ui/FenceTime.h> |
| 27 | |
| 28 | #include <scheduler/TimeKeeper.h> |
| 29 | |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame^] | 30 | #include "VSyncTracker.h" |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 31 | #include "VsyncController.h" |
Dominik Laskowski | 4e0d20d | 2021-12-06 11:31:02 -0800 | [diff] [blame] | 32 | |
Kevin DuBois | b2501ba | 2019-11-12 14:20:29 -0800 | [diff] [blame] | 33 | namespace android::scheduler { |
| 34 | |
Kevin DuBois | 2fd3cea | 2019-11-14 08:52:45 -0800 | [diff] [blame] | 35 | class Clock; |
Kevin DuBois | b2501ba | 2019-11-12 14:20:29 -0800 | [diff] [blame] | 36 | class VSyncDispatch; |
| 37 | class VSyncTracker; |
| 38 | |
| 39 | // TODO (b/145217110): consider renaming. |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 40 | class VSyncReactor : public VsyncController { |
Kevin DuBois | b2501ba | 2019-11-12 14:20:29 -0800 | [diff] [blame] | 41 | public: |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 42 | VSyncReactor(PhysicalDisplayId, std::unique_ptr<Clock> clock, VSyncTracker& tracker, |
| 43 | size_t pendingFenceLimit, bool supportKernelIdleTimer); |
Kevin DuBois | f91e923 | 2019-11-21 10:51:23 -0800 | [diff] [blame] | 44 | ~VSyncReactor(); |
Kevin DuBois | b2501ba | 2019-11-12 14:20:29 -0800 | [diff] [blame] | 45 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 46 | bool addPresentFence(std::shared_ptr<FenceTime>) final; |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 47 | void setIgnorePresentFences(bool ignore) final; |
Kevin DuBois | b2501ba | 2019-11-12 14:20:29 -0800 | [diff] [blame] | 48 | |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame^] | 49 | void onDisplayModeChanged(ftl::NonNull<DisplayModePtr>, bool force) final; |
Kevin DuBois | 2fd3cea | 2019-11-14 08:52:45 -0800 | [diff] [blame] | 50 | |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 51 | bool addHwVsyncTimestamp(nsecs_t timestamp, std::optional<nsecs_t> hwcVsyncPeriod, |
| 52 | bool* periodFlushed) final; |
Kevin DuBois | 0028738 | 2019-11-19 15:11:55 -0800 | [diff] [blame] | 53 | |
Rachel Lee | 6a9731d | 2022-06-06 17:08:14 -0700 | [diff] [blame] | 54 | void setDisplayPowerMode(hal::PowerMode powerMode) final; |
| 55 | |
Kevin DuBois | 0028738 | 2019-11-19 15:11:55 -0800 | [diff] [blame] | 56 | void dump(std::string& result) const final; |
Kevin DuBois | f91e923 | 2019-11-21 10:51:23 -0800 | [diff] [blame] | 57 | |
Kevin DuBois | b2501ba | 2019-11-12 14:20:29 -0800 | [diff] [blame] | 58 | private: |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 59 | void setIgnorePresentFencesInternal(bool ignore) REQUIRES(mMutex); |
Kevin DuBois | 02d5ed9 | 2020-01-27 11:05:46 -0800 | [diff] [blame] | 60 | void updateIgnorePresentFencesInternal() REQUIRES(mMutex); |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame^] | 61 | void startPeriodTransitionInternal(ftl::NonNull<DisplayModePtr>) REQUIRES(mMutex); |
Kevin DuBois | c4cdd37 | 2020-01-09 14:12:02 -0800 | [diff] [blame] | 62 | void endPeriodTransition() REQUIRES(mMutex); |
Ady Abraham | 5dee2f1 | 2020-02-05 17:49:47 -0800 | [diff] [blame] | 63 | bool periodConfirmed(nsecs_t vsync_timestamp, std::optional<nsecs_t> hwcVsyncPeriod) |
| 64 | REQUIRES(mMutex); |
Kevin DuBois | f77025c | 2019-12-18 16:13:24 -0800 | [diff] [blame] | 65 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 66 | const PhysicalDisplayId mId; |
Kevin DuBois | 2fd3cea | 2019-11-14 08:52:45 -0800 | [diff] [blame] | 67 | std::unique_ptr<Clock> const mClock; |
Ady Abraham | 5a85855 | 2020-03-31 17:54:56 -0700 | [diff] [blame] | 68 | VSyncTracker& mTracker; |
Kevin DuBois | b2501ba | 2019-11-12 14:20:29 -0800 | [diff] [blame] | 69 | size_t const mPendingLimit; |
| 70 | |
Ady Abraham | 5e7371c | 2020-03-24 14:47:24 -0700 | [diff] [blame] | 71 | mutable std::mutex mMutex; |
Kevin DuBois | 02d5ed9 | 2020-01-27 11:05:46 -0800 | [diff] [blame] | 72 | bool mInternalIgnoreFences GUARDED_BY(mMutex) = false; |
| 73 | bool mExternalIgnoreFences GUARDED_BY(mMutex) = false; |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 74 | std::vector<std::shared_ptr<android::FenceTime>> mUnfiredFences GUARDED_BY(mMutex); |
Kevin DuBois | f77025c | 2019-12-18 16:13:24 -0800 | [diff] [blame] | 75 | |
| 76 | bool mMoreSamplesNeeded GUARDED_BY(mMutex) = false; |
Kevin DuBois | 02d5ed9 | 2020-01-27 11:05:46 -0800 | [diff] [blame] | 77 | bool mPeriodConfirmationInProgress GUARDED_BY(mMutex) = false; |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame^] | 78 | DisplayModePtr mModePtrTransitioningTo GUARDED_BY(mMutex); |
Kevin DuBois | f77025c | 2019-12-18 16:13:24 -0800 | [diff] [blame] | 79 | std::optional<nsecs_t> mLastHwVsync GUARDED_BY(mMutex); |
| 80 | |
Rachel Lee | 6a9731d | 2022-06-06 17:08:14 -0700 | [diff] [blame] | 81 | hal::PowerMode mDisplayPowerMode GUARDED_BY(mMutex) = hal::PowerMode::ON; |
| 82 | |
Dan Stoza | 027d365 | 2020-05-26 17:26:34 -0700 | [diff] [blame] | 83 | const bool mSupportKernelIdleTimer = false; |
Kevin DuBois | b2501ba | 2019-11-12 14:20:29 -0800 | [diff] [blame] | 84 | }; |
| 85 | |
Kevin DuBois | 0028738 | 2019-11-19 15:11:55 -0800 | [diff] [blame] | 86 | class SystemClock : public Clock { |
| 87 | nsecs_t now() const final; |
| 88 | }; |
| 89 | |
Kevin DuBois | b2501ba | 2019-11-12 14:20:29 -0800 | [diff] [blame] | 90 | } // namespace android::scheduler |