1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_LAYER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_LAYER_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
33 class RenderableAttachment;
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 > {};
45 * Pair of node-renderer
54 NodeRenderer( Node* node, Renderer* renderer )
63 typedef Dali::Vector< NodeRenderer > NodeRendererContainer;
66 * Layers have a "depth" relative to all other layers in the scene-graph.
67 * Non-layer child nodes (and their attachments) are considered part of the layer.
69 * Layers are rendered separately, and the depth buffer is cleared before each layer is rendered.
70 * Objects in higher layers, are rendered after (in front of) objects in lower layers.
72 class Layer : public Node
76 typedef Dali::Layer::SortFunctionType SortFunctionType;
81 * Construct a new Layer.
82 * @return A smart-pointer to a newly allocated Node
84 static SceneGraph::Layer* New();
92 * From Node, to convert a node to a layer.
95 virtual Layer* GetLayer()
101 * Sets the sort-function of a layer.
102 * @param [in] function The new sort-function.
104 void SetSortFunction( Dali::Layer::SortFunctionType function );
107 * Retrieve the function used to sort semi-transparent geometry in this layer.
108 * @return The sort function.
110 Dali::Layer::SortFunctionType GetSortFunction() const
112 return mSortFunction;
116 * Sets whether clipping is enabled for a layer.
117 * @param [in] enabled True if clipping is enabled.
119 void SetClipping( bool enabled );
122 * Query whether clipping is enabled for a layer.
123 * @return True if clipping is enabled.
125 bool IsClipping() const
131 * Sets the clipping box of a layer, in window coordinates.
132 * The contents of the layer will not be visible outside this box, when clipping is
133 * enabled. The default clipping box is empty (0,0,0,0).
134 * @param [in] box The clipping box
136 void SetClippingBox( const ClippingBox& box );
139 * Retrieves the clipping box of a layer, in window coordinates.
140 * @return The clipping box
142 const ClippingBox& GetClippingBox() const
148 * Sets the behavior of the layer
149 * @param [in] behavior The behavior of the layer
151 void SetBehavior( Dali::Layer::Behavior behavior );
154 * Retrieves the behavior of the layer.
155 * @return The behavior
157 Dali::Layer::Behavior GetBehavior() const
163 * @copydoc Dali::Layer::SetDepthTestDisabled()
165 void SetDepthTestDisabled( bool disable );
168 * @copydoc Dali::Layer::IsDepthTestDisabled()
170 bool IsDepthTestDisabled() const;
173 * Enables the reuse of the model view matrices of all renderers for this layer
174 * @param[in] updateBufferIndex The current update buffer index.
175 * @param value to set
177 void SetReuseRenderers( BufferIndex updateBufferIndex, bool value )
179 mAllChildTransformsClean[ updateBufferIndex ] = value;
183 * Checks if it is ok to reuse renderers. Renderers can be reused if ModelView transform for all the renderers
184 * has not changed from previous use.
185 * @param[in] camera A pointer to the camera that we want to use to render the list.
186 * @return True if all children transforms have been clean for two consecutive frames and the camera we are going
187 * to use is the same than the one used before ( Otherwise View transform will be different )
190 bool CanReuseRenderers(Node* camera)
192 bool bReturn( mAllChildTransformsClean[ 0 ] && mAllChildTransformsClean[ 1 ] && camera == mLastCamera );
193 mLastCamera = camera;
199 * @return True if default sort function is used
201 bool UsesDefaultSortFunction()
203 return mIsDefaultSortFunction;
209 * Private constructor.
210 * See also Layer::New()
218 Layer& operator=(const Layer& rhs);
220 public: // For update-algorithms
222 RenderableAttachmentContainer stencilRenderables;
223 RenderableAttachmentContainer colorRenderables;
224 RenderableAttachmentContainer overlayRenderables;
226 NodeRendererContainer stencilRenderers;
227 NodeRendererContainer colorRenderers;
228 NodeRendererContainer overlayRenderers;
232 SortFunctionType mSortFunction; ///< Used to sort semi-transparent geometry
234 ClippingBox mClippingBox; ///< The clipping box, in window coordinates
235 Node* mLastCamera; ///< Pointer to the last camera that has rendered the layer
237 Dali::Layer::Behavior mBehavior; ///< The behavior of the layer
239 bool mAllChildTransformsClean[ 2 ]; ///< True if all child nodes transforms are clean,
240 /// double buffered as we need two clean frames before we can reuse N-1 for N+1
241 /// this allows us to cache render items when layer is "static"
242 bool mIsClipping:1; ///< True when clipping is enabled
243 bool mDepthTestDisabled:1; ///< Whether depth test is disabled.
244 bool mIsDefaultSortFunction:1; ///< whether the default depth sort function is used
248 // Messages for Layer
251 * Create a message to set the sort-function of a layer
252 * @param[in] layer The layer
253 * @param[in] function The new sort-function.
255 inline void SetSortFunctionMessage( EventThreadServices& eventThreadServices, const Layer& layer, Dali::Layer::SortFunctionType function )
257 typedef MessageValue1< Layer, Dali::Layer::SortFunctionType > LocalType;
259 // Reserve some memory inside the message queue
260 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
262 // Construct message in the message queue memory; note that delete should not be called on the return value
263 new (slot) LocalType( &layer, &Layer::SetSortFunction, function );
267 * Create a message for enabling/disabling layer clipping
268 * @param[in] layer The layer
269 * @param[in] enabled True if clipping is enabled
271 inline void SetClippingMessage( EventThreadServices& eventThreadServices, const Layer& layer, bool enabled )
273 typedef MessageValue1< Layer, bool > LocalType;
275 // Reserve some memory inside the message queue
276 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
278 // Construct message in the message queue memory; note that delete should not be called on the return value
279 new (slot) LocalType( &layer, &Layer::SetClipping, enabled );
283 * Create a message to set the clipping box of a layer
284 * @param[in] layer The layer
285 * @param[in] clippingbox The clipping box
287 inline void SetClippingBoxMessage( EventThreadServices& eventThreadServices, const Layer& layer, const Dali::ClippingBox& clippingbox )
289 typedef MessageValue1< Layer, Dali::ClippingBox > LocalType;
291 // Reserve some memory inside the message queue
292 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
294 // Construct message in the message queue memory; note that delete should not be called on the return value
295 new (slot) LocalType( &layer, &Layer::SetClippingBox, clippingbox );
299 * Create a message to set the behavior of a layer
300 * @param[in] layer The layer
301 * @param[in] behavior The behavior
303 inline void SetBehaviorMessage( EventThreadServices& eventThreadServices,
305 Dali::Layer::Behavior behavior )
307 typedef MessageValue1< Layer, Dali::Layer::Behavior > LocalType;
309 // Reserve some memory inside the message queue
310 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
312 // Construct message in the message queue memory; note that delete should not be called on the return value
313 new (slot) LocalType( &layer, &Layer::SetBehavior, behavior );
317 * Create a message for disabling/enabling depth test.
319 * @see Dali::Layer::SetDepthTestDisabled().
321 * @param[in] layer The layer
322 * @param[in] disable \e true disables depth test. \e false sets the default behavior.
324 inline void SetDepthTestDisabledMessage( EventThreadServices& eventThreadServices, const Layer& layer, bool disable )
326 typedef MessageValue1< Layer, bool > LocalType;
328 // Reserve some memory inside the message queue
329 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
331 // Construct message in the message queue memory; note that delete should not be called on the return value
332 new (slot) LocalType( &layer, &Layer::SetDepthTestDisabled, disable );
335 } // namespace SceneGraph
337 } // namespace Internal
341 #endif // __DALI_INTERNAL_SCENE_GRAPH_LAYER_H__