Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | #ifndef ANDROID_GUI_FRAMETIMESTAMPS_H |
| 18 | #define ANDROID_GUI_FRAMETIMESTAMPS_H |
| 19 | |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 20 | #include <android/gui/FrameEvent.h> |
| 21 | |
Dominik Laskowski | 5a5e01e | 2022-07-08 07:52:44 -0700 | [diff] [blame] | 22 | #include <gui/CompositorTiming.h> |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 23 | #include <ui/FenceTime.h> |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 24 | #include <utils/Flattenable.h> |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 25 | #include <utils/StrongPointer.h> |
| 26 | #include <utils/Timers.h> |
| 27 | |
| 28 | #include <array> |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 29 | #include <bitset> |
| 30 | #include <vector> |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 31 | |
| 32 | namespace android { |
| 33 | |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 34 | struct FrameEvents; |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 35 | class FrameEventHistoryDelta; |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 36 | |
Dominik Laskowski | 5a5e01e | 2022-07-08 07:52:44 -0700 | [diff] [blame] | 37 | using gui::CompositorTiming; |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 38 | using gui::FrameEvent; |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 39 | |
| 40 | // A collection of timestamps corresponding to a single frame. |
| 41 | struct FrameEvents { |
Brian Anderson | ed816e6 | 2016-10-26 16:12:21 -0700 | [diff] [blame] | 42 | static constexpr auto EVENT_COUNT = |
| 43 | static_cast<size_t>(FrameEvent::EVENT_COUNT); |
| 44 | static_assert(EVENT_COUNT <= 32, "Event count sanity check failed."); |
Brian Anderson | dc96fdf | 2017-03-20 16:54:25 -0700 | [diff] [blame] | 45 | static constexpr nsecs_t TIMESTAMP_PENDING = -2; |
Brian Anderson | ed816e6 | 2016-10-26 16:12:21 -0700 | [diff] [blame] | 46 | |
| 47 | static inline bool isValidTimestamp(nsecs_t time) { |
| 48 | return time != TIMESTAMP_PENDING; |
| 49 | } |
| 50 | |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 51 | bool hasPostedInfo() const; |
| 52 | bool hasRequestedPresentInfo() const; |
| 53 | bool hasLatchInfo() const; |
| 54 | bool hasFirstRefreshStartInfo() const; |
| 55 | bool hasLastRefreshStartInfo() const; |
| 56 | bool hasAcquireInfo() const; |
| 57 | bool hasGpuCompositionDoneInfo() const; |
| 58 | bool hasDisplayPresentInfo() const; |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 59 | bool hasReleaseInfo() const; |
Brian Anderson | f638686 | 2016-10-31 16:34:13 -0700 | [diff] [blame] | 60 | bool hasDequeueReadyInfo() const; |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 61 | |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 62 | void checkFencesForCompletion(); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 63 | void dump(std::string& outString) const; |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 64 | |
| 65 | bool valid{false}; |
Brian Anderson | 5ea5e59 | 2016-12-01 16:54:33 -0800 | [diff] [blame] | 66 | int connectId{0}; |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 67 | uint64_t frameNumber{0}; |
| 68 | |
| 69 | // Whether or not certain points in the frame's life cycle have been |
| 70 | // encountered help us determine if timestamps aren't available because |
| 71 | // a) we'll just never get them or b) they're not ready yet. |
| 72 | bool addPostCompositeCalled{false}; |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 73 | bool addReleaseCalled{false}; |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 74 | |
Brian Anderson | ed816e6 | 2016-10-26 16:12:21 -0700 | [diff] [blame] | 75 | nsecs_t postedTime{TIMESTAMP_PENDING}; |
| 76 | nsecs_t requestedPresentTime{TIMESTAMP_PENDING}; |
| 77 | nsecs_t latchTime{TIMESTAMP_PENDING}; |
| 78 | nsecs_t firstRefreshStartTime{TIMESTAMP_PENDING}; |
| 79 | nsecs_t lastRefreshStartTime{TIMESTAMP_PENDING}; |
| 80 | nsecs_t dequeueReadyTime{TIMESTAMP_PENDING}; |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 81 | |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 82 | std::shared_ptr<FenceTime> acquireFence{FenceTime::NO_FENCE}; |
| 83 | std::shared_ptr<FenceTime> gpuCompositionDoneFence{FenceTime::NO_FENCE}; |
| 84 | std::shared_ptr<FenceTime> displayPresentFence{FenceTime::NO_FENCE}; |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 85 | std::shared_ptr<FenceTime> releaseFence{FenceTime::NO_FENCE}; |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 88 | // A short history of frames that are synchronized between the consumer and |
| 89 | // producer via deltas. |
| 90 | class FrameEventHistory { |
| 91 | public: |
David Stevens | 7347f0b | 2020-01-15 20:19:22 +0900 | [diff] [blame] | 92 | FrameEventHistory(); |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 93 | virtual ~FrameEventHistory(); |
| 94 | |
| 95 | FrameEvents* getFrame(uint64_t frameNumber); |
| 96 | FrameEvents* getFrame(uint64_t frameNumber, size_t* iHint); |
| 97 | void checkFencesForCompletion(); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 98 | void dump(std::string& outString) const; |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 99 | |
Brian Lindahl | 957985b | 2023-01-31 15:42:47 -0700 | [diff] [blame] | 100 | static const size_t INITIAL_MAX_FRAME_HISTORY; |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 101 | |
| 102 | protected: |
Brian Lindahl | 957985b | 2023-01-31 15:42:47 -0700 | [diff] [blame] | 103 | void resize(size_t newSize); |
| 104 | |
David Stevens | 7347f0b | 2020-01-15 20:19:22 +0900 | [diff] [blame] | 105 | std::vector<FrameEvents> mFrames; |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 106 | |
| 107 | CompositorTiming mCompositorTiming; |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | |
| 111 | // The producer's interface to FrameEventHistory |
| 112 | class ProducerFrameEventHistory : public FrameEventHistory { |
| 113 | public: |
| 114 | ~ProducerFrameEventHistory() override; |
| 115 | |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 116 | // Public for testing. |
| 117 | static nsecs_t snapToNextTick( |
| 118 | nsecs_t timestamp, nsecs_t tickPhase, nsecs_t tickInterval); |
Vishnu Nair | 9a69a04 | 2021-06-18 13:19:49 -0700 | [diff] [blame] | 119 | nsecs_t getReportedCompositeDeadline() const { return mCompositorTiming.deadline; }; |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 120 | |
| 121 | nsecs_t getNextCompositeDeadline(const nsecs_t now) const; |
| 122 | nsecs_t getCompositeInterval() const { return mCompositorTiming.interval; } |
| 123 | nsecs_t getCompositeToPresentLatency() const { |
| 124 | return mCompositorTiming.presentLatency; |
| 125 | } |
| 126 | |
Brian Anderson | 3da8d27 | 2016-07-28 16:20:47 -0700 | [diff] [blame] | 127 | // virtual for testing. |
| 128 | virtual void updateAcquireFence( |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 129 | uint64_t frameNumber, std::shared_ptr<FenceTime>&& acquire); |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 130 | void applyDelta(const FrameEventHistoryDelta& delta); |
| 131 | |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 132 | void updateSignalTimes(); |
| 133 | |
Brian Anderson | 3da8d27 | 2016-07-28 16:20:47 -0700 | [diff] [blame] | 134 | protected: |
| 135 | void applyFenceDelta(FenceTimeline* timeline, |
| 136 | std::shared_ptr<FenceTime>* dst, |
| 137 | const FenceTime::Snapshot& src) const; |
| 138 | |
| 139 | // virtual for testing. |
| 140 | virtual std::shared_ptr<FenceTime> createFenceTime( |
| 141 | const sp<Fence>& fence) const; |
| 142 | |
Brian Lindahl | 957985b | 2023-01-31 15:42:47 -0700 | [diff] [blame] | 143 | void resize(size_t newSize); |
| 144 | |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 145 | size_t mAcquireOffset{0}; |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 146 | |
| 147 | // The consumer updates it's timelines in Layer and SurfaceFlinger since |
| 148 | // they can coordinate shared timelines better. The producer doesn't have |
| 149 | // shared timelines though, so just let it own and update all of them. |
| 150 | FenceTimeline mAcquireTimeline; |
| 151 | FenceTimeline mGpuCompositionDoneTimeline; |
| 152 | FenceTimeline mPresentTimeline; |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 153 | FenceTimeline mReleaseTimeline; |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | |
| 157 | // Used by the consumer to create a new frame event record that is |
| 158 | // partially complete. |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 159 | struct NewFrameEventsEntry { |
| 160 | uint64_t frameNumber{0}; |
| 161 | nsecs_t postedTime{0}; |
| 162 | nsecs_t requestedPresentTime{0}; |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 163 | std::shared_ptr<FenceTime> acquireFence{FenceTime::NO_FENCE}; |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 164 | }; |
| 165 | |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 166 | // Used by the consumer to keep track of which fields it already sent to |
| 167 | // the producer. |
| 168 | class FrameEventDirtyFields { |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 169 | public: |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 170 | inline void reset() { mBitset.reset(); } |
| 171 | inline bool anyDirty() const { return mBitset.any(); } |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 172 | |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 173 | template <FrameEvent event> |
| 174 | inline void setDirty() { |
| 175 | constexpr size_t eventIndex = static_cast<size_t>(event); |
| 176 | static_assert(eventIndex < FrameEvents::EVENT_COUNT, "Bad index."); |
| 177 | mBitset.set(eventIndex); |
| 178 | } |
| 179 | |
| 180 | template <FrameEvent event> |
| 181 | inline bool isDirty() const { |
| 182 | constexpr size_t eventIndex = static_cast<size_t>(event); |
| 183 | static_assert(eventIndex < FrameEvents::EVENT_COUNT, "Bad index."); |
| 184 | return mBitset[eventIndex]; |
| 185 | } |
| 186 | |
| 187 | private: |
| 188 | std::bitset<FrameEvents::EVENT_COUNT> mBitset; |
| 189 | }; |
| 190 | |
| 191 | |
| 192 | // The consumer's interface to FrameEventHistory |
| 193 | class ConsumerFrameEventHistory : public FrameEventHistory { |
| 194 | public: |
David Stevens | 7347f0b | 2020-01-15 20:19:22 +0900 | [diff] [blame] | 195 | ConsumerFrameEventHistory(); |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 196 | ~ConsumerFrameEventHistory() override; |
| 197 | |
Brian Anderson | 5ea5e59 | 2016-12-01 16:54:33 -0800 | [diff] [blame] | 198 | void onDisconnect(); |
Valerie Hau | 0ca3f99 | 2020-01-30 16:07:35 -0800 | [diff] [blame] | 199 | void setProducerWantsEvents(); |
Brian Anderson | 5ea5e59 | 2016-12-01 16:54:33 -0800 | [diff] [blame] | 200 | |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 201 | void initializeCompositorTiming(const CompositorTiming& compositorTiming); |
| 202 | |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 203 | void addQueue(const NewFrameEventsEntry& newEntry); |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 204 | void addLatch(uint64_t frameNumber, nsecs_t latchTime); |
| 205 | void addPreComposition(uint64_t frameNumber, nsecs_t refreshStartTime); |
| 206 | void addPostComposition(uint64_t frameNumber, |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 207 | const std::shared_ptr<FenceTime>& gpuCompositionDone, |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 208 | const std::shared_ptr<FenceTime>& displayPresent, |
| 209 | const CompositorTiming& compositorTiming); |
Brian Anderson | f638686 | 2016-10-31 16:34:13 -0700 | [diff] [blame] | 210 | void addRelease(uint64_t frameNumber, nsecs_t dequeueReadyTime, |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 211 | std::shared_ptr<FenceTime>&& release); |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 212 | |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 213 | void getAndResetDelta(FrameEventHistoryDelta* delta); |
| 214 | |
Brian Lindahl | 957985b | 2023-01-31 15:42:47 -0700 | [diff] [blame] | 215 | void resize(size_t newSize); |
| 216 | |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 217 | private: |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 218 | void getFrameDelta(FrameEventHistoryDelta* delta, |
David Stevens | 7347f0b | 2020-01-15 20:19:22 +0900 | [diff] [blame] | 219 | const std::vector<FrameEvents>::iterator& frame); |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 220 | |
David Stevens | 7347f0b | 2020-01-15 20:19:22 +0900 | [diff] [blame] | 221 | std::vector<FrameEventDirtyFields> mFramesDirty; |
Brian Anderson | 5ea5e59 | 2016-12-01 16:54:33 -0800 | [diff] [blame] | 222 | |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 223 | size_t mQueueOffset{0}; |
| 224 | size_t mCompositionOffset{0}; |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 225 | size_t mReleaseOffset{0}; |
Brian Anderson | 4565daa | 2016-12-13 15:41:28 -0800 | [diff] [blame] | 226 | |
Brian Anderson | 5ea5e59 | 2016-12-01 16:54:33 -0800 | [diff] [blame] | 227 | int mCurrentConnectId{0}; |
Brian Anderson | 4565daa | 2016-12-13 15:41:28 -0800 | [diff] [blame] | 228 | bool mProducerWantsEvents{false}; |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 229 | }; |
| 230 | |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 231 | |
| 232 | // A single frame update from the consumer to producer that can be sent |
| 233 | // through Binder. |
| 234 | // Although this may be sent multiple times for the same frame as new |
| 235 | // timestamps are set, Fences only need to be sent once. |
| 236 | class FrameEventsDelta : public Flattenable<FrameEventsDelta> { |
| 237 | friend class ProducerFrameEventHistory; |
| 238 | public: |
| 239 | FrameEventsDelta() = default; |
| 240 | FrameEventsDelta(size_t index, |
| 241 | const FrameEvents& frameTimestamps, |
| 242 | const FrameEventDirtyFields& dirtyFields); |
| 243 | |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 244 | // Movable. |
| 245 | FrameEventsDelta(FrameEventsDelta&& src) = default; |
| 246 | FrameEventsDelta& operator=(FrameEventsDelta&& src) = default; |
| 247 | // Not copyable. |
| 248 | FrameEventsDelta(const FrameEventsDelta& src) = delete; |
| 249 | FrameEventsDelta& operator=(const FrameEventsDelta& src) = delete; |
| 250 | |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 251 | // Flattenable implementation |
| 252 | size_t getFlattenedSize() const; |
| 253 | size_t getFdCount() const; |
| 254 | status_t flatten(void*& buffer, size_t& size, int*& fds, |
| 255 | size_t& count) const; |
| 256 | status_t unflatten(void const*& buffer, size_t& size, int const*& fds, |
| 257 | size_t& count); |
| 258 | |
Brian Lindahl | 957985b | 2023-01-31 15:42:47 -0700 | [diff] [blame] | 259 | uint64_t getFrameNumber() const; |
| 260 | bool getLatchTime(nsecs_t* latchTime) const; |
| 261 | bool getDisplayPresentFence(sp<Fence>* fence) const; |
| 262 | |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 263 | private: |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 264 | static constexpr size_t minFlattenedSize(); |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 265 | |
| 266 | size_t mIndex{0}; |
| 267 | uint64_t mFrameNumber{0}; |
| 268 | |
| 269 | bool mAddPostCompositeCalled{0}; |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 270 | bool mAddReleaseCalled{0}; |
| 271 | |
Brian Anderson | ed816e6 | 2016-10-26 16:12:21 -0700 | [diff] [blame] | 272 | nsecs_t mPostedTime{FrameEvents::TIMESTAMP_PENDING}; |
| 273 | nsecs_t mRequestedPresentTime{FrameEvents::TIMESTAMP_PENDING}; |
| 274 | nsecs_t mLatchTime{FrameEvents::TIMESTAMP_PENDING}; |
| 275 | nsecs_t mFirstRefreshStartTime{FrameEvents::TIMESTAMP_PENDING}; |
| 276 | nsecs_t mLastRefreshStartTime{FrameEvents::TIMESTAMP_PENDING}; |
| 277 | nsecs_t mDequeueReadyTime{FrameEvents::TIMESTAMP_PENDING}; |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 278 | |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 279 | FenceTime::Snapshot mGpuCompositionDoneFence; |
| 280 | FenceTime::Snapshot mDisplayPresentFence; |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 281 | FenceTime::Snapshot mReleaseFence; |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 282 | |
| 283 | // This is a static method with an auto return value so we can call |
| 284 | // it without needing const and non-const versions. |
Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 285 | template <typename ThisT> |
| 286 | static inline auto allFences(ThisT fed) -> |
Brian Anderson | 4e606e3 | 2017-03-16 15:34:57 -0700 | [diff] [blame] | 287 | std::array<decltype(&fed->mReleaseFence), 3> { |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 288 | return {{ |
Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 289 | &fed->mGpuCompositionDoneFence, &fed->mDisplayPresentFence, |
Brian Anderson | 4e606e3 | 2017-03-16 15:34:57 -0700 | [diff] [blame] | 290 | &fed->mReleaseFence |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 291 | }}; |
| 292 | } |
| 293 | }; |
| 294 | |
| 295 | |
| 296 | // A collection of updates from consumer to producer that can be sent |
| 297 | // through Binder. |
| 298 | class FrameEventHistoryDelta |
| 299 | : public Flattenable<FrameEventHistoryDelta> { |
| 300 | |
| 301 | friend class ConsumerFrameEventHistory; |
| 302 | friend class ProducerFrameEventHistory; |
| 303 | |
| 304 | public: |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 305 | FrameEventHistoryDelta() = default; |
| 306 | |
| 307 | // Movable. |
| 308 | FrameEventHistoryDelta(FrameEventHistoryDelta&& src) = default; |
Chih-Hung Hsieh | 5bc849f | 2018-09-25 14:21:50 -0700 | [diff] [blame] | 309 | FrameEventHistoryDelta& operator=(FrameEventHistoryDelta&& src) noexcept; |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 310 | // Not copyable. |
| 311 | FrameEventHistoryDelta(const FrameEventHistoryDelta& src) = delete; |
| 312 | FrameEventHistoryDelta& operator=( |
| 313 | const FrameEventHistoryDelta& src) = delete; |
| 314 | |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 315 | // Flattenable implementation. |
| 316 | size_t getFlattenedSize() const; |
| 317 | size_t getFdCount() const; |
| 318 | status_t flatten(void*& buffer, size_t& size, int*& fds, |
| 319 | size_t& count) const; |
| 320 | status_t unflatten(void const*& buffer, size_t& size, int const*& fds, |
| 321 | size_t& count); |
| 322 | |
Brian Lindahl | 957985b | 2023-01-31 15:42:47 -0700 | [diff] [blame] | 323 | std::vector<FrameEventsDelta>::const_iterator begin() const; |
| 324 | std::vector<FrameEventsDelta>::const_iterator end() const; |
| 325 | |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 326 | private: |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 327 | static constexpr size_t minFlattenedSize(); |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 328 | |
| 329 | std::vector<FrameEventsDelta> mDeltas; |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 330 | CompositorTiming mCompositorTiming; |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 331 | }; |
| 332 | |
| 333 | |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 334 | } // namespace android |
| 335 | #endif |