LayerStats.h 3.0 KB

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