John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 26 | namespace android { |
| 27 | namespace uirenderer { |
| 28 | |
| 29 | #define UI_THREAD_FRAME_INFO_SIZE 9 |
| 30 | |
John Reck | c87be99 | 2015-02-20 10:57:22 -0800 | [diff] [blame] | 31 | enum class FrameInfoIndex { |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 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 |
John Reck | c87be99 | 2015-02-20 10:57:22 -0800 | [diff] [blame] | 50 | }; |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 51 | |
John Reck | c87be99 | 2015-02-20 10:57:22 -0800 | [diff] [blame] | 52 | enum class FrameInfoFlags { |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 53 | kWindowLayoutChanged = 1 << 0, |
| 54 | kRTAnimation = 1 << 1, |
| 55 | kSurfaceCanvas = 1 << 2, |
John Reck | 240ff62 | 2015-04-28 13:50:00 -0700 | [diff] [blame] | 56 | kSkippedFrame = 1 << 3, |
John Reck | c87be99 | 2015-02-20 10:57:22 -0800 | [diff] [blame] | 57 | }; |
| 58 | MAKE_FLAGS_ENUM(FrameInfoFlags) |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 59 | |
| 60 | class ANDROID_API UiFrameInfoBuilder { |
| 61 | public: |
| 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 Reck | c87be99 | 2015-02-20 10:57:22 -0800 | [diff] [blame] | 67 | set(FrameInfoIndex::kVsync) = vsyncTime; |
| 68 | set(FrameInfoIndex::kIntendedVsync) = intendedVsync; |
John Reck | bf3c602 | 2015-06-02 15:55:00 -0700 | [diff] [blame^] | 69 | // Pretend the other fields are all at vsync, too, so that naive |
| 70 | // duration calculations end up being 0 instead of very large |
| 71 | set(FrameInfoIndex::kHandleInputStart) = vsyncTime; |
| 72 | set(FrameInfoIndex::kAnimationStart) = vsyncTime; |
| 73 | set(FrameInfoIndex::kPerformTraversalsStart) = vsyncTime; |
| 74 | set(FrameInfoIndex::kDrawStart) = vsyncTime; |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 75 | return *this; |
| 76 | } |
| 77 | |
John Reck | c87be99 | 2015-02-20 10:57:22 -0800 | [diff] [blame] | 78 | UiFrameInfoBuilder& addFlag(FrameInfoFlags flag) { |
| 79 | set(FrameInfoIndex::kFlags) |= static_cast<uint64_t>(flag); |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 80 | return *this; |
| 81 | } |
| 82 | |
| 83 | private: |
John Reck | c87be99 | 2015-02-20 10:57:22 -0800 | [diff] [blame] | 84 | inline int64_t& set(FrameInfoIndex index) { |
| 85 | return mBuffer[static_cast<int>(index)]; |
| 86 | } |
| 87 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 88 | int64_t* mBuffer; |
| 89 | }; |
| 90 | |
| 91 | class FrameInfo { |
| 92 | public: |
| 93 | void importUiThreadInfo(int64_t* info); |
| 94 | |
| 95 | void markSyncStart() { |
John Reck | c87be99 | 2015-02-20 10:57:22 -0800 | [diff] [blame] | 96 | set(FrameInfoIndex::kSyncStart) = systemTime(CLOCK_MONOTONIC); |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | void markIssueDrawCommandsStart() { |
John Reck | c87be99 | 2015-02-20 10:57:22 -0800 | [diff] [blame] | 100 | set(FrameInfoIndex::kIssueDrawCommandsStart) = systemTime(CLOCK_MONOTONIC); |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | void markSwapBuffers() { |
John Reck | c87be99 | 2015-02-20 10:57:22 -0800 | [diff] [blame] | 104 | set(FrameInfoIndex::kSwapBuffers) = systemTime(CLOCK_MONOTONIC); |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void markFrameCompleted() { |
John Reck | c87be99 | 2015-02-20 10:57:22 -0800 | [diff] [blame] | 108 | set(FrameInfoIndex::kFrameCompleted) = systemTime(CLOCK_MONOTONIC); |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 109 | } |
| 110 | |
John Reck | 240ff62 | 2015-04-28 13:50:00 -0700 | [diff] [blame] | 111 | void addFlag(FrameInfoFlags flag) { |
| 112 | set(FrameInfoIndex::kFlags) |= static_cast<uint64_t>(flag); |
| 113 | } |
| 114 | |
John Reck | c87be99 | 2015-02-20 10:57:22 -0800 | [diff] [blame] | 115 | int64_t operator[](FrameInfoIndex index) const { |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 116 | if (index == FrameInfoIndex::kNumIndexes) return 0; |
| 117 | return mFrameInfo[static_cast<int>(index)]; |
| 118 | } |
| 119 | |
| 120 | int64_t operator[](int index) const { |
John Reck | c87be99 | 2015-02-20 10:57:22 -0800 | [diff] [blame] | 121 | if (index < 0 || index >= static_cast<int>(FrameInfoIndex::kNumIndexes)) return 0; |
| 122 | return mFrameInfo[index]; |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | private: |
John Reck | c87be99 | 2015-02-20 10:57:22 -0800 | [diff] [blame] | 126 | inline int64_t& set(FrameInfoIndex index) { |
| 127 | return mFrameInfo[static_cast<int>(index)]; |
| 128 | } |
| 129 | |
| 130 | int64_t mFrameInfo[static_cast<int>(FrameInfoIndex::kNumIndexes)]; |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | } /* namespace uirenderer */ |
| 134 | } /* namespace android */ |
| 135 | |
| 136 | #endif /* FRAMEINFO_H_ */ |