Merge patches between Valeo and BMW Car IT
[profile/ivi/layer-management.git] / LayerManagerService / include / Scene.h
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 #ifndef _SCENE_H_
20 #define _SCENE_H_
21
22 #include "IScene.h"
23 #include "Layermanager.h"
24 #include "CommandList.h"
25 #include "ShaderMap.h"
26 #include "LayerGroup.h"
27 #include "LayerGroupMap.h"
28 #include "SurfaceGroup.h"
29 #include "SurfaceGroupMap.h"
30 #include "SurfaceMap.h"
31 #include "LayerMap.h"
32 #include "ShaderMap.h"
33 #include "LayerList.h"
34 #include <pthread.h>
35
36 class Layer;
37 class Surface;
38
39 /*
40  * Represents a list of Layers which contain the Surfaces.
41  */
42 class Scene: public IScene
43 {
44     // TODO: these should use public interface instead
45     friend class Layermanager;
46     friend class CommitCommand;
47     friend class CreateShaderCommand;
48     friend class DestroyShaderCommand;
49     friend class SetShaderCommand;
50     friend class SetUniformsCommand;
51
52 public:
53     Scene();
54     ~Scene();
55
56     virtual Layer* createLayer(const uint id);
57     virtual Surface *createSurface(const uint id);
58     virtual LayerGroup *createLayerGroup(const uint id);
59     virtual SurfaceGroup *createSurfaceGroup(const uint id);
60
61     virtual void removeLayer(Layer* layer);
62     virtual void removeSurface(Surface* surface);
63     virtual Layer* getLayer(const uint id) const;
64     virtual Surface* getSurface(const uint id) const;
65     virtual SurfaceGroup* getSurfaceGroup(const uint id) const;
66     virtual LayerGroup* getLayerGroup(const uint id) const;
67
68     virtual void getLayerIDs(uint* length, uint** array) const;
69     virtual bool getLayerIDsOfScreen(const uint screenID, uint* length, uint** array) const;
70     virtual void getSurfaceGroupIDs(uint* length, uint** array) const;
71     virtual void getLayerGroupIDs(uint* length, uint** array) const;
72     virtual void getSurfaceIDs(uint* length, uint** array) const;
73
74     virtual void lockScene();
75     virtual void unlockScene();
76
77 public:
78     // TODO: should be private -> not in ILayerList; clients should use only the interface
79     LayerList& getCurrentRenderOrder();
80     void removeSurfaceGroup(SurfaceGroup *surface);
81     void removeLayerGroup(LayerGroup *layer);
82     const SurfaceMap getAllSurfaces() const;
83     Surface* getSurfaceAt(unsigned int *x, unsigned int *y, double minOpacity);
84
85 private:
86     const LayerMap getAllLayers() const;
87     void removeLayerFromAllLayerGroups(Layer* layer);
88     void removeSurfaceFromAllLayers(Surface* surface);
89     void removeSurfaceFromAllSurfaceGroups(Surface* surface);
90
91 private:
92     CommandList m_toBeCommittedList;
93     ShaderMap m_shaderMap;
94     pthread_mutex_t m_layerListMutex;
95     LayerGroupMap m_layerGroupMap;
96     SurfaceGroupMap m_surfaceGroupMap;
97     SurfaceMap m_surfaceMap;
98     LayerMap m_layerMap;
99     LayerList m_currentRenderOrder;
100 };
101
102 inline const LayerMap Scene::getAllLayers() const
103 {
104     return m_layerMap;
105 }
106
107 inline LayerList& Scene::getCurrentRenderOrder() // TODO: const
108 {
109     return m_currentRenderOrder;
110 }
111
112 inline const SurfaceMap Scene::getAllSurfaces() const
113 {
114     return m_surfaceMap;
115 }
116
117 inline void Scene::lockScene()
118 {
119     pthread_mutex_lock(&m_layerListMutex);
120 }
121
122 inline void Scene::unlockScene()
123 {
124     pthread_mutex_unlock(&m_layerListMutex);
125 }
126
127 #endif /* _SCENE_H_ */