blob: c8189b8df955dd53456b624cfa99c7ffc0ea3c7e [file] [log] [blame]
John Reckba6adf62015-02-19 14:36:50 -08001/*
2 * Copyright (C) 2015 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#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 <memory.h>
25
26namespace android {
27namespace uirenderer {
28
29#define UI_THREAD_FRAME_INFO_SIZE 9
30
John Reckc87be992015-02-20 10:57:22 -080031enum class FrameInfoIndex {
John Reckba6adf62015-02-19 14:36:50 -080032 kFlags = 0,
33 kIntendedVsync,
34 kVsync,
35 kOldestInputEvent,
36 kNewestInputEvent,
37 kHandleInputStart,
38 kAnimationStart,
39 kPerformTraversalsStart,
40 kDrawStart,
41 // End of UI frame info
42
43 kSyncStart,
44 kIssueDrawCommandsStart,
45 kSwapBuffers,
46 kFrameCompleted,
47
48 // Must be the last value!
49 kNumIndexes
John Reckc87be992015-02-20 10:57:22 -080050};
John Reckba6adf62015-02-19 14:36:50 -080051
John Reckc87be992015-02-20 10:57:22 -080052enum class FrameInfoFlags {
John Reckba6adf62015-02-19 14:36:50 -080053 kWindowLayoutChanged = 1 << 0,
54 kRTAnimation = 1 << 1,
55 kSurfaceCanvas = 1 << 2,
John Reck240ff622015-04-28 13:50:00 -070056 kSkippedFrame = 1 << 3,
John Reckc87be992015-02-20 10:57:22 -080057};
58MAKE_FLAGS_ENUM(FrameInfoFlags)
John Reckba6adf62015-02-19 14:36:50 -080059
60class ANDROID_API UiFrameInfoBuilder {
61public:
62 UiFrameInfoBuilder(int64_t* buffer) : mBuffer(buffer) {
63 memset(mBuffer, 0, UI_THREAD_FRAME_INFO_SIZE * sizeof(int64_t));
64 }
65
66 UiFrameInfoBuilder& setVsync(nsecs_t vsyncTime, nsecs_t intendedVsync) {
John Reckc87be992015-02-20 10:57:22 -080067 set(FrameInfoIndex::kVsync) = vsyncTime;
68 set(FrameInfoIndex::kIntendedVsync) = intendedVsync;
John Reckba6adf62015-02-19 14:36:50 -080069 return *this;
70 }
71
John Reckc87be992015-02-20 10:57:22 -080072 UiFrameInfoBuilder& addFlag(FrameInfoFlags flag) {
73 set(FrameInfoIndex::kFlags) |= static_cast<uint64_t>(flag);
John Reckba6adf62015-02-19 14:36:50 -080074 return *this;
75 }
76
77private:
John Reckc87be992015-02-20 10:57:22 -080078 inline int64_t& set(FrameInfoIndex index) {
79 return mBuffer[static_cast<int>(index)];
80 }
81
John Reckba6adf62015-02-19 14:36:50 -080082 int64_t* mBuffer;
83};
84
85class FrameInfo {
86public:
87 void importUiThreadInfo(int64_t* info);
88
89 void markSyncStart() {
John Reckc87be992015-02-20 10:57:22 -080090 set(FrameInfoIndex::kSyncStart) = systemTime(CLOCK_MONOTONIC);
John Reckba6adf62015-02-19 14:36:50 -080091 }
92
93 void markIssueDrawCommandsStart() {
John Reckc87be992015-02-20 10:57:22 -080094 set(FrameInfoIndex::kIssueDrawCommandsStart) = systemTime(CLOCK_MONOTONIC);
John Reckba6adf62015-02-19 14:36:50 -080095 }
96
97 void markSwapBuffers() {
John Reckc87be992015-02-20 10:57:22 -080098 set(FrameInfoIndex::kSwapBuffers) = systemTime(CLOCK_MONOTONIC);
John Reckba6adf62015-02-19 14:36:50 -080099 }
100
101 void markFrameCompleted() {
John Reckc87be992015-02-20 10:57:22 -0800102 set(FrameInfoIndex::kFrameCompleted) = systemTime(CLOCK_MONOTONIC);
John Reckba6adf62015-02-19 14:36:50 -0800103 }
104
John Reck240ff622015-04-28 13:50:00 -0700105 void addFlag(FrameInfoFlags flag) {
106 set(FrameInfoIndex::kFlags) |= static_cast<uint64_t>(flag);
107 }
108
John Reckc87be992015-02-20 10:57:22 -0800109 int64_t operator[](FrameInfoIndex index) const {
John Reckba6adf62015-02-19 14:36:50 -0800110 if (index == FrameInfoIndex::kNumIndexes) return 0;
111 return mFrameInfo[static_cast<int>(index)];
112 }
113
114 int64_t operator[](int index) const {
John Reckc87be992015-02-20 10:57:22 -0800115 if (index < 0 || index >= static_cast<int>(FrameInfoIndex::kNumIndexes)) return 0;
116 return mFrameInfo[index];
John Reckba6adf62015-02-19 14:36:50 -0800117 }
118
119private:
John Reckc87be992015-02-20 10:57:22 -0800120 inline int64_t& set(FrameInfoIndex index) {
121 return mFrameInfo[static_cast<int>(index)];
122 }
123
124 int64_t mFrameInfo[static_cast<int>(FrameInfoIndex::kNumIndexes)];
John Reckba6adf62015-02-19 14:36:50 -0800125};
126
127} /* namespace uirenderer */
128} /* namespace android */
129
130#endif /* FRAMEINFO_H_ */