Health: added thread dead-lock detection
[profile/ivi/layer-management.git] / LayerManagerPlugins / SceneProvider / ExampleSceneProvider / src / ExampleSceneProvider.cpp
1 /***************************************************************************
2  *
3  * Copyright 2010,2011 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 "ExampleSceneProvider.h"
21 #include "ICommandExecutor.h"
22 #include "CommitCommand.h"
23 #include "LayerCreateCommand.h"
24 #include "LayerSetDestinationRectangleCommand.h"
25 #include "LayerSetSourceRectangleCommand.h"
26 #include "LayerSetVisibilityCommand.h"
27 #include "LayerSetOpacityCommand.h"
28 #include "ScreenSetRenderOrderCommand.h"
29 #include "ExampleAppIds.h"
30 #include "SurfaceCreateCommand.h"
31 #include "SurfaceSetVisibilityCommand.h"
32 #include "SurfaceSetOpacityCommand.h"
33 #include "Configuration.h"
34 #include <unistd.h>
35
36 ExampleSceneProvider::ExampleSceneProvider(ICommandExecutor& executor, Configuration& config)
37 : ISceneProvider(&executor)
38 , PluginBase(executor, config, SceneProvider_Api_v1)
39 , mExecutor(executor)
40 , mConfiguration(config)
41 {
42 }
43
44 typedef struct t_layerScene
45 {
46     unsigned int layer;
47     bool visibility;
48     float opacity;
49 } layerScene;
50
51 typedef struct t_surfaceScene
52 {
53     unsigned int surface;
54     bool visibility;
55     float opacity;
56 } surfaceScene;
57
58
59 static layerScene gInitialLayerScene[] =
60 {
61     { LAYER_EXAMPLE_VIDEO_APPLICATIONS, true, 1.0 },
62     { LAYER_EXAMPLE_GLES_APPLICATIONS, true, 1.0 },
63     { LAYER_EXAMPLE_X_APPLICATIONS, true, 1.0 }
64 };
65
66 static surfaceScene gInitialSurfaceScene[] =
67 {
68     { SURFACE_EXAMPLE_EGLX11_APPLICATION, false, 1.0 },
69     { SURFACE_EXAMPLE_GDTESTENV_APPLICATION_1, false, 1.0 },
70     { SURFACE_EXAMPLE_GDTESTENV_APPLICATION_2, false, 1.0 },
71     { SURFACE_EXAMPLE_GDTESTENV_APPLICATION_3, false, 1.0 },
72     { SURFACE_EXAMPLE_GDTESTENV_APPLICATION_4, false, 1.0 },
73     { SURFACE_EXAMPLE_GDTESTENV_APPLICATION_5, false, 1.0 },
74     { SURFACE_EXAMPLE_GDTESTENV_APPLICATION_6, false, 1.0 },
75     { SURFACE_EXAMPLE_GDTESTENV_APPLICATION_7, false, 1.0 },
76     { SURFACE_EXAMPLE_GDTESTENV_APPLICATION_8, false, 1.0 },
77     { SURFACE_EXAMPLE_GDTESTENV_APPLICATION_9, false, 1.0 },
78     { SURFACE_EXAMPLE_GLXX11_APPLICATION, false, 1.0 },
79     { SURFACE_EXAMPLE_EGLRAW_APPLICATION, false, 1.0 },
80     { SURFACE_EXAMPLE_VIDEO_APPLICATION, false, 1.0 }
81 };
82
83
84 bool ExampleSceneProvider::delegateScene()
85 {
86     bool result = true;
87     pid_t layermanagerPid = getpid();
88     int i = 0;
89     int numberOfLayers = sizeof(gInitialLayerScene) / sizeof(layerScene);
90     int numberOfSurfaces = sizeof(gInitialSurfaceScene) / sizeof(surfaceScene);
91     unsigned int *renderOrder = new unsigned int [numberOfLayers];
92     unsigned int* screenResolution = mExecutor.getScreenResolution(0);
93     if (numberOfLayers > 0)
94     {
95         /* setup inital layer scenery */
96         for (i = 0; i<numberOfLayers; i++)
97         {
98             result &= mExecutor.execute(new LayerCreateCommand(layermanagerPid,
99                                                                screenResolution[0],
100                                                                screenResolution[1],
101                                                                &(gInitialLayerScene[i].layer)));
102             result &= mExecutor.execute(new LayerSetSourceRectangleCommand(layermanagerPid,
103                                                                            gInitialLayerScene[i].layer,
104                                                                            0, 0,
105                                                                            screenResolution[0],
106                                                                            screenResolution[1]));
107             result &= mExecutor.execute(new LayerSetDestinationRectangleCommand(layermanagerPid,
108                                                                                 gInitialLayerScene[i].layer,
109                                                                                 0, 0,
110                                                                                 screenResolution[0],
111                                                                                 screenResolution[1]));
112             result &= mExecutor.execute(new LayerSetOpacityCommand(layermanagerPid,
113                                                                    gInitialLayerScene[i].layer,
114                                                                    gInitialLayerScene[i].opacity));
115             result &= mExecutor.execute(new LayerSetVisibilityCommand(layermanagerPid,
116                                                                       gInitialLayerScene[i].layer,
117                                                                       gInitialLayerScene[i].visibility));
118             result &= mExecutor.execute(new CommitCommand(layermanagerPid));
119             renderOrder[i]=gInitialLayerScene[i].layer;
120         }
121         /* Finally set the first executed renderorder */
122         result &= mExecutor.execute(new ScreenSetRenderOrderCommand(layermanagerPid, 0, renderOrder, numberOfLayers));
123         result &= mExecutor.execute(new CommitCommand(layermanagerPid));
124     }
125
126     if (numberOfSurfaces > 0)
127     {
128         /* setup inital surface scenery */
129         for (i = 0; i<numberOfSurfaces; i++)
130         {
131             result &= mExecutor.execute(new SurfaceCreateCommand(layermanagerPid,
132                                                                  &(gInitialSurfaceScene[i].surface)));
133             result &= mExecutor.execute(new SurfaceSetOpacityCommand(layermanagerPid,
134                                                                      gInitialSurfaceScene[i].surface,
135                                                                      gInitialSurfaceScene[i].opacity));
136             result &= mExecutor.execute(new SurfaceSetVisibilityCommand(layermanagerPid,
137                                                                         gInitialSurfaceScene[i].surface,
138                                                                         gInitialSurfaceScene[i].visibility));
139             result &= mExecutor.execute(new CommitCommand(layermanagerPid));
140         }
141         /* Finally set the first executed renderorder */
142     }
143     return result;
144 }
145
146 t_ilm_const_string ExampleSceneProvider::pluginGetName() const
147 {
148     return "ExampleSceneProvider";
149 }
150
151 int ExampleSceneProvider::getIterationCounter()
152 {
153     // this plugin is one-shot and is not monitored.
154     static int dummyValue = 0;
155     return ++dummyValue;
156 }
157
158 DECLARE_LAYERMANAGEMENT_PLUGIN(ExampleSceneProvider)