LayerManagerControl: fixed handling error in ILM calls
[profile/ivi/layer-management.git] / LayerManagerControl / src / print.cpp
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 #include "ilm_client.h"
21 #include "LMControl.h"
22
23 #include <iostream>
24 using std::cout;
25 using std::cin;
26 using std::endl;
27
28 #include <iomanip>
29 using std::dec;
30 using std::hex;
31
32
33 #include <map>
34 using std::map;
35
36 #include <vector>
37 using std::vector;
38
39
40 void printArray(const char* text, unsigned int* array, int count)
41 {
42     cout << count << " " << text << "(s):\n";
43     for (int i = 0; i < count; ++i)
44     {
45         cout << "- " << text << " " << dec << array[i] << hex << " (0x"
46                 << array[i] << ")" << dec << "\n";
47     }
48 }
49
50 template<typename T>
51 void printArray(const char* text, T* array, int count)
52 {
53     cout << count << " " << text << "(s):\n";
54     for (int i = 0; i < count; ++i)
55     {
56         cout << "- " << text << " " << "[" << array[i] << "]" << "\n";
57     }
58 }
59
60 template<typename T>
61 void printVector(const char* text, vector<T> v)
62 {
63     cout << v.size() << " " << text << "(s) Vector:\n";
64     for (int i = 0; i < v.size(); ++i)
65     {
66         cout << "- " << text << " " << v[i] << endl;
67     }
68 }
69
70 template<typename K, typename V>
71 void printMap(const char* text, std::map<K, V> m)
72 {
73     cout << m.size() << " " << text << endl;
74
75     for (typename map<K, V>::iterator it = m.begin(); it != m.end(); ++it)
76     {
77         cout << "- " << (*it).first << " -> " << (*it).second << endl;
78     }
79 }
80
81 void printScreenProperties(unsigned int screenid, const char* prefix)
82 {
83     cout << prefix << "screen " << screenid << " (0x" << hex << screenid << dec
84             << ")\n";
85     cout << prefix << "---------------------------------------\n";
86
87     ilmScreenProperties screenProperties;
88
89     ilmErrorTypes callResult = ilm_getPropertiesOfScreen(screenid, &screenProperties);
90     if (ILM_SUCCESS != callResult)
91     {
92         cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
93         cout << "Failed to get properties of screen with ID " << screenid << " found\n";
94         return;
95     }
96
97     cout << prefix << "- resolution:           x=" << screenProperties.screenWidth << ", y="
98             << screenProperties.screenHeight << "\n";
99
100     cout << prefix << "- hardware layer count: " << screenProperties.harwareLayerCount << "\n";
101
102     cout << prefix << "- layer render order:   ";
103
104     for (t_ilm_uint layerIndex = 0; layerIndex < screenProperties.layerCount; ++layerIndex)
105     {
106         t_ilm_layer layerid = screenProperties.layerIds[layerIndex];
107         cout << layerid << "(0x" << hex << layerid << dec << "), ";
108     }
109     cout << "\n";
110 }
111
112 void printLayerProperties(unsigned int layerid, const char* prefix)
113 {
114     cout << prefix << "layer " << layerid << " (0x" << hex << layerid << dec
115             << ")\n";
116     cout << prefix << "---------------------------------------\n";
117
118     ilmLayerProperties p;
119
120     ilmErrorTypes callResult = ilm_getPropertiesOfLayer(layerid, &p);
121     if (ILM_SUCCESS != callResult)
122     {
123         cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
124         cout << "Failed to get properties of layer with ID " << layerid << " found\n";
125         return;
126     }
127
128     cout << prefix << "- created by pid:       " << p.creatorPid << "\n";
129
130     cout << prefix << "- original size:        x=" << p.origSourceWidth
131             << ", y=" << p.origSourceHeight << "\n";
132     cout << prefix << "- destination region:   x=" << p.destX << ", y="
133             << p.destY << ", w=" << p.destWidth << ", h=" << p.destHeight
134             << "\n";
135     cout << prefix << "- source region:        x=" << p.sourceX << ", y="
136             << p.sourceY << ", w=" << p.sourceWidth << ", h=" << p.sourceHeight
137             << "\n";
138
139     cout << prefix << "- orientation:          " << p.orientation << " (";
140     switch (p.orientation)
141     {
142     case 0/*Zero*/:
143         cout << "up is top)\n";
144         break;
145     case 1/*Ninety*/:
146         cout << "up is right)\n";
147         break;
148     case 2/*OneEighty*/:
149         cout << "up is bottom)\n";
150         break;
151     case 3/*TwoSeventy*/:
152         cout << "up is left)\n";
153         break;
154     default:
155         cout << "unknown)\n";
156         break;
157     }
158
159     cout << prefix << "- opacity:              " << p.opacity << "\n";
160     cout << prefix << "- visibility:           " << p.visibility << "\n";
161
162     cout << prefix << "- type:                 " << p.type << " (";
163     switch (p.type)
164     {
165     case 1/*Hardware*/:
166         cout << "hardware)\n";
167         break;
168     case 2/*Software_2D*/:
169         cout << "software 2d)\n";
170         break;
171     case 3/*Software_2_5D*/:
172         cout << "software 2.5d)\n";
173         break;
174     default:
175         cout << "unknown)\n";
176         break;
177     }
178
179     cout << prefix << "- chromakey:            "
180             << (p.chromaKeyEnabled ? "enabled " : "disabled ")
181             << "(r=" << p.chromaKeyRed << ", g=" << p.chromaKeyGreen << ", b=" << p.chromaKeyBlue << ")\n";
182
183     cout << prefix << "- surface render order: ";
184
185     int surfaceCount = 0;
186     unsigned int* surfaceArray = NULL;
187
188     callResult = ilm_getSurfaceIDsOnLayer(layerid, &surfaceCount, &surfaceArray);
189     if (ILM_SUCCESS != callResult)
190     {
191         cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
192         cout << "Failed to get surfaces on layer with ID " << layerid << " \n";
193         return;
194     }
195
196     for (int surfaceIndex = 0; surfaceIndex < surfaceCount; ++surfaceIndex)
197     {
198         cout << surfaceArray[surfaceIndex] << "(0x" << hex
199                 << surfaceArray[surfaceIndex] << dec << "), ";
200     }
201     cout << "\n";
202
203     cout << prefix << "- on screen:            ";
204
205     unsigned int screenCount = 0;
206     unsigned int* screenArray = NULL;
207
208     callResult = ilm_getScreenIDs(&screenCount, &screenArray);
209     if (ILM_SUCCESS != callResult)
210     {
211         cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
212         cout << "Failed to get available screens\n";
213         return;
214     }
215
216     for (unsigned int screenIndex = 0; screenIndex < screenCount;
217             ++screenIndex)
218     {
219         unsigned int screenid = screenArray[screenIndex];
220         int layerCount = 0;
221         unsigned int* layerArray = NULL;
222
223         callResult = ilm_getLayerIDsOnScreen(screenid, &layerCount, &layerArray);
224         if (ILM_SUCCESS != callResult)
225         {
226             cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
227             cout << "Failed to get available layers on screen with ID" << screenid << "\n";
228             return;
229         }
230
231         for (int layerIndex = 0; layerIndex < layerCount; ++layerIndex)
232         {
233             unsigned int id = layerArray[layerIndex];
234             if (id == layerid)
235             {
236                 cout << screenid << "(0x" << hex << screenid << dec << ") ";
237             }
238         }
239     }
240     cout << "\n";
241 }
242
243 void printSurfaceProperties(unsigned int surfaceid, const char* prefix)
244 {
245     cout << prefix << "surface " << surfaceid << " (0x" << hex << surfaceid
246             << dec << ")\n";
247     cout << prefix << "---------------------------------------\n";
248
249     ilmSurfaceProperties p;
250
251     ilmErrorTypes callResult = ilm_getPropertiesOfSurface(surfaceid, &p);
252     if (ILM_SUCCESS != callResult)
253     {
254         cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
255         cout << "No surface with ID " << surfaceid << " found\n";
256         return;
257     }
258
259     cout << prefix << "- created by pid:       " << p.creatorPid << "\n";
260
261     cout << prefix << "- original size:      x=" << p.origSourceWidth << ", y="
262             << p.origSourceHeight << "\n";
263     cout << prefix << "- destination region: x=" << p.destX << ", y=" << p.destY
264             << ", w=" << p.destWidth << ", h=" << p.destHeight << "\n";
265     cout << prefix << "- source region:      x=" << p.sourceX << ", y="
266             << p.sourceY << ", w=" << p.sourceWidth << ", h=" << p.sourceHeight
267             << "\n";
268
269     cout << prefix << "- orientation:        " << p.orientation << " (";
270     switch (p.orientation)
271     {
272     case 0/*Zero*/:
273         cout << "up is top)\n";
274         break;
275     case 1/*Ninety*/:
276         cout << "up is right)\n";
277         break;
278     case 2/*OneEighty*/:
279         cout << "up is bottom)\n";
280         break;
281     case 3/*TwoSeventy*/:
282         cout << "up is left)\n";
283         break;
284     default:
285         cout << "unknown)\n";
286         break;
287     }
288
289     cout << prefix << "- opacity:            " << p.opacity << "\n";
290     cout << prefix << "- visibility:         " << p.visibility << "\n";
291
292     cout << prefix << "- pixel format:       " << p.pixelformat << " (";
293     switch (p.pixelformat)
294     {
295     case 0/*PIXELFORMAT_R8*/:
296         cout << "R-8)\n";
297         break;
298     case 1/*PIXELFORMAT_RGB888*/:
299         cout << "RGB-888)\n";
300         break;
301     case 2/*PIXELFORMAT_RGBA8888*/:
302         cout << "RGBA-8888)\n";
303         break;
304     case 3/*PIXELFORMAT_RGB565*/:
305         cout << "RGB-565)\n";
306         break;
307     case 4/*PIXELFORMAT_RGBA5551*/:
308         cout << "RGBA-5551)\n";
309         break;
310     case 5/*PIXELFORMAT_RGBA6661*/:
311         cout << "RGBA-6661)\n";
312         break;
313     case 6/*PIXELFORMAT_RGBA4444*/:
314         cout << "RGBA-4444)\n";
315         break;
316     default:
317         cout << "unknown)\n";
318         break;
319     }
320
321     cout << prefix << "- native surface:     " << p.nativeSurface << "\n";
322
323     cout << prefix << "- accepts input from: "
324             << (p.inputDevicesAcceptance & ILM_INPUT_DEVICE_KEYBOARD ? "keyboard " : "")
325             << (p.inputDevicesAcceptance & ILM_INPUT_DEVICE_POINTER ? "mouse " : "")
326             << (p.inputDevicesAcceptance & ILM_INPUT_DEVICE_TOUCH ? "touch " : "")
327             << "\n";
328
329     t_ilm_surface keyboardFocusSurfaceId;
330     callResult = ilm_GetKeyboardFocusSurfaceId(&keyboardFocusSurfaceId);
331     if (ILM_SUCCESS != callResult)
332     {
333         cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
334         cout << "Failed to get keyboard focus surface ID\n";
335         return;
336     }
337
338     cout << prefix << "- has keyboard focus: "
339             << (keyboardFocusSurfaceId == surfaceid ? "true" : "false")
340             << "\n";
341
342     cout << prefix << "- chromakey:          "
343             << (p.chromaKeyEnabled ? "enabled " : "disabled ")
344             << "(r=" << p.chromaKeyRed << ", g=" << p.chromaKeyGreen << ", b=" << p.chromaKeyBlue << ")\n";
345
346     cout << prefix << "- counters:           frame=" << p.frameCounter
347             << ", draw=" << p.drawCounter << ", update=" << p.updateCounter
348             << "\n";
349
350     cout << prefix << "- on layer:           ";
351     int layerCount = 0;
352     unsigned int* layerArray = NULL;
353
354     callResult = ilm_getLayerIDs(&layerCount, &layerArray);
355     if (ILM_SUCCESS != callResult)
356     {
357         cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
358         cout << "Failed to get available layer IDs\n";
359         return;
360     }
361
362     for (int layerIndex = 0; layerIndex < layerCount; ++layerIndex)
363     {
364         unsigned int layerid = layerArray[layerIndex];
365         int surfaceCount = 0;
366         unsigned int* surfaceArray = NULL;
367
368         callResult = ilm_getSurfaceIDsOnLayer(layerid, &surfaceCount, &surfaceArray);
369         if (ILM_SUCCESS != callResult)
370         {
371             cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
372             cout << "Failed to get surface IDs on layer" << layerid << "\n";
373             return;
374         }
375
376         for (int surfaceIndex = 0; surfaceIndex < surfaceCount;
377                 ++surfaceIndex)
378         {
379             unsigned int id = surfaceArray[surfaceIndex];
380             if (id == surfaceid)
381             {
382                 cout << layerid << "(0x" << hex << layerid << dec << ") ";
383             }
384         }
385     }
386     cout << "\n";
387 }
388
389 void printScene()
390 {
391     unsigned int screenCount = 0;
392     unsigned int* screenArray = NULL;
393
394     ilmErrorTypes callResult = ilm_getScreenIDs(&screenCount, &screenArray);
395     if (ILM_SUCCESS != callResult)
396     {
397         cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
398         cout << "Failed to get available screen IDs\n";
399         return;
400     }
401
402     for (unsigned int screenIndex = 0; screenIndex < screenCount; ++screenIndex)
403     {
404         unsigned int screenid = screenArray[screenIndex];
405         printScreenProperties(screenid);
406         cout << "\n";
407
408         int layerCount = 0;
409         unsigned int* layerArray = NULL;
410
411         callResult = ilm_getLayerIDsOnScreen(screenid, &layerCount, &layerArray);
412         if (ILM_SUCCESS != callResult)
413         {
414             cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
415             cout << "Failed to get available layers on screen with ID" << screenid << "\n";
416             return;
417         }
418
419         for (int layerIndex = 0; layerIndex < layerCount; ++layerIndex)
420         {
421             unsigned int layerid = layerArray[layerIndex];
422             printLayerProperties(layerid, "    ");
423             cout << "\n";
424
425             int surfaceCount = 0;
426             unsigned int* surfaceArray = NULL;
427
428             callResult = ilm_getSurfaceIDsOnLayer(layerid, &surfaceCount, &surfaceArray);
429             if (ILM_SUCCESS != callResult)
430             {
431                 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
432                 cout << "Failed to get available surfaces on layer with ID" << layerid << "\n";
433                 return;
434             }
435
436             for (int surfaceIndex = 0; surfaceIndex < surfaceCount; ++surfaceIndex)
437             {
438                 unsigned int surfaceid = surfaceArray[surfaceIndex];
439                 printSurfaceProperties(surfaceid, "        ");
440                 cout << "\n";
441             }
442         }
443     }
444 }