FrameInfo.h revision 4db3d17debef68f72d23999d69ae68b75f59dda3
1ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck/*
2ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck * Copyright (C) 2015 The Android Open Source Project
3ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck *
4ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck * Licensed under the Apache License, Version 2.0 (the "License");
5ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck * you may not use this file except in compliance with the License.
6ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck * You may obtain a copy of the License at
7ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck *
8ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck *      http://www.apache.org/licenses/LICENSE-2.0
9ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck *
10ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck * Unless required by applicable law or agreed to in writing, software
11ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck * distributed under the License is distributed on an "AS IS" BASIS,
12ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck * See the License for the specific language governing permissions and
14ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck * limitations under the License.
15ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck */
16ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck#ifndef FRAMEINFO_H_
17ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck#define FRAMEINFO_H_
18ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
19ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck#include "utils/Macros.h"
20ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
21ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck#include <cutils/compiler.h>
22ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck#include <utils/Timers.h>
23ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
24ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck#include <memory.h>
254db3d17debef68f72d23999d69ae68b75f59dda3John Reck#include <string>
26ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
27ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Recknamespace android {
28ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Recknamespace uirenderer {
29ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
30ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck#define UI_THREAD_FRAME_INFO_SIZE 9
31ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
32c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reckenum class FrameInfoIndex {
33ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kFlags = 0,
34ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kIntendedVsync,
35ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kVsync,
36ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kOldestInputEvent,
37ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kNewestInputEvent,
38ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kHandleInputStart,
39ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kAnimationStart,
40ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kPerformTraversalsStart,
41ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kDrawStart,
42ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    // End of UI frame info
43ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
44ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kSyncStart,
45ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kIssueDrawCommandsStart,
46ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kSwapBuffers,
47ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kFrameCompleted,
48ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
49ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    // Must be the last value!
50ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kNumIndexes
51c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck};
52ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
534db3d17debef68f72d23999d69ae68b75f59dda3John Reckextern std::string FrameInfoNames[];
544db3d17debef68f72d23999d69ae68b75f59dda3John Reck
55c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reckenum class FrameInfoFlags {
56ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kWindowLayoutChanged = 1 << 0,
57ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kRTAnimation = 1 << 1,
58ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kSurfaceCanvas = 1 << 2,
59240ff6246a29602539fd0295274e1c769e743a2eJohn Reck    kSkippedFrame = 1 << 3,
60c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck};
61c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John ReckMAKE_FLAGS_ENUM(FrameInfoFlags)
62ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
63ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckclass ANDROID_API UiFrameInfoBuilder {
64ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckpublic:
65ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    UiFrameInfoBuilder(int64_t* buffer) : mBuffer(buffer) {
66ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck        memset(mBuffer, 0, UI_THREAD_FRAME_INFO_SIZE * sizeof(int64_t));
67ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
68ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
69ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    UiFrameInfoBuilder& setVsync(nsecs_t vsyncTime, nsecs_t intendedVsync) {
70c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        set(FrameInfoIndex::kVsync) = vsyncTime;
71c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        set(FrameInfoIndex::kIntendedVsync) = intendedVsync;
72ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck        return *this;
73ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
74ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
75c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck    UiFrameInfoBuilder& addFlag(FrameInfoFlags flag) {
76c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        set(FrameInfoIndex::kFlags) |= static_cast<uint64_t>(flag);
77ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck        return *this;
78ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
79ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
80ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckprivate:
81c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck    inline int64_t& set(FrameInfoIndex index) {
82c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        return mBuffer[static_cast<int>(index)];
83c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck    }
84c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck
85ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    int64_t* mBuffer;
86ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck};
87ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
88ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckclass FrameInfo {
89ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckpublic:
90ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    void importUiThreadInfo(int64_t* info);
91ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
92ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    void markSyncStart() {
93c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        set(FrameInfoIndex::kSyncStart) = systemTime(CLOCK_MONOTONIC);
94ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
95ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
96ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    void markIssueDrawCommandsStart() {
97c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        set(FrameInfoIndex::kIssueDrawCommandsStart) = systemTime(CLOCK_MONOTONIC);
98ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
99ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
100ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    void markSwapBuffers() {
101c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        set(FrameInfoIndex::kSwapBuffers) = systemTime(CLOCK_MONOTONIC);
102ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
103ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
104ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    void markFrameCompleted() {
105c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        set(FrameInfoIndex::kFrameCompleted) = systemTime(CLOCK_MONOTONIC);
106ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
107ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
108240ff6246a29602539fd0295274e1c769e743a2eJohn Reck    void addFlag(FrameInfoFlags flag) {
109240ff6246a29602539fd0295274e1c769e743a2eJohn Reck        set(FrameInfoIndex::kFlags) |= static_cast<uint64_t>(flag);
110240ff6246a29602539fd0295274e1c769e743a2eJohn Reck    }
111240ff6246a29602539fd0295274e1c769e743a2eJohn Reck
112c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck    int64_t operator[](FrameInfoIndex index) const {
113ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck        if (index == FrameInfoIndex::kNumIndexes) return 0;
114ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck        return mFrameInfo[static_cast<int>(index)];
115ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
116ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
117ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    int64_t operator[](int index) const {
118c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        if (index < 0 || index >= static_cast<int>(FrameInfoIndex::kNumIndexes)) return 0;
119c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        return mFrameInfo[index];
120ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
121ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
122ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckprivate:
123c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck    inline int64_t& set(FrameInfoIndex index) {
124c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        return mFrameInfo[static_cast<int>(index)];
125c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck    }
126c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck
127c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck    int64_t mFrameInfo[static_cast<int>(FrameInfoIndex::kNumIndexes)];
128ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck};
129ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
130ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck} /* namespace uirenderer */
131ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck} /* namespace android */
132ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
133ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck#endif /* FRAMEINFO_H_ */
134