[dali_2.3.26] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / update / nodes / scene-graph-layer.h
old mode 100755 (executable)
new mode 100644 (file)
index c49f84f..5f2c70a
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_SCENE_GRAPH_LAYER_H
 
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 
 // INTERNAL INCLUDES
-#include <dali/public-api/actors/layer.h>
 #include <dali/internal/event/common/event-thread-services.h>
 #include <dali/internal/update/nodes/node.h>
+#include <dali/public-api/actors/layer.h>
 
 namespace Dali
 {
-
 namespace Internal
 {
-
 // value types used by messages
-template <> struct ParameterType< Dali::Layer::SortFunctionType >
-: public BasicType< Dali::Layer::SortFunctionType > {};
-template <> struct ParameterType< Dali::Layer::Behavior >
-: public BasicType< Dali::Layer::Behavior > {};
+template<>
+struct ParameterType<Dali::Layer::SortFunctionType>
+: public BasicType<Dali::Layer::SortFunctionType>
+{
+};
+template<>
+struct ParameterType<Dali::Layer::Behavior>
+: public BasicType<Dali::Layer::Behavior>
+{
+};
 
 namespace SceneGraph
 {
@@ -44,21 +48,36 @@ class Camera;
  */
 struct Renderable
 {
-  Renderable()
-  : mNode( 0 ),
-    mRenderer( 0 )
-  {}
-
-  Renderable( Node* node, Renderer* renderer )
-  : mNode( node ),
-    mRenderer( renderer )
-  {}
-
-  Node* mNode;
-  Renderer* mRenderer;
+  Renderable() = default;
+
+  Renderable(Node* node, RendererKey renderer)
+  : mNode(node),
+    mRenderer(renderer)
+  {
+  }
+
+  Node*       mNode{nullptr};
+  RendererKey mRenderer{};
+};
+
+} // namespace SceneGraph
+} // Namespace Internal
+
+/// Enable Renderable to be used as a trivial type in Dali::Vector.
+template<>
+struct TypeTraits<Internal::SceneGraph::Renderable> : public Dali::BasicTypes<Internal::SceneGraph::Renderable>
+{
+  enum
+  {
+    IS_TRIVIAL_TYPE = true
+  };
 };
 
-typedef Dali::Vector< Renderable > RenderableContainer;
+namespace Internal
+{
+namespace SceneGraph
+{
+using RenderableContainer = Dali::Vector<Renderable>;
 
 /**
  * Layers have a "depth" relative to all other layers in the scene-graph.
@@ -70,8 +89,7 @@ typedef Dali::Vector< Renderable > RenderableContainer;
 class Layer : public Node
 {
 public:
-
-  typedef Dali::Layer::SortFunctionType SortFunctionType;
+  using SortFunctionType = Dali::Layer::SortFunctionType;
 
   // Creation methods
 
@@ -84,13 +102,13 @@ public:
   /**
    * Virtual destructor
    */
-  virtual ~Layer();
+  ~Layer() override;
 
   /**
    * From Node, to convert a node to a layer.
    * @return The layer.
    */
-  virtual Layer* GetLayer()
+  Layer* GetLayer() override
   {
     return this;
   }
@@ -99,7 +117,7 @@ public:
    * Sets the sort-function of a layer.
    * @param [in] function The new sort-function.
    */
-  void SetSortFunction( Dali::Layer::SortFunctionType function );
+  void SetSortFunction(Dali::Layer::SortFunctionType function);
 
   /**
    * Retrieve the function used to sort semi-transparent geometry in this layer.
@@ -114,7 +132,7 @@ public:
    * Sets whether clipping is enabled for a layer.
    * @param [in] enabled True if clipping is enabled.
    */
-  void SetClipping( bool enabled );
+  void SetClipping(bool enabled);
 
   /**
    * Query whether clipping is enabled for a layer.
@@ -131,7 +149,7 @@ public:
    * enabled. The default clipping box is empty (0,0,0,0).
    * @param [in] box The clipping box
    */
-  void SetClippingBox( const ClippingBox& box );
+  void SetClippingBox(const ClippingBox& box);
 
   /**
    * Retrieves the clipping box of a layer, in window coordinates.
@@ -146,7 +164,7 @@ public:
    * Sets the behavior of the layer
    * @param [in] behavior The behavior of the layer
    */
-  void SetBehavior( Dali::Layer::Behavior behavior );
+  void SetBehavior(Dali::Layer::Behavior behavior);
 
   /**
    * Retrieves the behavior of the layer.
@@ -160,7 +178,7 @@ public:
   /**
    * @copydoc Dali::Layer::SetDepthTestDisabled()
    */
-  void SetDepthTestDisabled( bool disable );
+  void SetDepthTestDisabled(bool disable);
 
   /**
    * @copydoc Dali::Layer::IsDepthTestDisabled()
@@ -170,11 +188,21 @@ public:
   /**
    * Enables the reuse of the model view matrices of all renderers for this layer
    * @param[in] updateBufferIndex The current update buffer index.
-   * @param value to set
+   * @param[in] value to set
    */
-  void SetReuseRenderers( BufferIndex updateBufferIndex, bool value )
+  void SetReuseRenderers(BufferIndex updateBufferIndex, bool value)
   {
-    mAllChildTransformsClean[ updateBufferIndex ] = value;
+    mAllChildTransformsClean[updateBufferIndex] = value;
+  }
+
+  /**
+   * Get the reuse of the model view matrices of all renderers for this layer is enabled.
+   * @param[in] updateBufferIndex The current update buffer index.
+   * @return Whether all child transform was clean or not.
+   */
+  bool GetReuseRenderers(BufferIndex updateBufferIndex) const
+  {
+    return mAllChildTransformsClean[updateBufferIndex];
   }
 
   /**
@@ -185,9 +213,9 @@ public:
    * to use is the same than the one used before ( Otherwise View transform will be different )
    *
    */
-  bool CanReuseRenderers( Camera* camera )
+  bool CanReuseRenderers(const Camera* camera)
   {
-    bool bReturn( mAllChildTransformsClean[ 0 ] && mAllChildTransformsClean[ 1 ] && camera == mLastCamera );
+    bool bReturn(mAllChildTransformsClean[0] && mAllChildTransformsClean[1] && camera == mLastCamera);
     mLastCamera = camera;
 
     return bReturn;
@@ -207,40 +235,36 @@ public:
   void ClearRenderables();
 
 private:
-
   /**
    * Private constructor.
    * See also Layer::New()
    */
   Layer();
 
-  // Undefined
-  Layer(const Layer&);
-
-  // Undefined
-  Layer& operator=(const Layer& rhs);
+  // Delete copy and move
+  Layer(const Layer&) = delete;
+  Layer(Layer&&)      = delete;
+  Layer& operator=(const Layer& rhs) = delete;
+  Layer& operator=(Layer&& rhs) = delete;
 
 public: // For update-algorithms
-
   RenderableContainer colorRenderables;
   RenderableContainer overlayRenderables;
 
 private:
+  SortFunctionType mSortFunction; ///< Used to sort semi-transparent geometry
 
-  SortFunctionType mSortFunction;     ///< Used to sort semi-transparent geometry
-
-  ClippingBox mClippingBox;           ///< The clipping box, in window coordinates
-  Camera* mLastCamera;                ///< Pointer to the last camera that has rendered the layer
-
-  Dali::Layer::Behavior mBehavior;    ///< The behavior of the layer
+  ClippingBox   mClippingBox; ///< The clipping box, in window coordinates
+  const Camera* mLastCamera;  ///< Pointer to the last camera that has rendered the layer
 
-  bool mAllChildTransformsClean[ 2 ]; ///< True if all child nodes transforms are clean,
-                                      ///  double buffered as we need two clean frames before we can reuse N-1 for N+1
-                                      ///  this allows us to cache render items when layer is "static"
-  bool mIsClipping:1;                 ///< True when clipping is enabled
-  bool mDepthTestDisabled:1;          ///< Whether depth test is disabled.
-  bool mIsDefaultSortFunction:1;      ///< whether the default depth sort function is used
+  Dali::Layer::Behavior mBehavior; ///< The behavior of the layer
 
+  bool mAllChildTransformsClean[2]; ///< True if all child nodes transforms are clean,
+                                    ///  double buffered as we need two clean frames before we can reuse N-1 for N+1
+                                    ///  this allows us to cache render items when layer is "static"
+  bool mIsClipping : 1;             ///< True when clipping is enabled
+  bool mDepthTestDisabled : 1;      ///< Whether depth test is disabled.
+  bool mIsDefaultSortFunction : 1;  ///< whether the default depth sort function is used
 };
 
 // Messages for Layer
@@ -250,15 +274,15 @@ private:
  * @param[in] layer The layer
  * @param[in] function The new sort-function.
  */
-inline void SetSortFunctionMessage( EventThreadServices& eventThreadServices, const Layer& layer, Dali::Layer::SortFunctionType function )
+inline void SetSortFunctionMessage(EventThreadServices& eventThreadServices, const Layer& layer, Dali::Layer::SortFunctionType function)
 {
-  typedef MessageValue1< Layer, Dali::Layer::SortFunctionType > LocalType;
+  using LocalType = MessageValue1<Layer, Dali::Layer::SortFunctionType>;
 
   // Reserve some memory inside the message queue
-  uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+  uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
-  new (slot) LocalType( &layer, &Layer::SetSortFunction, function );
+  new(slot) LocalType(&layer, &Layer::SetSortFunction, function);
 }
 
 /**
@@ -266,15 +290,15 @@ inline void SetSortFunctionMessage( EventThreadServices& eventThreadServices, co
  * @param[in] layer The layer
  * @param[in] enabled True if clipping is enabled
  */
-inline void SetClippingMessage( EventThreadServices& eventThreadServices, const Layer& layer, bool enabled )
+inline void SetClippingMessage(EventThreadServices& eventThreadServices, const Layer& layer, bool enabled)
 {
-  typedef MessageValue1< Layer, bool > LocalType;
+  using LocalType = MessageValue1<Layer, bool>;
 
   // Reserve some memory inside the message queue
-  uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+  uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
-  new (slot) LocalType( &layer, &Layer::SetClipping, enabled );
+  new(slot) LocalType(&layer, &Layer::SetClipping, enabled);
 }
 
 /**
@@ -282,15 +306,15 @@ inline void SetClippingMessage( EventThreadServices& eventThreadServices, const
  * @param[in] layer The layer
  * @param[in] clippingbox The clipping box
  */
-inline void SetClippingBoxMessage( EventThreadServices& eventThreadServices, const Layer& layer, const Dali::ClippingBox& clippingbox )
+inline void SetClippingBoxMessage(EventThreadServices& eventThreadServices, const Layer& layer, const Dali::ClippingBox& clippingbox)
 {
-  typedef MessageValue1< Layer, Dali::ClippingBox > LocalType;
+  using LocalType = MessageValue1<Layer, Dali::ClippingBox>;
 
   // Reserve some memory inside the message queue
-  uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+  uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
-  new (slot) LocalType( &layer, &Layer::SetClippingBox, clippingbox );
+  new(slot) LocalType(&layer, &Layer::SetClippingBox, clippingbox);
 }
 
 /**
@@ -298,17 +322,17 @@ inline void SetClippingBoxMessage( EventThreadServices& eventThreadServices, con
  * @param[in] layer The layer
  * @param[in] behavior The behavior
  */
-inline void SetBehaviorMessage( EventThreadServices& eventThreadServices,
-                                const Layer& layer,
-                                Dali::Layer::Behavior behavior )
+inline void SetBehaviorMessage(EventThreadServices&  eventThreadServices,
+                               const Layer&          layer,
+                               Dali::Layer::Behavior behavior)
 {
-  typedef MessageValue1< Layer, Dali::Layer::Behavior > LocalType;
+  using LocalType = MessageValue1<Layer, Dali::Layer::Behavior>;
 
   // Reserve some memory inside the message queue
-  uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+  uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
-  new (slot) LocalType( &layer, &Layer::SetBehavior, behavior );
+  new(slot) LocalType(&layer, &Layer::SetBehavior, behavior);
 }
 
 /**
@@ -319,27 +343,27 @@ inline void SetBehaviorMessage( EventThreadServices& eventThreadServices,
  * @param[in] layer The layer
  * @param[in] disable \e true disables depth test. \e false sets the default behavior.
  */
-inline void SetDepthTestDisabledMessage( EventThreadServices& eventThreadServices, const Layer& layer, bool disable )
+inline void SetDepthTestDisabledMessage(EventThreadServices& eventThreadServices, const Layer& layer, bool disable)
 {
-  typedef MessageValue1< Layer, bool > LocalType;
+  using LocalType = MessageValue1<Layer, bool>;
 
   // Reserve some memory inside the message queue
-  uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+  uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
-  new (slot) LocalType( &layer, &Layer::SetDepthTestDisabled, disable );
+  new(slot) LocalType(&layer, &Layer::SetDepthTestDisabled, disable);
 }
 
 } // namespace SceneGraph
 
 // Template specialisation for OwnerPointer<Layer>, because delete is protected
-template <>
+template<>
 inline void OwnerPointer<Dali::Internal::SceneGraph::Layer>::Reset()
 {
-  if (mObject != NULL)
+  if(mObject != nullptr)
   {
     Dali::Internal::SceneGraph::Node::Delete(mObject);
-    mObject = NULL;
+    mObject = nullptr;
   }
 }
 } // namespace Internal