• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 <utils/Timers.h>
20 #include "Rect.h"
21 
22 namespace android {
23 namespace uirenderer {
24 
25 class OpenGLRenderer;
26 
27 class DrawProfiler {
28 public:
29     DrawProfiler();
30     ~DrawProfiler();
31 
32     bool loadSystemProperties();
33     void setDensity(float density);
34 
35     void startFrame(nsecs_t recordDurationNanos = 0);
36     void markPlaybackStart();
37     void markPlaybackEnd();
38     void finishFrame();
39 
40     void unionDirty(SkRect* dirty);
41     void draw(OpenGLRenderer* canvas);
42 
43     void dumpData(int fd);
44 
45 private:
46     enum ProfileType {
47         kNone,
48         kConsole,
49         kBars,
50     };
51 
52     typedef struct {
53         float record;
54         float prepare;
55         float playback;
56         float swapBuffers;
57     } FrameTimingData;
58 
59     void createData();
60     void destroyData();
61 
62     void addRect(Rect& r, float data, float* shapeOutput);
63     void prepareShapes(const int baseline);
64     void drawGraph(OpenGLRenderer* canvas);
65     void drawCurrentFrame(OpenGLRenderer* canvas);
66     void drawThreshold(OpenGLRenderer* canvas);
67 
68     ProfileType loadRequestedProfileType();
69 
70     ProfileType mType;
71     float mDensity;
72 
73     FrameTimingData* mData;
74     int mDataSize;
75 
76     int mCurrentFrame;
77     nsecs_t mPreviousTime;
78 
79     int mVerticalUnit;
80     int mHorizontalUnit;
81     int mThresholdStroke;
82 
83     /*
84      * mRects represents an array of rect shapes, divided into NUM_ELEMENTS
85      * groups such that each group is drawn with the same paint.
86      * For example mRects[0] is the array of rect floats suitable for
87      * OpenGLRenderer:drawRects() that makes up all the FrameTimingData:record
88      * information.
89      */
90     float** mRects;
91 
92     bool mShowDirtyRegions;
93     SkRect mDirtyRegion;
94     bool mFlashToggle;
95 };
96 
97 } /* namespace uirenderer */
98 } /* namespace android */
99 
100 #endif /* DRAWPROFILER_H */
101