blob: 6d3bd6ca23829268f7bface3d65e741d241a7905 [file] [log] [blame]
Pablo Ceballosce796e72016-02-04 19:10:51 -08001/*
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
Brian Andersond6927fb2016-07-23 23:37:30 -070020#include <ui/Fence.h>
Pablo Ceballosce796e72016-02-04 19:10:51 -080021#include <utils/Flattenable.h>
Brian Andersond6927fb2016-07-23 23:37:30 -070022#include <utils/StrongPointer.h>
23#include <utils/Timers.h>
24
25#include <array>
Pablo Ceballosce796e72016-02-04 19:10:51 -080026
27namespace android {
28
Brian Andersond6927fb2016-07-23 23:37:30 -070029
30struct FrameEvents;
31class String8;
32
33
Brian Anderson069b3652016-07-22 10:32:47 -070034enum class SupportableFrameTimestamps {
35 REQUESTED_PRESENT,
36 ACQUIRE,
37 REFRESH_START,
38 GL_COMPOSITION_DONE_TIME,
39 DISPLAY_PRESENT_TIME,
40 DISPLAY_RETIRE_TIME,
41 RELEASE_TIME,
42};
Pablo Ceballosce796e72016-02-04 19:10:51 -080043
Brian Andersond6927fb2016-07-23 23:37:30 -070044
45// The timestamps the consumer sends to the producer over binder.
Brian Anderson069b3652016-07-22 10:32:47 -070046struct FrameTimestamps : public LightFlattenablePod<FrameTimestamps> {
Brian Andersond6927fb2016-07-23 23:37:30 -070047 FrameTimestamps() = default;
48 explicit FrameTimestamps(const FrameEvents& fences);
49
Brian Anderson069b3652016-07-22 10:32:47 -070050 uint64_t frameNumber{0};
Brian Andersond6927fb2016-07-23 23:37:30 -070051 nsecs_t postedTime{0};
Brian Anderson069b3652016-07-22 10:32:47 -070052 nsecs_t requestedPresentTime{0};
53 nsecs_t acquireTime{0};
54 nsecs_t refreshStartTime{0};
55 nsecs_t glCompositionDoneTime{0};
56 nsecs_t displayPresentTime{0};
57 nsecs_t displayRetireTime{0};
58 nsecs_t releaseTime{0};
Pablo Ceballosce796e72016-02-04 19:10:51 -080059};
60
Brian Andersond6927fb2016-07-23 23:37:30 -070061
62// A collection of timestamps corresponding to a single frame.
63struct FrameEvents {
64 void checkFencesForCompletion();
65 void dump(String8& outString) const;
66
67 bool valid{false};
68 uint64_t frameNumber{0};
69
70 // Whether or not certain points in the frame's life cycle have been
71 // encountered help us determine if timestamps aren't available because
72 // a) we'll just never get them or b) they're not ready yet.
73 bool addPostCompositeCalled{false};
74 bool addRetireCalled{false};
75
76 nsecs_t postedTime{0};
77 nsecs_t requestedPresentTime{0};
78 nsecs_t latchTime{0};
79 nsecs_t firstRefreshStartTime{0};
80 nsecs_t lastRefreshStartTime{0};
81
82 nsecs_t acquireTime{0};
83 nsecs_t gpuCompositionDoneTime{0};
84 nsecs_t displayPresentTime{0};
85 nsecs_t displayRetireTime{0};
86 nsecs_t releaseTime{0};
87
88 sp<Fence> acquireFence{Fence::NO_FENCE};
89 sp<Fence> gpuCompositionDoneFence{Fence::NO_FENCE};
90 sp<Fence> displayPresentFence{Fence::NO_FENCE};
91 sp<Fence> displayRetireFence{Fence::NO_FENCE};
92 sp<Fence> releaseFence{Fence::NO_FENCE};
93};
94
95
96struct NewFrameEventsEntry {
97 uint64_t frameNumber{0};
98 nsecs_t postedTime{0};
99 nsecs_t requestedPresentTime{0};
100 sp<Fence> acquireFence{Fence::NO_FENCE};
101};
102
103
104class FrameEventHistory {
105public:
106 FrameEvents* getFrame(uint64_t frameNumber);
107 FrameEvents* getFrame(uint64_t frameNumber, size_t* iHint);
108 void checkFencesForCompletion();
109 void dump(String8& outString) const;
110
111 void addQueue(const NewFrameEventsEntry& newFrameEntry);
112 void addLatch(uint64_t frameNumber, nsecs_t latchTime);
113 void addPreComposition(uint64_t frameNumber, nsecs_t refreshStartTime);
114 void addPostComposition(uint64_t frameNumber,
115 sp<Fence> gpuCompositionDone, sp<Fence> displayPresent);
116 void addRetire(uint64_t frameNumber, sp<Fence> displayRetire);
117 void addRelease(uint64_t frameNumber, sp<Fence> release);
118
119private:
120 static constexpr size_t MAX_FRAME_HISTORY = 8;
121 std::array<FrameEvents, MAX_FRAME_HISTORY> mFrames;
122 size_t mQueueOffset{0};
123 size_t mCompositionOffset{0};
124 size_t mRetireOffset{0};
125 size_t mReleaseOffset{0};
126};
127
Pablo Ceballosce796e72016-02-04 19:10:51 -0800128} // namespace android
129#endif