| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#ifndef FRAMEINFO_H_ |
| 17 |
#define FRAMEINFO_H_ |
| 18 |
|
| 19 |
#include "utils/Macros.h" |
| 20 |
|
| 21 |
#include <cutils/compiler.h> |
| 22 |
#include <utils/Timers.h> |
| 23 |
|
| 24 |
#include <array> |
| 25 |
#include <memory.h> |
| 26 |
#include <string> |
| 27 |
|
| 28 |
namespace android { |
| 29 |
namespace uirenderer { |
| 30 |
|
| 31 |
static constexpr size_t UI_THREAD_FRAME_INFO_SIZE = 12; |
| 32 |
|
| 33 |
enum class FrameInfoIndex { |
| 34 |
Flags = 0, |
| 35 |
FrameTimelineVsyncId, |
| 36 |
IntendedVsync, |
| 37 |
Vsync, |
| 38 |
InputEventId, |
| 39 |
HandleInputStart, |
| 40 |
AnimationStart, |
| 41 |
PerformTraversalsStart, |
| 42 |
DrawStart, |
| 43 |
FrameDeadline, |
| 44 |
FrameStartTime, |
| 45 |
FrameInterval, |
| 46 |
|
| 47 |
|
| 48 |
SyncQueued, |
| 49 |
|
| 50 |
SyncStart, |
| 51 |
IssueDrawCommandsStart, |
| 52 |
SwapBuffers, |
| 53 |
FrameCompleted, |
| 54 |
|
| 55 |
DequeueBufferDuration, |
| 56 |
QueueBufferDuration, |
| 57 |
|
| 58 |
GpuCompleted, |
| 59 |
SwapBuffersCompleted, |
| 60 |
DisplayPresentTime, |
| 61 |
CommandSubmissionCompleted, |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
NumIndexes |
| 66 |
}; |
| 67 |
|
| 68 |
extern const std::array<const char*, static_cast<int>(FrameInfoIndex::NumIndexes)> FrameInfoNames; |
| 69 |
|
| 70 |
namespace FrameInfoFlags { |
| 71 |
enum { |
| 72 |
WindowVisibilityChanged = 1 << 0, |
| 73 |
RTAnimation = 1 << 1, |
| 74 |
SurfaceCanvas = 1 << 2, |
| 75 |
SkippedFrame = 1 << 3, |
| 76 |
}; |
| 77 |
}; |
| 78 |
|
| 79 |
class UiFrameInfoBuilder { |
| 80 |
public: |
| 81 |
static constexpr int64_t INVALID_VSYNC_ID = -1; |
| 82 |
static constexpr int64_t UNKNOWN_DEADLINE = std::numeric_limits<int64_t>::max(); |
| 83 |
static constexpr int64_t UNKNOWN_FRAME_INTERVAL = -1; |
| 84 |
|
| 85 |
|
| 86 |
explicit UiFrameInfoBuilder(int64_t* buffer) : mBuffer(buffer) { |
| 87 |
memset(mBuffer, 0, UI_THREAD_FRAME_INFO_SIZE * sizeof(int64_t)); |
| 88 |
set(FrameInfoIndex::FrameTimelineVsyncId) = INVALID_VSYNC_ID; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
set(FrameInfoIndex::FrameDeadline) = std::numeric_limits<int64_t>::max(); |
| 94 |
} |
| 95 |
|
| 96 |
UiFrameInfoBuilder& setVsync(nsecs_t vsyncTime, nsecs_t intendedVsync, |
| 97 |
int64_t vsyncId, int64_t frameDeadline, nsecs_t frameInterval) { |
| 98 |
set(FrameInfoIndex::FrameTimelineVsyncId) = vsyncId; |
| 99 |
set(FrameInfoIndex::Vsync) = vsyncTime; |
| 100 |
set(FrameInfoIndex::IntendedVsync) = intendedVsync; |
| 101 |
|
| 102 |
|
| 103 |
set(FrameInfoIndex::HandleInputStart) = vsyncTime; |
| 104 |
set(FrameInfoIndex::AnimationStart) = vsyncTime; |
| 105 |
set(FrameInfoIndex::PerformTraversalsStart) = vsyncTime; |
| 106 |
set(FrameInfoIndex::DrawStart) = vsyncTime; |
| 107 |
set(FrameInfoIndex::FrameDeadline) = frameDeadline; |
| 108 |
set(FrameInfoIndex::FrameInterval) = frameInterval; |
| 109 |
return *this; |
| 110 |
} |
| 111 |
|
| 112 |
UiFrameInfoBuilder& addFlag(int frameInfoFlag) { |
| 113 |
set(FrameInfoIndex::Flags) |= static_cast<uint64_t>(frameInfoFlag); |
| 114 |
return *this; |
| 115 |
} |
| 116 |
|
| 117 |
private: |
| 118 |
inline int64_t& set(FrameInfoIndex index) { return mBuffer[static_cast<int>(index)]; } |
| 119 |
|
| 120 |
int64_t* mBuffer; |
| 121 |
}; |
| 122 |
|
| 123 |
class FrameInfo { |
| 124 |
public: |
| 125 |
void importUiThreadInfo(int64_t* info); |
| 126 |
|
| 127 |
void markSyncStart() { set(FrameInfoIndex::SyncStart) = systemTime(SYSTEM_TIME_MONOTONIC); } |
| 128 |
|
| 129 |
void markIssueDrawCommandsStart() { |
| 130 |
set(FrameInfoIndex::IssueDrawCommandsStart) = systemTime(SYSTEM_TIME_MONOTONIC); |
| 131 |
} |
| 132 |
|
| 133 |
void markSwapBuffers() { set(FrameInfoIndex::SwapBuffers) = systemTime(SYSTEM_TIME_MONOTONIC); } |
| 134 |
|
| 135 |
void markSwapBuffersCompleted() { |
| 136 |
set(FrameInfoIndex::SwapBuffersCompleted) = systemTime(SYSTEM_TIME_MONOTONIC); |
| 137 |
} |
| 138 |
|
| 139 |
void markFrameCompleted() { set(FrameInfoIndex::FrameCompleted) = systemTime(SYSTEM_TIME_MONOTONIC); } |
| 140 |
|
| 141 |
void addFlag(int frameInfoFlag) { |
| 142 |
set(FrameInfoIndex::Flags) |= static_cast<uint64_t>(frameInfoFlag); |
| 143 |
} |
| 144 |
|
| 145 |
const int64_t* data() const { return mFrameInfo; } |
| 146 |
|
| 147 |
inline int64_t operator[](FrameInfoIndex index) const { return get(index); } |
| 148 |
|
| 149 |
inline int64_t operator[](int index) const { |
| 150 |
if (index < 0 || index >= static_cast<int>(FrameInfoIndex::NumIndexes)) return 0; |
| 151 |
return mFrameInfo[index]; |
| 152 |
} |
| 153 |
|
| 154 |
inline int64_t duration(FrameInfoIndex start, FrameInfoIndex end) const { |
| 155 |
int64_t endtime = get(end); |
| 156 |
int64_t starttime = get(start); |
| 157 |
int64_t gap = endtime - starttime; |
| 158 |
gap = starttime > 0 ? gap : 0; |
| 159 |
if (end > FrameInfoIndex::SyncQueued && start < FrameInfoIndex::SyncQueued) { |
| 160 |
|
| 161 |
|
| 162 |
int64_t offset = get(FrameInfoIndex::SyncStart) - get(FrameInfoIndex::SyncQueued); |
| 163 |
if (offset > 0) { |
| 164 |
gap -= offset; |
| 165 |
} |
| 166 |
} |
| 167 |
return gap > 0 ? gap : 0; |
| 168 |
} |
| 169 |
|
| 170 |
inline int64_t totalDuration() const { |
| 171 |
return duration(FrameInfoIndex::IntendedVsync, FrameInfoIndex::FrameCompleted); |
| 172 |
} |
| 173 |
|
| 174 |
inline int64_t gpuDrawTime() const { |
| 175 |
|
| 176 |
|
| 177 |
int64_t endTime = get(FrameInfoIndex::GpuCompleted); |
| 178 |
return endTime > 0 ? endTime - get(FrameInfoIndex::SwapBuffers) : -1; |
| 179 |
} |
| 180 |
|
| 181 |
inline int64_t& set(FrameInfoIndex index) { return mFrameInfo[static_cast<int>(index)]; } |
| 182 |
|
| 183 |
inline int64_t get(FrameInfoIndex index) const { |
| 184 |
if (index == FrameInfoIndex::NumIndexes) return 0; |
| 185 |
return mFrameInfo[static_cast<int>(index)]; |
| 186 |
} |
| 187 |
|
| 188 |
private: |
| 189 |
int64_t mFrameInfo[static_cast<int>(FrameInfoIndex::NumIndexes)]; |
| 190 |
}; |
| 191 |
|
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
#endif |