| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright 2018 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 <cstdint> | 
| Kevin DuBois | 413287f | 2019-02-25 08:46:47 -0800 | [diff] [blame] | 20 | #include <functional> | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 21 | #include <memory> | 
|  | 22 |  | 
| Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 23 | #include <ui/DisplayStatInfo.h> | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 24 | #include <ui/GraphicTypes.h> | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 25 |  | 
|  | 26 | #include "DispSync.h" | 
| Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 27 | #include "EventControlThread.h" | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 28 | #include "EventThread.h" | 
|  | 29 | #include "InjectVSyncSource.h" | 
| Ana Krulec | 3084c05 | 2018-11-21 20:27:17 +0100 | [diff] [blame] | 30 | #include "LayerHistory.h" | 
| Ana Krulec | f2c006d | 2019-06-21 15:37:07 -0700 | [diff] [blame] | 31 | #include "OneShotTimer.h" | 
| Ana Krulec | 8d3e4f3 | 2019-03-05 10:40:33 -0800 | [diff] [blame] | 32 | #include "RefreshRateConfigs.h" | 
| Ana Krulec | 434c22d | 2018-11-28 13:48:36 +0100 | [diff] [blame] | 33 | #include "SchedulerUtils.h" | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 34 |  | 
|  | 35 | namespace android { | 
|  | 36 |  | 
| Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 37 | class EventControlThread; | 
|  | 38 |  | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 39 | class Scheduler { | 
|  | 40 | public: | 
| Ana Krulec | 8d3e4f3 | 2019-03-05 10:40:33 -0800 | [diff] [blame] | 41 | // Enum to keep track of whether we trigger event to notify choreographer of config changes. | 
|  | 42 | enum class ConfigEvent { None, Changed }; | 
|  | 43 |  | 
|  | 44 | // logical or operator with the semantics of at least one of the events is Changed | 
|  | 45 | friend ConfigEvent operator|(const ConfigEvent& first, const ConfigEvent& second) { | 
|  | 46 | if (first == ConfigEvent::Changed) return ConfigEvent::Changed; | 
|  | 47 | if (second == ConfigEvent::Changed) return ConfigEvent::Changed; | 
|  | 48 | return ConfigEvent::None; | 
|  | 49 | } | 
|  | 50 |  | 
|  | 51 | using RefreshRateType = scheduler::RefreshRateConfigs::RefreshRateType; | 
| Alec Mouri | 7f01518 | 2019-07-11 13:56:22 -0700 | [diff] [blame] | 52 | using GetCurrentRefreshRateTypeCallback = std::function<RefreshRateType()>; | 
| Ana Krulec | 8d3e4f3 | 2019-03-05 10:40:33 -0800 | [diff] [blame] | 53 | using ChangeRefreshRateCallback = std::function<void(RefreshRateType, ConfigEvent)>; | 
| Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 54 | using GetVsyncPeriod = std::function<nsecs_t()>; | 
| Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 55 |  | 
| Ana Krulec | 7ecce8c | 2018-10-12 13:44:41 -0700 | [diff] [blame] | 56 | // Enum to indicate whether to start the transaction early, or at vsync time. | 
|  | 57 | enum class TransactionStart { EARLY, NORMAL }; | 
|  | 58 |  | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 59 | /* The scheduler handle is a BBinder object passed to the client from which we can extract | 
|  | 60 | * an ID for subsequent operations. | 
|  | 61 | */ | 
|  | 62 | class ConnectionHandle : public BBinder { | 
|  | 63 | public: | 
|  | 64 | ConnectionHandle(int64_t id) : id(id) {} | 
| Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 65 |  | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 66 | ~ConnectionHandle() = default; | 
| Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 67 |  | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 68 | const int64_t id; | 
|  | 69 | }; | 
|  | 70 |  | 
|  | 71 | class Connection { | 
|  | 72 | public: | 
| Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 73 | Connection(sp<ConnectionHandle> handle, sp<EventThreadConnection> eventConnection, | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 74 | std::unique_ptr<EventThread> eventThread) | 
|  | 75 | : handle(handle), eventConnection(eventConnection), thread(std::move(eventThread)) {} | 
| Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 76 |  | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 77 | ~Connection() = default; | 
|  | 78 |  | 
|  | 79 | sp<ConnectionHandle> handle; | 
| Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 80 | sp<EventThreadConnection> eventConnection; | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 81 | const std::unique_ptr<EventThread> thread; | 
|  | 82 | }; | 
|  | 83 |  | 
| Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 84 | // Stores per-display state about VSYNC. | 
|  | 85 | struct VsyncState { | 
|  | 86 | explicit VsyncState(Scheduler& scheduler) : scheduler(scheduler) {} | 
|  | 87 |  | 
|  | 88 | void resync(const GetVsyncPeriod&); | 
|  | 89 |  | 
|  | 90 | Scheduler& scheduler; | 
|  | 91 | std::atomic<nsecs_t> lastResyncTime = 0; | 
|  | 92 | }; | 
|  | 93 |  | 
| Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 94 | explicit Scheduler(impl::EventControlThread::SetVSyncEnabledFunction function, | 
|  | 95 | const scheduler::RefreshRateConfigs& refreshRateConfig); | 
| Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 96 |  | 
| Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 97 | virtual ~Scheduler(); | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 98 |  | 
|  | 99 | /** Creates an EventThread connection. */ | 
| Ady Abraham | 45e4e36 | 2019-06-07 18:20:51 -0700 | [diff] [blame] | 100 | sp<ConnectionHandle> createConnection(const char* connectionName, nsecs_t phaseOffsetNs, | 
|  | 101 | nsecs_t offsetThresholdForNextVsync, ResyncCallback, | 
| Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 102 | impl::EventThread::InterceptVSyncsCallback); | 
| Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 103 |  | 
| Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 104 | sp<IDisplayEventConnection> createDisplayEventConnection( | 
|  | 105 | const sp<ConnectionHandle>& handle, ResyncCallback, | 
|  | 106 | ISurfaceComposer::ConfigChanged configChanged); | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 107 |  | 
|  | 108 | // Getter methods. | 
|  | 109 | EventThread* getEventThread(const sp<ConnectionHandle>& handle); | 
| Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 110 |  | 
| Kevin DuBois | 413287f | 2019-02-25 08:46:47 -0800 | [diff] [blame] | 111 | // Provides access to the DispSync object for the primary display. | 
|  | 112 | void withPrimaryDispSync(std::function<void(DispSync&)> const& fn); | 
|  | 113 |  | 
| Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 114 | sp<EventThreadConnection> getEventConnection(const sp<ConnectionHandle>& handle); | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 115 |  | 
|  | 116 | // Should be called when receiving a hotplug event. | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 117 | void hotplugReceived(const sp<ConnectionHandle>& handle, PhysicalDisplayId displayId, | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 118 | bool connected); | 
| Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 119 |  | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 120 | // Should be called after the screen is turned on. | 
|  | 121 | void onScreenAcquired(const sp<ConnectionHandle>& handle); | 
| Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 122 |  | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 123 | // Should be called before the screen is turned off. | 
|  | 124 | void onScreenReleased(const sp<ConnectionHandle>& handle); | 
| Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 125 |  | 
| Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 126 | // Should be called when display config changed | 
|  | 127 | void onConfigChanged(const sp<ConnectionHandle>& handle, PhysicalDisplayId displayId, | 
|  | 128 | int32_t configId); | 
|  | 129 |  | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 130 | // Should be called when dumpsys command is received. | 
| Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 131 | void dump(const sp<ConnectionHandle>& handle, std::string& result) const; | 
| Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 132 |  | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 133 | // Offers ability to modify phase offset in the event thread. | 
|  | 134 | void setPhaseOffset(const sp<ConnectionHandle>& handle, nsecs_t phaseOffset); | 
|  | 135 |  | 
| Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 136 | void getDisplayStatInfo(DisplayStatInfo* stats); | 
|  | 137 |  | 
|  | 138 | void enableHardwareVsync(); | 
|  | 139 | void disableHardwareVsync(bool makeUnavailable); | 
| Alec Mouri | f8e689c | 2019-05-20 18:32:22 -0700 | [diff] [blame] | 140 | // Resyncs the scheduler to hardware vsync. | 
|  | 141 | // If makeAvailable is true, then hardware vsync will be turned on. | 
|  | 142 | // Otherwise, if hardware vsync is not already enabled then this method will | 
|  | 143 | // no-op. | 
|  | 144 | // The period is the vsync period from the current display configuration. | 
| Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 145 | void resyncToHardwareVsync(bool makeAvailable, nsecs_t period); | 
|  | 146 | // Creates a callback for resyncing. | 
|  | 147 | ResyncCallback makeResyncCallback(GetVsyncPeriod&& getVsyncPeriod); | 
|  | 148 | void setRefreshSkipCount(int count); | 
| Alec Mouri | f8e689c | 2019-05-20 18:32:22 -0700 | [diff] [blame] | 149 | // Passes a vsync sample to DispSync. periodFlushed will be true if | 
|  | 150 | // DispSync detected that the vsync period changed, and false otherwise. | 
|  | 151 | void addResyncSample(const nsecs_t timestamp, bool* periodFlushed); | 
| Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 152 | void addPresentFence(const std::shared_ptr<FenceTime>& fenceTime); | 
|  | 153 | void setIgnorePresentFences(bool ignore); | 
| Ady Abraham | 8fe1102 | 2019-06-12 17:11:12 -0700 | [diff] [blame] | 154 | nsecs_t getDispSyncExpectedPresentTime(); | 
| Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 155 | // Registers the layer in the scheduler, and returns the handle for future references. | 
| Ady Abraham | 8f1ee7f | 2019-04-05 10:32:50 -0700 | [diff] [blame] | 156 | std::unique_ptr<scheduler::LayerHistory::LayerHandle> registerLayer(std::string const& name, | 
|  | 157 | int windowType); | 
|  | 158 |  | 
| Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 159 | // Stores present time for a layer. | 
| Ady Abraham | a315ce7 | 2019-04-24 14:35:20 -0700 | [diff] [blame] | 160 | void addLayerPresentTimeAndHDR( | 
| Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 161 | const std::unique_ptr<scheduler::LayerHistory::LayerHandle>& layerHandle, | 
| Ady Abraham | a315ce7 | 2019-04-24 14:35:20 -0700 | [diff] [blame] | 162 | nsecs_t presentTime, bool isHDR); | 
|  | 163 | // Stores visibility for a layer. | 
|  | 164 | void setLayerVisibility( | 
|  | 165 | const std::unique_ptr<scheduler::LayerHistory::LayerHandle>& layerHandle, bool visible); | 
| Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 166 | // Updates FPS based on the most content presented. | 
|  | 167 | void updateFpsBasedOnContent(); | 
| Ana Krulec | 8d3e4f3 | 2019-03-05 10:40:33 -0800 | [diff] [blame] | 168 | // Callback that gets invoked when Scheduler wants to change the refresh rate. | 
| Alec Mouri | 7f01518 | 2019-07-11 13:56:22 -0700 | [diff] [blame] | 169 | void setChangeRefreshRateCallback(const ChangeRefreshRateCallback&& changeRefreshRateCallback); | 
|  | 170 | void setGetCurrentRefreshRateTypeCallback( | 
|  | 171 | const GetCurrentRefreshRateTypeCallback&& getCurrentRefreshRateType); | 
| Alec Mouri | dc28b37 | 2019-04-18 21:17:13 -0700 | [diff] [blame] | 172 | void setGetVsyncPeriodCallback(const GetVsyncPeriod&& getVsyncPeriod); | 
| Ady Abraham | 97d0423 | 2019-03-05 19:48:12 -0800 | [diff] [blame] | 173 |  | 
|  | 174 | // Returns whether idle timer is enabled or not | 
|  | 175 | bool isIdleTimerEnabled() { return mSetIdleTimerMs > 0; } | 
| Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 176 |  | 
| Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 177 | // Function that resets the idle timer. | 
|  | 178 | void resetIdleTimer(); | 
|  | 179 |  | 
|  | 180 | // Function that resets the touch timer. | 
|  | 181 | void notifyTouchEvent(); | 
|  | 182 |  | 
| Ady Abraham | 6fe2c17 | 2019-07-12 12:37:57 -0700 | [diff] [blame] | 183 | // Function that sets whether display power mode is normal or not. | 
|  | 184 | void setDisplayPowerState(bool normal); | 
|  | 185 |  | 
| Ana Krulec | b43429d | 2019-01-09 14:28:51 -0800 | [diff] [blame] | 186 | // Returns relevant information about Scheduler for dumpsys purposes. | 
|  | 187 | std::string doDump(); | 
| Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 188 |  | 
| Ady Abraham | 3aff917 | 2019-02-07 19:10:26 -0800 | [diff] [blame] | 189 | // calls DispSync::dump() on primary disp sync | 
|  | 190 | void dumpPrimaryDispSync(std::string& result) const; | 
|  | 191 |  | 
| Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 192 | protected: | 
|  | 193 | virtual std::unique_ptr<EventThread> makeEventThread( | 
| Ady Abraham | 45e4e36 | 2019-06-07 18:20:51 -0700 | [diff] [blame] | 194 | const char* connectionName, DispSync* dispSync, nsecs_t phaseOffsetNs, | 
|  | 195 | nsecs_t offsetThresholdForNextVsync, | 
| Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 196 | impl::EventThread::InterceptVSyncsCallback interceptCallback); | 
|  | 197 |  | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 198 | private: | 
| Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 199 | friend class TestableScheduler; | 
|  | 200 |  | 
| Ana Krulec | fefd6ae | 2019-02-13 17:53:08 -0800 | [diff] [blame] | 201 | // In order to make sure that the features don't override themselves, we need a state machine | 
|  | 202 | // to keep track which feature requested the config change. | 
| Dominik Laskowski | dd252cd | 2019-07-26 09:10:16 -0700 | [diff] [blame] | 203 | enum class ContentDetectionState { Off, On }; | 
|  | 204 | enum class TimerState { Reset, Expired }; | 
|  | 205 | enum class TouchState { Inactive, Active }; | 
| Ana Krulec | fefd6ae | 2019-02-13 17:53:08 -0800 | [diff] [blame] | 206 |  | 
| Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 207 | // Creates a connection on the given EventThread and forwards the given callbacks. | 
| Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 208 | sp<EventThreadConnection> createConnectionInternal(EventThread*, ResyncCallback&&, | 
|  | 209 | ISurfaceComposer::ConfigChanged); | 
| Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 210 |  | 
| Ana Krulec | 7ab5603 | 2018-11-02 20:51:06 +0100 | [diff] [blame] | 211 | nsecs_t calculateAverage() const; | 
|  | 212 | void updateFrameSkipping(const int64_t skipCount); | 
| Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 213 |  | 
| Dominik Laskowski | 3a80a38 | 2019-07-25 11:16:07 -0700 | [diff] [blame] | 214 | // Update feature state machine to given state when corresponding timer resets or expires. | 
|  | 215 | void kernelIdleTimerCallback(TimerState); | 
|  | 216 | void idleTimerCallback(TimerState); | 
|  | 217 | void touchTimerCallback(TimerState); | 
|  | 218 | void displayPowerTimerCallback(TimerState); | 
|  | 219 |  | 
| Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 220 | // Sets vsync period. | 
|  | 221 | void setVsyncPeriod(const nsecs_t period); | 
| Ady Abraham | 6fe2c17 | 2019-07-12 12:37:57 -0700 | [diff] [blame] | 222 | // handles various timer features to change the refresh rate. | 
|  | 223 | template <class T> | 
|  | 224 | void handleTimerStateChanged(T* currentState, T newState, bool eventOnContentDetection); | 
| Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 225 | // Calculate the new refresh rate type | 
|  | 226 | RefreshRateType calculateRefreshRateType() REQUIRES(mFeatureStateLock); | 
| Ana Krulec | fefd6ae | 2019-02-13 17:53:08 -0800 | [diff] [blame] | 227 | // Acquires a lock and calls the ChangeRefreshRateCallback() with given parameters. | 
|  | 228 | void changeRefreshRate(RefreshRateType refreshRateType, ConfigEvent configEvent); | 
| Ana Krulec | 7ab5603 | 2018-11-02 20:51:06 +0100 | [diff] [blame] | 229 |  | 
| Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 230 | // Helper function to calculate error frames | 
|  | 231 | float getErrorFrames(float contentFps, float configFps); | 
|  | 232 |  | 
| Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 233 | // If fences from sync Framework are supported. | 
|  | 234 | const bool mHasSyncFramework; | 
|  | 235 |  | 
|  | 236 | // The offset in nanoseconds to use, when DispSync timestamps present fence | 
|  | 237 | // signaling time. | 
| Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 238 | nsecs_t mDispSyncPresentTimeOffset; | 
| Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 239 |  | 
|  | 240 | // Each connection has it's own ID. This variable keeps track of the count. | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 241 | static std::atomic<int64_t> sNextId; | 
| Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 242 |  | 
|  | 243 | // Connections are stored in a map <connection ID, connection> for easy retrieval. | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 244 | std::unordered_map<int64_t, std::unique_ptr<Connection>> mConnections; | 
| Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 245 |  | 
|  | 246 | std::mutex mHWVsyncLock; | 
|  | 247 | bool mPrimaryHWVsyncEnabled GUARDED_BY(mHWVsyncLock); | 
|  | 248 | bool mHWVsyncAvailable GUARDED_BY(mHWVsyncLock); | 
| Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 249 | const std::shared_ptr<VsyncState> mPrimaryVsyncState{std::make_shared<VsyncState>(*this)}; | 
| Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 250 |  | 
|  | 251 | std::unique_ptr<DispSync> mPrimaryDispSync; | 
|  | 252 | std::unique_ptr<EventControlThread> mEventControlThread; | 
| Ana Krulec | 7ab5603 | 2018-11-02 20:51:06 +0100 | [diff] [blame] | 253 |  | 
|  | 254 | // TODO(b/113612090): The following set of variables needs to be revised. For now, this is | 
|  | 255 | // a proof of concept. We turn on frame skipping if the difference between the timestamps | 
|  | 256 | // is between 32 and 34ms. We expect this currently for 30fps videos, so we render them at 30Hz. | 
|  | 257 | nsecs_t mPreviousFrameTimestamp = 0; | 
|  | 258 | // Keeping track of whether we are skipping the refresh count. If we want to | 
|  | 259 | // simulate 30Hz rendering, we skip every other frame, and this variable is set | 
|  | 260 | // to 1. | 
|  | 261 | int64_t mSkipCount = 0; | 
| Ana Krulec | 434c22d | 2018-11-28 13:48:36 +0100 | [diff] [blame] | 262 | std::array<int64_t, scheduler::ARRAY_SIZE> mTimeDifferences{}; | 
| Ana Krulec | 7ab5603 | 2018-11-02 20:51:06 +0100 | [diff] [blame] | 263 | size_t mCounter = 0; | 
| Ana Krulec | 3084c05 | 2018-11-21 20:27:17 +0100 | [diff] [blame] | 264 |  | 
| Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 265 | // Historical information about individual layers. Used for predicting the refresh rate. | 
|  | 266 | scheduler::LayerHistory mLayerHistory; | 
| Ana Krulec | fb77282 | 2018-11-30 10:44:07 +0100 | [diff] [blame] | 267 |  | 
|  | 268 | // Timer that records time between requests for next vsync. If the time is higher than a given | 
|  | 269 | // interval, a callback is fired. Set this variable to >0 to use this feature. | 
|  | 270 | int64_t mSetIdleTimerMs = 0; | 
| Ana Krulec | f2c006d | 2019-06-21 15:37:07 -0700 | [diff] [blame] | 271 | std::unique_ptr<scheduler::OneShotTimer> mIdleTimer; | 
| Alec Mouri | dc28b37 | 2019-04-18 21:17:13 -0700 | [diff] [blame] | 272 | // Enables whether to use idle timer callbacks that support the kernel | 
|  | 273 | // timer. | 
|  | 274 | bool mSupportKernelTimer; | 
| Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 275 |  | 
| Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 276 | // Timer used to monitor touch events. | 
|  | 277 | int64_t mSetTouchTimerMs = 0; | 
| Ana Krulec | f2c006d | 2019-06-21 15:37:07 -0700 | [diff] [blame] | 278 | std::unique_ptr<scheduler::OneShotTimer> mTouchTimer; | 
| Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 279 |  | 
| Ady Abraham | 6fe2c17 | 2019-07-12 12:37:57 -0700 | [diff] [blame] | 280 | // Timer used to monitor display power mode. | 
|  | 281 | int64_t mSetDisplayPowerTimerMs = 0; | 
|  | 282 | std::unique_ptr<scheduler::OneShotTimer> mDisplayPowerTimer; | 
|  | 283 |  | 
| Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 284 | std::mutex mCallbackLock; | 
| Alec Mouri | 7f01518 | 2019-07-11 13:56:22 -0700 | [diff] [blame] | 285 | GetCurrentRefreshRateTypeCallback mGetCurrentRefreshRateTypeCallback GUARDED_BY(mCallbackLock); | 
| Ana Krulec | 8d3e4f3 | 2019-03-05 10:40:33 -0800 | [diff] [blame] | 286 | ChangeRefreshRateCallback mChangeRefreshRateCallback GUARDED_BY(mCallbackLock); | 
| Alec Mouri | dc28b37 | 2019-04-18 21:17:13 -0700 | [diff] [blame] | 287 | GetVsyncPeriod mGetVsyncPeriod GUARDED_BY(mCallbackLock); | 
| Ana Krulec | fefd6ae | 2019-02-13 17:53:08 -0800 | [diff] [blame] | 288 |  | 
|  | 289 | // In order to make sure that the features don't override themselves, we need a state machine | 
|  | 290 | // to keep track which feature requested the config change. | 
|  | 291 | std::mutex mFeatureStateLock; | 
| Dominik Laskowski | dd252cd | 2019-07-26 09:10:16 -0700 | [diff] [blame] | 292 |  | 
|  | 293 | struct { | 
|  | 294 | ContentDetectionState contentDetection = ContentDetectionState::Off; | 
|  | 295 | TimerState idleTimer = TimerState::Reset; | 
|  | 296 | TouchState touch = TouchState::Inactive; | 
|  | 297 | TimerState displayPowerTimer = TimerState::Expired; | 
|  | 298 |  | 
|  | 299 | RefreshRateType refreshRateType = RefreshRateType::DEFAULT; | 
|  | 300 | uint32_t contentRefreshRate = 0; | 
|  | 301 |  | 
|  | 302 | bool isHDRContent = false; | 
|  | 303 | bool isDisplayPowerStateNormal = true; | 
|  | 304 | } mFeatures GUARDED_BY(mFeatureStateLock); | 
| Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 305 |  | 
|  | 306 | const scheduler::RefreshRateConfigs& mRefreshRateConfigs; | 
| Ady Abraham | a315ce7 | 2019-04-24 14:35:20 -0700 | [diff] [blame] | 307 |  | 
|  | 308 | // Global config to force HDR content to work on DEFAULT refreshRate | 
| Ady Abraham | 8444c36 | 2019-05-30 17:59:36 -0700 | [diff] [blame] | 309 | static constexpr bool mForceHDRContentToDefaultRefreshRate = false; | 
| Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 310 | }; | 
|  | 311 |  | 
| Ana Krulec | 7ab5603 | 2018-11-02 20:51:06 +0100 | [diff] [blame] | 312 | } // namespace android |