1 #ifndef DALI_INTERNAL_SCENE_GRAPH_LAYER_H
2 #define DALI_INTERNAL_SCENE_GRAPH_LAYER_H
5 * Copyright (c) 2021 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/internal/event/common/event-thread-services.h>
23 #include <dali/internal/update/nodes/node.h>
24 #include <dali/public-api/actors/layer.h>
30 // value types used by messages
32 struct ParameterType<Dali::Layer::SortFunctionType>
33 : public BasicType<Dali::Layer::SortFunctionType>
37 struct ParameterType<Dali::Layer::Behavior>
38 : public BasicType<Dali::Layer::Behavior>
47 * Pair of node-renderer
57 Renderable(Node* node, Renderer* renderer)
67 using RenderableContainer = Dali::Vector<Renderable>;
70 * Layers have a "depth" relative to all other layers in the scene-graph.
71 * Non-layer child nodes are considered part of the layer.
73 * Layers are rendered separately, and by default the depth buffer is cleared before each layer is rendered.
74 * Objects in higher layers, are rendered after (in front of) objects in lower layers.
76 class Layer : public Node
79 using SortFunctionType = Dali::Layer::SortFunctionType;
84 * Construct a new Layer.
85 * @return A smart-pointer to a newly allocated Node
87 static SceneGraph::Layer* New();
95 * From Node, to convert a node to a layer.
98 Layer* GetLayer() override
104 * Sets the sort-function of a layer.
105 * @param [in] function The new sort-function.
107 void SetSortFunction(Dali::Layer::SortFunctionType function);
110 * Retrieve the function used to sort semi-transparent geometry in this layer.
111 * @return The sort function.
113 Dali::Layer::SortFunctionType GetSortFunction() const
115 return mSortFunction;
119 * Sets whether clipping is enabled for a layer.
120 * @param [in] enabled True if clipping is enabled.
122 void SetClipping(bool enabled);
125 * Query whether clipping is enabled for a layer.
126 * @return True if clipping is enabled.
128 bool IsClipping() const
134 * Sets the clipping box of a layer, in window coordinates.
135 * The contents of the layer will not be visible outside this box, when clipping is
136 * enabled. The default clipping box is empty (0,0,0,0).
137 * @param [in] box The clipping box
139 void SetClippingBox(const ClippingBox& box);
142 * Retrieves the clipping box of a layer, in window coordinates.
143 * @return The clipping box
145 const ClippingBox& GetClippingBox() const
151 * Sets the behavior of the layer
152 * @param [in] behavior The behavior of the layer
154 void SetBehavior(Dali::Layer::Behavior behavior);
157 * Retrieves the behavior of the layer.
158 * @return The behavior
160 Dali::Layer::Behavior GetBehavior() const
166 * @copydoc Dali::Layer::SetDepthTestDisabled()
168 void SetDepthTestDisabled(bool disable);
171 * @copydoc Dali::Layer::IsDepthTestDisabled()
173 bool IsDepthTestDisabled() const;
176 * Enables the reuse of the model view matrices of all renderers for this layer
177 * @param[in] updateBufferIndex The current update buffer index.
178 * @param value to set
180 void SetReuseRenderers(BufferIndex updateBufferIndex, bool value)
182 mAllChildTransformsClean[updateBufferIndex] = value;
186 * Checks if it is ok to reuse renderers. Renderers can be reused if ModelView transform for all the renderers
187 * has not changed from previous use.
188 * @param[in] camera A pointer to the camera that we want to use to render the list.
189 * @return True if all children transforms have been clean for two consecutive frames and the camera we are going
190 * to use is the same than the one used before ( Otherwise View transform will be different )
193 bool CanReuseRenderers(Camera* camera)
195 bool bReturn(mAllChildTransformsClean[0] && mAllChildTransformsClean[1] && camera == mLastCamera);
196 mLastCamera = camera;
202 * @return True if default sort function is used
204 bool UsesDefaultSortFunction()
206 return mIsDefaultSortFunction;
210 * Clears all the renderable lists
212 void ClearRenderables();
216 * Private constructor.
217 * See also Layer::New()
225 Layer& operator=(const Layer& rhs);
227 public: // For update-algorithms
228 RenderableContainer colorRenderables;
229 RenderableContainer overlayRenderables;
232 SortFunctionType mSortFunction; ///< Used to sort semi-transparent geometry
234 ClippingBox mClippingBox; ///< The clipping box, in window coordinates
235 Camera* 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
247 // Messages for Layer
250 * Create a message to set the sort-function of a layer
251 * @param[in] layer The layer
252 * @param[in] function The new sort-function.
254 inline void SetSortFunctionMessage(EventThreadServices& eventThreadServices, const Layer& layer, Dali::Layer::SortFunctionType function)
256 using LocalType = MessageValue1<Layer, Dali::Layer::SortFunctionType>;
258 // Reserve some memory inside the message queue
259 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
261 // Construct message in the message queue memory; note that delete should not be called on the return value
262 new(slot) LocalType(&layer, &Layer::SetSortFunction, function);
266 * Create a message for enabling/disabling layer clipping
267 * @param[in] layer The layer
268 * @param[in] enabled True if clipping is enabled
270 inline void SetClippingMessage(EventThreadServices& eventThreadServices, const Layer& layer, bool enabled)
272 using LocalType = MessageValue1<Layer, bool>;
274 // Reserve some memory inside the message queue
275 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
277 // Construct message in the message queue memory; note that delete should not be called on the return value
278 new(slot) LocalType(&layer, &Layer::SetClipping, enabled);
282 * Create a message to set the clipping box of a layer
283 * @param[in] layer The layer
284 * @param[in] clippingbox The clipping box
286 inline void SetClippingBoxMessage(EventThreadServices& eventThreadServices, const Layer& layer, const Dali::ClippingBox& clippingbox)
288 using LocalType = MessageValue1<Layer, Dali::ClippingBox>;
290 // Reserve some memory inside the message queue
291 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
293 // Construct message in the message queue memory; note that delete should not be called on the return value
294 new(slot) LocalType(&layer, &Layer::SetClippingBox, clippingbox);
298 * Create a message to set the behavior of a layer
299 * @param[in] layer The layer
300 * @param[in] behavior The behavior
302 inline void SetBehaviorMessage(EventThreadServices& eventThreadServices,
304 Dali::Layer::Behavior behavior)
306 using LocalType = MessageValue1<Layer, Dali::Layer::Behavior>;
308 // Reserve some memory inside the message queue
309 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
311 // Construct message in the message queue memory; note that delete should not be called on the return value
312 new(slot) LocalType(&layer, &Layer::SetBehavior, behavior);
316 * Create a message for disabling/enabling depth test.
318 * @see Dali::Layer::SetDepthTestDisabled().
320 * @param[in] layer The layer
321 * @param[in] disable \e true disables depth test. \e false sets the default behavior.
323 inline void SetDepthTestDisabledMessage(EventThreadServices& eventThreadServices, const Layer& layer, bool disable)
325 using LocalType = MessageValue1<Layer, bool>;
327 // Reserve some memory inside the message queue
328 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
330 // Construct message in the message queue memory; note that delete should not be called on the return value
331 new(slot) LocalType(&layer, &Layer::SetDepthTestDisabled, disable);
334 } // namespace SceneGraph
336 // Template specialisation for OwnerPointer<Layer>, because delete is protected
338 inline void OwnerPointer<Dali::Internal::SceneGraph::Layer>::Reset()
340 if(mObject != nullptr)
342 Dali::Internal::SceneGraph::Node::Delete(mObject);
346 } // namespace Internal
350 #endif // DALI_INTERNAL_SCENE_GRAPH_LAYER_H