Update wm_layer
[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     std::function<void(unsigned)> layerCreated;
50     std::function<void(unsigned)> layerDestroyed; */
51 };
52
53 class WMLayer;
54 class LayerState;
55 class WMAction;
56 class WMClient;
57
58 class LayerControl
59 {
60   public:
61     explicit LayerControl(const std::string& root);
62     ~LayerControl() = default;
63     WMError init(const LayerControlCallbacks& cb);
64     void createNewLayer(unsigned id);
65     unsigned getNewLayerID(const std::string& role, std::string* layer_name);
66     std::shared_ptr<WMLayer> getWMLayer(unsigned layer);
67     // std::shared_ptr<WMLayer> getWMLayer(std::string layer_name);
68     struct rect getAreaSize(const std::string& area);
69     void setupArea(double scaling);
70     Screen getScreenInfo();
71     double scale();
72     // void setRenderOrder(const std::vector<unsigned> layer_render_order);
73     // std::vector<unsigned> getAllRenderOrder();
74     // std::vector<std::shared_ptr<WMLayer>>& getAllLayers();
75     // std::vector<unsigned> getRenderOrder(const std::string& layer_name);
76     WMError updateLayer(LayerState& layer_state);
77     WMError commitChange();
78     // WMError renderWMLayers();
79     void undoUpdate();
80     WMError layoutChange(const WMAction& action);
81     WMError visibilityChange(const WMAction &action);
82
83     // Don't use this function.
84     void dispatchCreateEvent(ilmObjectType object, unsigned id, bool created);
85     void dispatchPropertyChangeEvent(unsigned id, struct ilmSurfaceProperties*, t_ilm_notification_mask);
86     void dispatchPropertyChangeEvent(unsigned id, struct ilmLayerProperties*, t_ilm_notification_mask);
87   private:
88     WMError makeVisible(const std::shared_ptr<WMClient> client);
89     WMError makeInvisible(const std::shared_ptr<WMClient> client);
90     WMError loadLayerSetting(const std::string& path);
91     WMError loadAreaDb(const std::string& path);
92
93     std::vector<std::shared_ptr<WMLayer>> wm_layers;
94     std::unordered_map<unsigned, unsigned> lid2wmlid;
95     std::unordered_map<std::string, struct rect> area2size;
96     unsigned screenID;
97     struct ilmScreenProperties screen_prop;
98     double scaling;
99     LayerControlCallbacks cb;
100 };
101
102 } // namespace wm