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