LayerProtoParser.h revision 5bf9d6835d2103a0d7181852939189316e446195
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
17#include <layerproto/LayerProtoHeader.h>
18
19#include <math/vec4.h>
20
21#include <unordered_map>
22#include <vector>
23
24namespace android {
25namespace surfaceflinger {
26
27class LayerProtoParser {
28public:
29    class ActiveBuffer {
30    public:
31        uint32_t width;
32        uint32_t height;
33        uint32_t stride;
34        int32_t format;
35
36        std::string to_string() const;
37    };
38
39    class Transform {
40    public:
41        float dsdx;
42        float dtdx;
43        float dsdy;
44        float dtdy;
45
46        std::string to_string() const;
47    };
48
49    class Rect {
50    public:
51        int32_t left;
52        int32_t top;
53        int32_t right;
54        int32_t bottom;
55
56        std::string to_string() const;
57    };
58
59    class Region {
60    public:
61        uint64_t id;
62        std::vector<Rect> rects;
63
64        std::string to_string(const char* what) const;
65    };
66
67    class Layer {
68    public:
69        int32_t id;
70        std::string name;
71        std::vector<const Layer*> children;
72        std::vector<const Layer*> relatives;
73        std::string type;
74        LayerProtoParser::Region transparentRegion;
75        LayerProtoParser::Region visibleRegion;
76        LayerProtoParser::Region damageRegion;
77        uint32_t layerStack;
78        int32_t z;
79        float2 position;
80        float2 requestedPosition;
81        int2 size;
82        LayerProtoParser::Rect crop;
83        LayerProtoParser::Rect finalCrop;
84        bool isOpaque;
85        bool invalidate;
86        std::string dataspace;
87        std::string pixelFormat;
88        half4 color;
89        half4 requestedColor;
90        uint32_t flags;
91        Transform transform;
92        Transform requestedTransform;
93        Layer* parent = 0;
94        Layer* zOrderRelativeOf = 0;
95        LayerProtoParser::ActiveBuffer activeBuffer;
96        int32_t queuedFrames;
97        bool refreshPending;
98
99        std::string to_string() const;
100    };
101
102    static std::vector<const Layer*> generateLayerTree(const LayersProto& layersProto);
103    static std::string layersToString(const std::vector<const LayerProtoParser::Layer*> layers);
104
105private:
106    static std::unordered_map<int32_t, Layer*> generateMap(const LayersProto& layersProto);
107    static LayerProtoParser::Layer* generateLayer(const LayerProto& layerProto);
108    static LayerProtoParser::Region generateRegion(const RegionProto& regionProto);
109    static LayerProtoParser::Rect generateRect(const RectProto& rectProto);
110    static LayerProtoParser::Transform generateTransform(const TransformProto& transformProto);
111    static LayerProtoParser::ActiveBuffer generateActiveBuffer(
112            const ActiveBufferProto& activeBufferProto);
113    static void updateChildrenAndRelative(const LayerProto& layerProto,
114                                          std::unordered_map<int32_t, Layer*>& layerMap);
115
116    static std::string layerToString(const LayerProtoParser::Layer* layer);
117};
118
119} // namespace surfaceflinger
120} // namespace android
121