LayerManagerControl: added feature "analyze surface"
[profile/ivi/layer-management.git] / LayerManagerExamples / LayerManagerControl / include / LMControl.h
1 /***************************************************************************
2  *
3  * Copyright 2012 BMW Car IT GmbH
4  *
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  ****************************************************************************/
19
20 #ifndef __LMCONTROL_H__
21 #define __LMCONTROL_H__
22
23 #include <map>
24 using std::map;
25
26 #include <vector>
27 using std::vector;
28
29 #include <set>
30 using std::set;
31
32 #include <string>
33 using std::string;
34
35 /*
36  * Datastructure that contains all information about a scene
37  */
38 struct t_scene_data
39 {
40     map<t_ilm_display, vector<t_ilm_layer> > screenLayers;
41     map<t_ilm_layer, vector<t_ilm_surface> > layerSurfaces;
42
43     map<t_ilm_surface, ilmSurfaceProperties> surfaceProperties;
44     map<t_ilm_layer, ilmLayerProperties> layerProperties;
45
46     map<t_ilm_layer, t_ilm_display> layerScreen;
47     map<t_ilm_surface, t_ilm_layer> surfaceLayer;
48
49     vector<t_ilm_surface> surfaces;
50     vector<t_ilm_surface> layers;
51     vector<t_ilm_display> screens;
52
53     t_ilm_layer extraLayer;
54     t_ilm_uint screenWidth;
55     t_ilm_uint screenHeight;
56 };
57
58 /*
59  * Vector of four integers <x y z w>
60  */
61 class tuple4
62 {
63 public:
64     int x, y, z, w;
65     tuple4(int _x, int _y, int _z, int _w) :
66         x(_x), y(_y), z(_z), w(_w)
67     {
68
69     }
70
71     tuple4() :
72         x(0), y(0), z(0), w(0)
73     {
74
75     }
76
77     tuple4(const tuple4& other)
78     {
79         x = other.x;
80         y = other.y;
81         z = other.z;
82         w = other.w;
83     }
84
85     void scale(float s)
86     {
87         x = static_cast<int>(x * s);
88         y = static_cast<int>(y * s);
89         z = static_cast<int>(z * s);
90         w = static_cast<int>(w * s);
91     }
92
93     const tuple4& operator=(const tuple4& other)
94     {
95         x = other.x;
96         y = other.y;
97         z = other.z;
98         w = other.w;
99         return *this;
100     }
101
102 };
103
104
105
106 //=============================================================================
107 //common.cpp
108 //=============================================================================
109 /*
110  * Captures all information about the rendered scene into an object of type t_scene_data
111  */
112 void captureSceneData(t_scene_data* pScene);
113
114 /*
115  * Calculates the final coordinates of a surface on the screen in the scene
116  */
117 tuple4 getSurfaceScreenCoordinates(t_scene_data* pScene, t_ilm_surface surface);
118
119 /*
120  * Gets render order of surfaces in a scene. A surface is execluded from the render order
121  * if it does not belong to a layer or if it belongs to a layer that does not belong to a screen
122  *
123  * The surface at index 0 is the deepest surface in the scene, and surface at size()-1 is
124  * the topmost surface
125  */
126 vector<t_ilm_surface> getSceneRenderOrder(t_scene_data* pScene);
127
128 /*
129  * Sets a scene to be restored if an interrupt signal (Ctrl+C) is received
130  */
131 void setSceneToRestore(t_scene_data* pScene);
132
133 /*
134  * Clones the given scene into another t_scene_data object that would look exactly the same
135  * but all rendered surfaces are rendered on one (newly created) layer.
136  * Order, sizes and positions of rendered surfaces are preserved relative to screen
137  *
138  */
139 t_scene_data cloneToUniLayerScene(t_scene_data* pScene);
140
141 /*
142  * Hide the currently rendered scene, and render the given scene instead
143  * If clean is set to true all layers and surfaces that do not exist in the given
144  * scene are destroyed
145  */
146 void setScene(t_scene_data* pScene, bool clean = false);
147
148 /*
149  * Makes a smooth transformation effect from the intial to the final scene
150  */
151 void transformScene(t_scene_data* pInitialScene, t_scene_data* pFinalScene, t_ilm_long durationMillis, t_ilm_int frameCount);
152
153 /*
154  * Creates a new empty scene
155  */
156 void emptyScene(t_scene_data* pScene);
157
158 /*
159  * Returns true if the surface is rendered to the screen
160  * (If the surface belongs to a layer that belongs to a screen)
161  */
162 t_ilm_bool surfaceRenderedOnScreen(t_scene_data& scene, t_ilm_surface surface);
163
164
165 //=============================================================================
166 //util.cpp
167 //=============================================================================
168
169 /*
170  * Returns true if the rectangle A is inside (or typical with) rectangle B
171  * (each tuple represents a rectangle in 2-D coordinates as <x1 y1 x2 y2>)
172  */
173 t_ilm_bool inside(tuple4 A, tuple4 B);
174
175 /*
176  * Returns true if a is in the interval between b1 and b2 (inclusive)
177  */
178 t_ilm_bool between(int b1, int a, int b2);
179
180
181 /*
182  * Returns true if the rectangle A intersects (or touches) rectangle B
183  * (each tuple represents a rectangle in 2-D coordinates as <x1 y1 x2 y2>)
184  */
185 t_ilm_bool intersect(tuple4 A, tuple4 B);
186
187 /*
188  * Trim white space characters from the beginning of the string
189  */
190 string rtrim(string s);
191
192 /*
193  * Replace all occurances of a in s by b
194  */
195 string replaceAll(string s, string a, string b);
196 string replaceAll(string s, char a, char b);
197
198 /*
199  * For every pair (a,b) in the map: replace all occurances of a in the string by b
200  */
201 string replaceAll(string s, map<string, string> replacements);
202
203 /*
204  * Split the string using the giving delimiter
205  */
206 set<string> split(string s, char d);
207
208
209 //=============================================================================
210 //print.cpp
211 //=============================================================================
212
213 /*
214  * Functions for printing arrays, vector and maps
215  */
216 void printArray(const char* text, unsigned int* array, int count);
217
218 template<typename T>
219 void printArray(const char* text, T* array, int count);
220
221 template<typename T>
222 void printVector(const char* text, vector<T> v);
223
224 template<typename K, typename V>
225 void printMap(const char* text, std::map<K, V> m);
226
227 /*
228  * Prints information about the specified screen
229  */
230 void printScreenProperties(unsigned int screenid, const char* prefix = "");
231
232 /*
233  * Prints information about the specified layer
234  */
235 void printLayerProperties(unsigned int layerid, const char* prefix = "");
236
237 /*
238  * Prints information about the specified surface
239  */
240 void printSurfaceProperties(unsigned int surfaceid, const char* prefix = "");
241
242 /*
243  * Prints information about rendered scene
244  * (All screens, all rendered layers, all rendered surfaces)
245  */
246 void printScene();
247
248
249 //=============================================================================
250 //control.cpp
251 //=============================================================================
252 void getCommunicatorPerformance();
253 void setSurfaceKeyboardFocus(t_ilm_surface surface);
254 void getKeyboardFocus();
255 void setSurfaceAcceptsInput(t_ilm_surface surfaceId, string kbdPointerTouch, t_ilm_bool acceptance);
256 void testNotificationLayer(t_ilm_layer layerid);
257 void watchLayer(unsigned int* layerids, unsigned int layeridCount);
258 void watchSurface(unsigned int* surfaceids, unsigned int surfaceidCount);
259 void setOptimization(t_ilm_uint id, t_ilm_uint mode);
260 void getOptimization(t_ilm_uint id);
261
262
263 //=============================================================================
264 //analyze.cpp
265 //=============================================================================
266
267 /*
268  * Runs and prints the results for a set of analysis procedures to check if there are any potential problems that
269  * might lead to the surface being not rendered or not visible
270  */
271 t_ilm_bool analyzeSurface(t_ilm_surface targetSurfaceId);
272
273 #endif