FrameInfo.h revision 240ff6246a29602539fd0295274e1c769e743a2e
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>
25ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
26ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Recknamespace android {
27ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Recknamespace uirenderer {
28ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
29ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck#define UI_THREAD_FRAME_INFO_SIZE 9
30ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
31c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reckenum class FrameInfoIndex {
32ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kFlags = 0,
33ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kIntendedVsync,
34ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kVsync,
35ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kOldestInputEvent,
36ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kNewestInputEvent,
37ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kHandleInputStart,
38ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kAnimationStart,
39ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kPerformTraversalsStart,
40ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kDrawStart,
41ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    // End of UI frame info
42ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
43ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kSyncStart,
44ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kIssueDrawCommandsStart,
45ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kSwapBuffers,
46ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kFrameCompleted,
47ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
48ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    // Must be the last value!
49ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kNumIndexes
50c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck};
51ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
52c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reckenum class FrameInfoFlags {
53ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kWindowLayoutChanged = 1 << 0,
54ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kRTAnimation = 1 << 1,
55ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    kSurfaceCanvas = 1 << 2,
56240ff6246a29602539fd0295274e1c769e743a2eJohn Reck    kSkippedFrame = 1 << 3,
57c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck};
58c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John ReckMAKE_FLAGS_ENUM(FrameInfoFlags)
59ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
60ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckclass ANDROID_API UiFrameInfoBuilder {
61ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckpublic:
62ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    UiFrameInfoBuilder(int64_t* buffer) : mBuffer(buffer) {
63ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck        memset(mBuffer, 0, UI_THREAD_FRAME_INFO_SIZE * sizeof(int64_t));
64ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
65ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
66ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    UiFrameInfoBuilder& setVsync(nsecs_t vsyncTime, nsecs_t intendedVsync) {
67c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        set(FrameInfoIndex::kVsync) = vsyncTime;
68c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        set(FrameInfoIndex::kIntendedVsync) = intendedVsync;
69ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck        return *this;
70ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
71ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
72c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck    UiFrameInfoBuilder& addFlag(FrameInfoFlags flag) {
73c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        set(FrameInfoIndex::kFlags) |= static_cast<uint64_t>(flag);
74ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck        return *this;
75ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
76ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
77ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckprivate:
78c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck    inline int64_t& set(FrameInfoIndex index) {
79c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        return mBuffer[static_cast<int>(index)];
80c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck    }
81c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck
82ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    int64_t* mBuffer;
83ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck};
84ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
85ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckclass FrameInfo {
86ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckpublic:
87ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    void importUiThreadInfo(int64_t* info);
88ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
89ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    void markSyncStart() {
90c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        set(FrameInfoIndex::kSyncStart) = systemTime(CLOCK_MONOTONIC);
91ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
92ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
93ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    void markIssueDrawCommandsStart() {
94c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        set(FrameInfoIndex::kIssueDrawCommandsStart) = systemTime(CLOCK_MONOTONIC);
95ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
96ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
97ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    void markSwapBuffers() {
98c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        set(FrameInfoIndex::kSwapBuffers) = systemTime(CLOCK_MONOTONIC);
99ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
100ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
101ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    void markFrameCompleted() {
102c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        set(FrameInfoIndex::kFrameCompleted) = systemTime(CLOCK_MONOTONIC);
103ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
104ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
105240ff6246a29602539fd0295274e1c769e743a2eJohn Reck    void addFlag(FrameInfoFlags flag) {
106240ff6246a29602539fd0295274e1c769e743a2eJohn Reck        set(FrameInfoIndex::kFlags) |= static_cast<uint64_t>(flag);
107240ff6246a29602539fd0295274e1c769e743a2eJohn Reck    }
108240ff6246a29602539fd0295274e1c769e743a2eJohn Reck
109c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck    int64_t operator[](FrameInfoIndex index) const {
110ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck        if (index == FrameInfoIndex::kNumIndexes) return 0;
111ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck        return mFrameInfo[static_cast<int>(index)];
112ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
113ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
114ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    int64_t operator[](int index) const {
115c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        if (index < 0 || index >= static_cast<int>(FrameInfoIndex::kNumIndexes)) return 0;
116c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        return mFrameInfo[index];
117ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
118ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
119ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckprivate:
120c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck    inline int64_t& set(FrameInfoIndex index) {
121c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        return mFrameInfo[static_cast<int>(index)];
122c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck    }
123c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck
124c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck    int64_t mFrameInfo[static_cast<int>(FrameInfoIndex::kNumIndexes)];
125ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck};
126ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
127ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck} /* namespace uirenderer */
128ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck} /* namespace android */
129ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
130ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck#endif /* FRAMEINFO_H_ */
131