Revert "License conversion from Flora to Apache 2.0"
[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   /**
152    * @return True if default sort function is used
153    */
154   bool UsesDefaultSortFunction()
155   {
156     return mIsDefaultSortFunction;
157   }
158
159 private:
160
161   /**
162    * Private constructor.
163    * See also Layer::New()
164    */
165   Layer();
166
167   // Undefined
168   Layer(const Layer&);
169
170   // Undefined
171   Layer& operator=(const Layer& rhs);
172
173 public: // For update-algorithms
174
175   RenderableAttachmentContainer stencilRenderables;
176   RenderableAttachmentContainer transparentRenderables;
177   RenderableAttachmentContainer opaqueRenderables;
178   RenderableAttachmentContainer overlayRenderables;
179
180 private:
181
182   SortFunctionType mSortFunction; ///< Used to sort semi-transparent geometry
183
184   ClippingBox mClippingBox;           ///< The clipping box, in window coordinates
185   bool mAllChildTransformsClean[ 2 ]; ///< True if all child nodes transforms are clean,
186                                       /// double buffered as we need two clean frames before we can reuse N-1 for N+1
187                                       /// this allows us to cache render items when layer is "static"
188   bool mIsClipping:1;                 ///< True when clipping is enabled
189   bool mDepthTestDisabled:1;          ///< Whether depth test is disabled.
190   bool mIsDefaultSortFunction:1;      ///< whether the default depth sort function is used
191
192 };
193
194 // Messages for Layer
195
196 /**
197  * Create a message to set the sort-function of a layer
198  * @param[in] layer The layer
199  * @param[in] function The new sort-function.
200  */
201 inline void SetSortFunctionMessage( EventToUpdate& eventToUpdate, const Layer& layer, Dali::Layer::SortFunctionType function )
202 {
203   typedef MessageValue1< Layer, Dali::Layer::SortFunctionType > LocalType;
204
205   // Reserve some memory inside the message queue
206   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
207
208   // Construct message in the message queue memory; note that delete should not be called on the return value
209   new (slot) LocalType( &layer, &Layer::SetSortFunction, function );
210 }
211
212 /**
213  * Create a message for enabling/disabling layer clipping
214  * @param[in] layer The layer
215  * @param[in] enabled True if clipping is enabled
216  */
217 inline void SetClippingMessage( EventToUpdate& eventToUpdate, const Layer& layer, bool enabled )
218 {
219   typedef MessageValue1< Layer, bool > LocalType;
220
221   // Reserve some memory inside the message queue
222   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
223
224   // Construct message in the message queue memory; note that delete should not be called on the return value
225   new (slot) LocalType( &layer, &Layer::SetClipping, enabled );
226 }
227
228 /**
229  * Create a message to set the clipping box of a layer
230  * @param[in] layer The layer
231  * @param[in] clippingbox The clipping box
232  */
233 inline void SetClippingBoxMessage( EventToUpdate& eventToUpdate, const Layer& layer, const Dali::ClippingBox& clippingbox )
234 {
235   typedef MessageValue1< Layer, Dali::ClippingBox > LocalType;
236
237   // Reserve some memory inside the message queue
238   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
239
240   // Construct message in the message queue memory; note that delete should not be called on the return value
241   new (slot) LocalType( &layer, &Layer::SetClippingBox, clippingbox );
242 }
243
244 /**
245  * Create a message for disabling/enabling depth test.
246  *
247  * @see Dali::Layer::SetDepthTestDisabled().
248  *
249  * @param[in] layer The layer
250  * @param[in] disable \e true disables depth test. \e false sets the default behaviour.
251  */
252 inline void SetDepthTestDisabledMessage( EventToUpdate& eventToUpdate, const Layer& layer, bool disable )
253 {
254   typedef MessageValue1< Layer, bool > LocalType;
255
256   // Reserve some memory inside the message queue
257   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
258
259   // Construct message in the message queue memory; note that delete should not be called on the return value
260   new (slot) LocalType( &layer, &Layer::SetDepthTestDisabled, disable );
261 }
262
263 } // namespace SceneGraph
264
265 } // namespace Internal
266
267 } // namespace Dali
268
269 #endif // __DALI_INTERNAL_SCENE_GRAPH_LAYER_H__