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 19 #include <memory> 20 #include <mutex> 21 #include <unordered_map> 22 #include <vector> 23 24 #include <android-base/thread_annotations.h> 25 #include <ui/FenceTime.h> 26 27 #include <scheduler/TimeKeeper.h> 28 29 #include "VsyncController.h" 30 31 namespace android::scheduler { 32 33 class Clock; 34 class VSyncDispatch; 35 class VSyncTracker; 36 37 // TODO (b/145217110): consider renaming. 38 class VSyncReactor : public VsyncController { 39 public: 40 VSyncReactor(std::unique_ptr<Clock> clock, VSyncTracker& tracker, size_t pendingFenceLimit, 41 bool supportKernelIdleTimer); 42 ~VSyncReactor(); 43 44 bool addPresentFence(std::shared_ptr<FenceTime>) final; 45 void setIgnorePresentFences(bool ignore) final; 46 47 void startPeriodTransition(nsecs_t period) final; 48 49 bool addHwVsyncTimestamp(nsecs_t timestamp, std::optional<nsecs_t> hwcVsyncPeriod, 50 bool* periodFlushed) final; 51 52 void setDisplayPowerMode(hal::PowerMode powerMode) final; 53 54 void dump(std::string& result) const final; 55 56 private: 57 void setIgnorePresentFencesInternal(bool ignore) REQUIRES(mMutex); 58 void updateIgnorePresentFencesInternal() REQUIRES(mMutex); 59 void startPeriodTransitionInternal(nsecs_t newPeriod) REQUIRES(mMutex); 60 void endPeriodTransition() REQUIRES(mMutex); 61 bool periodConfirmed(nsecs_t vsync_timestamp, std::optional<nsecs_t> hwcVsyncPeriod) 62 REQUIRES(mMutex); 63 64 std::unique_ptr<Clock> const mClock; 65 VSyncTracker& mTracker; 66 size_t const mPendingLimit; 67 68 mutable std::mutex mMutex; 69 bool mInternalIgnoreFences GUARDED_BY(mMutex) = false; 70 bool mExternalIgnoreFences GUARDED_BY(mMutex) = false; 71 std::vector<std::shared_ptr<android::FenceTime>> mUnfiredFences GUARDED_BY(mMutex); 72 73 bool mMoreSamplesNeeded GUARDED_BY(mMutex) = false; 74 bool mPeriodConfirmationInProgress GUARDED_BY(mMutex) = false; 75 std::optional<nsecs_t> mPeriodTransitioningTo GUARDED_BY(mMutex); 76 std::optional<nsecs_t> mLastHwVsync GUARDED_BY(mMutex); 77 78 hal::PowerMode mDisplayPowerMode GUARDED_BY(mMutex) = hal::PowerMode::ON; 79 80 const bool mSupportKernelIdleTimer = false; 81 }; 82 83 class SystemClock : public Clock { 84 nsecs_t now() const final; 85 }; 86 87 } // namespace android::scheduler 88