blob: 3c3167721d2b94148b68cec99c3c777ff0c0d481 [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
31HWUI_ENUM(FrameInfoIndex,
32 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
50);
51
52HWUI_ENUM(FrameInfoFlags,
53 kWindowLayoutChanged = 1 << 0,
54 kRTAnimation = 1 << 1,
55 kSurfaceCanvas = 1 << 2,
56);
57
58class ANDROID_API UiFrameInfoBuilder {
59public:
60 UiFrameInfoBuilder(int64_t* buffer) : mBuffer(buffer) {
61 memset(mBuffer, 0, UI_THREAD_FRAME_INFO_SIZE * sizeof(int64_t));
62 }
63
64 UiFrameInfoBuilder& setVsync(nsecs_t vsyncTime, nsecs_t intendedVsync) {
65 mBuffer[FrameInfoIndex::kVsync] = vsyncTime;
66 mBuffer[FrameInfoIndex::kIntendedVsync] = intendedVsync;
67 return *this;
68 }
69
70 UiFrameInfoBuilder& addFlag(FrameInfoFlagsEnum flag) {
71 mBuffer[FrameInfoIndex::kFlags] |= static_cast<uint64_t>(flag);
72 return *this;
73 }
74
75private:
76 int64_t* mBuffer;
77};
78
79class FrameInfo {
80public:
81 void importUiThreadInfo(int64_t* info);
82
83 void markSyncStart() {
84 mFrameInfo[FrameInfoIndex::kSyncStart] = systemTime(CLOCK_MONOTONIC);
85 }
86
87 void markIssueDrawCommandsStart() {
88 mFrameInfo[FrameInfoIndex::kIssueDrawCommandsStart] = systemTime(CLOCK_MONOTONIC);
89 }
90
91 void markSwapBuffers() {
92 mFrameInfo[FrameInfoIndex::kSwapBuffers] = systemTime(CLOCK_MONOTONIC);
93 }
94
95 void markFrameCompleted() {
96 mFrameInfo[FrameInfoIndex::kFrameCompleted] = systemTime(CLOCK_MONOTONIC);
97 }
98
99 int64_t operator[](FrameInfoIndexEnum index) const {
100 if (index == FrameInfoIndex::kNumIndexes) return 0;
101 return mFrameInfo[static_cast<int>(index)];
102 }
103
104 int64_t operator[](int index) const {
105 if (index < 0 || index >= FrameInfoIndex::kNumIndexes) return 0;
106 return mFrameInfo[static_cast<int>(index)];
107 }
108
109private:
110 int64_t mFrameInfo[FrameInfoIndex::kNumIndexes];
111};
112
113} /* namespace uirenderer */
114} /* namespace android */
115
116#endif /* FRAMEINFO_H_ */