1 /* 2 * Copyright (C) 2017 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 18 #include <layerproto/LayerProtoHeader.h> 19 20 #include <gui/LayerMetadata.h> 21 #include <math/vec4.h> 22 23 #include <memory> 24 #include <unordered_map> 25 #include <vector> 26 27 using android::gui::LayerMetadata; 28 29 namespace android { 30 namespace surfaceflinger { 31 32 class LayerProtoParser { 33 public: 34 class ActiveBuffer { 35 public: 36 uint32_t width; 37 uint32_t height; 38 uint32_t stride; 39 int32_t format; 40 41 std::string to_string() const; 42 }; 43 44 class Transform { 45 public: 46 float dsdx; 47 float dtdx; 48 float dsdy; 49 float dtdy; 50 51 std::string to_string() const; 52 }; 53 54 class Rect { 55 public: 56 int32_t left; 57 int32_t top; 58 int32_t right; 59 int32_t bottom; 60 61 std::string to_string() const; 62 }; 63 64 class FloatRect { 65 public: 66 float left; 67 float top; 68 float right; 69 float bottom; 70 71 std::string to_string() const; 72 }; 73 74 class Region { 75 public: 76 uint64_t id; 77 std::vector<Rect> rects; 78 79 std::string to_string(const char* what) const; 80 }; 81 82 class Layer { 83 public: 84 int32_t id; 85 std::string name; 86 std::vector<Layer*> children; 87 std::vector<Layer*> relatives; 88 std::string type; 89 LayerProtoParser::Region transparentRegion; 90 LayerProtoParser::Region visibleRegion; 91 LayerProtoParser::Region damageRegion; 92 uint32_t layerStack; 93 int32_t z; 94 float2 position; 95 float2 requestedPosition; 96 int2 size; 97 LayerProtoParser::Rect crop; 98 bool isOpaque; 99 bool invalidate; 100 std::string dataspace; 101 std::string pixelFormat; 102 half4 color; 103 half4 requestedColor; 104 uint32_t flags; 105 Transform transform; 106 Transform requestedTransform; 107 Layer* parent = 0; 108 Layer* zOrderRelativeOf = 0; 109 LayerProtoParser::ActiveBuffer activeBuffer; 110 Transform bufferTransform; 111 int32_t queuedFrames; 112 bool refreshPending; 113 bool isProtected; 114 bool isTrustedOverlay; 115 float cornerRadius; 116 int backgroundBlurRadius; 117 LayerMetadata metadata; 118 LayerProtoParser::FloatRect cornerRadiusCrop; 119 float shadowRadius; 120 uid_t ownerUid; 121 122 std::string to_string() const; 123 }; 124 125 class LayerTree { 126 public: 127 // all layers in LayersProto and in the original order 128 std::vector<Layer> allLayers; 129 130 // pointers to top-level layers in allLayers 131 std::vector<Layer*> topLevelLayers; 132 }; 133 134 static LayerTree generateLayerTree(const perfetto::protos::LayersProto& layersProto); 135 static std::string layerTreeToString(const LayerTree& layerTree); 136 137 private: 138 static std::vector<Layer> generateLayerList(const perfetto::protos::LayersProto& layersProto); 139 static LayerProtoParser::Layer generateLayer(const perfetto::protos::LayerProto& layerProto); 140 static LayerProtoParser::Region generateRegion( 141 const perfetto::protos::RegionProto& regionProto); 142 static LayerProtoParser::Rect generateRect(const perfetto::protos::RectProto& rectProto); 143 static LayerProtoParser::FloatRect generateFloatRect( 144 const perfetto::protos::FloatRectProto& rectProto); 145 static LayerProtoParser::Transform generateTransform( 146 const perfetto::protos::TransformProto& transformProto); 147 static LayerProtoParser::ActiveBuffer generateActiveBuffer( 148 const perfetto::protos::ActiveBufferProto& activeBufferProto); 149 static void updateChildrenAndRelative(const perfetto::protos::LayerProto& layerProto, 150 std::unordered_map<int32_t, Layer*>& layerMap); 151 152 static std::string layerToString(const LayerProtoParser::Layer* layer); 153 }; 154 155 } // namespace surfaceflinger 156 } // namespace android 157