blob: f62e34dacbf478a70cb19934be63e81eadd25bea [file] [log] [blame]
John Reck4c9e59d2015-05-12 07:17:50 -07001/*
2 * Copyright (C) 2014 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 DRAWPROFILER_H
17#define DRAWPROFILER_H
18
19#include "FrameInfo.h"
20#include "Properties.h"
21#include "Rect.h"
22#include "utils/RingBuffer.h"
23
24#include <utils/Timers.h>
25
26#include <memory>
27
28namespace android {
29namespace uirenderer {
30
31class OpenGLRenderer;
32
33// TODO: This is a bit awkward as it needs to match the thing in CanvasContext
34// A better abstraction here would be nice but iterators are painful
35// and RingBuffer having the size baked into the template is also painful
36// But making DrawProfiler also be templated is ALSO painful
37// At least this is a compile failure if this doesn't match, so there's that.
38typedef RingBuffer<FrameInfo, 120> FrameInfoSource;
39
40class FrameInfoVisualizer {
41public:
42 FrameInfoVisualizer(FrameInfoSource& source);
43 ~FrameInfoVisualizer();
44
45 bool consumeProperties();
46 void setDensity(float density);
47
48 void unionDirty(SkRect* dirty);
49 void draw(OpenGLRenderer* canvas);
50
51 void dumpData(int fd);
52
53private:
54 void createData();
55 void destroyData();
56
57 void addRect(Rect& r, float data, float* shapeOutput);
58 void prepareShapes(const int baseline);
59 void drawGraph(OpenGLRenderer* canvas);
60 void drawCurrentFrame(OpenGLRenderer* canvas);
61 void drawThreshold(OpenGLRenderer* canvas);
62
63 static inline float duration(nsecs_t start, nsecs_t end) {
64 float duration = ((end - start) * 0.000001f);
65 return duration > 0.0f ? duration : 0.0f;
66 }
67
68 inline float recordDuration(size_t index) {
69 return duration(
70 mFrameSource[index][FrameInfoIndex::kIntendedVsync],
71 mFrameSource[index][FrameInfoIndex::kSyncStart]);
72 }
73
74 inline float prepareDuration(size_t index) {
75 return duration(
76 mFrameSource[index][FrameInfoIndex::kSyncStart],
77 mFrameSource[index][FrameInfoIndex::kIssueDrawCommandsStart]);
78 }
79
80 inline float issueDrawDuration(size_t index) {
81 return duration(
82 mFrameSource[index][FrameInfoIndex::kIssueDrawCommandsStart],
83 mFrameSource[index][FrameInfoIndex::kSwapBuffers]);
84 }
85
86 inline float swapBuffersDuration(size_t index) {
87 return duration(
88 mFrameSource[index][FrameInfoIndex::kSwapBuffers],
89 mFrameSource[index][FrameInfoIndex::kFrameCompleted]);
90 }
91
92 ProfileType mType = ProfileType::None;
93 float mDensity = 0;
94
95 FrameInfoSource& mFrameSource;
96
97 int mVerticalUnit = 0;
98 int mHorizontalUnit = 0;
99 int mThresholdStroke = 0;
100
101 /*
102 * mRects represents an array of rect shapes, divided into NUM_ELEMENTS
103 * groups such that each group is drawn with the same paint.
104 * For example mRects[0] is the array of rect floats suitable for
105 * OpenGLRenderer:drawRects() that makes up all the FrameTimingData:record
106 * information.
107 */
108 std::unique_ptr<float*> mRects;
109
110 bool mShowDirtyRegions = false;
111 SkRect mDirtyRegion;
112 bool mFlashToggle = false;
113 nsecs_t mLastFrameLogged = 0;
114};
115
116} /* namespace uirenderer */
117} /* namespace android */
118
119#endif /* DRAWPROFILER_H */