2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/update/manager/update-algorithms.h>
25 #include <dali/internal/render/renderers/render-renderer.h>
26 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
27 #include <dali/internal/update/nodes/node.h>
28 #include <dali/internal/update/nodes/scene-graph-layer.h>
29 #include <dali/public-api/actors/draw-mode.h>
30 #include <dali/public-api/math/matrix.h>
31 #include <dali/public-api/math/vector3.h>
33 #include <dali/integration-api/debug.h>
41 #if defined(DEBUG_ENABLED)
42 Debug::Filter* gUpdateFilter = Debug::Filter::New(Debug::Concise, false, "LOG_UPDATE_ALGORITHMS");
45 /******************************************************************************
46 *********************** Apply Constraints ************************************
47 ******************************************************************************/
50 * Constrain the local properties of the PropertyOwner.
51 * @param propertyOwner to constrain
52 * @param updateBufferIndex buffer index to use
54 void ConstrainPropertyOwner(PropertyOwner& propertyOwner, BufferIndex updateBufferIndex)
56 ConstraintOwnerContainer& constraints = propertyOwner.GetConstraints();
58 const ConstraintIter endIter = constraints.End();
59 for(ConstraintIter iter = constraints.Begin(); iter != endIter; ++iter)
61 ConstraintBase& constraint = **iter;
62 constraint.Apply(updateBufferIndex);
66 /******************************************************************************
67 ************************** Update node hierarchy *****************************
68 ******************************************************************************/
70 inline void UpdateRootNodeOpacity(Layer& rootNode, NodePropertyFlags nodeDirtyFlags, BufferIndex updateBufferIndex)
72 if(nodeDirtyFlags & NodePropertyFlags::COLOR)
74 rootNode.SetWorldColor(rootNode.GetColor(updateBufferIndex), updateBufferIndex);
78 // Copy previous value, in case it changed in the previous frame
79 rootNode.CopyPreviousWorldColor(updateBufferIndex);
83 inline void UpdateNodeOpacity(Node& node, NodePropertyFlags nodeDirtyFlags, BufferIndex updateBufferIndex)
85 // If opacity needs to be recalculated
86 if(nodeDirtyFlags & NodePropertyFlags::COLOR)
88 node.InheritWorldColor(updateBufferIndex);
92 // Copy inherited value, if changed in the previous frame
93 node.CopyPreviousWorldColor(updateBufferIndex);
98 * This is called recursively for all children of the root Node
100 inline NodePropertyFlags UpdateNodes(Node& node,
101 NodePropertyFlags parentFlags,
102 BufferIndex updateBufferIndex,
103 RenderQueue& renderQueue,
106 // Apply constraints to the node
107 ConstrainPropertyOwner(node, updateBufferIndex);
109 // Some dirty flags are inherited from parent
110 NodePropertyFlags nodeDirtyFlags = node.GetDirtyFlags() | node.GetInheritedDirtyFlags(parentFlags);
112 NodePropertyFlags cumulativeDirtyFlags = nodeDirtyFlags;
114 UpdateNodeOpacity(node, nodeDirtyFlags, updateBufferIndex);
118 // For partial update, mark all children of an animating node as updated.
119 if(updated) // Only set to updated if parent was updated.
121 node.SetUpdated(true);
123 else if(node.Updated()) // Only propagate updated==true downwards.
129 NodeContainer& children = node.GetChildren();
130 const NodeIter endIter = children.End();
131 for(NodeIter iter = children.Begin(); iter != endIter; ++iter)
133 Node& child = **iter;
134 cumulativeDirtyFlags |= UpdateNodes(child,
141 return cumulativeDirtyFlags;
145 * The root node is treated separately; it cannot inherit values since it has no parent
147 NodePropertyFlags UpdateNodeTree(Layer& rootNode,
148 BufferIndex updateBufferIndex,
149 RenderQueue& renderQueue)
151 DALI_ASSERT_DEBUG(rootNode.IsRoot());
153 // Short-circuit for invisible nodes
154 if(DALI_UNLIKELY(!rootNode.IsVisible(updateBufferIndex))) // almost never ever true
156 return NodePropertyFlags::NOTHING;
159 // If the root node was not previously visible
160 BufferIndex previousBuffer = updateBufferIndex ? 0u : 1u;
161 if(DALI_UNLIKELY(!rootNode.IsVisible(previousBuffer))) // almost never ever true
163 // The node was skipped in the previous update; it must recalculate everything
164 rootNode.SetAllDirtyFlags();
167 NodePropertyFlags nodeDirtyFlags(rootNode.GetDirtyFlags());
169 NodePropertyFlags cumulativeDirtyFlags = nodeDirtyFlags;
171 UpdateRootNodeOpacity(rootNode, nodeDirtyFlags, updateBufferIndex);
173 bool updated = rootNode.Updated();
176 NodeContainer& children = rootNode.GetChildren();
177 const NodeIter endIter = children.End();
178 for(NodeIter iter = children.Begin(); iter != endIter; ++iter)
180 Node& child = **iter;
181 cumulativeDirtyFlags |= UpdateNodes(child,
188 return cumulativeDirtyFlags;
191 inline void UpdateLayers(Node& node,
192 NodePropertyFlags parentFlags,
193 BufferIndex updateBufferIndex,
196 // Some dirty flags are inherited from parent
197 NodePropertyFlags nodeDirtyFlags = node.GetDirtyFlags() | node.GetInheritedDirtyFlags(parentFlags);
198 nodeDirtyFlags |= (node.IsLocalMatrixDirty() ? NodePropertyFlags::TRANSFORM : NodePropertyFlags::NOTHING);
200 Layer* nodeIsLayer(node.GetLayer());
201 Layer* layer = nodeIsLayer ? nodeIsLayer : ¤tLayer;
204 layer->SetReuseRenderers(updateBufferIndex, true);
206 DALI_ASSERT_DEBUG(nullptr != layer);
208 // if any child node has moved or had its sort modifier changed, layer is not clean and old frame cannot be reused
209 // also if node has been deleted, dont reuse old render items
210 if(nodeDirtyFlags != NodePropertyFlags::NOTHING)
212 layer->SetReuseRenderers(updateBufferIndex, false);
216 NodeContainer& children = node.GetChildren();
217 const NodeIter endIter = children.End();
218 for(NodeIter iter = children.Begin(); iter != endIter; ++iter)
220 Node& child = **iter;
221 UpdateLayers(child, nodeDirtyFlags, updateBufferIndex, *layer);
225 void UpdateLayerTree(Layer& layer,
226 BufferIndex updateBufferIndex)
228 NodePropertyFlags nodeDirtyFlags = layer.GetDirtyFlags();
229 nodeDirtyFlags |= (layer.IsLocalMatrixDirty() ? NodePropertyFlags::TRANSFORM : NodePropertyFlags::NOTHING);
232 NodeContainer& children = layer.GetChildren();
233 const NodeIter endIter = children.End();
234 for(NodeIter iter = children.Begin(); iter != endIter; ++iter)
236 Node& child = **iter;
237 UpdateLayers(child, nodeDirtyFlags, updateBufferIndex, layer);
241 } // namespace SceneGraph
243 } // namespace Internal