| John Reck | 4c9e59d | 2015-05-12 07:17:50 -0700 | [diff] [blame] | 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 "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 |  | 
 | 28 | namespace android { | 
 | 29 | namespace uirenderer { | 
 | 30 |  | 
| Chris Craik | 1dfa070 | 2016-03-04 15:59:24 -0800 | [diff] [blame] | 31 | #if HWUI_NEW_OPS | 
 | 32 | class BakedOpRenderer; | 
 | 33 | typedef BakedOpRenderer ContentRenderer; | 
 | 34 | #else | 
| John Reck | 4c9e59d | 2015-05-12 07:17:50 -0700 | [diff] [blame] | 35 | class OpenGLRenderer; | 
| Chris Craik | 1dfa070 | 2016-03-04 15:59:24 -0800 | [diff] [blame] | 36 | typedef OpenGLRenderer ContentRenderer; | 
 | 37 | #endif | 
| John Reck | 4c9e59d | 2015-05-12 07:17:50 -0700 | [diff] [blame] | 38 |  | 
 | 39 | // TODO: This is a bit awkward as it needs to match the thing in CanvasContext | 
 | 40 | // A better abstraction here would be nice but iterators are painful | 
 | 41 | // and RingBuffer having the size baked into the template is also painful | 
 | 42 | // But making DrawProfiler also be templated is ALSO painful | 
 | 43 | // At least this is a compile failure if this doesn't match, so there's that. | 
 | 44 | typedef RingBuffer<FrameInfo, 120> FrameInfoSource; | 
 | 45 |  | 
 | 46 | class FrameInfoVisualizer { | 
 | 47 | public: | 
| Chih-Hung Hsieh | faecb78 | 2016-07-21 11:23:06 -0700 | [diff] [blame] | 48 |     explicit FrameInfoVisualizer(FrameInfoSource& source); | 
| John Reck | 4c9e59d | 2015-05-12 07:17:50 -0700 | [diff] [blame] | 49 |     ~FrameInfoVisualizer(); | 
 | 50 |  | 
 | 51 |     bool consumeProperties(); | 
 | 52 |     void setDensity(float density); | 
 | 53 |  | 
 | 54 |     void unionDirty(SkRect* dirty); | 
| Chris Craik | 1dfa070 | 2016-03-04 15:59:24 -0800 | [diff] [blame] | 55 |     void draw(ContentRenderer* renderer); | 
| John Reck | 4c9e59d | 2015-05-12 07:17:50 -0700 | [diff] [blame] | 56 |  | 
 | 57 |     void dumpData(int fd); | 
 | 58 |  | 
 | 59 | private: | 
 | 60 |     void createData(); | 
 | 61 |     void destroyData(); | 
 | 62 |  | 
| John Reck | 4130027 | 2015-06-03 14:42:34 -0700 | [diff] [blame] | 63 |     void initializeRects(const int baseline, const int width); | 
| John Reck | bf3c602 | 2015-06-02 15:55:00 -0700 | [diff] [blame] | 64 |     void nextBarSegment(FrameInfoIndex start, FrameInfoIndex end); | 
| Chris Craik | 1dfa070 | 2016-03-04 15:59:24 -0800 | [diff] [blame] | 65 |     void drawGraph(ContentRenderer* renderer); | 
 | 66 |     void drawThreshold(ContentRenderer* renderer); | 
| John Reck | 4c9e59d | 2015-05-12 07:17:50 -0700 | [diff] [blame] | 67 |  | 
| John Reck | be3fba0 | 2015-07-06 13:49:58 -0700 | [diff] [blame] | 68 |     inline float durationMS(size_t index, FrameInfoIndex start, FrameInfoIndex end) { | 
 | 69 |         float duration = mFrameSource[index].duration(start, end) * 0.000001f; | 
| John Reck | bf3c602 | 2015-06-02 15:55:00 -0700 | [diff] [blame] | 70 |         // Clamp to large to avoid spiking off the top of the screen | 
 | 71 |         duration = duration > 50.0f ? 50.0f : duration; | 
| John Reck | 4c9e59d | 2015-05-12 07:17:50 -0700 | [diff] [blame] | 72 |         return duration > 0.0f ? duration : 0.0f; | 
 | 73 |     } | 
 | 74 |  | 
| John Reck | 4c9e59d | 2015-05-12 07:17:50 -0700 | [diff] [blame] | 75 |     ProfileType mType = ProfileType::None; | 
 | 76 |     float mDensity = 0; | 
 | 77 |  | 
 | 78 |     FrameInfoSource& mFrameSource; | 
 | 79 |  | 
 | 80 |     int mVerticalUnit = 0; | 
| John Reck | 4c9e59d | 2015-05-12 07:17:50 -0700 | [diff] [blame] | 81 |     int mThresholdStroke = 0; | 
 | 82 |  | 
| John Reck | 4130027 | 2015-06-03 14:42:34 -0700 | [diff] [blame] | 83 |     int mNumFastRects; | 
 | 84 |     std::unique_ptr<float[]> mFastRects; | 
 | 85 |     int mNumJankyRects; | 
 | 86 |     std::unique_ptr<float[]> mJankyRects; | 
| John Reck | 4c9e59d | 2015-05-12 07:17:50 -0700 | [diff] [blame] | 87 |  | 
 | 88 |     bool mShowDirtyRegions = false; | 
 | 89 |     SkRect mDirtyRegion; | 
 | 90 |     bool mFlashToggle = false; | 
 | 91 |     nsecs_t mLastFrameLogged = 0; | 
 | 92 | }; | 
 | 93 |  | 
 | 94 | } /* namespace uirenderer */ | 
 | 95 | } /* namespace android */ | 
 | 96 |  | 
 | 97 | #endif /* DRAWPROFILER_H */ |