Bug Fix : wm_layer
[apps/agl-service-windowmanager-2017.git] / src / wm_layer_control.hpp
1 /*\r
2  * Copyright (c) 2017 TOYOTA MOTOR CORPORATION\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *      http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 #include <string>\r
18 #include <memory>\r
19 #include <vector>\r
20 #include <unordered_map>\r
21 #include <functional>\r
22 #include <ilm/ilm_control.h>\r
23 #include "wm_error.hpp"\r
24 #include "util.hpp"\r
25 \r
26 namespace wm {\r
27 \r
28 class Screen {\r
29   public:\r
30     Screen(unsigned w, unsigned h) : _width(w), _height(h){}\r
31     unsigned width() { return _width; }\r
32     unsigned height() { return _height; }\r
33   private:\r
34     unsigned _width;\r
35     unsigned _height;\r
36     unsigned _pysical_width = 0;\r
37     unsigned _pysical_height = 0;\r
38 };\r
39 \r
40 class LayerControlCallbacks {\r
41   public:\r
42     LayerControlCallbacks() {};\r
43     ~LayerControlCallbacks() = default;\r
44     LayerControlCallbacks(const LayerControlCallbacks &obj) = default;\r
45 \r
46     // callback functions\r
47     void test(unsigned i) { HMI_DEBUG("test %d", i); }\r
48     std::function<void(unsigned)> surfaceCreated;\r
49     /* std::function<void(unsigned)> surfaceDestroyed;\r
50     std::function<void(unsigned)> layerCreated;\r
51     std::function<void(unsigned)> layerDestroyed; */\r
52 };\r
53 \r
54 class WMLayer;\r
55 class LayerState;\r
56 class WMAction;\r
57 class WMClient;\r
58 \r
59 class LayerControl\r
60 {\r
61   public:\r
62     explicit LayerControl(const std::string& root);\r
63     ~LayerControl() = default;\r
64     WMError init(const LayerControlCallbacks& cb);\r
65     void createNewLayer(unsigned id);\r
66     unsigned getNewLayerID(const std::string& role, std::string* layer_name);\r
67     struct rect getAreaSize(const std::string& area);\r
68     void setupArea(double scaling);\r
69     Screen getScreenInfo();\r
70     double scale();\r
71     // void setRenderOrder(const std::vector<unsigned> layer_render_order);\r
72     // std::vector<unsigned> getAllRenderOrder();\r
73     // std::vector<std::shared_ptr<WMLayer>>& getAllLayers();\r
74     // std::vector<unsigned> getRenderOrder(const std::string& layer_name);\r
75     WMError updateLayer(LayerState& layer_state);\r
76     WMError commitChange();\r
77     void undoUpdate();\r
78     WMError layoutChange(const WMAction& action);\r
79     WMError visibilityChange(const WMAction &action);\r
80 \r
81     // Don't use this function.\r
82     void dispatchCreateEvent(ilmObjectType object, unsigned id, bool created);\r
83     void dispatchPropertyChangeEvent(unsigned id, struct ilmSurfaceProperties*, t_ilm_notification_mask);\r
84     void dispatchPropertyChangeEvent(unsigned id, struct ilmLayerProperties*, t_ilm_notification_mask);\r
85   private:\r
86     WMError makeVisible(const std::shared_ptr<WMClient> client);\r
87     WMError makeInvisible(const std::shared_ptr<WMClient> client);\r
88     WMError loadLayerSetting(const std::string& path);\r
89     WMError loadAreaDb(const std::string& path);\r
90 \r
91     std::vector<std::shared_ptr<WMLayer>> wm_layers;\r
92     std::unordered_map<std::string, struct rect> area2size;\r
93     unsigned screenID;\r
94     struct ilmScreenProperties screen_prop;\r
95     double scaling;\r
96     LayerControlCallbacks cb;\r
97 };\r
98 \r
99 } // namespace wm