2 * Copyright (c) 2018 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/public-api/actors/draw-mode.h>
26 #include <dali/public-api/math/matrix.h>
27 #include <dali/public-api/math/vector3.h>
28 #include <dali/internal/update/nodes/node.h>
29 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
30 #include <dali/internal/update/nodes/scene-graph-layer.h>
31 #include <dali/internal/render/renderers/render-renderer.h>
33 #include <dali/integration-api/debug.h>
44 #if defined(DEBUG_ENABLED)
45 Debug::Filter* gUpdateFilter = Debug::Filter::New(Debug::Concise, false, "LOG_UPDATE_ALGORITHMS");
48 /******************************************************************************
49 *********************** Apply Constraints ************************************
50 ******************************************************************************/
54 * Constrain the local properties of the PropertyOwner.
55 * @param propertyOwner to constrain
56 * @param updateBufferIndex buffer index to use
58 void ConstrainPropertyOwner( PropertyOwner& propertyOwner, BufferIndex updateBufferIndex )
60 ConstraintOwnerContainer& constraints = propertyOwner.GetConstraints();
62 const ConstraintIter endIter = constraints.End();
63 for( ConstraintIter iter = constraints.Begin(); iter != endIter; ++iter )
65 ConstraintBase& constraint = **iter;
66 constraint.Apply( updateBufferIndex );
70 /******************************************************************************
71 ************************** Update node hierarchy *****************************
72 ******************************************************************************/
74 inline void UpdateRootNodeOpacity( Layer& rootNode, NodePropertyFlags nodeDirtyFlags, BufferIndex updateBufferIndex )
76 if ( nodeDirtyFlags & NodePropertyFlags::COLOR )
78 rootNode.SetWorldColor( rootNode.GetColor( updateBufferIndex ), updateBufferIndex );
82 // Copy previous value, in case it changed in the previous frame
83 rootNode.CopyPreviousWorldColor( updateBufferIndex );
87 inline void UpdateNodeOpacity( Node& node, NodePropertyFlags nodeDirtyFlags, BufferIndex updateBufferIndex )
89 // If opacity needs to be recalculated
90 if ( nodeDirtyFlags & NodePropertyFlags::COLOR )
92 node.InheritWorldColor( updateBufferIndex );
96 // Copy inherited value, if changed in the previous frame
97 node.CopyPreviousWorldColor( updateBufferIndex );
102 * This is called recursively for all children of the root Node
104 inline NodePropertyFlags UpdateNodes( Node& node,
105 NodePropertyFlags parentFlags,
106 BufferIndex updateBufferIndex,
107 RenderQueue& renderQueue,
109 uint32_t inheritedDrawMode )
111 // Apply constraints to the node
112 ConstrainPropertyOwner( node, updateBufferIndex );
114 // Some dirty flags are inherited from parent
115 NodePropertyFlags nodeDirtyFlags = node.GetInheritedDirtyFlags( parentFlags );
117 NodePropertyFlags cumulativeDirtyFlags = nodeDirtyFlags;
119 Layer* layer = ¤tLayer;
120 Layer* nodeIsLayer( node.GetLayer() );
123 // all childs go to this layer
126 // assume layer is clean to begin with
127 layer->SetReuseRenderers( updateBufferIndex, true );
129 // Layers do not inherit the DrawMode from their parents
130 inheritedDrawMode = DrawMode::NORMAL;
132 DALI_ASSERT_DEBUG( NULL != layer );
134 UpdateNodeOpacity( node, nodeDirtyFlags, updateBufferIndex );
136 // Draw mode inheritance is treated as or-ing the modes together (as they are a bit-mask).
137 inheritedDrawMode |= node.GetDrawMode();
139 node.PrepareRender( updateBufferIndex );
141 // if any child node has moved or had its sort modifier changed, layer is not clean and old frame cannot be reused
142 // also if node has been deleted, dont reuse old render items
143 if( nodeDirtyFlags & RenderableUpdateFlags )
145 layer->SetReuseRenderers( updateBufferIndex, false );
149 NodeContainer& children = node.GetChildren();
150 const NodeIter endIter = children.End();
151 for ( NodeIter iter = children.Begin(); iter != endIter; ++iter )
153 Node& child = **iter;
154 cumulativeDirtyFlags |=UpdateNodes( child,
162 return cumulativeDirtyFlags;
166 * The root node is treated separately; it cannot inherit values since it has no parent
168 NodePropertyFlags UpdateNodeTree( Layer& rootNode,
169 BufferIndex updateBufferIndex,
170 RenderQueue& renderQueue )
172 DALI_ASSERT_DEBUG( rootNode.IsRoot() );
174 // Short-circuit for invisible nodes
175 if ( DALI_UNLIKELY( !rootNode.IsVisible( updateBufferIndex ) ) ) // almost never ever true
177 return NodePropertyFlags::NOTHING;
180 // If the root node was not previously visible
181 BufferIndex previousBuffer = updateBufferIndex ? 0u : 1u;
182 if ( DALI_UNLIKELY( !rootNode.IsVisible( previousBuffer ) ) ) // almost never ever true
184 // The node was skipped in the previous update; it must recalculate everything
185 rootNode.SetAllDirtyFlags();
188 NodePropertyFlags nodeDirtyFlags( rootNode.GetDirtyFlags() );
190 NodePropertyFlags cumulativeDirtyFlags = nodeDirtyFlags;
192 UpdateRootNodeOpacity( rootNode, nodeDirtyFlags, updateBufferIndex );
194 DrawMode::Type drawMode( rootNode.GetDrawMode() );
197 NodeContainer& children = rootNode.GetChildren();
198 const NodeIter endIter = children.End();
199 for ( NodeIter iter = children.Begin(); iter != endIter; ++iter )
201 Node& child = **iter;
202 cumulativeDirtyFlags |= UpdateNodes( child,
210 return cumulativeDirtyFlags;
213 } // namespace SceneGraph
215 } // namespace Internal