blob: fc958b8b414a568f69423a40af8152ca8a4426b2 [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 */
Chris Craik5e00c7c2016-07-06 16:10:09 -070016
17#pragma once
John Reck4c9e59d2015-05-12 07:17:50 -070018
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
Chris Craik1dfa0702016-03-04 15:59:24 -080031class BakedOpRenderer;
32typedef BakedOpRenderer ContentRenderer;
John Reck4c9e59d2015-05-12 07:17:50 -070033
34// TODO: This is a bit awkward as it needs to match the thing in CanvasContext
35// A better abstraction here would be nice but iterators are painful
36// and RingBuffer having the size baked into the template is also painful
37// But making DrawProfiler also be templated is ALSO painful
38// At least this is a compile failure if this doesn't match, so there's that.
39typedef RingBuffer<FrameInfo, 120> FrameInfoSource;
40
41class FrameInfoVisualizer {
42public:
43 FrameInfoVisualizer(FrameInfoSource& source);
44 ~FrameInfoVisualizer();
45
46 bool consumeProperties();
47 void setDensity(float density);
48
49 void unionDirty(SkRect* dirty);
Chris Craik1dfa0702016-03-04 15:59:24 -080050 void draw(ContentRenderer* renderer);
John Reck4c9e59d2015-05-12 07:17:50 -070051
52 void dumpData(int fd);
53
54private:
55 void createData();
56 void destroyData();
57
John Reck41300272015-06-03 14:42:34 -070058 void initializeRects(const int baseline, const int width);
John Reckbf3c6022015-06-02 15:55:00 -070059 void nextBarSegment(FrameInfoIndex start, FrameInfoIndex end);
Chris Craik1dfa0702016-03-04 15:59:24 -080060 void drawGraph(ContentRenderer* renderer);
61 void drawThreshold(ContentRenderer* renderer);
John Reck4c9e59d2015-05-12 07:17:50 -070062
John Reckbe3fba02015-07-06 13:49:58 -070063 inline float durationMS(size_t index, FrameInfoIndex start, FrameInfoIndex end) {
64 float duration = mFrameSource[index].duration(start, end) * 0.000001f;
John Reckbf3c6022015-06-02 15:55:00 -070065 // Clamp to large to avoid spiking off the top of the screen
66 duration = duration > 50.0f ? 50.0f : duration;
John Reck4c9e59d2015-05-12 07:17:50 -070067 return duration > 0.0f ? duration : 0.0f;
68 }
69
John Reck4c9e59d2015-05-12 07:17:50 -070070 ProfileType mType = ProfileType::None;
71 float mDensity = 0;
72
73 FrameInfoSource& mFrameSource;
74
75 int mVerticalUnit = 0;
John Reck4c9e59d2015-05-12 07:17:50 -070076 int mThresholdStroke = 0;
77
John Reck41300272015-06-03 14:42:34 -070078 int mNumFastRects;
79 std::unique_ptr<float[]> mFastRects;
80 int mNumJankyRects;
81 std::unique_ptr<float[]> mJankyRects;
John Reck4c9e59d2015-05-12 07:17:50 -070082
83 bool mShowDirtyRegions = false;
84 SkRect mDirtyRegion;
85 bool mFlashToggle = false;
86 nsecs_t mLastFrameLogged = 0;
87};
88
89} /* namespace uirenderer */
90} /* namespace android */