blob: f1dc954198683609a6f41ddb378d4a932b4d4a98 [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
John Reck41300272015-06-03 14:42:34 -070057 void initializeRects(const int baseline, const int width);
John Reckbf3c6022015-06-02 15:55:00 -070058 void nextBarSegment(FrameInfoIndex start, FrameInfoIndex end);
John Reck4c9e59d2015-05-12 07:17:50 -070059 void drawGraph(OpenGLRenderer* canvas);
John Reck4c9e59d2015-05-12 07:17:50 -070060 void drawThreshold(OpenGLRenderer* canvas);
61
John Reckbf3c6022015-06-02 15:55:00 -070062 inline float duration(size_t index, FrameInfoIndex start, FrameInfoIndex end) {
63 nsecs_t ns_start = mFrameSource[index][start];
64 nsecs_t ns_end = mFrameSource[index][end];
65 float duration = ((ns_end - ns_start) * 0.000001f);
66 // Clamp to large to avoid spiking off the top of the screen
67 duration = duration > 50.0f ? 50.0f : duration;
John Reck4c9e59d2015-05-12 07:17:50 -070068 return duration > 0.0f ? duration : 0.0f;
69 }
70
John Reck4c9e59d2015-05-12 07:17:50 -070071 ProfileType mType = ProfileType::None;
72 float mDensity = 0;
73
74 FrameInfoSource& mFrameSource;
75
76 int mVerticalUnit = 0;
John Reck4c9e59d2015-05-12 07:17:50 -070077 int mThresholdStroke = 0;
78
John Reck41300272015-06-03 14:42:34 -070079 int mNumFastRects;
80 std::unique_ptr<float[]> mFastRects;
81 int mNumJankyRects;
82 std::unique_ptr<float[]> mJankyRects;
John Reck4c9e59d2015-05-12 07:17:50 -070083
84 bool mShowDirtyRegions = false;
85 SkRect mDirtyRegion;
86 bool mFlashToggle = false;
87 nsecs_t mLastFrameLogged = 0;
88};
89
90} /* namespace uirenderer */
91} /* namespace android */
92
93#endif /* DRAWPROFILER_H */