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 #include "FrameInfo.h"
17 
18 #include <gui/TraceUtils.h>
19 
20 #include <cstring>
21 
22 namespace android {
23 namespace uirenderer {
24 
25 const std::array FrameInfoNames{"Flags",
26                                 "FrameTimelineVsyncId",
27                                 "IntendedVsync",
28                                 "Vsync",
29                                 "InputEventId",
30                                 "HandleInputStart",
31                                 "AnimationStart",
32                                 "PerformTraversalsStart",
33                                 "DrawStart",
34                                 "FrameDeadline",
35                                 "FrameInterval",
36                                 "FrameStartTime",
37                                 "SyncQueued",
38                                 "SyncStart",
39                                 "IssueDrawCommandsStart",
40                                 "SwapBuffers",
41                                 "FrameCompleted",
42                                 "DequeueBufferDuration",
43                                 "QueueBufferDuration",
44                                 "GpuCompleted",
45                                 "SwapBuffersCompleted",
46                                 "DisplayPresentTime",
47                                 "CommandSubmissionCompleted"
48 
49 };
50 
51 static_assert(static_cast<int>(FrameInfoIndex::NumIndexes) == 23,
52               "Must update value in FrameMetrics.java#FRAME_STATS_COUNT (and here)");
53 
importUiThreadInfo(int64_t * info)54 void FrameInfo::importUiThreadInfo(int64_t* info) {
55     memcpy(mFrameInfo, info, UI_THREAD_FRAME_INFO_SIZE * sizeof(int64_t));
56     mSkippedFrameReason.reset();
57 }
58 
toString(SkippedFrameReason reason)59 const char* toString(SkippedFrameReason reason) {
60     switch (reason) {
61         case SkippedFrameReason::DrawingOff:
62             return "DrawingOff";
63         case SkippedFrameReason::ContextIsStopped:
64             return "ContextIsStopped";
65         case SkippedFrameReason::NothingToDraw:
66             return "NothingToDraw";
67         case SkippedFrameReason::NoOutputTarget:
68             return "NoOutputTarget";
69         case SkippedFrameReason::NoBuffer:
70             return "NoBuffer";
71         case SkippedFrameReason::AlreadyDrawn:
72             return "AlreadyDrawn";
73     }
74 }
75 
setSkippedFrameReason(android::uirenderer::SkippedFrameReason reason)76 void FrameInfo::setSkippedFrameReason(android::uirenderer::SkippedFrameReason reason) {
77     ATRACE_FORMAT_INSTANT("Frame skipped: %s", toString(reason));
78     addFlag(FrameInfoFlags::SkippedFrame);
79     mSkippedFrameReason = reason;
80 }
81 
82 } /* namespace uirenderer */
83 } /* namespace android */
84