LayerManagerControl: added support for GetPropertiesOfScreen
[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     ilm_getPropertiesOfScreen(screenid, &screenProperties);
89     cout << prefix << "- resolution:           x=" << screenProperties.screenWidth << ", y="
90             << screenProperties.screenHeight << "\n";
91
92     cout << prefix << "- hardware layer count: " << screenProperties.harwareLayerCount << "\n";
93
94     cout << prefix << "- layer render order:   ";
95
96     for (int layerIndex = 0; layerIndex < screenProperties.layerCount; ++layerIndex)
97     {
98         t_ilm_layer layerid = screenProperties.layerIds[layerIndex];
99         cout << layerid << "(0x" << hex << layerid << dec << "), ";
100     }
101     cout << "\n";
102 }
103
104 void printLayerProperties(unsigned int layerid, const char* prefix)
105 {
106     cout << prefix << "layer " << layerid << " (0x" << hex << layerid << dec
107             << ")\n";
108     cout << prefix << "---------------------------------------\n";
109
110     ilmLayerProperties p;
111     ilm_getPropertiesOfLayer(layerid, &p);
112
113     cout << prefix << "- created by pid:       " << p.creatorPid << "\n";
114
115     cout << prefix << "- original size:        x=" << p.origSourceWidth
116             << ", y=" << p.origSourceHeight << "\n";
117     cout << prefix << "- destination region:   x=" << p.destX << ", y="
118             << p.destY << ", w=" << p.destWidth << ", h=" << p.destHeight
119             << "\n";
120     cout << prefix << "- source region:        x=" << p.sourceX << ", y="
121             << p.sourceY << ", w=" << p.sourceWidth << ", h=" << p.sourceHeight
122             << "\n";
123
124     cout << prefix << "- orientation:          " << p.orientation << " (";
125     switch (p.orientation)
126     {
127     case 0/*Zero*/:
128         cout << "up is top)\n";
129         break;
130     case 1/*Ninety*/:
131         cout << "up is right)\n";
132         break;
133     case 2/*OneEighty*/:
134         cout << "up is bottom)\n";
135         break;
136     case 3/*TwoSeventy*/:
137         cout << "up is left)\n";
138         break;
139     default:
140         cout << "unknown)\n";
141         break;
142     }
143
144     cout << prefix << "- opacity:              " << p.opacity << "\n";
145     cout << prefix << "- visibility:           " << p.visibility << "\n";
146
147     cout << prefix << "- type:                 " << p.type << " (";
148     switch (p.type)
149     {
150     case 1/*Hardware*/:
151         cout << "hardware)\n";
152         break;
153     case 2/*Software_2D*/:
154         cout << "software 2d)\n";
155         break;
156     case 3/*Software_2_5D*/:
157         cout << "software 2.5d)\n";
158         break;
159     default:
160         cout << "unknown)\n";
161         break;
162     }
163
164     cout << prefix << "- chromakey:            "
165             << (p.chromaKeyEnabled ? "enabled " : "disabled ")
166             << "(r=" << p.chromaKeyRed << ", g=" << p.chromaKeyGreen << ", b=" << p.chromaKeyBlue << ")\n";
167
168     cout << prefix << "- surface render order: ";
169     int surfaceCount = 0;
170     unsigned int* surfaceArray = NULL;
171     ilm_getSurfaceIDsOnLayer(layerid, &surfaceCount, &surfaceArray);
172     for (int surfaceIndex = 0; surfaceIndex < surfaceCount; ++surfaceIndex)
173     {
174         cout << surfaceArray[surfaceIndex] << "(0x" << hex
175                 << surfaceArray[surfaceIndex] << dec << "), ";
176     }
177     cout << "\n";
178
179     cout << prefix << "- on screen:            ";
180     unsigned int screenCount = 0;
181     unsigned int* screenArray = NULL;
182     ilm_getScreenIDs(&screenCount, &screenArray);
183     for (unsigned int screenIndex = 0; screenIndex < screenCount;
184             ++screenIndex)
185     {
186         unsigned int screenid = screenArray[screenIndex];
187         int layerCount = 0;
188         unsigned int* layerArray = NULL;
189         ilm_getLayerIDsOnScreen(screenid, &layerCount, &layerArray);
190         for (int layerIndex = 0; layerIndex < layerCount; ++layerIndex)
191         {
192             unsigned int id = layerArray[layerIndex];
193             if (id == layerid)
194             {
195                 cout << screenid << "(0x" << hex << screenid << dec << ") ";
196             }
197         }
198     }
199     cout << "\n";
200 }
201
202 void printSurfaceProperties(unsigned int surfaceid, const char* prefix)
203 {
204     cout << prefix << "surface " << surfaceid << " (0x" << hex << surfaceid
205             << dec << ")\n";
206     cout << prefix << "---------------------------------------\n";
207
208     ilmSurfaceProperties p;
209     ilm_getPropertiesOfSurface(surfaceid, &p);
210
211     cout << prefix << "- created by pid:       " << p.creatorPid << "\n";
212
213     cout << prefix << "- original size:      x=" << p.origSourceWidth << ", y="
214             << p.origSourceHeight << "\n";
215     cout << prefix << "- destination region: x=" << p.destX << ", y=" << p.destY
216             << ", w=" << p.destWidth << ", h=" << p.destHeight << "\n";
217     cout << prefix << "- source region:      x=" << p.sourceX << ", y="
218             << p.sourceY << ", w=" << p.sourceWidth << ", h=" << p.sourceHeight
219             << "\n";
220
221     cout << prefix << "- orientation:        " << p.orientation << " (";
222     switch (p.orientation)
223     {
224     case 0/*Zero*/:
225         cout << "up is top)\n";
226         break;
227     case 1/*Ninety*/:
228         cout << "up is right)\n";
229         break;
230     case 2/*OneEighty*/:
231         cout << "up is bottom)\n";
232         break;
233     case 3/*TwoSeventy*/:
234         cout << "up is left)\n";
235         break;
236     default:
237         cout << "unknown)\n";
238         break;
239     }
240
241     cout << prefix << "- opacity:            " << p.opacity << "\n";
242     cout << prefix << "- visibility:         " << p.visibility << "\n";
243
244     cout << prefix << "- pixel format:       " << p.pixelformat << " (";
245     switch (p.pixelformat)
246     {
247     case 0/*PIXELFORMAT_R8*/:
248         cout << "R-8)\n";
249         break;
250     case 1/*PIXELFORMAT_RGB888*/:
251         cout << "RGB-888)\n";
252         break;
253     case 2/*PIXELFORMAT_RGBA8888*/:
254         cout << "RGBA-8888)\n";
255         break;
256     case 3/*PIXELFORMAT_RGB565*/:
257         cout << "RGB-565)\n";
258         break;
259     case 4/*PIXELFORMAT_RGBA5551*/:
260         cout << "RGBA-5551)\n";
261         break;
262     case 5/*PIXELFORMAT_RGBA6661*/:
263         cout << "RGBA-6661)\n";
264         break;
265     case 6/*PIXELFORMAT_RGBA4444*/:
266         cout << "RGBA-4444)\n";
267         break;
268     default:
269         cout << "unknown)\n";
270         break;
271     }
272
273     cout << prefix << "- native surface:     " << p.nativeSurface << "\n";
274
275     cout << prefix << "- accepts input from: "
276             << (p.inputDevicesAcceptance & ILM_INPUT_DEVICE_KEYBOARD ? "keyboard " : "")
277             << (p.inputDevicesAcceptance & ILM_INPUT_DEVICE_POINTER ? "mouse " : "")
278             << (p.inputDevicesAcceptance & ILM_INPUT_DEVICE_TOUCH ? "touch " : "")
279             << "\n";
280
281     t_ilm_surface keyboardFocusSurfaceId;
282     ilm_GetKeyboardFocusSurfaceId(&keyboardFocusSurfaceId);
283
284     cout << prefix << "- has keyboard focus: "
285             << (keyboardFocusSurfaceId == surfaceid ? "true" : "false")
286             << "\n";
287
288     cout << prefix << "- chromakey:          "
289             << (p.chromaKeyEnabled ? "enabled " : "disabled ")
290             << "(r=" << p.chromaKeyRed << ", g=" << p.chromaKeyGreen << ", b=" << p.chromaKeyBlue << ")\n";
291
292     cout << prefix << "- counters:           frame=" << p.frameCounter
293             << ", draw=" << p.drawCounter << ", update=" << p.updateCounter
294             << "\n";
295
296     cout << prefix << "- on layer:           ";
297     int layerCount = 0;
298     unsigned int* layerArray = NULL;
299     ilm_getLayerIDs(&layerCount, &layerArray);
300     for (unsigned int layerIndex = 0; layerIndex < layerCount; ++layerIndex)
301     {
302         unsigned int layerid = layerArray[layerIndex];
303         int surfaceCount = 0;
304         unsigned int* surfaceArray = NULL;
305         ilm_getSurfaceIDsOnLayer(layerid, &surfaceCount, &surfaceArray);
306         for (int surfaceIndex = 0; surfaceIndex < surfaceCount;
307                 ++surfaceIndex)
308         {
309             unsigned int id = surfaceArray[surfaceIndex];
310             if (id == surfaceid)
311             {
312                 cout << layerid << "(0x" << hex << layerid << dec << ") ";
313             }
314         }
315     }
316     cout << "\n";
317 }
318
319 void printScene()
320 {
321     unsigned int screenCount = 0;
322     unsigned int* screenArray = NULL;
323
324     ilm_getScreenIDs(&screenCount, &screenArray);
325
326     for (unsigned int screenIndex = 0; screenIndex < screenCount; ++screenIndex)
327     {
328         unsigned int screenid = screenArray[screenIndex];
329         printScreenProperties(screenid);
330         cout << "\n";
331
332         int layerCount = 0;
333         unsigned int* layerArray = NULL;
334         ilm_getLayerIDsOnScreen(screenid, &layerCount, &layerArray);
335         for (int layerIndex = 0; layerIndex < layerCount; ++layerIndex)
336         {
337             unsigned int layerid = layerArray[layerIndex];
338             printLayerProperties(layerid, "    ");
339             cout << "\n";
340
341             int surfaceCount = 0;
342             unsigned int* surfaceArray = NULL;
343             ilm_getSurfaceIDsOnLayer(layerid, &surfaceCount, &surfaceArray);
344             for (int surfaceIndex = 0; surfaceIndex < surfaceCount; ++surfaceIndex)
345             {
346                 unsigned int surfaceid = surfaceArray[surfaceIndex];
347                 printSurfaceProperties(surfaceid, "        ");
348                 cout << "\n";
349             }
350         }
351     }
352 }