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