FrameInfo.h revision c87be99c6ead0720a8918ea38ce3b25e5c49e1c6
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,
56c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck};
57c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John ReckMAKE_FLAGS_ENUM(FrameInfoFlags)
58ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
59ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckclass ANDROID_API UiFrameInfoBuilder {
60ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckpublic:
61ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    UiFrameInfoBuilder(int64_t* buffer) : mBuffer(buffer) {
62ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck        memset(mBuffer, 0, UI_THREAD_FRAME_INFO_SIZE * sizeof(int64_t));
63ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
64ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
65ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    UiFrameInfoBuilder& setVsync(nsecs_t vsyncTime, nsecs_t intendedVsync) {
66c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        set(FrameInfoIndex::kVsync) = vsyncTime;
67c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        set(FrameInfoIndex::kIntendedVsync) = intendedVsync;
68ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck        return *this;
69ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
70ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
71c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck    UiFrameInfoBuilder& addFlag(FrameInfoFlags flag) {
72c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        set(FrameInfoIndex::kFlags) |= static_cast<uint64_t>(flag);
73ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck        return *this;
74ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
75ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
76ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckprivate:
77c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck    inline int64_t& set(FrameInfoIndex index) {
78c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        return mBuffer[static_cast<int>(index)];
79c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck    }
80c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck
81ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    int64_t* mBuffer;
82ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck};
83ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
84ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckclass FrameInfo {
85ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckpublic:
86ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    void importUiThreadInfo(int64_t* info);
87ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
88ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    void markSyncStart() {
89c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        set(FrameInfoIndex::kSyncStart) = systemTime(CLOCK_MONOTONIC);
90ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
91ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
92ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    void markIssueDrawCommandsStart() {
93c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        set(FrameInfoIndex::kIssueDrawCommandsStart) = systemTime(CLOCK_MONOTONIC);
94ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
95ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
96ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    void markSwapBuffers() {
97c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        set(FrameInfoIndex::kSwapBuffers) = systemTime(CLOCK_MONOTONIC);
98ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
99ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
100ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    void markFrameCompleted() {
101c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        set(FrameInfoIndex::kFrameCompleted) = systemTime(CLOCK_MONOTONIC);
102ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
103ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
104c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck    int64_t operator[](FrameInfoIndex index) const {
105ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck        if (index == FrameInfoIndex::kNumIndexes) return 0;
106ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck        return mFrameInfo[static_cast<int>(index)];
107ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
108ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
109ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    int64_t operator[](int index) const {
110c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        if (index < 0 || index >= static_cast<int>(FrameInfoIndex::kNumIndexes)) return 0;
111c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        return mFrameInfo[index];
112ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck    }
113ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
114ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckprivate:
115c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck    inline int64_t& set(FrameInfoIndex index) {
116c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck        return mFrameInfo[static_cast<int>(index)];
117c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck    }
118c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck
119c87be99c6ead0720a8918ea38ce3b25e5c49e1c6John Reck    int64_t mFrameInfo[static_cast<int>(FrameInfoIndex::kNumIndexes)];
120ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck};
121ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
122ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck} /* namespace uirenderer */
123ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck} /* namespace android */
124ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck
125ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck#endif /* FRAMEINFO_H_ */
126