1 #ifndef DALI_INTERNAL_SCENE_GRAPH_PARTIAL_RENDERING_DATA_H
2 #define DALI_INTERNAL_SCENE_GRAPH_PARTIAL_RENDERING_DATA_H
5 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
25 namespace Dali::Internal::SceneGraph
31 * Structure contains partial rendering data used in order to determine
32 * whether anything has changed and node has to be updated
34 struct PartialRenderingData
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 hash{0u}; /// Last frame's hash
42 bool mVisible{true}; /// Visible state (Not hashed)
43 bool mRendered{false}; /// Rendering state (Not hashed)
46 * Calculate a hash from the cache data
50 hash = Dali::INITIAL_HASH_VALUE;
51 AddToHash(hash, &matrix, sizeof(decltype(matrix)));
52 AddToHash(hash, &color, sizeof(decltype(color)));
53 AddToHash(hash, &updatedPositionSize, sizeof(decltype(updatedPositionSize)));
54 AddToHash(hash, &size, sizeof(decltype(size)));
58 * @brief Tests whether cache changed since last frame
59 * @return True if changed
61 bool IsUpdated(PartialRenderingData& frameCache)
63 frameCache.CalculateHash();
65 return hash != frameCache.hash ||
66 matrix != frameCache.matrix ||
67 color != frameCache.color ||
68 updatedPositionSize != frameCache.updatedPositionSize ||
69 size != frameCache.size ||
70 !mRendered; // If everything is the same, check if we didn't render last frame.
73 void Update(const PartialRenderingData& frameCache)
75 matrix = frameCache.matrix;
76 color = frameCache.color;
77 updatedPositionSize = frameCache.updatedPositionSize;
78 size = frameCache.size;
79 hash = frameCache.hash;
82 // Don't change mVisible.
86 void AddToHash(uint32_t& aHash, void* el, size_t numBytes)
88 uint8_t* elBytes = static_cast<uint8_t*>(el);
89 for(size_t i = 0; i < numBytes; ++i)
91 aHash = aHash * 33 + *elBytes++;
96 } // namespace Dali::Internal::SceneGraph
98 #endif // DALI_INTERNAL_SCENE_GRAPH_PARTIAL_RENDERING_DATA_H