blob: 7871fc6602bdd4054a6efa583c896c63562cd970 [file] [log] [blame]
Yiwei Zhang068e31b2018-02-21 13:02:45 -08001/*
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
24using namespace android::surfaceflinger;
25
26namespace android {
27class String8;
28
29class LayerStats {
30public:
31 void enable();
32 void disable();
33 void clear();
34 bool isEnabled();
35 void logLayerStats(const LayersProto& layersProto);
36 void dump(String8& result);
37
38private:
39 // Traverse layer tree to get all visible layers' stats
40 void traverseLayerTreeStatsLocked(
41 std::vector<std::unique_ptr<LayerProtoParser::Layer>> layerTree,
Yiwei Zhang7c64f172018-03-07 14:52:28 -080042 const LayerProtoParser::LayerGlobal* layerGlobal,
43 std::vector<std::string>& layerShapeVec);
Yiwei Zhang068e31b2018-02-21 13:02:45 -080044 // Convert layer's top-left position into 8x8 percentage of the display
45 static const char* destinationLocation(int32_t location, int32_t range, bool isHorizontal);
46 // Convert layer's size into 8x8 percentage of the display
47 static const char* destinationSize(int32_t size, int32_t range, bool isWidth);
48 // Return the name of the transform
49 static const char* layerTransform(int32_t transform);
Yiwei Zhang7c64f172018-03-07 14:52:28 -080050 // Return the name of the composition type
51 static const char* layerCompositionType(int32_t compositionType);
52 // Return the name of the pixel format
53 static const char* layerPixelFormat(int32_t pixelFormat);
Yiwei Zhang068e31b2018-02-21 13:02:45 -080054 // Calculate scale ratios of layer's width/height with rotation information
55 static std::string scaleRatioWH(const LayerProtoParser::Layer* layer);
56 // Calculate scale ratio from source to destination and convert to string
57 static const char* scaleRatio(int32_t destinationScale, int32_t sourceScale);
Yiwei Zhang7c64f172018-03-07 14:52:28 -080058 // Bucket the alpha into designed buckets
59 static const char* alpha(float a);
Yiwei Zhang068e31b2018-02-21 13:02:45 -080060 // Return whether the original buffer is rotated in final composition
61 static bool isRotated(int32_t transform);
62 // Return whether the original buffer is V-flipped in final composition
63 static bool isVFlipped(int32_t transform);
64 // Return whether the original buffer is H-flipped in final composition
65 static bool isHFlipped(int32_t transform);
66
67 bool mEnabled = false;
68 // Protect mLayersStatsMap
69 std::mutex mMutex;
Yiwei Zhang7c64f172018-03-07 14:52:28 -080070 // Hashmap for tracking the frame(layer shape) stats
71 // KEY is a concatenation of all layers' properties within a frame
72 // VALUE is the number of times this particular set has been scanned out
73 std::unordered_map<std::string, uint32_t> mLayerShapeStatsMap;
Yiwei Zhang068e31b2018-02-21 13:02:45 -080074};
75
Yiwei Zhang7c64f172018-03-07 14:52:28 -080076} // namespace android