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 Node* node{nullptr}; /// Node associated with the entry
37 Renderer* renderer{nullptr}; /// Renderer object
38 const TextureSet* textureSet{nullptr}; /// TextureSet object
39 Matrix matrix{}; /// Model-view matrix
40 Vector4 color{}; /// Color
41 Vector4 updatedPositionSize{}; /// Updated position/size (x, y, width, height)
42 Vector3 size{}; /// Size
43 uint32_t depthIndex{0u}; /// Depth index
44 uint32_t hash; /// Last frame's hash
45 bool isOpaque{}; /// Opacity state
47 bool mVisible{true}; /// Visible state (Not hashed)
48 bool mRendered{false}; /// Rendering state (Not hashed)
51 * Calculate a hash from the cache data
55 hash = Dali::INITIAL_HASH_VALUE;
56 AddToHash(hash, &node, sizeof(decltype(node)));
57 AddToHash(hash, &renderer, sizeof(decltype(renderer)));
58 AddToHash(hash, &textureSet, sizeof(decltype(textureSet)));
59 AddToHash(hash, &matrix, sizeof(decltype(matrix)));
60 AddToHash(hash, &color, sizeof(decltype(color)));
61 AddToHash(hash, &updatedPositionSize, sizeof(decltype(updatedPositionSize)));
62 AddToHash(hash, &size, sizeof(decltype(size)));
63 AddToHash(hash, &depthIndex, sizeof(decltype(depthIndex)));
64 AddToHash(hash, &isOpaque, sizeof(decltype(isOpaque)));
68 * @brief Tests whether cache changed since last frame
69 * @return True if changed
71 bool IsUpdated(PartialRenderingData& frameCache)
73 frameCache.CalculateHash();
75 return hash != frameCache.hash ||
76 node != frameCache.node ||
77 renderer != frameCache.renderer ||
78 textureSet != frameCache.textureSet ||
79 matrix != frameCache.matrix ||
80 color != frameCache.color ||
81 updatedPositionSize != frameCache.updatedPositionSize ||
82 size != frameCache.size ||
83 depthIndex != frameCache.depthIndex ||
84 isOpaque != frameCache.isOpaque ||
86 !mRendered; // If everything is the same, check if we didn't render last frame.
89 void Update(const PartialRenderingData& frameCache)
91 node = frameCache.node;
92 renderer = frameCache.renderer;
93 textureSet = frameCache.textureSet;
94 matrix = frameCache.matrix;
95 color = frameCache.color;
96 updatedPositionSize = frameCache.updatedPositionSize;
97 size = frameCache.size;
98 depthIndex = frameCache.depthIndex;
99 isOpaque = frameCache.isOpaque;
100 hash = frameCache.hash;
103 // Don't change mVisible.
107 void AddToHash(uint32_t& aHash, void* el, size_t numBytes)
109 uint8_t* elBytes = static_cast<uint8_t*>(el);
110 for(size_t i = 0; i < numBytes; ++i)
112 aHash = aHash * 33 + *elBytes++;
117 } // namespace Dali::Internal::SceneGraph
119 #endif // DALI_INTERNAL_SCENE_GRAPH_PARTIAL_RENDERING_DATA_H