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