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 "LMControl.h"
39 #include <sys/types.h>
43 bool gBenchmark_running;
45 void benchmarkSigHandler(int sig)
48 gBenchmark_running = false;
51 void getCommunicatorPerformance()
55 unsigned int hwLayerCnt = 0;
56 cout << "running performance test for " << runtimeInSec << " seconds... ";
59 signal(SIGALRM, benchmarkSigHandler);
61 gBenchmark_running = true;
65 while (gBenchmark_running)
67 t_ilm_uint screenid = 0;
69 ilmErrorTypes callResult = ilm_getNumberOfHardwareLayers(screenid, &hwLayerCnt);
70 if (ILM_SUCCESS != callResult)
72 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
73 cout << "Failed to get number of hardware layers for screen with ID " << screenid << "\n";
80 signal(SIGALRM, SIG_DFL);
82 cout << (runs/runtimeInSec) << " transactions/second\n";
85 void setSurfaceKeyboardFocus(t_ilm_surface surface)
87 ilmErrorTypes callResult = ilm_SetKeyboardFocusOn(surface);
88 if (ILM_SUCCESS != callResult)
90 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
91 cout << "Failed to set keyboard focus at surface with ID " << surface << "\n";
96 void getKeyboardFocus()
98 t_ilm_surface surfaceId;
100 ilmErrorTypes callResult = ilm_GetKeyboardFocusSurfaceId(&surfaceId);
101 if (ILM_SUCCESS == callResult)
103 cout << "keyboardFocusSurfaceId == " << surfaceId << endl;
107 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
108 cout << "Failed to get keyboard focus surface ID\n";
113 void setSurfaceAcceptsInput(t_ilm_surface surfaceId, string kbdPointerTouch, t_ilm_bool acceptance)
118 ilmInputDevice devices = (ilmInputDevice)0;
120 str = new char [kbdPointerTouch.size()+1];
121 strcpy (str, kbdPointerTouch.c_str());
122 tok = strtok(str, ":");
125 if (!strcmp(tok, "kbd"))
127 devices |= ILM_INPUT_DEVICE_KEYBOARD;
129 else if (!strcmp(tok, "pointer"))
131 devices |= ILM_INPUT_DEVICE_POINTER;
133 else if (!strcmp(tok, "touch"))
135 devices |= ILM_INPUT_DEVICE_TOUCH;
139 cerr << "Unknown devices specified." << endl;
142 tok = strtok(NULL, ":");
145 ilmErrorTypes callResult = ilm_UpdateInputEventAcceptanceOn(surfaceId, devices, acceptance);
146 if (ILM_SUCCESS != callResult)
148 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
149 cout << "Failed to update input event acceptance on surface with ID " << surfaceId << "\n";
158 void layerNotificationCallback(t_ilm_layer layer, struct ilmLayerProperties* properties, t_ilm_notification_mask mask)
160 cout << "\nNotification: layer " << layer << " updated properties:\n";
162 if (ILM_NOTIFICATION_VISIBILITY & mask)
164 cout << "\tvisibility = " << properties->visibility << "\n";
167 if (ILM_NOTIFICATION_OPACITY & mask)
169 cout << "\topacity = " << properties->opacity << "\n";
172 if (ILM_NOTIFICATION_ORIENTATION & mask)
174 cout << "\torientation = " << properties->orientation << "\n";
177 if (ILM_NOTIFICATION_SOURCE_RECT & mask)
179 cout << "\tsource rect = x:" << properties->sourceX
180 << ", y:" << properties->sourceY
181 << ", width:" << properties->sourceWidth
182 << ", height:" << properties->sourceHeight
186 if (ILM_NOTIFICATION_DEST_RECT & mask)
188 cout << "\tdest rect = x:" << properties->destX
189 << ", y:" << properties->destY
190 << ", width:" << properties->destWidth
191 << ", height:" << properties->destHeight
196 void testNotificationLayer(t_ilm_layer layerid)
198 cout << "Setup notification for layer " << layerid << " \n";
200 ilmErrorTypes callResult = ilm_layerAddNotification(layerid, layerNotificationCallback);
201 if (ILM_SUCCESS != callResult)
203 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
204 cout << "Failed to add notification callback to layer with ID " << layerid << "\n";
208 for (int i = 0; i < 2; ++i)
211 cout << "Set layer 1000 visbility to FALSE\n";
212 ilm_layerSetVisibility(layerid, ILM_FALSE);
216 cout << "Set layer 1000 visbility to TRUE\n";
217 ilm_layerSetVisibility(layerid, ILM_TRUE);
219 cout << "Set layer 1000 opacity to 0.3\n";
220 ilm_layerSetOpacity(layerid, 0.3);
224 cout << "Set layer 1000 opacity to 1.0\n";
225 ilm_layerSetOpacity(layerid, 1.0);
229 ilm_commitChanges(); // make sure, app lives long enough to receive last notification
232 void watchLayer(unsigned int* layerids, unsigned int layeridCount)
234 for (unsigned int i = 0; i < layeridCount; ++i)
236 unsigned int layerid = layerids[i];
237 cout << "Setup notification for layer " << layerid << "\n";
239 ilmErrorTypes callResult = ilm_layerAddNotification(layerid, layerNotificationCallback);
240 if (ILM_SUCCESS != callResult)
242 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
243 cout << "Failed to add notification callback to layer with ID " << layerid << "\n";
248 cout << "Waiting for notifications...\n";
252 for (unsigned int i = 0; i < layeridCount; ++i)
254 unsigned int layerid = layerids[i];
255 cout << "Removing notification for layer " << layerid << "\n";
257 ilmErrorTypes callResult = ilm_layerRemoveNotification(layerid);
258 if (ILM_SUCCESS != callResult)
260 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
261 cout << "Failed to remove notification callback of layer with ID " << layerid << "\n";
272 void surfaceNotificationCallback(t_ilm_layer surface, struct ilmSurfaceProperties* properties, t_ilm_notification_mask mask)
274 cout << "\nNotification: surface " << surface << " updated properties:\n";
276 if (ILM_NOTIFICATION_VISIBILITY & mask)
278 cout << "\tvisibility = " << properties->visibility << "\n";
281 if (ILM_NOTIFICATION_OPACITY & mask)
283 cout << "\topacity = " << properties->opacity << "\n";
286 if (ILM_NOTIFICATION_ORIENTATION & mask)
288 cout << "\torientation = " << properties->orientation << "\n";
291 if (ILM_NOTIFICATION_SOURCE_RECT & mask)
293 cout << "\tsource rect = x:" << properties->sourceX
294 << ", y:" << properties->sourceY
295 << ", width:" << properties->sourceWidth
296 << ", height:" << properties->sourceHeight
300 if (ILM_NOTIFICATION_DEST_RECT & mask)
302 cout << "\tdest rect = x:" << properties->destX
303 << ", y:" << properties->destY
304 << ", width:" << properties->destWidth
305 << ", height:" << properties->destHeight
310 void watchSurface(unsigned int* surfaceids, unsigned int surfaceidCount)
312 for (unsigned int i = 0; i < surfaceidCount; ++i)
314 unsigned int surfaceid = surfaceids[i];
315 cout << "Setup notification for surface " << surfaceid << "\n";
317 ilmErrorTypes callResult = ilm_surfaceAddNotification(surfaceid, surfaceNotificationCallback);
318 if (ILM_SUCCESS != callResult)
320 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
321 cout << "Failed to add notification callback to surface with ID " << surfaceid << "\n";
326 cout << "Waiting for notifications...\n";
330 for (unsigned int i = 0; i < surfaceidCount; ++i)
332 unsigned int surfaceid = surfaceids[i];
333 cout << "Removing notification for surface " << surfaceid << "\n";
335 ilmErrorTypes callResult = ilm_surfaceRemoveNotification(surfaceid);
336 if (ILM_SUCCESS != callResult)
338 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
339 cout << "Failed to remove notification callback of surface with ID " << surfaceid << "\n";
350 void setOptimization(t_ilm_uint id, t_ilm_uint mode)
352 ilmErrorTypes callResult = ilm_SetOptimizationMode((ilmOptimization)id,
353 (ilmOptimizationMode)mode);
354 if (ILM_SUCCESS != callResult)
356 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
357 cout << "Failed to set optimization with ID "<< id <<" mode " << mode << "\n";
364 void getOptimization(t_ilm_uint id)
366 ilmOptimization optimizationId = (ilmOptimization)id;
367 ilmOptimizationMode optimizationMode;
369 ilmErrorTypes callResult = ilm_GetOptimizationMode(optimizationId, &optimizationMode);
370 if (callResult == ILM_SUCCESS)
372 switch ( optimizationId )
374 case ILM_OPT_MULTITEXTURE :
375 cout << "Optimization " << (int)optimizationId << " (Multitexture Optimization)" << endl;
378 case ILM_OPT_SKIP_CLEAR :
379 cout << "Optimization " << (int)optimizationId << " (Skip Clear)" << endl;
382 cout << "Optimization " << "unknown" << endl;
386 switch (optimizationMode)
388 case ILM_OPT_MODE_FORCE_OFF :
389 cout << "Mode " << (int)optimizationMode << " (forced off)" << endl;
392 case ILM_OPT_MODE_FORCE_ON :
393 cout << "Mode " << (int)optimizationMode << " (forced on)" << endl;
395 case ILM_OPT_MODE_HEURISTIC :
396 cout << "Mode " << (int)optimizationMode << " (Heuristic / Render choose the optimization)" << endl;
398 case ILM_OPT_MODE_TOGGLE :
399 cout << "Mode " << (int)optimizationMode << " (Toggle on/and off rapidly for debugging)" << endl;
403 cout <<"Mode " << "unknown" << endl ;
409 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
410 cout << "Failed to get mode for optimization with ID "<< optimizationId << "\n";