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 | */ |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 16 | |
| 17 | #pragma once |
John Reck | 4c9e59d | 2015-05-12 07:17:50 -0700 | [diff] [blame] | 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 | |
Matt Sarett | de97307 | 2016-10-25 11:07:40 -0400 | [diff] [blame] | 31 | class IProfileRenderer; |
John Reck | 4c9e59d | 2015-05-12 07:17:50 -0700 | [diff] [blame] | 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. |
| 38 | typedef RingBuffer<FrameInfo, 120> FrameInfoSource; |
| 39 | |
| 40 | class FrameInfoVisualizer { |
| 41 | public: |
Chih-Hung Hsieh | faecb78 | 2016-07-21 11:23:06 -0700 | [diff] [blame] | 42 | explicit FrameInfoVisualizer(FrameInfoSource& source); |
John Reck | 4c9e59d | 2015-05-12 07:17:50 -0700 | [diff] [blame] | 43 | ~FrameInfoVisualizer(); |
| 44 | |
| 45 | bool consumeProperties(); |
| 46 | void setDensity(float density); |
| 47 | |
| 48 | void unionDirty(SkRect* dirty); |
Matt Sarett | de97307 | 2016-10-25 11:07:40 -0400 | [diff] [blame] | 49 | void draw(IProfileRenderer& renderer); |
John Reck | 4c9e59d | 2015-05-12 07:17:50 -0700 | [diff] [blame] | 50 | |
| 51 | void dumpData(int fd); |
| 52 | |
| 53 | private: |
| 54 | void createData(); |
| 55 | void destroyData(); |
| 56 | |
John Reck | 4130027 | 2015-06-03 14:42:34 -0700 | [diff] [blame] | 57 | void initializeRects(const int baseline, const int width); |
John Reck | bf3c602 | 2015-06-02 15:55:00 -0700 | [diff] [blame] | 58 | void nextBarSegment(FrameInfoIndex start, FrameInfoIndex end); |
Matt Sarett | de97307 | 2016-10-25 11:07:40 -0400 | [diff] [blame] | 59 | void drawGraph(IProfileRenderer& renderer); |
| 60 | void drawThreshold(IProfileRenderer& renderer); |
John Reck | 4c9e59d | 2015-05-12 07:17:50 -0700 | [diff] [blame] | 61 | |
John Reck | be3fba0 | 2015-07-06 13:49:58 -0700 | [diff] [blame] | 62 | inline float durationMS(size_t index, FrameInfoIndex start, FrameInfoIndex end) { |
| 63 | float duration = mFrameSource[index].duration(start, end) * 0.000001f; |
John Reck | bf3c602 | 2015-06-02 15:55:00 -0700 | [diff] [blame] | 64 | // Clamp to large to avoid spiking off the top of the screen |
| 65 | duration = duration > 50.0f ? 50.0f : duration; |
John Reck | 4c9e59d | 2015-05-12 07:17:50 -0700 | [diff] [blame] | 66 | return duration > 0.0f ? duration : 0.0f; |
| 67 | } |
| 68 | |
John Reck | 4c9e59d | 2015-05-12 07:17:50 -0700 | [diff] [blame] | 69 | ProfileType mType = ProfileType::None; |
| 70 | float mDensity = 0; |
| 71 | |
| 72 | FrameInfoSource& mFrameSource; |
| 73 | |
| 74 | int mVerticalUnit = 0; |
John Reck | 4c9e59d | 2015-05-12 07:17:50 -0700 | [diff] [blame] | 75 | int mThresholdStroke = 0; |
| 76 | |
John Reck | 4130027 | 2015-06-03 14:42:34 -0700 | [diff] [blame] | 77 | int mNumFastRects; |
| 78 | std::unique_ptr<float[]> mFastRects; |
| 79 | int mNumJankyRects; |
| 80 | std::unique_ptr<float[]> mJankyRects; |
John Reck | 4c9e59d | 2015-05-12 07:17:50 -0700 | [diff] [blame] | 81 | |
| 82 | bool mShowDirtyRegions = false; |
| 83 | SkRect mDirtyRegion; |
| 84 | bool mFlashToggle = false; |
| 85 | nsecs_t mLastFrameLogged = 0; |
| 86 | }; |
| 87 | |
| 88 | } /* namespace uirenderer */ |
| 89 | } /* namespace android */ |