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)
107 // Apply constraints to the node
108 ConstrainPropertyOwner(node, updateBufferIndex);
110 // Some dirty flags are inherited from parent
111 NodePropertyFlags nodeDirtyFlags = node.GetInheritedDirtyFlags(parentFlags);
113 NodePropertyFlags cumulativeDirtyFlags = nodeDirtyFlags;
115 Layer* layer = ¤tLayer;
116 Layer* nodeIsLayer(node.GetLayer());
119 // all childs go to this layer
122 // assume layer is clean to begin with
123 layer->SetReuseRenderers(updateBufferIndex, true);
125 // Layers do not inherit the DrawMode from their parents
126 inheritedDrawMode = DrawMode::NORMAL;
128 DALI_ASSERT_DEBUG(NULL != layer);
130 UpdateNodeOpacity(node, nodeDirtyFlags, updateBufferIndex);
132 // Draw mode inheritance is treated as or-ing the modes together (as they are a bit-mask).
133 inheritedDrawMode |= node.GetDrawMode();
135 node.PrepareRender(updateBufferIndex);
137 // if any child node has moved or had its sort modifier changed, layer is not clean and old frame cannot be reused
138 // also if node has been deleted, dont reuse old render items
139 if(nodeDirtyFlags & RenderableUpdateFlags)
141 layer->SetReuseRenderers(updateBufferIndex, false);
145 NodeContainer& children = node.GetChildren();
146 const NodeIter endIter = children.End();
147 for(NodeIter iter = children.Begin(); iter != endIter; ++iter)
149 Node& child = **iter;
150 cumulativeDirtyFlags |= UpdateNodes(child,
158 return cumulativeDirtyFlags;
162 * The root node is treated separately; it cannot inherit values since it has no parent
164 NodePropertyFlags UpdateNodeTree(Layer& rootNode,
165 BufferIndex updateBufferIndex,
166 RenderQueue& renderQueue)
168 DALI_ASSERT_DEBUG(rootNode.IsRoot());
170 // Short-circuit for invisible nodes
171 if(DALI_UNLIKELY(!rootNode.IsVisible(updateBufferIndex))) // almost never ever true
173 return NodePropertyFlags::NOTHING;
176 // If the root node was not previously visible
177 BufferIndex previousBuffer = updateBufferIndex ? 0u : 1u;
178 if(DALI_UNLIKELY(!rootNode.IsVisible(previousBuffer))) // almost never ever true
180 // The node was skipped in the previous update; it must recalculate everything
181 rootNode.SetAllDirtyFlags();
184 NodePropertyFlags nodeDirtyFlags(rootNode.GetDirtyFlags());
186 NodePropertyFlags cumulativeDirtyFlags = nodeDirtyFlags;
188 UpdateRootNodeOpacity(rootNode, nodeDirtyFlags, updateBufferIndex);
190 DrawMode::Type drawMode(rootNode.GetDrawMode());
193 NodeContainer& children = rootNode.GetChildren();
194 const NodeIter endIter = children.End();
195 for(NodeIter iter = children.Begin(); iter != endIter; ++iter)
197 Node& child = **iter;
198 cumulativeDirtyFlags |= UpdateNodes(child,
206 return cumulativeDirtyFlags;
209 } // namespace SceneGraph
211 } // namespace Internal