Yiwei Zhang | 068e31b | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <layerproto/LayerProtoHeader.h> |
| 20 | #include <layerproto/LayerProtoParser.h> |
| 21 | #include <mutex> |
| 22 | #include <unordered_map> |
| 23 | |
| 24 | using namespace android::surfaceflinger; |
| 25 | |
| 26 | namespace android { |
Yiwei Zhang | 068e31b | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 27 | |
| 28 | class LayerStats { |
| 29 | public: |
| 30 | void enable(); |
| 31 | void disable(); |
| 32 | void clear(); |
| 33 | bool isEnabled(); |
| 34 | void logLayerStats(const LayersProto& layersProto); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 35 | void dump(std::string& result); |
Yiwei Zhang | 068e31b | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 36 | |
| 37 | private: |
| 38 | // Traverse layer tree to get all visible layers' stats |
| 39 | void traverseLayerTreeStatsLocked( |
Chia-I Wu | 2f88413 | 2018-09-13 15:17:58 -0700 | [diff] [blame] | 40 | const std::vector<LayerProtoParser::Layer*>& layerTree, |
Yiwei Zhang | 2418010 | 2018-04-09 11:05:39 -0700 | [diff] [blame] | 41 | const LayerProtoParser::LayerGlobal& layerGlobal, |
| 42 | std::vector<std::string>* const outLayerShapeVec); |
Yiwei Zhang | 068e31b | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 43 | // Convert layer's top-left position into 8x8 percentage of the display |
| 44 | static const char* destinationLocation(int32_t location, int32_t range, bool isHorizontal); |
| 45 | // Convert layer's size into 8x8 percentage of the display |
| 46 | static const char* destinationSize(int32_t size, int32_t range, bool isWidth); |
| 47 | // Return the name of the transform |
| 48 | static const char* layerTransform(int32_t transform); |
Yiwei Zhang | 7c64f17 | 2018-03-07 14:52:28 -0800 | [diff] [blame] | 49 | // Return the name of the composition type |
| 50 | static const char* layerCompositionType(int32_t compositionType); |
| 51 | // Return the name of the pixel format |
George Burgess IV | 3ebb48d | 2018-10-03 12:08:27 -0700 | [diff] [blame] | 52 | static std::string layerPixelFormat(int32_t pixelFormat); |
Yiwei Zhang | 068e31b | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 53 | // Calculate scale ratios of layer's width/height with rotation information |
| 54 | static std::string scaleRatioWH(const LayerProtoParser::Layer* layer); |
| 55 | // Calculate scale ratio from source to destination and convert to string |
| 56 | static const char* scaleRatio(int32_t destinationScale, int32_t sourceScale); |
Yiwei Zhang | 7c64f17 | 2018-03-07 14:52:28 -0800 | [diff] [blame] | 57 | // Bucket the alpha into designed buckets |
| 58 | static const char* alpha(float a); |
Yiwei Zhang | 068e31b | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 59 | // Return whether the original buffer is rotated in final composition |
| 60 | static bool isRotated(int32_t transform); |
| 61 | // Return whether the original buffer is V-flipped in final composition |
| 62 | static bool isVFlipped(int32_t transform); |
| 63 | // Return whether the original buffer is H-flipped in final composition |
| 64 | static bool isHFlipped(int32_t transform); |
| 65 | |
| 66 | bool mEnabled = false; |
| 67 | // Protect mLayersStatsMap |
| 68 | std::mutex mMutex; |
Yiwei Zhang | 7c64f17 | 2018-03-07 14:52:28 -0800 | [diff] [blame] | 69 | // Hashmap for tracking the frame(layer shape) stats |
| 70 | // KEY is a concatenation of all layers' properties within a frame |
| 71 | // VALUE is the number of times this particular set has been scanned out |
| 72 | std::unordered_map<std::string, uint32_t> mLayerShapeStatsMap; |
Yiwei Zhang | 068e31b | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 73 | }; |
| 74 | |
Yiwei Zhang | 7c64f17 | 2018-03-07 14:52:28 -0800 | [diff] [blame] | 75 | } // namespace android |