Add API to UpdateProxy
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / update-proxy-impl.h
index f730a75..7ae5655 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_UPDATE_PROXY_IMPL_H
 
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
  */
 
 // EXTERNAL INCLUDES
-#include <dali/public-api/common/vector-wrapper.h>
+#include <cstdint>
+#include <memory>
 
 // INTERNAL INCLUDES
-#include <dali/public-api/math/matrix.h>
-#include <dali/public-api/math/vector3.h>
 #include <dali/internal/common/buffer-index.h>
 #include <dali/internal/update/manager/transform-manager.h>
 #include <dali/internal/update/nodes/node.h>
+#include <dali/public-api/common/vector-wrapper.h>
+#include <dali/public-api/math/matrix.h>
+#include <dali/public-api/math/vector3.h>
 
 namespace Dali
 {
-
 namespace Internal
 {
+namespace SceneGraph
+{
+class UpdateManager;
+}
 
 /**
  * @brief The implementation of Dali::UpdateProxy.
@@ -44,13 +49,13 @@ namespace Internal
 class UpdateProxy
 {
 public:
-
   /**
    * @brief Constructor.
+   * @param[in]  updateManager      Ref to the UpdateManager in order to add property resetters
    * @param[in]  transformManager   Ref to the TransformManager in order to set/get transform properties of nodes
    * @param[in]  rootNode           The root node for this proxy
    */
-  UpdateProxy( SceneGraph::TransformManager& transformManager, SceneGraph::Node& rootNode );
+  UpdateProxy(SceneGraph::UpdateManager& updateManager, SceneGraph::TransformManager& transformManager, SceneGraph::Node& rootNode);
 
   /**
    * @brief Destructor.
@@ -59,60 +64,80 @@ public:
 
   // Movable but not copyable
 
-  UpdateProxy( const UpdateProxy& )            = delete;  ///< Deleted copy constructor.
-  UpdateProxy( UpdateProxy&& )                 = default; ///< Default move constructor.
-  UpdateProxy& operator=( const UpdateProxy& ) = delete;  ///< Deleted copy assignment operator.
-  UpdateProxy& operator=( UpdateProxy&& )      = default; ///< Default move assignment operator.
+  UpdateProxy(const UpdateProxy&) = delete;            ///< Deleted copy constructor.
+  UpdateProxy(UpdateProxy&&)      = default;           ///< Default move constructor.
+  UpdateProxy& operator=(const UpdateProxy&) = delete; ///< Deleted copy assignment operator.
+  UpdateProxy& operator=(UpdateProxy&&) = delete;      ///< Deleted move assignment operator.
 
   /**
    * @copydoc Dali::UpdateProxy::GetPosition()
    */
-  Vector3 GetPosition( unsigned int id ) const;
+  bool GetPosition(uint32_t id, Vector3& position) const;
 
   /**
    * @copydoc Dali::UpdateProxy::SetPosition()
    */
-  void SetPosition( unsigned int id, const Vector3& position );
+  bool SetPosition(uint32_t id, const Vector3& position);
+
+  /**
+   * @copydoc Dali::UpdateProxy::BakePosition()
+   */
+  bool BakePosition(uint32_t id, const Vector3& position);
 
   /**
    * @copydoc Dali::UpdateProxy::GetSize()
    */
-  const Vector3& GetSize( unsigned int id ) const;
+  bool GetSize(uint32_t id, Vector3& size) const;
 
   /**
    * @copydoc Dali::UpdateProxy::SetSize()
    */
-  void SetSize( unsigned int id, const Vector3& size );
+  bool SetSize(uint32_t id, const Vector3& size);
+
+  /**
+   * @copydoc Dali::UpdateProxy::BakeSize()
+   */
+  bool BakeSize(uint32_t id, const Vector3& size);
 
   /**
    * @copydoc Dali::UpdateProxy::GetPositionAndSize()
    */
-  void GetPositionAndSize( unsigned int id, Vector3& position, Vector3& size ) const;
+  bool GetPositionAndSize(uint32_t id, Vector3& position, Vector3& size) const;
 
   /**
-   * @copydoc Dali::UpdateProxy::GetColor()
+   * @copydoc Dali::UpdateProxy::GetWorldPositionScaleAndSize()
    */
-  Vector4 GetWorldColor( unsigned int id ) const;
+  bool GetWorldPositionScaleAndSize(uint32_t id, Vector3& position, Vector3& scale, Vector3& size) const;
 
   /**
-   * @copydoc Dali::UpdateProxy::SetColor()
+   * @copydoc Dali::UpdateProxy::GetScale()
+   */
+  bool GetScale(uint32_t id, Vector3& scale) const;
+
+  /**
+   * @copydoc Dali::UpdateProxy::SetScale()
    */
-  void SetWorldColor( unsigned int id, const Vector4& color ) const;
+  bool SetScale(uint32_t id, const Vector3& scale);
 
   /**
-   * @copydoc Dali::UpdateProxy::GetWorldMatrixAndSize()
+   * @copydoc Dali::UpdateProxy::BakeScale()
    */
-  void GetWorldMatrixAndSize( unsigned int id, Matrix& worldMatrix, Vector3& size ) const;
+  bool BakeScale(uint32_t id, const Vector3& scale);
 
   /**
-   * @copydoc Dali::UpdateProxy::GetWorldMatrix()
+   * @copydoc Dali::UpdateProxy::GetColor()
+   */
+  bool GetColor(uint32_t id, Vector4& color) const;
+
+  /**
+   * @copydoc Dali::UpdateProxy::SetColor()
    */
-  const Matrix& GetWorldMatrix( unsigned int id ) const;
+  bool SetColor(uint32_t id, const Vector4& color);
 
   /**
-   * @copydoc Dali::UpdateProxy::SetWorldMatrix()
+   * @copydoc Dali::UpdateProxy::BakeColor()
    */
-  void SetWorldMatrix( unsigned int id, const Matrix& worldMatrix );
+  bool BakeColor(uint32_t id, const Vector4& color);
 
   /**
    * @brief Retrieves the root-node used by this class
@@ -123,38 +148,64 @@ public:
     return mRootNode;
   }
 
-  void SetCurrentBufferIndex( BufferIndex bufferIndex )
+  /**
+   * @brief Sets the buffer index to use when processing the next callback.
+   * @param[in]  bufferIndex  The current buffer index
+   */
+  void SetCurrentBufferIndex(BufferIndex bufferIndex)
   {
     mCurrentBufferIndex = bufferIndex;
   }
 
-private:
+  /**
+   * @brief Informs the update-proxy that the node hierarchy has changed.
+   */
+  void NodeHierarchyChanged();
 
   /**
+   * @brief Adds node resetter for each dirty node whose animatable properties have been changed.
+   */
+  void AddNodeResetters();
+
+private:
+  /**
    * @brief Retrieves the node with the specified ID.
    * @param[in]  id  The ID of the node required
    * @return A pointer to the required node if found.
    * @note This caches the last accessed node.
    */
-  SceneGraph::Node* GetNodeWithId( unsigned int id ) const;
+  SceneGraph::Node* GetNodeWithId(uint32_t id) const;
 
-private:
+  /**
+   * @brief Adds a property-resetter for non-transform properties so that they can be reset to their base value every frame.
+   * @param[in]  node          The node the property belongs to
+   * @param[in]  propertyBase  The property itself
+   */
+  void AddResetter(SceneGraph::Node& node, SceneGraph::PropertyBase& propertyBase);
 
+private:
   /**
    * Structure to store the ID & Node pair
    */
   struct IdNodePair
   {
-    unsigned int id; ///< The ID of the node
+    uint32_t          id;   ///< The ID of the node
     SceneGraph::Node* node; ///< The node itself
   };
 
-  mutable std::vector< IdNodePair > mNodeContainer; ///< Used to store cached pointers to already searched for Nodes.
-  mutable IdNodePair mLastCachedIdNodePair; ///< Used to cache the last retrieved id-node pair.
-  unsigned int mCurrentBufferIndex;
+  class PropertyModifier;
+  using PropertyModifierPtr = std::unique_ptr<PropertyModifier>;
 
+  mutable std::vector<IdNodePair> mNodeContainer;        ///< Used to store cached pointers to already searched for Nodes.
+  mutable IdNodePair              mLastCachedIdNodePair; ///< Used to cache the last retrieved id-node pair.
+  mutable std::vector<uint32_t>   mDirtyNodes;           ///< Used to store the ID of the dirty nodes with non-transform property modifications.
+  BufferIndex                     mCurrentBufferIndex;
+
+  SceneGraph::UpdateManager&    mUpdateManager;    ///< Reference to the Update Manager.
   SceneGraph::TransformManager& mTransformManager; ///< Reference to the Transform Manager.
-  SceneGraph::Node& mRootNode; ///< The root node of this update proxy.
+  SceneGraph::Node&             mRootNode;         ///< The root node of this update proxy.
+
+  PropertyModifierPtr mPropertyModifier; ///< To ensure non-transform property modifications reset to base values.
 };
 
 } // namespace Internal