1 #ifndef DALI_INTERNAL_SCENE_GRAPH_LAYER_H
2 #define DALI_INTERNAL_SCENE_GRAPH_LAYER_H
5 * Copyright (c) 2022 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
51 Renderable() = default;
53 Renderable(Node* node, RendererKey renderer)
60 RendererKey mRenderer{};
63 } // namespace SceneGraph
64 } // Namespace Internal
66 /// Enable Renderable to be used as a trivial type in Dali::Vector.
68 struct TypeTraits<Internal::SceneGraph::Renderable> : public Dali::BasicTypes<Internal::SceneGraph::Renderable>
72 IS_TRIVIAL_TYPE = true
81 using RenderableContainer = Dali::Vector<Renderable>;
84 * Layers have a "depth" relative to all other layers in the scene-graph.
85 * Non-layer child nodes are considered part of the layer.
87 * Layers are rendered separately, and by default the depth buffer is cleared before each layer is rendered.
88 * Objects in higher layers, are rendered after (in front of) objects in lower layers.
90 class Layer : public Node
93 using SortFunctionType = Dali::Layer::SortFunctionType;
98 * Construct a new Layer.
99 * @return A smart-pointer to a newly allocated Node
101 static SceneGraph::Layer* New();
109 * From Node, to convert a node to a layer.
112 Layer* GetLayer() override
118 * Sets the sort-function of a layer.
119 * @param [in] function The new sort-function.
121 void SetSortFunction(Dali::Layer::SortFunctionType function);
124 * Retrieve the function used to sort semi-transparent geometry in this layer.
125 * @return The sort function.
127 Dali::Layer::SortFunctionType GetSortFunction() const
129 return mSortFunction;
133 * Sets whether clipping is enabled for a layer.
134 * @param [in] enabled True if clipping is enabled.
136 void SetClipping(bool enabled);
139 * Query whether clipping is enabled for a layer.
140 * @return True if clipping is enabled.
142 bool IsClipping() const
148 * Sets the clipping box of a layer, in window coordinates.
149 * The contents of the layer will not be visible outside this box, when clipping is
150 * enabled. The default clipping box is empty (0,0,0,0).
151 * @param [in] box The clipping box
153 void SetClippingBox(const ClippingBox& box);
156 * Retrieves the clipping box of a layer, in window coordinates.
157 * @return The clipping box
159 const ClippingBox& GetClippingBox() const
165 * Sets the behavior of the layer
166 * @param [in] behavior The behavior of the layer
168 void SetBehavior(Dali::Layer::Behavior behavior);
171 * Retrieves the behavior of the layer.
172 * @return The behavior
174 Dali::Layer::Behavior GetBehavior() const
180 * @copydoc Dali::Layer::SetDepthTestDisabled()
182 void SetDepthTestDisabled(bool disable);
185 * @copydoc Dali::Layer::IsDepthTestDisabled()
187 bool IsDepthTestDisabled() const;
190 * Enables the reuse of the model view matrices of all renderers for this layer
191 * @param[in] updateBufferIndex The current update buffer index.
192 * @param value to set
194 void SetReuseRenderers(BufferIndex updateBufferIndex, bool value)
196 mAllChildTransformsClean[updateBufferIndex] = value;
200 * Checks if it is ok to reuse renderers. Renderers can be reused if ModelView transform for all the renderers
201 * has not changed from previous use.
202 * @param[in] camera A pointer to the camera that we want to use to render the list.
203 * @return True if all children transforms have been clean for two consecutive frames and the camera we are going
204 * to use is the same than the one used before ( Otherwise View transform will be different )
207 bool CanReuseRenderers(const Camera* camera)
209 bool bReturn(mAllChildTransformsClean[0] && mAllChildTransformsClean[1] && camera == mLastCamera);
210 mLastCamera = camera;
216 * @return True if default sort function is used
218 bool UsesDefaultSortFunction()
220 return mIsDefaultSortFunction;
224 * Clears all the renderable lists
226 void ClearRenderables();
230 * Private constructor.
231 * See also Layer::New()
235 // Delete copy and move
236 Layer(const Layer&) = delete;
237 Layer(Layer&&) = delete;
238 Layer& operator=(const Layer& rhs) = delete;
239 Layer& operator=(Layer&& rhs) = delete;
241 public: // For update-algorithms
242 RenderableContainer colorRenderables;
243 RenderableContainer overlayRenderables;
246 SortFunctionType mSortFunction; ///< Used to sort semi-transparent geometry
248 ClippingBox mClippingBox; ///< The clipping box, in window coordinates
249 const Camera* mLastCamera; ///< Pointer to the last camera that has rendered the layer
251 Dali::Layer::Behavior mBehavior; ///< The behavior of the layer
253 bool mAllChildTransformsClean[2]; ///< True if all child nodes transforms are clean,
254 /// double buffered as we need two clean frames before we can reuse N-1 for N+1
255 /// this allows us to cache render items when layer is "static"
256 bool mIsClipping : 1; ///< True when clipping is enabled
257 bool mDepthTestDisabled : 1; ///< Whether depth test is disabled.
258 bool mIsDefaultSortFunction : 1; ///< whether the default depth sort function is used
261 // Messages for Layer
264 * Create a message to set the sort-function of a layer
265 * @param[in] layer The layer
266 * @param[in] function The new sort-function.
268 inline void SetSortFunctionMessage(EventThreadServices& eventThreadServices, const Layer& layer, Dali::Layer::SortFunctionType function)
270 using LocalType = MessageValue1<Layer, Dali::Layer::SortFunctionType>;
272 // Reserve some memory inside the message queue
273 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
275 // Construct message in the message queue memory; note that delete should not be called on the return value
276 new(slot) LocalType(&layer, &Layer::SetSortFunction, function);
280 * Create a message for enabling/disabling layer clipping
281 * @param[in] layer The layer
282 * @param[in] enabled True if clipping is enabled
284 inline void SetClippingMessage(EventThreadServices& eventThreadServices, const Layer& layer, bool enabled)
286 using LocalType = MessageValue1<Layer, bool>;
288 // Reserve some memory inside the message queue
289 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
291 // Construct message in the message queue memory; note that delete should not be called on the return value
292 new(slot) LocalType(&layer, &Layer::SetClipping, enabled);
296 * Create a message to set the clipping box of a layer
297 * @param[in] layer The layer
298 * @param[in] clippingbox The clipping box
300 inline void SetClippingBoxMessage(EventThreadServices& eventThreadServices, const Layer& layer, const Dali::ClippingBox& clippingbox)
302 using LocalType = MessageValue1<Layer, Dali::ClippingBox>;
304 // Reserve some memory inside the message queue
305 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
307 // Construct message in the message queue memory; note that delete should not be called on the return value
308 new(slot) LocalType(&layer, &Layer::SetClippingBox, clippingbox);
312 * Create a message to set the behavior of a layer
313 * @param[in] layer The layer
314 * @param[in] behavior The behavior
316 inline void SetBehaviorMessage(EventThreadServices& eventThreadServices,
318 Dali::Layer::Behavior behavior)
320 using LocalType = MessageValue1<Layer, Dali::Layer::Behavior>;
322 // Reserve some memory inside the message queue
323 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
325 // Construct message in the message queue memory; note that delete should not be called on the return value
326 new(slot) LocalType(&layer, &Layer::SetBehavior, behavior);
330 * Create a message for disabling/enabling depth test.
332 * @see Dali::Layer::SetDepthTestDisabled().
334 * @param[in] layer The layer
335 * @param[in] disable \e true disables depth test. \e false sets the default behavior.
337 inline void SetDepthTestDisabledMessage(EventThreadServices& eventThreadServices, const Layer& layer, bool disable)
339 using LocalType = MessageValue1<Layer, bool>;
341 // Reserve some memory inside the message queue
342 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
344 // Construct message in the message queue memory; note that delete should not be called on the return value
345 new(slot) LocalType(&layer, &Layer::SetDepthTestDisabled, disable);
348 } // namespace SceneGraph
350 // Template specialisation for OwnerPointer<Layer>, because delete is protected
352 inline void OwnerPointer<Dali::Internal::SceneGraph::Layer>::Reset()
354 if(mObject != nullptr)
356 Dali::Internal::SceneGraph::Node::Delete(mObject);
360 } // namespace Internal
364 #endif // DALI_INTERNAL_SCENE_GRAPH_LAYER_H