Sync UTC harness
[platform/core/uifw/dali-core.git] / dali / internal / update / nodes / partial-rendering-data.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_PARTIAL_RENDERING_DATA_H
2 #define DALI_INTERNAL_SCENE_GRAPH_PARTIAL_RENDERING_DATA_H
3
4 /*
5  * Copyright (c) 2022 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 #include <dali/internal/update/rendering/scene-graph-renderer.h>
21 #include <dali/public-api/math/matrix.h>
22 #include <dali/public-api/math/vector3.h>
23 #include <dali/public-api/math/vector4.h>
24
25 namespace Dali::Internal::SceneGraph
26 {
27 class Node;
28 class TextureSet;
29
30 /**
31  * Structure contains partial rendering data used in order to determine
32  * whether anything has changed and node has to be updated
33  */
34 struct PartialRenderingData
35 {
36   Matrix   matrix{};              /// Model-view matrix
37   Vector4  color{};               /// Color
38   Vector4  updatedPositionSize{}; /// Updated position/size (x, y, width, height)
39   Vector3  size{};                /// Size
40   uint32_t depthIndex{0u};        /// Depth index
41   uint32_t hash;                  /// Last frame's hash
42
43   bool mVisible{true};   /// Visible state (Not hashed)
44   bool mRendered{false}; /// Rendering state (Not hashed)
45
46   /**
47    * Calculate a hash from the cache data
48    */
49   void CalculateHash()
50   {
51     hash = Dali::INITIAL_HASH_VALUE;
52     AddToHash(hash, &matrix, sizeof(decltype(matrix)));
53     AddToHash(hash, &color, sizeof(decltype(color)));
54     AddToHash(hash, &updatedPositionSize, sizeof(decltype(updatedPositionSize)));
55     AddToHash(hash, &size, sizeof(decltype(size)));
56     AddToHash(hash, &depthIndex, sizeof(decltype(depthIndex)));
57   }
58
59   /**
60    * @brief Tests whether cache changed since last frame
61    * @return True if changed
62    */
63   bool IsUpdated(PartialRenderingData& frameCache)
64   {
65     frameCache.CalculateHash();
66
67     return hash != frameCache.hash ||
68            matrix != frameCache.matrix ||
69            color != frameCache.color ||
70            updatedPositionSize != frameCache.updatedPositionSize ||
71            size != frameCache.size ||
72            depthIndex != frameCache.depthIndex ||
73            !mRendered; // If everything is the same, check if we didn't render last frame.
74   }
75
76   void Update(const PartialRenderingData& frameCache)
77   {
78     matrix              = frameCache.matrix;
79     color               = frameCache.color;
80     updatedPositionSize = frameCache.updatedPositionSize;
81     size                = frameCache.size;
82     depthIndex          = frameCache.depthIndex;
83     hash                = frameCache.hash;
84
85     mRendered = true;
86     // Don't change mVisible.
87   }
88
89 private:
90   void AddToHash(uint32_t& aHash, void* el, size_t numBytes)
91   {
92     uint8_t* elBytes = static_cast<uint8_t*>(el);
93     for(size_t i = 0; i < numBytes; ++i)
94     {
95       aHash = aHash * 33 + *elBytes++;
96     }
97   }
98 };
99
100 } // namespace Dali::Internal::SceneGraph
101
102 #endif // DALI_INTERNAL_SCENE_GRAPH_PARTIAL_RENDERING_DATA_H