1 /***************************************************************************
3 * Copyright 2012 BMW Car IT GmbH
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 ****************************************************************************/
20 #include "ilm_client.h"
21 #include "ilm_control.h"
22 #include "LMControl.h"
40 #include <sys/types.h>
44 bool gBenchmark_running;
46 void benchmarkSigHandler(int sig)
49 gBenchmark_running = false;
52 void getCommunicatorPerformance()
56 unsigned int hwLayerCnt = 0;
57 cout << "running performance test for " << runtimeInSec << " seconds... ";
60 signal(SIGALRM, benchmarkSigHandler);
62 gBenchmark_running = true;
66 while (gBenchmark_running)
68 t_ilm_uint screenid = 0;
70 ilmErrorTypes callResult = ilm_getNumberOfHardwareLayers(screenid, &hwLayerCnt);
71 if (ILM_SUCCESS != callResult)
73 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
74 cout << "Failed to get number of hardware layers for screen with ID " << screenid << "\n";
81 signal(SIGALRM, SIG_DFL);
83 cout << (runs/runtimeInSec) << " transactions/second\n";
86 void setSurfaceKeyboardFocus(t_ilm_surface surface)
88 ilmErrorTypes callResult = ilm_SetKeyboardFocusOn(surface);
89 if (ILM_SUCCESS != callResult)
91 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
92 cout << "Failed to set keyboard focus at surface with ID " << surface << "\n";
97 void getKeyboardFocus()
99 t_ilm_surface surfaceId;
101 ilmErrorTypes callResult = ilm_GetKeyboardFocusSurfaceId(&surfaceId);
102 if (ILM_SUCCESS == callResult)
104 cout << "keyboardFocusSurfaceId == " << surfaceId << endl;
108 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
109 cout << "Failed to get keyboard focus surface ID\n";
114 void setSurfaceAcceptsInput(t_ilm_surface surfaceId, string kbdPointerTouch, t_ilm_bool acceptance)
119 ilmInputDevice devices = (ilmInputDevice)0;
121 str = new char [kbdPointerTouch.size()+1];
122 strcpy(str, kbdPointerTouch.c_str());
123 tok = strtok(str, ":");
126 if (!strcmp(tok, "kbd"))
128 devices |= ILM_INPUT_DEVICE_KEYBOARD;
130 else if (!strcmp(tok, "pointer"))
132 devices |= ILM_INPUT_DEVICE_POINTER;
134 else if (!strcmp(tok, "touch"))
136 devices |= ILM_INPUT_DEVICE_TOUCH;
140 cerr << "Unknown devices specified." << endl;
143 tok = strtok(NULL, ":");
146 ilmErrorTypes callResult = ilm_UpdateInputEventAcceptanceOn(surfaceId, devices, acceptance);
147 if (ILM_SUCCESS != callResult)
149 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
150 cout << "Failed to update input event acceptance on surface with ID " << surfaceId << "\n";
159 void layerNotificationCallback(t_ilm_layer layer, struct ilmLayerProperties* properties, t_ilm_notification_mask mask)
161 cout << "\nNotification: layer " << layer << " updated properties:\n";
163 if (ILM_NOTIFICATION_VISIBILITY & mask)
165 cout << "\tvisibility = " << properties->visibility << "\n";
168 if (ILM_NOTIFICATION_OPACITY & mask)
170 cout << "\topacity = " << properties->opacity << "\n";
173 if (ILM_NOTIFICATION_ORIENTATION & mask)
175 cout << "\torientation = " << properties->orientation << "\n";
178 if (ILM_NOTIFICATION_SOURCE_RECT & mask)
180 cout << "\tsource rect = x:" << properties->sourceX
181 << ", y:" << properties->sourceY
182 << ", width:" << properties->sourceWidth
183 << ", height:" << properties->sourceHeight
187 if (ILM_NOTIFICATION_DEST_RECT & mask)
189 cout << "\tdest rect = x:" << properties->destX
190 << ", y:" << properties->destY
191 << ", width:" << properties->destWidth
192 << ", height:" << properties->destHeight
197 void testNotificationLayer(t_ilm_layer layerid)
199 cout << "Setup notification for layer " << layerid << " \n";
201 ilmErrorTypes callResult = ilm_layerAddNotification(layerid, layerNotificationCallback);
202 if (ILM_SUCCESS != callResult)
204 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
205 cout << "Failed to add notification callback to layer with ID " << layerid << "\n";
209 for (int i = 0; i < 2; ++i)
212 cout << "Set layer 1000 visbility to FALSE\n";
213 ilm_layerSetVisibility(layerid, ILM_FALSE);
217 cout << "Set layer 1000 visbility to TRUE\n";
218 ilm_layerSetVisibility(layerid, ILM_TRUE);
220 cout << "Set layer 1000 opacity to 0.3\n";
221 ilm_layerSetOpacity(layerid, 0.3);
225 cout << "Set layer 1000 opacity to 1.0\n";
226 ilm_layerSetOpacity(layerid, 1.0);
230 ilm_commitChanges(); // make sure, app lives long enough to receive last notification
233 void watchLayer(unsigned int* layerids, unsigned int layeridCount)
235 for (unsigned int i = 0; i < layeridCount; ++i)
237 unsigned int layerid = layerids[i];
238 cout << "Setup notification for layer " << layerid << "\n";
240 ilmErrorTypes callResult = ilm_layerAddNotification(layerid, layerNotificationCallback);
241 if (ILM_SUCCESS != callResult)
243 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
244 cout << "Failed to add notification callback to layer with ID " << layerid << "\n";
249 cout << "Waiting for notifications...\n";
253 for (unsigned int i = 0; i < layeridCount; ++i)
255 unsigned int layerid = layerids[i];
256 cout << "Removing notification for layer " << layerid << "\n";
258 ilmErrorTypes callResult = ilm_layerRemoveNotification(layerid);
259 if (ILM_SUCCESS != callResult)
261 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
262 cout << "Failed to remove notification callback of layer with ID " << layerid << "\n";
273 void surfaceNotificationCallback(t_ilm_layer surface, struct ilmSurfaceProperties* properties, t_ilm_notification_mask mask)
275 cout << "\nNotification: surface " << surface << " updated properties:\n";
277 if (ILM_NOTIFICATION_VISIBILITY & mask)
279 cout << "\tvisibility = " << properties->visibility << "\n";
282 if (ILM_NOTIFICATION_OPACITY & mask)
284 cout << "\topacity = " << properties->opacity << "\n";
287 if (ILM_NOTIFICATION_ORIENTATION & mask)
289 cout << "\torientation = " << properties->orientation << "\n";
292 if (ILM_NOTIFICATION_SOURCE_RECT & mask)
294 cout << "\tsource rect = x:" << properties->sourceX
295 << ", y:" << properties->sourceY
296 << ", width:" << properties->sourceWidth
297 << ", height:" << properties->sourceHeight
301 if (ILM_NOTIFICATION_DEST_RECT & mask)
303 cout << "\tdest rect = x:" << properties->destX
304 << ", y:" << properties->destY
305 << ", width:" << properties->destWidth
306 << ", height:" << properties->destHeight
311 void watchSurface(unsigned int* surfaceids, unsigned int surfaceidCount)
313 for (unsigned int i = 0; i < surfaceidCount; ++i)
315 unsigned int surfaceid = surfaceids[i];
316 cout << "Setup notification for surface " << surfaceid << "\n";
318 ilmErrorTypes callResult = ilm_surfaceAddNotification(surfaceid, surfaceNotificationCallback);
319 if (ILM_SUCCESS != callResult)
321 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
322 cout << "Failed to add notification callback to surface with ID " << surfaceid << "\n";
327 cout << "Waiting for notifications...\n";
331 for (unsigned int i = 0; i < surfaceidCount; ++i)
333 unsigned int surfaceid = surfaceids[i];
334 cout << "Removing notification for surface " << surfaceid << "\n";
336 ilmErrorTypes callResult = ilm_surfaceRemoveNotification(surfaceid);
337 if (ILM_SUCCESS != callResult)
339 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
340 cout << "Failed to remove notification callback of surface with ID " << surfaceid << "\n";
351 void setOptimization(t_ilm_uint id, t_ilm_uint mode)
353 ilmErrorTypes callResult = ilm_SetOptimizationMode((ilmOptimization)id,
354 (ilmOptimizationMode)mode);
355 if (ILM_SUCCESS != callResult)
357 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
358 cout << "Failed to set optimization with ID " << id << " mode " << mode << "\n";
365 void getOptimization(t_ilm_uint id)
367 ilmOptimization optimizationId = (ilmOptimization)id;
368 ilmOptimizationMode optimizationMode;
370 ilmErrorTypes callResult = ilm_GetOptimizationMode(optimizationId, &optimizationMode);
371 if (callResult == ILM_SUCCESS)
373 switch (optimizationId)
375 case ILM_OPT_MULTITEXTURE :
376 cout << "Optimization " << (int)optimizationId << " (Multitexture Optimization)" << endl;
379 case ILM_OPT_SKIP_CLEAR :
380 cout << "Optimization " << (int)optimizationId << " (Skip Clear)" << endl;
383 cout << "Optimization " << "unknown" << endl;
387 switch (optimizationMode)
389 case ILM_OPT_MODE_FORCE_OFF :
390 cout << "Mode " << (int)optimizationMode << " (forced off)" << endl;
393 case ILM_OPT_MODE_FORCE_ON :
394 cout << "Mode " << (int)optimizationMode << " (forced on)" << endl;
396 case ILM_OPT_MODE_HEURISTIC :
397 cout << "Mode " << (int)optimizationMode << " (Heuristic / Render choose the optimization)" << endl;
399 case ILM_OPT_MODE_TOGGLE :
400 cout << "Mode " << (int)optimizationMode << " (Toggle on/and off rapidly for debugging)" << endl;
404 cout << "Mode " << "unknown" << endl;
410 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
411 cout << "Failed to get mode for optimization with ID " << optimizationId << "\n";