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