[Tizen](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
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_NODE_DATA_PROVIDER_H
2 #define DALI_INTERNAL_SCENE_GRAPH_NODE_DATA_PROVIDER_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 #include <dali/internal/render/data-providers/uniform-map-data-provider.h>
22 #include <dali/public-api/math/matrix.h>
23 #include <cstring>
24
25 namespace Dali
26 {
27 struct Vector4;
28 class Matrix;
29
30 namespace Internal
31 {
32 namespace SceneGraph
33 {
34 class Node;
35 class Renderer;
36 class TextureSet;
37
38 /**
39  * Structure to store partial rendering cache data
40  */
41 struct PartialRenderingCacheInfo
42 {
43   Node*             node{nullptr};       /// Node associated with the entry
44   const Renderer*   renderer{nullptr};   /// Renderer object
45   const TextureSet* textureSet{nullptr}; /// TextureSet object
46   Matrix            matrix{};            /// Model-view matrix
47   Vector4           color{};             /// Color
48   Vector3           size{};              /// Size
49   Vector3           updatedSize{};       /// Updated size
50   bool              isOpaque{};          /// Opacity state
51   uint32_t          depthIndex{0u};      /// Depth index
52 };
53
54 /**
55  * Structure contains partial rendering data used in order to determine
56  * whether anything has changed and node has to be updated
57  */
58 struct PartialRenderingNodeData
59 {
60   /**
61    * @brief Retrieves current PartialDataCacheInfo structure
62    * @return Current PartialDataCacheInfo structure
63    */
64   PartialRenderingCacheInfo& GetCurrentCacheInfo()
65   {
66     return mData[mCurrentIndex];
67   }
68
69   /**
70    * @brief Tests whether cache changed since last frame
71    * @return True if changed
72    */
73   bool IsUpdated()
74   {
75     return (0 != memcmp(&mData[0], &mData[1], sizeof(PartialRenderingCacheInfo)) || !mRendered);
76   }
77
78   /**
79    * @brief Swaps cache buffers
80    */
81   void SwapBuffers()
82   {
83     mCurrentIndex = static_cast<uint8_t>((~mCurrentIndex) & 1);
84   }
85
86   PartialRenderingCacheInfo mData[2u];         /// Double-buffered data
87   uint8_t                   mCurrentIndex{0u}; /// Current buffer index
88   bool                      mVisible{true};    /// Visible state
89   bool                      mRendered{false};  /// Rendering state
90 };
91
92 /**
93  * An interface to provide partial rendering data
94  */
95 class PartialRenderingDataProvider
96 {
97 public:
98   /**
99    * Constructor
100    */
101   PartialRenderingDataProvider() = default;
102
103   /**
104    * Destructor
105    */
106   virtual ~PartialRenderingDataProvider() = default;
107
108   /**
109    * @brief Returns partial rendering data associated with the node.
110    * @return A valid pointer to the partial rendering data or nullptr
111    */
112   PartialRenderingNodeData& GetPartialRenderingData()
113   {
114     return mPartialRenderingData;
115   }
116
117 protected:
118   PartialRenderingNodeData mPartialRenderingData;
119 };
120
121 /**
122  * An interface to provide data for a Renderer
123  */
124 class NodeDataProvider : UniformMapDataProvider, public PartialRenderingDataProvider
125 {
126 public:
127   /**
128    * Constructor. Nothing to do as a pure interface.
129    */
130   NodeDataProvider() = default;
131
132   /**
133    * @param bufferIndex to use
134    * @return a reference to the model matrix
135    */
136   virtual const Matrix& GetModelMatrix(BufferIndex bufferIndex) const = 0;
137
138   /**
139    * @param bufferIndex to use
140    * @return a reference to the color
141    */
142   virtual const Vector4& GetRenderColor(BufferIndex bufferIndex) const = 0;
143
144   /**
145    * @copydoc Dali::Internal::SceneGraph::UniformMapDataProvider::GetUniformMapChanged()
146    */
147   bool GetUniformMapChanged(BufferIndex bufferIndex) const override = 0;
148
149   /**
150    * @copydoc Dali::Internal::SceneGraph::UniformMapDataProvider::GetUniformMap()
151    */
152   const CollectedUniformMap& GetUniformMap(BufferIndex bufferIndex) const override = 0;
153
154 protected:
155   /**
156    * Virtual destructor, this is an interface, no deletion through this interface
157    */
158   ~NodeDataProvider() override = default;
159 };
160
161 } // namespace SceneGraph
162 } // namespace Internal
163 } // namespace Dali
164
165 #endif // DALI_INTERNAL_SCENE_GRAPH_NODE_DATA_PROVIDER_H