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 bool isProtected; 112 float cornerRadius; 113 int backgroundBlurRadius; 114 LayerMetadata metadata; 115 LayerProtoParser::FloatRect cornerRadiusCrop; 116 float shadowRadius; 117 118 std::string to_string() const; 119 }; 120 121 class LayerTree { 122 public: 123 // all layers in LayersProto and in the original order 124 std::vector<Layer> allLayers; 125 126 // pointers to top-level layers in allLayers 127 std::vector<Layer*> topLevelLayers; 128 }; 129 130 static LayerTree generateLayerTree(const LayersProto& layersProto); 131 static std::string layerTreeToString(const LayerTree& layerTree); 132 133 private: 134 static std::vector<Layer> generateLayerList(const LayersProto& layersProto); 135 static LayerProtoParser::Layer generateLayer(const LayerProto& layerProto); 136 static LayerProtoParser::Region generateRegion(const RegionProto& regionProto); 137 static LayerProtoParser::Rect generateRect(const RectProto& rectProto); 138 static LayerProtoParser::FloatRect generateFloatRect(const FloatRectProto& rectProto); 139 static LayerProtoParser::Transform generateTransform(const TransformProto& transformProto); 140 static LayerProtoParser::ActiveBuffer generateActiveBuffer( 141 const ActiveBufferProto& activeBufferProto); 142 static void updateChildrenAndRelative(const LayerProto& layerProto, 143 std::unordered_map<int32_t, Layer*>& layerMap); 144 145 static std::string layerToString(const LayerProtoParser::Layer* layer); 146 }; 147 148 } // namespace surfaceflinger 149 } // namespace android 150