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, int nodeDirtyFlags, BufferIndex updateBufferIndex )
76 if ( nodeDirtyFlags & ColorFlag )
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, int nodeDirtyFlags, BufferIndex updateBufferIndex )
89 // If opacity needs to be recalculated
90 if ( nodeDirtyFlags & ColorFlag )
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 int UpdateNodes( Node& node,
106 BufferIndex updateBufferIndex,
107 RenderQueue& renderQueue,
109 int inheritedDrawMode )
111 // Apply constraints to the node
112 ConstrainPropertyOwner( node, updateBufferIndex );
114 // Short-circuit for invisible nodes
115 if ( !node.IsVisible( updateBufferIndex ) )
120 // If the node was not previously visible
121 BufferIndex previousBuffer = updateBufferIndex ? 0u : 1u;
122 if ( !node.IsVisible( previousBuffer ) )
124 // The node was skipped in the previous update; it must recalculate everything
125 node.SetAllDirtyFlags();
128 // Some dirty flags are inherited from parent
129 int nodeDirtyFlags( node.GetDirtyFlags() | ( parentFlags & InheritedDirtyFlags ) );
131 int cumulativeDirtyFlags = nodeDirtyFlags;
133 Layer* layer = ¤tLayer;
134 Layer* nodeIsLayer( node.GetLayer() );
137 // all childs go to this layer
140 // assume layer is clean to begin with
141 layer->SetReuseRenderers( updateBufferIndex, true );
143 // Layers do not inherit the DrawMode from their parents
144 inheritedDrawMode = DrawMode::NORMAL;
146 DALI_ASSERT_DEBUG( NULL != layer );
148 UpdateNodeOpacity( node, nodeDirtyFlags, updateBufferIndex );
150 // Draw mode inheritance is treated as or-ing the modes together (as they are a bit-mask).
151 inheritedDrawMode |= node.GetDrawMode();
153 node.PrepareRender( updateBufferIndex );
155 // if any child node has moved or had its sort modifier changed, layer is not clean and old frame cannot be reused
156 // also if node has been deleted, dont reuse old render items
157 if( nodeDirtyFlags & RenderableUpdateFlags )
159 layer->SetReuseRenderers( updateBufferIndex, false );
163 NodeContainer& children = node.GetChildren();
164 const NodeIter endIter = children.End();
165 for ( NodeIter iter = children.Begin(); iter != endIter; ++iter )
167 Node& child = **iter;
168 cumulativeDirtyFlags |=UpdateNodes( child,
176 return cumulativeDirtyFlags;
180 * The root node is treated separately; it cannot inherit values since it has no parent
182 int UpdateNodeTree( Layer& rootNode,
183 BufferIndex updateBufferIndex,
184 RenderQueue& renderQueue )
186 DALI_ASSERT_DEBUG( rootNode.IsRoot() );
188 // Short-circuit for invisible nodes
189 if ( DALI_UNLIKELY( !rootNode.IsVisible( updateBufferIndex ) ) ) // almost never ever true
194 // If the root node was not previously visible
195 BufferIndex previousBuffer = updateBufferIndex ? 0u : 1u;
196 if ( DALI_UNLIKELY( !rootNode.IsVisible( previousBuffer ) ) ) // almost never ever true
198 // The node was skipped in the previous update; it must recalculate everything
199 rootNode.SetAllDirtyFlags();
202 int nodeDirtyFlags( rootNode.GetDirtyFlags() );
204 int cumulativeDirtyFlags = nodeDirtyFlags;
206 UpdateRootNodeOpacity( rootNode, nodeDirtyFlags, updateBufferIndex );
208 DrawMode::Type drawMode( rootNode.GetDrawMode() );
211 NodeContainer& children = rootNode.GetChildren();
212 const NodeIter endIter = children.End();
213 for ( NodeIter iter = children.Begin(); iter != endIter; ++iter )
215 Node& child = **iter;
216 cumulativeDirtyFlags |= UpdateNodes( child,
224 return cumulativeDirtyFlags;
227 } // namespace SceneGraph
229 } // namespace Internal