Health: added thread dead-lock detection
[profile/ivi/layer-management.git] / LayerManagerBase / include / Layer.h
1 /***************************************************************************
2  *
3  * Copyright 2010,2011 BMW Car IT GmbH
4  * Copyright (C) 2012 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *        http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ****************************************************************************/
20
21 #ifndef _LAYER_H_
22 #define _LAYER_H_
23
24 #include "SurfaceList.h"
25 #include "Surface.h"
26 #include "GraphicalSurface.h"
27 #include "LayerType.h"
28 #include "LayerCapabilities.h"
29 #include "SurfaceList.h"
30
31 /*
32  * A graphical Layerobject which contains Surfaces.
33  */
34 class Layer : public GraphicalSurface
35 {
36     friend class Scene;
37
38 public:
39     Layer(int creatorPid);
40     Layer(int id, int creatorPid);
41
42     virtual ~Layer() {}
43
44     LayerType getLayerType() const;
45     bool setLayerType(LayerType lt);
46     bool setLayerCapabilities(unsigned int newCapabilities);
47     unsigned int getCapabilities() const;
48     bool addSurface(Surface* s);
49     bool removeSurface(Surface* s);
50     void applySurfaceTransform();
51     SurfaceList& getAllSurfaces();
52     bool removeAllSurfaces();
53     unsigned int getContainingScreenId();
54     void setContainingScreenId(unsigned int screenid);
55
56 private:
57     unsigned int m_screenId;
58     SurfaceList m_surfaces;
59     LayerType m_layerType;
60     uint m_capabilities;
61 };
62
63 inline Layer::Layer(int creatorPid)
64 : GraphicalSurface(TypeLayer, creatorPid)
65 , m_screenId(INVALID_ID)
66 , m_layerType(Software_2D)
67 , m_capabilities(0)
68 {
69 }
70
71 inline Layer::Layer(int id, int creatorPid)
72 : GraphicalSurface(id, TypeLayer, creatorPid)
73 , m_screenId(INVALID_ID)
74 , m_layerType(Software_2D)
75 , m_capabilities(0)
76 {
77 }
78
79 inline LayerType Layer::getLayerType() const
80 {
81     return m_layerType;
82 }
83
84 inline bool Layer::setLayerType(LayerType lt)
85 {
86     if (m_layerType != lt)
87     {
88         m_layerType = lt;
89         renderPropertyChanged = true;
90         return true;
91     }
92     return false;
93 }
94
95 inline bool Layer::setLayerCapabilities(uint newCapabilities)
96 {
97     if (m_capabilities != newCapabilities)
98     {
99         m_capabilities = newCapabilities;
100         renderPropertyChanged = true;
101         return true;
102     }
103     return false;
104 }
105
106 inline uint Layer::getCapabilities() const
107 {
108     return m_capabilities;
109 }
110
111 inline bool Layer::addSurface(Surface* s)
112 {
113     if (s->getContainingLayerId() == INVALID_ID)
114     {
115         m_surfaces.push_back(s);
116         s->setContainingLayerId(getID());
117         renderPropertyChanged = true;
118         return true;
119     }
120     return false;
121 }
122
123 inline bool Layer::removeSurface(Surface* s)
124 {
125     if (s->getContainingLayerId() == getID())
126     {
127         m_surfaces.remove(s);
128         s->setContainingLayerId(INVALID_ID);
129         renderPropertyChanged = true;
130         return true;
131     }
132     return false;
133 }
134
135 inline SurfaceList& Layer::getAllSurfaces()
136 {
137     return m_surfaces;
138 }
139
140 inline bool Layer::removeAllSurfaces()
141 {
142     SurfaceListConstIterator iter = m_surfaces.begin();
143     SurfaceListConstIterator iterEnd = m_surfaces.end();
144
145     if (iter == iterEnd)
146         return false;
147
148     for (; iter != iterEnd; ++iter)
149     {
150         (*iter)->setContainingLayerId(GraphicalObject::INVALID_ID);
151     }
152     m_surfaces.clear();
153     renderPropertyChanged = true;
154     return true;
155 }
156
157 inline unsigned int Layer::getContainingScreenId()
158 {
159     return m_screenId;
160 }
161
162 inline void Layer::setContainingScreenId(unsigned int id)
163 {
164     m_screenId = id;
165 }
166
167 inline void Layer::applySurfaceTransform()
168 {
169     SurfaceListConstIterator iter = m_surfaces.begin();
170     SurfaceListConstIterator iterEnd = m_surfaces.end();
171     if (iter != iterEnd)
172     {
173         for (; iter != iterEnd; ++iter)
174         {
175             (*iter)->calculateTargetDestination(getSourceRegion(), getDestinationRegion());
176         }
177     }
178 }
179
180 #endif /* _LAYER_H_ */