(Partial Update) Mark as not rendered if the node is transparent or culled
[platform/core/uifw/dali-core.git] / dali / internal / render / data-providers / node-data-provider.h
index 3a4f27a..c0a143f 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_INTERNAL_SCENE_GRAPH_NODE_DATA_PROVIDER_H__
-#define __DALI_INTERNAL_SCENE_GRAPH_NODE_DATA_PROVIDER_H__
+#ifndef DALI_INTERNAL_SCENE_GRAPH_NODE_DATA_PROVIDER_H
+#define DALI_INTERNAL_SCENE_GRAPH_NODE_DATA_PROVIDER_H
 
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -19,6 +19,8 @@
  */
 
 #include <dali/internal/render/data-providers/uniform-map-data-provider.h>
+#include <dali/public-api/math/matrix.h>
+#include <cstring>
 
 namespace Dali
 {
@@ -29,50 +31,135 @@ namespace Internal
 {
 namespace SceneGraph
 {
+class Node;
+class Renderer;
+class TextureSet;
 
 /**
- * An interface to provide data for a Renderer
+ * Structure to store partial rendering cache data
+ */
+struct PartialRenderingCacheInfo
+{
+  Node*             node{nullptr};       /// Node associated with the entry
+  const Renderer*   renderer{nullptr};   /// Renderer object
+  const TextureSet* textureSet{nullptr}; /// TextureSet object
+  Matrix            matrix{};            /// Model-view matrix
+  Vector4           color{};             /// Color
+  Vector3           size{};              /// Size
+  Vector3           updatedSize{};       /// Updated size
+  bool              isOpaque{};          /// Opacity state
+  uint32_t          depthIndex{0u};      /// Depth index
+};
+
+/**
+ * Structure contains partial rendering data used in order to determine
+ * whether anything has changed and node has to be updated
+ */
+struct PartialRenderingNodeData
+{
+  /**
+   * @brief Retrieves current PartialDataCacheInfo structure
+   * @return Current PartialDataCacheInfo structure
+   */
+  PartialRenderingCacheInfo& GetCurrentCacheInfo()
+  {
+    return mData[mCurrentIndex];
+  }
+
+  /**
+   * @brief Tests whether cache changed since last frame
+   * @return True if changed
+   */
+  bool IsUpdated()
+  {
+    return (0 != memcmp(&mData[0], &mData[1], sizeof(PartialRenderingCacheInfo)) || !mRendered);
+  }
+
+  /**
+   * @brief Swaps cache buffers
+   */
+  void SwapBuffers()
+  {
+    mCurrentIndex = static_cast<uint8_t>((~mCurrentIndex) & 1);
+  }
+
+  PartialRenderingCacheInfo mData[2u];         /// Double-buffered data
+  uint8_t                   mCurrentIndex{0u}; /// Current buffer index
+  bool                      mVisible{true};    /// Visible state
+  bool                      mRendered{false};  /// Rendering state
+};
+
+/**
+ * An interface to provide partial rendering data
  */
-class NodeDataProvider : UniformMapDataProvider
+class PartialRenderingDataProvider
 {
 public:
+  /**
+   * Constructor
+   */
+  PartialRenderingDataProvider() = default;
+
+  /**
+   * Destructor
+   */
+  virtual ~PartialRenderingDataProvider() = default;
+
+  /**
+   * @brief Returns partial rendering data associated with the node.
+   * @return A valid pointer to the partial rendering data or nullptr
+   */
+  PartialRenderingNodeData& GetPartialRenderingData()
+  {
+    return mPartialRenderingData;
+  }
 
+protected:
+  PartialRenderingNodeData mPartialRenderingData;
+};
+
+/**
+ * An interface to provide data for a Renderer
+ */
+class NodeDataProvider : UniformMapDataProvider, public PartialRenderingDataProvider
+{
+public:
   /**
    * Constructor. Nothing to do as a pure interface.
    */
-  NodeDataProvider() { }
+  NodeDataProvider() = default;
 
   /**
    * @param bufferIndex to use
    * @return a reference to the model matrix
    */
-  virtual const Matrix& GetModelMatrix( BufferIndex bufferIndex ) const = 0;
+  virtual const Matrix& GetModelMatrix(BufferIndex bufferIndex) const = 0;
 
   /**
    * @param bufferIndex to use
    * @return a reference to the color
    */
-  virtual const Vector4& GetRenderColor( BufferIndex bufferIndex ) const = 0;
+  virtual const Vector4& GetRenderColor(BufferIndex bufferIndex) const = 0;
 
   /**
    * @copydoc Dali::Internal::SceneGraph::UniformMapDataProvider::GetUniformMapChanged()
    */
-  virtual bool GetUniformMapChanged( BufferIndex bufferIndex ) const = 0;
+  bool GetUniformMapChanged(BufferIndex bufferIndex) const override = 0;
 
   /**
    * @copydoc Dali::Internal::SceneGraph::UniformMapDataProvider::GetUniformMap()
    */
-  virtual const CollectedUniformMap& GetUniformMap( BufferIndex bufferIndex ) const = 0;
+  const CollectedUniformMap& GetUniformMap(BufferIndex bufferIndex) const override = 0;
 
 protected:
   /**
    * Virtual destructor, this is an interface, no deletion through this interface
    */
-  virtual ~NodeDataProvider() { }
+  ~NodeDataProvider() override = default;
 };
 
-} // SceneGraph
-} // Internal
-} // Dali
+} // namespace SceneGraph
+} // namespace Internal
+} // namespace Dali
 
-#endif // __DALI_INTERNAL_SCENE_GRAPH_NODE_DATA_PROVIDER_H__
+#endif // DALI_INTERNAL_SCENE_GRAPH_NODE_DATA_PROVIDER_H