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 * 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.
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.
51 class Layer : public Node
55 typedef Dali::Layer::SortFunctionType SortFunctionType;
60 * Construct a new Layer.
61 * @return A smart-pointer to a newly allocated Node
63 static SceneGraph::Layer* New();
71 * From Node, to convert a node to a layer.
74 virtual Layer* GetLayer()
80 * Sets the sort-function of a layer.
81 * @param [in] function The new sort-function.
83 void SetSortFunction( Dali::Layer::SortFunctionType function );
86 * Retrieve the function used to sort semi-transparent geometry in this layer.
87 * @return The sort function.
89 Dali::Layer::SortFunctionType GetSortFunction() const
95 * Sets whether clipping is enabled for a layer.
96 * @param [in] enabled True if clipping is enabled.
98 void SetClipping( bool enabled );
101 * Query whether clipping is enabled for a layer.
102 * @return True if clipping is enabled.
104 bool IsClipping() const
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
115 void SetClippingBox( const ClippingBox& box );
118 * Retrieves the clipping box of a layer, in window coordinates.
119 * @return The clipping box
121 const ClippingBox& GetClippingBox() const
127 * Sets the behavior of the layer
128 * @param [in] behavior The behavior of the layer
130 void SetBehavior( Dali::Layer::Behavior behavior );
133 * Retrieves the behavior of the layer.
134 * @return The behavior
136 Dali::Layer::Behavior GetBehavior() const
142 * @copydoc Dali::Layer::SetDepthTestDisabled()
144 void SetDepthTestDisabled( bool disable );
147 * @copydoc Dali::Layer::IsDepthTestDisabled()
149 bool IsDepthTestDisabled() const;
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
156 void SetReuseRenderers( BufferIndex updateBufferIndex, bool value )
158 mAllChildTransformsClean[ updateBufferIndex ] = value;
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 )
169 bool CanReuseRenderers(Node* camera)
171 bool bReturn( mAllChildTransformsClean[ 0 ] && mAllChildTransformsClean[ 1 ] && camera == mLastCamera );
172 mLastCamera = camera;
178 * @return True if default sort function is used
180 bool UsesDefaultSortFunction()
182 return mIsDefaultSortFunction;
188 * Private constructor.
189 * See also Layer::New()
197 Layer& operator=(const Layer& rhs);
199 public: // For update-algorithms
201 RenderableAttachmentContainer stencilRenderables;
202 RenderableAttachmentContainer colorRenderables;
203 RenderableAttachmentContainer overlayRenderables;
207 SortFunctionType mSortFunction; ///< Used to sort semi-transparent geometry
209 ClippingBox mClippingBox; ///< The clipping box, in window coordinates
210 Node* mLastCamera; ///< Pointer to the last camera that has rendered the layer
212 Dali::Layer::Behavior mBehavior; ///< The behavior of the layer
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
223 // Messages for Layer
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.
230 inline void SetSortFunctionMessage( EventThreadServices& eventThreadServices, const Layer& layer, Dali::Layer::SortFunctionType function )
232 typedef MessageValue1< Layer, Dali::Layer::SortFunctionType > LocalType;
234 // Reserve some memory inside the message queue
235 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
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 );
242 * Create a message for enabling/disabling layer clipping
243 * @param[in] layer The layer
244 * @param[in] enabled True if clipping is enabled
246 inline void SetClippingMessage( EventThreadServices& eventThreadServices, const Layer& layer, bool enabled )
248 typedef MessageValue1< Layer, bool > LocalType;
250 // Reserve some memory inside the message queue
251 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
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 );
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
262 inline void SetClippingBoxMessage( EventThreadServices& eventThreadServices, const Layer& layer, const Dali::ClippingBox& clippingbox )
264 typedef MessageValue1< Layer, Dali::ClippingBox > LocalType;
266 // Reserve some memory inside the message queue
267 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
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 );
274 * Create a message to set the behavior of a layer
275 * @param[in] layer The layer
276 * @param[in] behavior The behavior
278 inline void SetBehaviorMessage( EventThreadServices& eventThreadServices,
280 Dali::Layer::Behavior behavior )
282 typedef MessageValue1< Layer, Dali::Layer::Behavior > LocalType;
284 // Reserve some memory inside the message queue
285 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
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 );
292 * Create a message for disabling/enabling depth test.
294 * @see Dali::Layer::SetDepthTestDisabled().
296 * @param[in] layer The layer
297 * @param[in] disable \e true disables depth test. \e false sets the default behavior.
299 inline void SetDepthTestDisabledMessage( EventThreadServices& eventThreadServices, const Layer& layer, bool disable )
301 typedef MessageValue1< Layer, bool > LocalType;
303 // Reserve some memory inside the message queue
304 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
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 );
310 } // namespace SceneGraph
312 } // namespace Internal
316 #endif // __DALI_INTERNAL_SCENE_GRAPH_LAYER_H__