Merge "Ensure synchronous buffer decode when using encoded buffer image." into devel...
[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 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 // INTERNAL INCLUDES
22 #include <dali/public-api/actors/layer.h>
23 #include <dali/internal/event/common/event-thread-services.h>
24 #include <dali/internal/update/nodes/node.h>
25 #include <dali/internal/update/node-attachments/scene-graph-renderable-attachment-declarations.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 class RenderableAttachment;
34
35 // value types used by messages
36 template <> struct ParameterType< Dali::Layer::SortFunctionType >
37 : public BasicType< Dali::Layer::SortFunctionType > {};
38 template <> struct ParameterType< Dali::Layer::Behavior >
39 : public BasicType< Dali::Layer::Behavior > {};
40
41 namespace SceneGraph
42 {
43
44 /**
45  * Layers have a "depth" relative to all other layers in the scene-graph.
46  * Non-layer child nodes (and their attachments) are considered part of the layer.
47  *
48  * Layers are rendered separately, and the depth buffer is cleared before each layer is rendered.
49  * Objects in higher layers, are rendered after (in front of) objects in lower layers.
50  */
51 class Layer : public Node
52 {
53 public:
54
55   typedef Dali::Layer::SortFunctionType SortFunctionType;
56
57   // Creation methods
58
59   /**
60    * Construct a new Layer.
61    * @return A smart-pointer to a newly allocated Node
62    */
63   static SceneGraph::Layer* New();
64
65   /**
66    * Virtual destructor
67    */
68   virtual ~Layer();
69
70   /**
71    * From Node, to convert a node to a layer.
72    * @return The layer.
73    */
74   virtual Layer* GetLayer()
75   {
76     return this;
77   }
78
79   /**
80    * Sets the sort-function of a layer.
81    * @param [in] function The new sort-function.
82    */
83   void SetSortFunction( Dali::Layer::SortFunctionType function );
84
85   /**
86    * Retrieve the function used to sort semi-transparent geometry in this layer.
87    * @return The sort function.
88    */
89   Dali::Layer::SortFunctionType GetSortFunction() const
90   {
91     return mSortFunction;
92   }
93
94   /**
95    * Sets whether clipping is enabled for a layer.
96    * @param [in] enabled True if clipping is enabled.
97    */
98   void SetClipping( bool enabled );
99
100   /**
101    * Query whether clipping is enabled for a layer.
102    * @return True if clipping is enabled.
103    */
104   bool IsClipping() const
105   {
106     return mIsClipping;
107   }
108
109   /**
110    * Sets the clipping box of a layer, in window coordinates.
111    * The contents of the layer will not be visible outside this box, when clipping is
112    * enabled. The default clipping box is empty (0,0,0,0).
113    * @param [in] box The clipping box
114    */
115   void SetClippingBox( const ClippingBox& box );
116
117   /**
118    * Retrieves the clipping box of a layer, in window coordinates.
119    * @return The clipping box
120    */
121   const ClippingBox& GetClippingBox() const
122   {
123     return mClippingBox;
124   }
125
126   /**
127    * Sets the behavior of the layer
128    * @param [in] behavior The behavior of the layer
129    */
130   void SetBehavior( Dali::Layer::Behavior behavior );
131
132   /**
133    * Retrieves the behavior of the layer.
134    * @return The behavior
135    */
136   Dali::Layer::Behavior GetBehavior() const
137   {
138     return mBehavior;
139   }
140
141   /**
142    * @copydoc Dali::Layer::SetDepthTestDisabled()
143    */
144   void SetDepthTestDisabled( bool disable );
145
146   /**
147    * @copydoc Dali::Layer::IsDepthTestDisabled()
148    */
149   bool IsDepthTestDisabled() const;
150
151   /**
152    * Enables the reuse of the model view matrices of all renderers for this layer
153    * @param[in] updateBufferIndex The current update buffer index.
154    * @param value to set
155    */
156   void SetReuseRenderers( BufferIndex updateBufferIndex, bool value )
157   {
158     mAllChildTransformsClean[ updateBufferIndex ] = value;
159   }
160
161   /**
162    * Checks if it is ok to reuse renderers. Renderers can be reused if ModelView transform for all the renderers
163    * has not changed from previous use.
164    * @param[in] camera A pointer to the camera that we want to use to render the list.
165    * @return True if all children transforms have been clean for two consecutive frames and the camera we are going
166    * to use is the same than the one used before ( Otherwise View transform will be different )
167    *
168    */
169   bool CanReuseRenderers(Node* camera)
170   {
171     bool bReturn( mAllChildTransformsClean[ 0 ] && mAllChildTransformsClean[ 1 ] && camera == mLastCamera );
172     mLastCamera = camera;
173
174     return bReturn;
175   }
176
177   /**
178    * @return True if default sort function is used
179    */
180   bool UsesDefaultSortFunction()
181   {
182     return mIsDefaultSortFunction;
183   }
184
185 private:
186
187   /**
188    * Private constructor.
189    * See also Layer::New()
190    */
191   Layer();
192
193   // Undefined
194   Layer(const Layer&);
195
196   // Undefined
197   Layer& operator=(const Layer& rhs);
198
199 public: // For update-algorithms
200
201   RenderableAttachmentContainer stencilRenderables;
202   RenderableAttachmentContainer colorRenderables;
203   RenderableAttachmentContainer overlayRenderables;
204
205 private:
206
207   SortFunctionType mSortFunction; ///< Used to sort semi-transparent geometry
208
209   ClippingBox mClippingBox;           ///< The clipping box, in window coordinates
210   Node* mLastCamera;                  ///< Pointer to the last camera that has rendered the layer
211
212   Dali::Layer::Behavior mBehavior;    ///< The behavior of the layer
213
214   bool mAllChildTransformsClean[ 2 ]; ///< True if all child nodes transforms are clean,
215                                       /// double buffered as we need two clean frames before we can reuse N-1 for N+1
216                                       /// this allows us to cache render items when layer is "static"
217   bool mIsClipping:1;                 ///< True when clipping is enabled
218   bool mDepthTestDisabled:1;          ///< Whether depth test is disabled.
219   bool mIsDefaultSortFunction:1;      ///< whether the default depth sort function is used
220
221 };
222
223 // Messages for Layer
224
225 /**
226  * Create a message to set the sort-function of a layer
227  * @param[in] layer The layer
228  * @param[in] function The new sort-function.
229  */
230 inline void SetSortFunctionMessage( EventThreadServices& eventThreadServices, const Layer& layer, Dali::Layer::SortFunctionType function )
231 {
232   typedef MessageValue1< Layer, Dali::Layer::SortFunctionType > LocalType;
233
234   // Reserve some memory inside the message queue
235   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
236
237   // Construct message in the message queue memory; note that delete should not be called on the return value
238   new (slot) LocalType( &layer, &Layer::SetSortFunction, function );
239 }
240
241 /**
242  * Create a message for enabling/disabling layer clipping
243  * @param[in] layer The layer
244  * @param[in] enabled True if clipping is enabled
245  */
246 inline void SetClippingMessage( EventThreadServices& eventThreadServices, const Layer& layer, bool enabled )
247 {
248   typedef MessageValue1< Layer, bool > LocalType;
249
250   // Reserve some memory inside the message queue
251   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
252
253   // Construct message in the message queue memory; note that delete should not be called on the return value
254   new (slot) LocalType( &layer, &Layer::SetClipping, enabled );
255 }
256
257 /**
258  * Create a message to set the clipping box of a layer
259  * @param[in] layer The layer
260  * @param[in] clippingbox The clipping box
261  */
262 inline void SetClippingBoxMessage( EventThreadServices& eventThreadServices, const Layer& layer, const Dali::ClippingBox& clippingbox )
263 {
264   typedef MessageValue1< Layer, Dali::ClippingBox > LocalType;
265
266   // Reserve some memory inside the message queue
267   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
268
269   // Construct message in the message queue memory; note that delete should not be called on the return value
270   new (slot) LocalType( &layer, &Layer::SetClippingBox, clippingbox );
271 }
272
273 /**
274  * Create a message to set the behavior of a layer
275  * @param[in] layer The layer
276  * @param[in] behavior The behavior
277  */
278 inline void SetBehaviorMessage( EventThreadServices& eventThreadServices,
279                                 const Layer& layer,
280                                 Dali::Layer::Behavior behavior )
281 {
282   typedef MessageValue1< Layer, Dali::Layer::Behavior > LocalType;
283
284   // Reserve some memory inside the message queue
285   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
286
287   // Construct message in the message queue memory; note that delete should not be called on the return value
288   new (slot) LocalType( &layer, &Layer::SetBehavior, behavior );
289 }
290
291 /**
292  * Create a message for disabling/enabling depth test.
293  *
294  * @see Dali::Layer::SetDepthTestDisabled().
295  *
296  * @param[in] layer The layer
297  * @param[in] disable \e true disables depth test. \e false sets the default behavior.
298  */
299 inline void SetDepthTestDisabledMessage( EventThreadServices& eventThreadServices, const Layer& layer, bool disable )
300 {
301   typedef MessageValue1< Layer, bool > LocalType;
302
303   // Reserve some memory inside the message queue
304   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
305
306   // Construct message in the message queue memory; note that delete should not be called on the return value
307   new (slot) LocalType( &layer, &Layer::SetDepthTestDisabled, disable );
308 }
309
310 } // namespace SceneGraph
311
312 } // namespace Internal
313
314 } // namespace Dali
315
316 #endif // __DALI_INTERNAL_SCENE_GRAPH_LAYER_H__