[SRUK] Initial copy from Tizen 2.2 version
[platform/core/uifw/dali-core.git] / dali / internal / update / nodes / scene-graph-layer.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_LAYER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_LAYER_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali/public-api/actors/layer.h>
22 #include <dali/internal/common/event-to-update.h>
23 #include <dali/internal/update/nodes/node.h>
24 #include <dali/internal/update/node-attachments/scene-graph-renderable-attachment-declarations.h>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 class RenderableAttachment;
33
34 // value types used by messages
35 template <> struct ParameterType< Dali::Layer::SortFunctionType >
36 : public BasicType< Dali::Layer::SortFunctionType > {};
37
38 namespace SceneGraph
39 {
40
41 /**
42  * Layers have a "depth" relative to all other layers in the scene-graph.
43  * Non-layer child nodes (and their attachments) are considered part of the layer.
44  *
45  * Layers are rendered separately, and the depth buffer is cleared before each layer is rendered.
46  * Objects in higher layers, are rendered after (in front of) objects in lower layers.
47  */
48 class Layer : public Node
49 {
50 public:
51
52   typedef Dali::Layer::SortFunctionType SortFunctionType;
53
54   // Creation methods
55
56   /**
57    * Construct a new Layer.
58    * @return A smart-pointer to a newly allocated Node
59    */
60   static SceneGraph::Layer* New();
61
62   /**
63    * Virtual destructor
64    */
65   virtual ~Layer();
66
67   /**
68    * From Node, to convert a node to a layer.
69    * @return The layer.
70    */
71   virtual Layer* GetLayer()
72   {
73     return this;
74   }
75
76   /**
77    * Sets the sort-function of a layer.
78    * @param [in] function The new sort-function.
79    */
80   void SetSortFunction( Dali::Layer::SortFunctionType function );
81
82   /**
83    * Retrieve the function used to sort semi-transparent geometry in this layer.
84    * @return The sort function.
85    */
86   Dali::Layer::SortFunctionType GetSortFunction() const
87   {
88     return mSortFunction;
89   }
90
91   /**
92    * Sets whether clipping is enabled for a layer.
93    * @param [in] enabled True if clipping is enabled.
94    */
95   void SetClipping( bool enabled );
96
97   /**
98    * Query whether clipping is enabled for a layer.
99    * @return True if clipping is enabled.
100    */
101   bool IsClipping() const
102   {
103     return mIsClipping;
104   }
105
106   /**
107    * Sets the clipping box of a layer, in window coordinates.
108    * The contents of the layer will not be visible outside this box, when clipping is
109    * enabled. The default clipping box is empty (0,0,0,0).
110    * @param [in] box The clipping box
111    */
112   void SetClippingBox( const ClippingBox& box );
113
114   /**
115    * Retrieves the clipping box of a layer, in window coordinates.
116    * @return The clipping box
117    */
118   const ClippingBox& GetClippingBox() const
119   {
120     return mClippingBox;
121   }
122
123   /**
124    * @copydoc Dali::Layer::SetDepthTestDisabled()
125    */
126   void SetDepthTestDisabled( bool disable );
127
128   /**
129    * @copydoc Dali::Layer::IsDepthTestDisabled()
130    */
131   bool IsDepthTestDisabled() const;
132
133   /**
134    * Enables the reuse of the model view matrices of all renderers for this layer
135    * @param[in] updateBufferIndex The current update buffer index.
136    * @param value to set
137    */
138   void SetReuseRenderers( BufferIndex updateBufferIndex, bool value )
139   {
140     mAllChildTransformsClean[ updateBufferIndex ] = value;
141   }
142
143   /**
144    * @return True if all children have been clean for two consequtive frames
145    */
146   bool CanReuseRenderers()
147   {
148     return mAllChildTransformsClean[ 0 ] && mAllChildTransformsClean[ 1 ];
149   }
150
151 private:
152
153   /**
154    * Private constructor.
155    * See also Layer::New()
156    */
157   Layer();
158
159   // Undefined
160   Layer(const Layer&);
161
162   // Undefined
163   Layer& operator=(const Layer& rhs);
164
165 public: // For update-algorithms
166
167   RenderableAttachmentContainer stencilRenderables;
168   RenderableAttachmentContainer transparentRenderables;
169   RenderableAttachmentContainer opaqueRenderables;
170   RenderableAttachmentContainer overlayRenderables;
171
172 private:
173
174   SortFunctionType mSortFunction; ///< Used to sort semi-transparent geometry
175
176   ClippingBox mClippingBox;           ///< The clipping box, in window coordinates
177   bool mAllChildTransformsClean[ 2 ]; ///< True if all child nodes transforms are clean,
178                                       /// double buffered as we need two clean frames before we can reuse N-1 for N+1
179                                       /// this allows us to cache render items when layer is "static"
180   bool mIsClipping:1;                 ///< True when clipping is enabled
181   bool mDepthTestDisabled:1;          ///< Whether depth test is disabled.
182 };
183
184 // Messages for Layer
185
186 /**
187  * Create a message to set the sort-function of a layer
188  * @param[in] layer The layer
189  * @param[in] function The new sort-function.
190  */
191 inline void SetSortFunctionMessage( EventToUpdate& eventToUpdate, const Layer& layer, Dali::Layer::SortFunctionType function )
192 {
193   typedef MessageValue1< Layer, Dali::Layer::SortFunctionType > LocalType;
194
195   // Reserve some memory inside the message queue
196   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
197
198   // Construct message in the message queue memory; note that delete should not be called on the return value
199   new (slot) LocalType( &layer, &Layer::SetSortFunction, function );
200 }
201
202 /**
203  * Create a message for enabling/disabling layer clipping
204  * @param[in] layer The layer
205  * @param[in] enabled True if clipping is enabled
206  */
207 inline void SetClippingMessage( EventToUpdate& eventToUpdate, const Layer& layer, bool enabled )
208 {
209   typedef MessageValue1< Layer, bool > LocalType;
210
211   // Reserve some memory inside the message queue
212   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
213
214   // Construct message in the message queue memory; note that delete should not be called on the return value
215   new (slot) LocalType( &layer, &Layer::SetClipping, enabled );
216 }
217
218 /**
219  * Create a message to set the clipping box of a layer
220  * @param[in] layer The layer
221  * @param[in] clippingbox The clipping box
222  */
223 inline void SetClippingBoxMessage( EventToUpdate& eventToUpdate, const Layer& layer, const Dali::ClippingBox& clippingbox )
224 {
225   typedef MessageValue1< Layer, Dali::ClippingBox > LocalType;
226
227   // Reserve some memory inside the message queue
228   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
229
230   // Construct message in the message queue memory; note that delete should not be called on the return value
231   new (slot) LocalType( &layer, &Layer::SetClippingBox, clippingbox );
232 }
233
234 /**
235  * Create a message for disabling/enabling depth test.
236  *
237  * @see Dali::Layer::SetDepthTestDisabled().
238  *
239  * @param[in] layer The layer
240  * @param[in] disable \e true disables depth test. \e false sets the default behaviour.
241  */
242 inline void SetDepthTestDisabledMessage( EventToUpdate& eventToUpdate, const Layer& layer, bool disable )
243 {
244   typedef MessageValue1< Layer, bool > LocalType;
245
246   // Reserve some memory inside the message queue
247   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
248
249   // Construct message in the message queue memory; note that delete should not be called on the return value
250   new (slot) LocalType( &layer, &Layer::SetDepthTestDisabled, disable );
251 }
252
253 } // namespace SceneGraph
254
255 } // namespace Internal
256
257 } // namespace Dali
258
259 #endif // __DALI_INTERNAL_SCENE_GRAPH_LAYER_H__