blob: ef6101c54ce62af9d21de0551bb971780e756be5 [file] [log] [blame]
John Reckfe5e7b72014-05-23 17:42:28 -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
Chris Craik2507c342015-05-04 14:36:49 -070019#include "Properties.h"
John Reckfe5e7b72014-05-23 17:42:28 -070020#include "Rect.h"
21
Chris Craik2507c342015-05-04 14:36:49 -070022#include <utils/Timers.h>
23
John Reckfe5e7b72014-05-23 17:42:28 -070024namespace android {
25namespace uirenderer {
26
27class OpenGLRenderer;
28
29class DrawProfiler {
30public:
31 DrawProfiler();
32 ~DrawProfiler();
33
Chris Craik2507c342015-05-04 14:36:49 -070034 bool consumeProperties();
John Reckfe5e7b72014-05-23 17:42:28 -070035 void setDensity(float density);
36
37 void startFrame(nsecs_t recordDurationNanos = 0);
38 void markPlaybackStart();
39 void markPlaybackEnd();
40 void finishFrame();
41
John Recke4267ea2014-06-03 15:53:15 -070042 void unionDirty(SkRect* dirty);
John Reckfe5e7b72014-05-23 17:42:28 -070043 void draw(OpenGLRenderer* canvas);
44
45 void dumpData(int fd);
46
47private:
John Reckfe5e7b72014-05-23 17:42:28 -070048 typedef struct {
49 float record;
50 float prepare;
51 float playback;
52 float swapBuffers;
53 } FrameTimingData;
54
55 void createData();
56 void destroyData();
57
58 void addRect(Rect& r, float data, float* shapeOutput);
59 void prepareShapes(const int baseline);
60 void drawGraph(OpenGLRenderer* canvas);
61 void drawCurrentFrame(OpenGLRenderer* canvas);
62 void drawThreshold(OpenGLRenderer* canvas);
63
Chris Craik2507c342015-05-04 14:36:49 -070064 ProfileType mType = ProfileType::None;
65 float mDensity = 0;
John Reckfe5e7b72014-05-23 17:42:28 -070066
Chris Craik2507c342015-05-04 14:36:49 -070067 FrameTimingData* mData = nullptr;
68 int mDataSize = 0;
John Reckfe5e7b72014-05-23 17:42:28 -070069
Chris Craik2507c342015-05-04 14:36:49 -070070 int mCurrentFrame = -1;
71 nsecs_t mPreviousTime = 0;
John Reckfe5e7b72014-05-23 17:42:28 -070072
Chris Craik2507c342015-05-04 14:36:49 -070073 int mVerticalUnit = 0;
74 int mHorizontalUnit = 0;
75 int mThresholdStroke = 0;
John Reckfe5e7b72014-05-23 17:42:28 -070076
77 /*
78 * mRects represents an array of rect shapes, divided into NUM_ELEMENTS
79 * groups such that each group is drawn with the same paint.
80 * For example mRects[0] is the array of rect floats suitable for
81 * OpenGLRenderer:drawRects() that makes up all the FrameTimingData:record
82 * information.
83 */
Chris Craik2507c342015-05-04 14:36:49 -070084 float** mRects = nullptr;
John Reck23d307c2014-10-27 12:38:48 -070085
Chris Craik2507c342015-05-04 14:36:49 -070086 bool mShowDirtyRegions = false;
John Reck23d307c2014-10-27 12:38:48 -070087 SkRect mDirtyRegion;
Chris Craik2507c342015-05-04 14:36:49 -070088 bool mFlashToggle = false;
John Reckfe5e7b72014-05-23 17:42:28 -070089};
90
91} /* namespace uirenderer */
92} /* namespace android */
93
94#endif /* DRAWPROFILER_H */