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