Improve window manager
[apps/agl-service-windowmanager-2017.git] / src / wm_layer_control.hpp
1 /*
2  * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
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 <string>
18 #include <memory>
19 #include <vector>
20 #include <unordered_map>
21 #include <functional>
22 #include <ilm/ilm_control.h>
23 #include "wm_error.hpp"
24 #include "util.hpp"
25
26 namespace wm {
27
28 class Screen {
29   public:
30     Screen(unsigned w, unsigned h) : _width(w), _height(h){}
31     unsigned width() { return _width; }
32     unsigned height() { return _height; }
33   private:
34     unsigned _width;
35     unsigned _height;
36     unsigned _pysical_width = 0;
37     unsigned _pysical_height = 0;
38 };
39
40 class LayerControlCallbacks {
41   public:
42     LayerControlCallbacks() {};
43     ~LayerControlCallbacks() = default;
44     LayerControlCallbacks(const LayerControlCallbacks &obj) = default;
45
46     // callback functions
47     std::function<void(unsigned, unsigned)> surfaceCreated;
48     std::function<void(unsigned)> surfaceDestroyed;
49     /*
50     std::function<void(unsigned)> layerCreated;
51     std::function<void(unsigned)> layerDestroyed;
52     */
53 };
54
55 class WMLayer;
56 class LayerState;
57 class WMAction;
58 class WMClient;
59
60 class LayerControl
61 {
62   public:
63     explicit LayerControl(const std::string& root, const std::string& ecu_name);
64     ~LayerControl() = default;
65     WMError init(const LayerControlCallbacks& cb);
66     void createNewLayer(unsigned id);
67     void createNewRemoteLayer(unsigned id);
68     unsigned getNewLayerID(const std::string& role, std::string* layer_name);
69     std::shared_ptr<WMLayer> getWMLayer(unsigned layer);
70     std::shared_ptr<WMLayer> getWMLayer(std::string layer_name);
71     struct rect getAreaSize(const std::string& area);
72     void setupArea(const rectangle& base_rct, double scaling);
73     Screen getScreenInfo();
74     double scale();
75     WMError updateLayer(LayerState& layer_state);
76     WMError renderLayers();
77     WMError renderLayersRemote();
78     WMError setXDGSurfaceOriginSize(unsigned surface);
79     void undoUpdate();
80     WMError layoutChange(const WMAction& action);
81     WMError visibilityChange(const WMAction &action);
82     void appTerminated(const std::shared_ptr<WMClient> client);
83
84     // Don't use this function.
85     void dispatchCreateEvent(ilmObjectType object, unsigned id, bool created);
86     void dispatchSurfacePropChangeEvent(unsigned id, struct ilmSurfaceProperties*, t_ilm_notification_mask);
87     void dispatchLayerPropChangeEvent(unsigned id, struct ilmLayerProperties*, t_ilm_notification_mask);
88
89   private:
90     WMError makeVisible(const std::shared_ptr<WMClient> client);
91     WMError makeInvisible(const std::shared_ptr<WMClient> client);
92     bool moveForeGround(const std::shared_ptr<WMClient> client);
93     bool moveBackGround(const std::shared_ptr<WMClient> client);
94     WMError loadLayerSetting(const std::string& path);
95     WMError loadAreasConfigFile(const std::string& path, const std::string& ecu_name);
96
97     // For Remote
98     WMError makeRemoteVisible(const std::shared_ptr<WMClient> client);
99     WMError makeRemoteInvisible(const std::shared_ptr<WMClient> client);
100
101     std::vector<std::shared_ptr<WMLayer>> wm_layers;
102     std::vector<std::shared_ptr<WMLayer>> wm_remote_layers;
103     std::unordered_map<unsigned, unsigned> lid2wmlid;
104     std::unordered_map<std::string, struct rect> area2size;
105     unsigned screenID;
106     signed remoteScreenID;
107     struct ilmScreenProperties screen_prop;
108     double scaling;
109     int offset_x;
110     int offset_y;
111     LayerControlCallbacks cb;
112 };
113
114 } // namespace wm