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,
105 uint32_t inheritedDrawMode,
108 // Apply constraints to the node
109 ConstrainPropertyOwner(node, updateBufferIndex);
111 // Some dirty flags are inherited from parent
112 NodePropertyFlags nodeDirtyFlags = node.GetDirtyFlags() | node.GetInheritedDirtyFlags(parentFlags);
114 NodePropertyFlags cumulativeDirtyFlags = nodeDirtyFlags;
116 Layer* layer = ¤tLayer;
117 Layer* nodeIsLayer(node.GetLayer());
120 // all childs go to this layer
123 // assume layer is clean to begin with
124 layer->SetReuseRenderers(updateBufferIndex, true);
126 // Layers do not inherit the DrawMode from their parents
127 inheritedDrawMode = DrawMode::NORMAL;
129 DALI_ASSERT_DEBUG(NULL != layer);
131 UpdateNodeOpacity(node, nodeDirtyFlags, updateBufferIndex);
133 // Draw mode inheritance is treated as or-ing the modes together (as they are a bit-mask).
134 inheritedDrawMode |= node.GetDrawMode();
136 node.PrepareRender(updateBufferIndex);
138 // if any child node has moved or had its sort modifier changed, layer is not clean and old frame cannot be reused
139 // also if node has been deleted, dont reuse old render items
140 if(nodeDirtyFlags & RenderableUpdateFlags)
142 layer->SetReuseRenderers(updateBufferIndex, false);
145 // For partial update, mark all children of an animating node as updated.
146 if(updated) // Only set to updated if parent was updated.
148 node.SetUpdated(true);
150 else if(node.Updated()) // Only propagate updated==true downwards.
156 NodeContainer& children = node.GetChildren();
157 const NodeIter endIter = children.End();
158 for(NodeIter iter = children.Begin(); iter != endIter; ++iter)
160 Node& child = **iter;
161 cumulativeDirtyFlags |= UpdateNodes(child,
170 return cumulativeDirtyFlags;
174 * The root node is treated separately; it cannot inherit values since it has no parent
176 NodePropertyFlags UpdateNodeTree(Layer& rootNode,
177 BufferIndex updateBufferIndex,
178 RenderQueue& renderQueue)
180 DALI_ASSERT_DEBUG(rootNode.IsRoot());
182 // Short-circuit for invisible nodes
183 if(DALI_UNLIKELY(!rootNode.IsVisible(updateBufferIndex))) // almost never ever true
185 return NodePropertyFlags::NOTHING;
188 // If the root node was not previously visible
189 BufferIndex previousBuffer = updateBufferIndex ? 0u : 1u;
190 if(DALI_UNLIKELY(!rootNode.IsVisible(previousBuffer))) // almost never ever true
192 // The node was skipped in the previous update; it must recalculate everything
193 rootNode.SetAllDirtyFlags();
196 NodePropertyFlags nodeDirtyFlags(rootNode.GetDirtyFlags());
198 NodePropertyFlags cumulativeDirtyFlags = nodeDirtyFlags;
200 UpdateRootNodeOpacity(rootNode, nodeDirtyFlags, updateBufferIndex);
202 DrawMode::Type drawMode(rootNode.GetDrawMode());
204 bool updated = rootNode.Updated();
207 NodeContainer& children = rootNode.GetChildren();
208 const NodeIter endIter = children.End();
209 for(NodeIter iter = children.Begin(); iter != endIter; ++iter)
211 Node& child = **iter;
212 cumulativeDirtyFlags |= UpdateNodes(child,
221 return cumulativeDirtyFlags;
224 } // namespace SceneGraph
226 } // namespace Internal