Bugfix and SceneProviderExample added
[profile/ivi/layer-management.git] / LayerManagerExamples / LayerSceneDescriptionExample / src / LayerSceneProvider.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 "LayerSceneProvider.h"
21
22 LayerSceneProvider::LayerSceneProvider(ICommandExecutor* executor)
23 : ISceneProvider(executor)
24 {
25 }
26
27 typedef struct t_layerScene 
28 {
29     unsigned int layer;
30     bool visibility;
31     float opacity;
32 } layerScene;
33
34 static layerScene gInitialLayerScene[] = 
35 {
36     { LAYER_EXAMPLE_VIDEO_APPLICATIONS, true, 1.0 },
37     { LAYER_EXAMPLE_GLES_APPLICATIONS, true, 1.0 },
38     { LAYER_EXAMPLE_X_APPLICATIONS, true, 1.0 }
39 };
40
41 bool LayerSceneProvider::delegateScene() 
42 {
43     bool result = true;
44     int i = 0;
45     int numberOfLayers = sizeof(gInitialLayerScene) / sizeof (layerScene);
46     unsigned int *renderOrder = new unsigned int [numberOfLayers];
47     unsigned int* screenResolution = m_executor->getScreenResolution(0);    
48     if ( numberOfLayers > 0 ) 
49     {
50         /* setup inital layer scenery */
51         for (i = 0;i<numberOfLayers;i++)
52         {
53             m_executor->execute(new CreateCommand(0, TypeLayer, PIXELFORMAT_R8, screenResolution[0], screenResolution[1], &(gInitialLayerScene[i].layer)));            
54             m_executor->execute(new SetSourceRectangleCommand(gInitialLayerScene[i].layer, TypeLayer, 0, 0, screenResolution[0], screenResolution[1]));
55             m_executor->execute(new SetDestinationRectangleCommand(gInitialLayerScene[i].layer, TypeLayer, 0, 0, screenResolution[0], screenResolution[1]));
56             m_executor->execute(new SetOpacityCommand(gInitialLayerScene[i].layer,TypeLayer,gInitialLayerScene[i].opacity) );
57             m_executor->execute(new SetVisibilityCommand(gInitialLayerScene[i].layer,TypeLayer,gInitialLayerScene[i].visibility) );
58             m_executor->execute(new CommitCommand());            
59             renderOrder[i]=gInitialLayerScene[i].layer;
60         }        
61         /* Finally set the first executed renderorder */
62         m_executor->execute(new SetLayerOrderCommand(renderOrder,numberOfLayers));
63         m_executor->execute(new CommitCommand());
64     }
65     return result;    
66 }
67
68 extern "C" ISceneProvider* createLayerScene(ICommandExecutor* executor)
69 {
70     return new LayerSceneProvider(executor);
71 }
72
73 extern "C" void destroyLayerScene(LayerSceneProvider* p)
74 {
75     delete p;
76 }